cancel
Showing results for 
Search instead for 
Did you mean: 

How to fix a glitch in output PWM from TIM1 of STM32G031xx?

HSing.5
Associate II

I am using STM32G031 where in my application I have to capture the frequency of Input signal from a sensor and then generate an output PWM with frequency which is twice of input frequency.

I am using TIM3 to capture the input signal from sensor and calculate the frequency and pulse width. Then I'm taking this pulse width as value for TIM1->ARR and half the value of pulse width is set as TIM1->CCR1.

The problem I am facing is that the generated PWM has glitches. The output PWM stops for 1-2ms and then starts again.

Please suggest how I can solve this issue.

2 REPLIES 2
Danish1
Lead II

I can think of a couple of lines of attack:

  1. How strongly do you know that the glitches come in the generation of the pwm rather than the measurement of the incoming frequency?
  2. How do you handle the case where the TIM1 counter is already higher than a new, lower-than-before ARR value? If you do nothing, you will have to wait for CNT to roll over from 65535 back to 0 before pwm will resume.

> How do you handle the case where the TIM1 counter is already higher than a new, lower-than-before ARR value?

ARR preload enabled by TIMx_CR1.ARPE is designed to prevent this problem.

(Btw. CCRx can/should be set to preloaded, too)

JW