Sten wrote:
> Herbert Demmel wrote:
>
>>Hi,
>>
>>I seem to miss something with setting up PWM5 output - the routine below
>>sometimes works, sometimes not (depending non additional code - this
>>versions below currentlly does NOT work).
>>
>>Any idea what I miss to setup?
>>
>>Thanks for your input.
>>
>>Regards
>>Herbert
>>
>>#include <LPC213x.H> /* LPC213x definitions */
>>
>>#define TICKS_PER_US 15
>>
>>void io_alarm_out(unsigned int freq)
>>{
>
>
> PWMTCR = (1ul << 0) | (1ul << 1); /* Enter reset state and force counter to zero*/
>
>
>> // match register 0 controls the cycle frequency
>> PWMMR0 = 1000000 * TICKS_PER_US / freq;
>>
>> // we want to have a duty cycle of 50% so always set PWMMR5 to
>>half of PWMMR0
>> PWMMR5 = PWMMR0 / 2;
>>
>> // enable PWM5 output
>> PWMPCR |= (0x01 << 13);
>
>
> PWMTCR = (1ul << 0) | (1ul << 3); /* Re-enable PWM */
>
>
>>}
>>
>>int main(void)
>>{
>> // --- PWM5 setup ---
>>
>> // Enable P0.21 to be PWM5
>> PINSEL1 |= (0x01 << 10);
>> PWMTCR = 1; // enable PWM timer, let shadow register
>>disabled
>>
>> // reset PWM timer when PWMMR0 matches
>
> // PWMMCR = 0x2;
>
>> // gives 1000Hz
>> io_alarm_out(1000);
>>
>> while (1)
>> ;
>>}
>>
>
>
> Hallo Herbert,
>
> Mmmmh, don't you need to turn on PWM module in PCONP? Or do you let all peripherials active on
> startup by default?
>
> But bit #3 in PWMTCR enables PWM module. Description of this bit says:
> "When one, PWM mode is enabled. PWM mode causes shadow registers..." (2294's datasheet, p.233)
>
> After you have enabled PWM module (if bit #3 in PWMTCR is set) and set up a value in a PWMMRx
> register you just need to set the appropriated bit in PWMLER register to take effect of new PWMMRx
> value.
>
> You do not need using PWMLER register if you hold PWM in reset state during changing PWMMRx values
> (see changes above).
>
> Try it!
> Sten
>
Oooops, sorry! Do not comment PWMMCR in main(). But you can uncomment PWMTCR statement instead.
Sten
--
/************************************************
Do you need a tiny and efficient real time
operating system (RTOS) with a preemtive
multitasking for LPC2000 or AT91SAM7?
http://nanortos.net-attack.de/
Or some open-source tools and code for LPC2000?
http://www.net-attack.de/
************************************************/Message
Re: [lpc2000] PWM output
2006-02-25 by Sten
Attachments
- No local attachments were found for this message.