cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_TIM_PWM_Stop leaves output pin in undefined state

frackers
Senior
Posted on October 18, 2016 at 02:28

I'm trying to start/stop a PWM signal to an LED (simple test!!). Using HAL_TIM_PWM_Start() starts the PWM output, HAL_TIM_PWM_Stop() stops the PWM but leaves the output in a random state rather than the (expected) inactive state. This means my LED stays on constantly sometimes without pulsing.

Should I expect HAL_TIM_PWM_Stop() to do this or should I be turning a PWM output on/off a different way?
4 REPLIES 4
Walid FTITI_O
Senior II
Posted on October 19, 2016 at 10:30

Hi frackers, 

As mentioned in the timer driver, the function just stop the generation of PWM from the Timer peripheral module and does not change the configuration of the GPIO, in order in case of second recall of PWM start function the generation will be in return and the PWM is on output directly. You can add a GPIO write function then to force the IO state.

-Hannibal-

frackers
Senior
Posted on October 23, 2016 at 13:21

I can't just add a GPIO write without changing the Alternate Function of the port from PWM output to PushPull or Open Drain output - to start PWM again then requires re-initialise of the timer with HAL_TIM_PWM_Init() and HAL_TIM_PWM_ConfigChannel().

If the Pulse register is set to either 0 or 0xffff does this set the output to a guaranteed steady state and can this be done through the HAL some way other than using  HAL_TIM_PWM_ConfigChannel() ?

Walid FTITI_O
Senior II
Posted on October 25, 2016 at 10:57

Hi frackers, , 

You can use the ''HAL_TIM_PWM_DeInit()'' function that disable Timer and call the HAL_TIM_PWM_MspDeInit() that you should create and define in the ''STM32Fxx_hal_msp.c'' file. Inside this function, you configure the GPIO as analog for example or other configuration you want. 

In case you want to back again just call HAL_TIM_PWM_Init() and your GPIO is reconfigured for PWM output.

-Hannibal-

takahasi
Associate II
Posted on October 26, 2016 at 05:53

Hi frackers,

Use the internal pull-up or down.

It canbe set through the CubeMX TIMx Configuration.