EmbeddedRelated.com
Forums

PWM example?

Started by volodymyr_tymchyshyn June 1, 2004
Can somebody post the sample code on how to setup PWM.
LPC documentation is not very clear.
Thanks!



An Engineer's Guide to the LPC2100 Series

On the 2129 here is the code that I have written:

REG(PWM0_PR)=0x0000; //no prescaler - one cpu clk is one PWM
clk
REG(PWM0_MCR)=0x0002; //Reset timer counter register on match0
REG(PWM0_PCR)=0x7E00; //enable each individual PWM, single edge
REG(PWM0_TCR)=0x000A; //Reset TC counter

REG(PWM0_MR0)=0x0400; //set up the PWM period
REG(PWM0_LER)|=BIT0; //Latch the value

REG(PWM0_MR1)=0x0050; //set up initial PWM duty cycle
REG(PWM0_LER)|=BIT1; //latch the value

REG(PWM0_MR2)=0x0100; //set up initial PWM duty cycle
REG(PWM0_LER)|=BIT2; //latch the value

REG(PWM0_MR3)=0x150; //set up initial PWM duty cycle
REG(PWM0_LER)|=BIT3; //latch the value

REG(PWM0_TCR)=0x0009; //set the TC coutner and enable all PWMs

Also, you must turn this functionality on in the system control
block, make sure the correct pins are set as outputs and set as PWMs
in the pin connect block.

Shane.

--- In , "volodymyr_tymchyshyn"
<volodymyr_tymchyshyn@y...> wrote:
> Can somebody post the sample code on how to setup PWM.
> LPC documentation is not very clear.
> Thanks!