cancel
Showing results for 
Search instead for 
Did you mean: 

Duty cycle of PWM unstable

David Garcia
Associate II
Posted on November 13, 2017 at 13:29

I have a problem with PWM generation.

I have my own PCB with the uC STM32F429IIH. I am trying to configure the PWM in TIM3 channel 1. My clock frecuency is 180 MHz and APB1 Timer Clock is 90 MHz.

I use STM32CubeMX to initialize the board. In the timer 3, I configure the prescaler with value 5 and the period with value 4095, so my PWM signal frecuency must be 3.66 KHz. Furthermore, I configure a fixed pulse of 500. In the main function I call the function HAL_TIM_PWM_Start to start the PWM signal.

In an oscilloscope I observe that the frequency is correct but the duty cycle is unstable. Most of the time, duty cycle varies between 12.2% and 12.3% but sometimes it downs till 11.6%. It seems that in some cycles the duty cycle changes too much.

I have tried to change the duty cycle, the prescaler and the period, but I always have the same problem: the duty cycle is unstable. I have tried with another oscilloscope too.

Does anyone know why the duty cycle varies so much? Am I configuring something wrong?

Thanks for your help.

#stm32f4-pwm #pwm #pwm-unstable #duty-cycle
5 REPLIES 5
Posted on November 13, 2017 at 15:32

For fine granularity get the prescaler to zero (DIV1), and do all the division in the period.

If you suspect the source clocks output them via PA8 (MCO), to look at HSE and PLL clocks. I wouldn't expect HSI to be terribly stable.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
knielsen
Associate II
Posted on November 13, 2017 at 15:55

How are you measuring your duty cycle?

If you are just reading off what your scope is giving you, the most likely explanation is that the instability is just the scope's inaccuracy, it's only in the order of +/- 0.5%.

Try to determine the accuracy of the duty cycle measurement.

Posted on November 13, 2017 at 16:07

It is only a 3 KHz signal, on presumably a 10+ MHz scope

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on November 13, 2017 at 16:25

Yes, but if there's too few samples per period (too many periods squeezed into the sampling window) then the granularity error will be way more than the sample timing error.

JW

Posted on November 13, 2017 at 17:03

Several orders of magnitude to play with though, assuming it's not some 1Msps POS

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..