7 years, 9 months ago.

PWM frequency is wrong


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);

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:

The PJRC Teensy 3.1 operates at CPU frequency of 96MHz. The powerful ARM-M4 Freescale MK20DX256VLH7 MCU has 256 kB of flash memory, 64 kB of RAM memory. This platform is …

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 2016

Appreciate 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

2 Answers

7 years, 9 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...

I've used a LPC1114 as a slow pulse source and I'm fairly sure I got the right period out. I didn't look very hard though.

posted by Oliver Broad 15 May 2016

I used this as my code:

void loop() 10uS TTL { { trig.period(0.07); trig.pulsewidth_us(10); } }

It was for an ultrasone sensor. The error is probably on my end because im very new to this.

posted by Stefan de Lange 15 May 2016
7 years, 9 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.