This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

PWM at the AT91

Hello,

I want to generate a PWM signal for two leds on my at91rm9200 board. But I need some helping information to get it to work.

void init_LEDs(void)
{
        AT91C_BASE_PIOC->PIO_OER = AT91C_PIO_PC0 | AT91C_PIO_PC1;
        AT91C_BASE_PIOC->PIO_PER = AT91C_PIO_PC0 | AT91C_PIO_PC1;
        pullupdisable->PIOD_PPUDR = AT91C_PIO_PC0 | AT91C_PIO_PC1;
        AT91C_BASE_PIOC->PIO_CODR = AT91C_PIO_PC1 | AT91C_PIO_PC0;
}
void timer2 (void)
{
        unsigned int temp;

        init_LEDs();

        AT91F_PIO_CfgPeriph(AT91C_BASE_PIOA,0, AT91C_PA17_TIOA0);
        // Base Adress PIO Controller A /        / TIOAO Peripheral am PIO Controller A PA17
        AT91F_PIO_CfgPeriph (AT91C_BASE_PIOA, 0, AT91C_PA18_TIOB0);
        // 0 = PIO Pin soll auf Peripherie B geschaltet werden   www.mikrocontroller.net/.../70120


        //config AIC
        AT91F_AIC_ConfigureIt(AT91C_BASE_AIC, AT91C_ID_TC0, AT91C_AIC_PRIOR_HIGHEST - 6, AT91C_AIC_SRCTYPE_EXT_POSITIVE_EDGE, (void (*) ())TC0_interrupt);
        // Base Adress AIC / Base Adress Timer0 / Priorität / Flanke-trigger / Handler

        AT91F_AIC_EnableIt( AT91C_BASE_AIC, AT91C_ID_TC0);
        // Base Adress AIC / Base Adress Timer0 --> enalbe interrupts for Timer0!

        //config PMC
        AT91F_PMC_EnablePeriphClock (AT91C_BASE_PMC,1 << AT91C_ID_TC0);
        // Base Adress PMC / Base Adress Timer0 --> wird mit Clock versorgt



        //Timer0 init

        //disable interrupts
        AT91C_BASE_TC0->TC_IER = 0;
        AT91C_BASE_TC0->TC_IDR = 0xF;

        // clear status bit
        temp = AT91C_BASE_TC0->TC_SR;
        temp = temp;                                                    // to get no warning ("temp" was set but never used)

        //TC_CMR Register
        AT91C_BASE_TC0->TC_CMR = 0x4                         // use TimerClock5
        | 0x0 << 1                                                                // CLKI (Counter is incremented on rising edge of the clock)
        | 0x0 << 2                                                                // BURST (clock is not gated by an external signal)
        | 0x0 << 3                                                                // CPCSTOP (counter is not stopped when counter reaches RC)
        | 0x0 << 4                                                                // CPCDIS  (counter is not disabled when counter reaches RC)
        | AT91C_TC_EEVTEDG_NONE                                 // EEVTEDG (none)
        | AT91C_TC_EEVT_RISING                                  // EEVT    (XC0 as output)
        | 0x0 << 7                                                                // ENETRG  (external event has no effect on the counter and the clock)
                                                                                        // the external event only controls the TIOA output
        | AT91C_TC_WAVESEL_UPDOWN                               // WAVESEL
        | AT91C_TC_WAVE                                                 // WAVE (waveform is enabled)
        | AT91C_TC_ACPA_SET                                     // ACPA (compare effect on TIOA)
        | AT91C_TC_AEEVT_NONE                                   // AEEVT (external event effect on TIOA)
        | AT91C_TC_ASWTRG_NONE                                  // ASWTRG (software trigger on TIOA)
        | AT91C_TC_BCPB_SET                                     // BCPB   (set - compare effect on TIOB)
        | AT91C_TC_BCPC_CLEAR                                   // BCPC
        | AT91C_TC_BEEVT_NONE                                   // BEEVT
        | AT91C_TC_BSWTRG_SET;                                  // BSWTRG


        AT91C_BASE_TC0->TC_RA = 900;                         AT91C_BASE_TC0->TC_RB = 500;
        AT91C_BASE_TC0->TC_RC = 1000;


        AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;


        temp = AT91C_BASE_TC0->TC_SR;



        while(1);
}

That's the whole code. I don't know how I can say that the PWM should be installed at LED1 and LED2 (PCO and PC1).

Moreover is there another notation for 0x0 << 1 (TC_CMR)? And I found nothing about the values I should use for TC_RA, TC_RB and TC_RC, in the datasheet.

best regards
Bernd