AnsweredAssumed Answered

Changing of PWM duty cycle in an efficient manner....

Question asked by corregedor.antonio on Aug 23, 2011
Latest reply on May 20, 2013 by Clive One
Hi all,

I am new to programming with the STM32 range and am currently experimenting on the Discovery Board.  I have been able to get the basics going such as reading inputs, setting outputs, measuring an ADC on a pin and setting a PWM wave output on a pin. 

I am now in the process of experimenting further with the PWM wave parameters such as changing the duty cycle of the PWM wave depending on the voltage that I read on the AD pin.  The current procedure I follow (after setting all the other relevant information) is that I change the value of TIM_OCInitStructure.TIM_Pulse to get the respective duty cycle that I desire and then I call TIM_OC4Init(TIM3, &TIM_OCInitStructure) to get my new duty cycle. 

The above seems to work but if I get stuck in a certain case and call TIM_OC4Init(TIM3, &TIM_OCInitStructure) repeatidly I have noticed that the PWM wave output on the pin becomes very noisy.  Does anyone have an explanation for this?  Is there a better way of setting the duty cycle for my application?  I have noticed that if I include a delay that the noisy effect dissapears but a delay is not appropriate in my system as it is a real time system; so I need to find an alternative solution.  My other feeling on the matter is that when I call TIM_OC4Init(TIM3, &TIM_OCInitStructure); that the PWM output on the pin is turned off, the micro then updates the respective timers with the new duty cycle and then outputs the PWM on the pin, I suspect that this on and off process is what causes the PWM signal to be noisy.  However, I still have not figured it out and would greatly appreciate it if someone here could help me.  Thanks in advance.

Kind Regards,