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.
8 years, 6 months ago.
PWM frequency is wrong
Hi,
First of all, I love Teensy and I'm very happy you support it in mbed!
I have noticed an issue: when I configure a pin for PWM out, it works but timing is exactly 2 times what it should be! For example:
PwmOut mypwm(PTC2); mypwm.period_ms(5); mypwm.pulsewidth_us(1520);
Here, I expect a 5 ms total pulse duration with 1520 us high period. What I get (observing by oscilloscope) is 10 ms total pulse duration and 3040 us high period. The same code works fine e.g. on Nucelo boards.
I tried various periods, puslewidths and different pins and consistently the timing is 2x what it should be.
Cheers, Arash
Question relating to:
2 Answers
8 years, 6 months ago.
I have exactly the same problem, very curious. Haven't found a solution yet though, im using the LPC1114FN28. Hope somebody finds the problem because I really need a PWM signal for my robot...
8 years, 6 months ago.
I am unfamiliar with your particular hardware but often the clock set-up options can be quite sophisticated. Check the clock settings the code is giving you - perhaps the code has the wrong frequency (when compared to the board's actual clock) or has some other divider/prescaler setting incorrect.
If you got it on the LPC1114 (which surprised me btw) it should be completely unrelated since they have completely different code bases.
Currently I can't do too much to look into this: The coming week and a half I don't have access to my Teensy. I can look a bit at some things, also regarding your other problem with interrupts, but not more than that. However an initial question: You are using the latest mbed lib? (If you just made a regular new HelloWorld program you will be fine, otherwise right mouse button on the mbed lib, click update).
posted by Erik - 15 May 2016Appreciate your feedback. I am using the latest mbed lib. I don't have an LPC1114 but I have a few Nucleo boards which are based on STM32 Cortex M4. I mentioned them since they work as expected (at least for PWM) so that you know the bug is probably not in my user level code.
posted by Alef Sin 15 May 2016