AnsweredAssumed Answered

How can I read the state of a pin, set up as a PWM output?

Question asked by Brian Clough on Jul 31, 2017
Latest reply on Jul 31, 2017 by Clive One

 I'm using the PWM function of TIM4, on an STM32F429, to control an RC servo.  This requires a pulse between 0.6 and 2.4 msec, at a rate of about 50Hz.  Everything works fine, if I don't need to change the pulse duration. 

 

However, I need to change the duration frequently, and when I do, it can cause problems.  If I try to change the value of the Cap/Com register, while the output is high, it cuts the pulse short, causing an erroneous control output to the servo.  20 msec later, the PWM puts out the correct pulse width, and the servo snaps back to its proper location. 

 

I need to eliminate this "twitch", by making sure I don't change the pulse width while the pin is high.

 

I'm using HAL_TIM_PWM_ConfigChannel() to set the new pulse width, and then calling HAL_TIM_PWM_Start() to re-enable the PWM output.

 

Is there a way to read the state of the timer or the pin, so that I can be sure to call HAL_TIM_PWM_ConfigChannel() when the output is low?

 

Or is there another way to change the pulse width, without interrupting a pulse in progress?

 

Brian

Outcomes