Today I tested both a Nucleo F411RE and a Nucleo F303K8 with a very simple code to generate a PWM of 1000ms of period and 0.5f of pulse width so 500ms. I tried many pin on both boards.
But nothings works and to visualise I plugged a led on it and it didn’t blink. The led say illuminated.
After few minutes and a lot of value randomization… I wrote this code that “blink” the led.
But with an oscilloscope I can read a period of 40ms and 20ms of pulse width… So the pulse width is respected as it is half of the period time, but the period time is… Not really what I expected ! And only the value of 10000 works to blink the led.
Does anyone found a bug on the mbed PwmOut library or anything that can explain my problem ? Or Did I misused the PwmOut ?
From what I have seen so far, I think the PWM is primary meant to run short periods. The spec says
Pulse lengths and waveform periods can be modulated from a few microseconds to several milliseconds
And the PWM driver as of now is configured to use a 1us unit.
As the period register is 16 bits, this will allow to define period up to 65535us = around 65ms.
When you set the period to 10000ms (eg 10000000us), it will be actually masked to only the 16 valid bits which gives you 38528 us. That probably explains the 40ms you’re reading.
So my conclusion is that for now, you should limit to 65ms maximum period. Maybe this could be improved somehow but at least this explains your observations.
Also I don’t see a way to return an error to the caller of the pwmout API … maybe this can be improved as well?
Nice analyse !
Sounds right for me…
Anyway I don’t really need a pwm with 10sec of period but it was interesting to have the right information about why it does not work
Do you know where I can found the sources, and may patch the problem then do a merge request ?
Hi
I had to go through the reference manual of the chip (from www.st.com) and check the way the pwm timers work.
The code was using a fixed prescaler setting which is fine for any period below 65ms, so we had to made use of this prescaler to also address wider range periods.
Please tell me if you can test the fix I propose here: https://github.com/LMESTM/mbed/commit/21e70e75b5e6b97ac455057fab13286be7e0432f
cheers