8 years, 8 months ago.

Any plan to add fastpwm for LPC8XX?

I am currently using LPC824 for a motorcontrol and would love to use FastPWM.

Question relating to:

Erik - / FastPWM Featured
Library that allows for higher resolution and speed than standard mbed PWM library using same syntax (drop-in replacement). pwm, resolution, Speed

Sure :). When the library was created the LPC812 did not have PWM available (due to a timer issue), but I believe it has now, and it uses the same as the LPC824. Since I only have the LPC812 it is handy if thats the case.

If I don't forget it (and I feel like it) I'll have a look at it somewhere coming week or so.

posted by Erik - 08 Mar 2016

1 Answer

8 years, 8 months ago.

It should work if you now update to latest one. However not sure because:

Windows 10 hates me and is writing something to usb flash drives on my laptop. Result is that I can't program half my mbeds, including the LPC800-MAX. Via Keil uvision I can program it, for about 10 seconds after which it does the same, so that is a bit limitted testing.

Next the issue is that while this was easy to implement, because I really like in general NXP peripherals (might be biased there), they just can't be bothered to use consistent names (match made in heaving, Freescale and NXP). So I had to add a bunch of #ifdefs in there to make it compile for both. If you can check if it works that would be nice.

Accepted Answer

There seem to be some problem. I have tested enabling four timers with same period but four different duty cycles using this code. The code works fine with PwmOut. But with FastPWM h1 and h3 both generates 1uS on time. h2 seems to work and h4 does not generate any pwm at all.

#include "mbed.h"
#include "FastPWM.h"
int main() {
    /* Enable SWM clock */
        LPC_SYSCON->SYSAHBCLKCTRL |= (1<<7);
        LPC_SWM->PINENABLE0 = 0xffffffcfUL; //all off except swclk and swdio
        //   LPC_SWM->PINASSIGN0 = 0xffff0100UL;   /* U0_TXD */     /* U0_RXD */
        wait(8);    //wait 8 seconds and now turn off swd
        LPC_SWM->PINENABLE0 = 0xffffffffUL; //all off
        
        FastPWM h1(P0_12,1);
        FastPWM h2(P0_5,1);
        FastPWM h3(P0_2,1);
        FastPWM h4(P0_9,1);
        h1.period_us (10);
        h1.pulsewidth_us( 1);
        h2.period_us (10);
        h2.pulsewidth_us( 3);
        h3.period_us (10);
        h3.pulsewidth_us( 6);
        h4.period_us (10);
        h4.pulsewidth_us( 9);
}
posted by Johan Stenberg 14 Mar 2016

Well that sucks. Quick check indicates that the LPC824 PWM on the SCT timer works fundamentally different from the LPC812 PWM on the SCT timer.

I will have to see one of these days if the issue is that they are different, or that PwmOut uses them in different modes (FastPWM lets PwmOut do all initialization, and just overwrites what we want different). But with windows erasing my board all the time this won't be easy. Also if they really are different then I dont have the LPC824 to work on.

posted by Erik - 14 Mar 2016

Can you try again? I tried to make the LPC824 behave like the LPC812.

posted by Erik - 14 Mar 2016

You must have got lucky this time! ;-).... I can not find any problem. Are there limitations vs timer peripherals on the LPC824 ?

posted by Johan Stenberg 15 Mar 2016

Good to hear :).

And nop, PWM uses completely seperate timer peripheral from the Timer. If you mean regarding maximum period, it has a 32-bit timer for PWM, for these ones in FastPWM I fix the prescaler to 'one', since you can still reach at 30MHz a period of 140 seconds, which already makes no sense to use PWM for such periods.

posted by Erik - 15 Mar 2016