8 years, 11 months ago.

Updating PWMout too frequently causing issues.

Hey all, I'm having a problem whereby my main loop runs significantly faster then my PWM Period and I update my PWM dutycycle every loop. It's causing my PWM output to fluctuate drastically. I can see the correct PWM frequency but instead of a solid square wave, it looks like a signal drawn over a carrier wave that has a frequency roughly equal to my main loop frequency. If I time control my PWM updates, it goes back to normal. Is there a better/different way to update PWM duty cycle? Should I go with a software driven PWM signal?

I'm using the Nucleo 401 as well as the 411 board.

Thanks,

W

1 Answer

8 years, 11 months ago.

Without checking specifically for your target, and I just found out recently that this lib also has some issues on the LPC11XXX devices, you can try replacing PwmOut with this: https://developer.mbed.org/users/Sissors/code/FastPWM/

Half the mbed targets have the questionable method of setting a new pulsewidth by resetting the PWM counter, which screws up your PwmOut. FastPWM never does this, only depending on target it can possibly give issues with reducing the pulsewidth: Lets say current pulsewidth is 500, counter is at 450, and you reduce it to 400. Then it never hits the compare match for that cycle, resulting in an incorrect value. But this depends on the target, and in general FastPWM is (almost) always superior to PwmOut. So give it a try.

Accepted Answer