Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 5 months ago.
PWM on LPC1114
I'm getting odd results with trying to use PWM on the 1114. So far I've tried dp18 and dp1
PwmOut mypwm(dp1);
mypwm.period_us(50000); mypwm.pulsewidth_us(25000);
I'd expect a 20Hz square wave which should give some visible flicker. Instead I'm getting constant on.
Writing to period appears to toggle the LED on and off.
What pin should I use? Do I need to set up anything else? Does the pin's timer requirements conflict with anything else e.g. serial or I2C?
1 Answer
9 years, 5 months ago.
Most of the LPC1114 PWM units are 16-bit, and I don't think in the mbed lib they can make a 50ms period. Not 100% sure, but try importing the FastPWM lib, that should support the LPC1114 IIRC and allows for larger range of periods.
In the mean time I'll just use dp24, I'm going to guess that's the 32 bit one. I'm actually interested in shorter periods though I was only using the long ones for testing.
posted by 14 Mar 2016FastPWM is also superior for very short periods, if your period is above the 100us-1ms (depending on your accuracy requirements) regular PWM is fine.
posted by 14 Mar 2016In that case I'll probably transfer to using FastPWM if I switch outputs. Right now I'm using dp24 and I'm assuming that with a 32 bit timer there's no advantage.
Incidentally are there any other PWM pins supported by MBED on the LPC1114? The datasheet seems to suggest pins 3 and 4 might be used, but they aren't marked on the reference card. I might be able to get this from the MBED sources but they can be difficult to follow.
I'm using serial programming and unlikely to connect a debugger so I should have no need to reserve SWCLK, SWDIO.
posted by 16 Mar 2016Some of the pins are not included in the pinout file for safety, but that does limit your options possibly. Here are the pins supported by the mbed lib (those connected to timer CT32B1 are I guess not included because the mbed Timer libs already use it): https://github.com/mbedmicro/mbed/blob/master/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/pwmout_api.c
In general difference between most mbed PwmOuts (including LPC1114) and FastPWM is that FastPWM modifies the prescaler to have as high resolution as possible. For 32-bit timers FastPWM fixes it to '1', so the full clock speed (since there is no real reason to have a prescaler here), while the mbed lib for the LPC1114 fixes the prescaler so it runs at 1us tick rate: So the 32-bit PWM is 30-times more accurate with FastPWM than with regular PwmOut. If this is required depends simply on your use case.
posted by 16 Mar 2016