4 years, 6 months ago.

Problem to understand how PWM is managed

Hi,

I'm looking for informations about how pwm are working in my F411RE. I found the official documentation of PWM (https://developer.mbed.org/handbook/PwmOut) but I still have some questions. For example I don't really understand how pin naming works. For example PC_13 or PH_0 or PB_14 ? Or PWM1/2 and PWM2/1 what does it means ?

My problem is I have to control 8 brushless motors with ESC so I need 8 different `PwmOut` to control everything. I don't know where to search for all the informations about myself, do you know where I can grab more informations ? Maybe a wiki with more infos than the official PWM page ?

Thanks,

RoToR

There's some "magic" in the MBED pin naming system, so the same pin may have more than one "correct" name and it just works. Unfortunately if you pick a pin name that exists but isn't valid for that function then it still compiles and only throws the error at run-time.

posted by Oliver Broad 09 May 2016

1 Answer

4 years, 6 months ago.

You just use the pin name when declaring the PwmOut. The code will find which PWM module belongs to that pin. If it says PWM1/2 it means Timer module 1, Channel 2. Different channels on the same timer will always have the same period. So if you need different periods they need to be on different Timer modules (I don't think that is relevant for you). Besides that if they have the same Timer AND the same channel you cannot independently control those pins.

Depending on how it works you might consider using FastPWM (drop-in replacement of PwmOut, so you don't need to change anything besides the name and including the FastPWM lib). The regular PwmOut of mbed gives glitches when you modify the pulsewidth / period. FastPWM should not do that (and otherwise send me a message). If these glitches are an issue probably depends on your system/ESCs.

Accepted Answer

Thanks,

After some tests, it appears that we used the PWM1/1 and PWM1/1N at the same time and we must not do that way. changed the PWM1/1N for the PWM2/3 and everything works fine. I'll check out the FastPWM as you said to see if we have a difference or not, but today it works well with the standard PWM system.

posted by Nicolas COMTE 10 May 2016