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'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!

Reply
  • 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!

Children