Showing results for 
Search instead for 
Did you mean: 

How to start and stop 2 Timers in synchronisation without using HAL library functions

Associate II

I am using STM32G4 series controller. I am using Timer 2 channel 2 as trigger source for Timer 4 and Timer 2 channel 3 for PWM generation. Also Timer4 channel 1 is used for PWM generation. First time both the timers Timer2 and Timer4 starts at exactly same time. I have observed that on DSO by checking position of the PWM pulse of  both the timers which starts at exactly same position. When I stop the timer using HAL_TIM_OC_Stop(&htim2, TIM_CHANNEL_2) and HAL_TIM_PWM_Stop(&htim2, TIM_CHANNEL_3); function, Both the timers stops but timers are not starting at the same time again when I start it using HAL_TIM_OC_Start(&htim2, TIM_CHANNEL_2); and HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_3); function. The PWM pulse of both the timers getting shifted and not at the same position even though I have keep the same duty cycle for both the PWM channels.

Can anyone help me in this case, how can we stop an restart the timers without using HAL library functions. By just changing  the registers values?

Any help would be appreciated.

Thanks in advance.




I don't know the details of your application nor do I use Cube/HAL so don't exactly understand what those functions do.

There's probably no single good way how to *stop* timers/PWM, especially coupled ones. But if you want to stop PWM generation, you may consider, instead of stopping timers, setting the related pins in GPIO_MODER from AF to Out, with GPIO_ODR having been set to an appropriate level. Timers then keep running, and re-enabling means again changing GPIO_MODER for given pins from Out back to AF.

This may or may not suit your particular needs.


Common Input Triggers..

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

This forum thread was marked by the moderator as needing a little more investigation, so a Support case was created in your name and will be handled off-line.