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 example for LPC2129

I'm looking for a single edge PWM example for the LPC2129.

Thanks.

Parents
  • I gather you would like it in 'C'.

    What sort of frequency and resolution do you require?

    What is the pwm to be used for? Controlling a motor, generating tones?

    On which timer,channel and pin do you want the pwm on?

    Do you want an interrupt on each cycle?

    What aspect of generating PWM are you unsure about? I gather you've read the datasheet, what does it not explain?

Reply
  • I gather you would like it in 'C'.

    What sort of frequency and resolution do you require?

    What is the pwm to be used for? Controlling a motor, generating tones?

    On which timer,channel and pin do you want the pwm on?

    Do you want an interrupt on each cycle?

    What aspect of generating PWM are you unsure about? I gather you've read the datasheet, what does it not explain?

Children
  • Frequency: > 1 kHz
    Resolution: 16 bit
    Channels: 3

    My code generates three 16 bit values (0-65535) that are directly proportional to 0-100% duty cycle. The following is what I have thus far:

    PINSEL0 = 0x0005800A; //Enable UART1 RxD1/TxD1 & PWM 1, 2, 3

    PWMPR = 0x0000; //no prescaler - one cpu clk is one PWM clk
    PWMMCR = 0x0002; //Reset timer counter register on match0
    PWMPCR = 0x7E00; //enable each individual PWM, single edge
    PWMTCR = 0x000A; //Reset TC counter

    PWMMR0 = 0x0400; //set up the PWM period

    I'm unsure of how to change PWMPR or PWMMR0 to manipulate the frequency and period respectively. In addition, does PWMMR1 need to be equated to the 16 bit value in hex in order to set the duty cycle?

    Thanks.

  • I've briefly read the user manual and what it tells me is:

    PWMMR0 sets the cycle rate.
    PWMMR1.. sets the pwm width

    the PWMMRx registers are a match register - therefore when the counter hits that value- something happens depending on the configuration. In the case of the PWM, the output is set and the counter reset when you get a match with PWMMR0 (this sets the overall period) and the outputx is reset when the counter gets a match with PWMMRx. So PWMMR1.. value is <= PWMMR0. Also, your counter clock is the peripheral clock which is 60MHz/4 = 15Mhz normally. So for a 1KHz PWM cycle - set PWMMR0 to 15000 (15,000,000 / 15,000 = 1000)
    unfortunately this gives you less than 16 bits of resolution - more like just under 14 bits. If you really need 16 bits of resolution then your PWM cycle would be 15,000,000 / 65536 = 228.8Hz. This is your tradeoff - more resolution = less frequency and vice- versa. As for your pwm width -at PWMMR0 = 15000, PWMMR1 = 7500 for 50% width.
    Your code will need to scale the values to suit. Read carefully section 16 in the user manual on the PWM - especially the note on the reset bit in PWMTCR - load the cycle time in PWMMR0 first!

    I, like most others are new to these parts and I am slowly exploring the features. I've haven't tried the PWM yet so take my words carefully!

  • You may use the Logic Analyzer that is built into the uVision Simulator to see the PWM output. In this way you can better analyze your algorithms.

  • How do you use the simulator to monitor a pin output?

    P.S. The PWM code is working =)

  • We have seen the problem with the update of the PWM pins in the meantime too. It works when you single step, but not when you run the code. It will get fixed in the next revision.

  • We have seen the problem with the update of the PWM pins in the meantime too. It works when you single step, but not when you run the code. It will get fixed in the next revision.