2024-04-01 09:58 PM
Hello,
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.
Kirti
Solved! Go to Solution.
2024-06-19 09:32 PM
Hello Douglas,
I have used the register settings as below to start and stop 2 Timers in synchronisation without using HAL library functions. These below settings are working fine now.
Start Timer 2 and Timer 4:
TIM4->CR1 |= (1<<0);
TIM2->CR1 |= (1<<0);
Stop Timer 2 and Timer 4:
TIM4->CR1 ^= (1<<0);
TIM2->CR1 ^= (1<<0);
Thanks for the support.
Kirti
2024-04-02 01:35 AM
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.
JW
2024-04-02 01:47 AM
Common Input Triggers..
2024-04-03 01:08 PM
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.
2024-06-19 09:32 PM
Hello Douglas,
I have used the register settings as below to start and stop 2 Timers in synchronisation without using HAL library functions. These below settings are working fine now.
Start Timer 2 and Timer 4:
TIM4->CR1 |= (1<<0);
TIM2->CR1 |= (1<<0);
Stop Timer 2 and Timer 4:
TIM4->CR1 ^= (1<<0);
TIM2->CR1 ^= (1<<0);
Thanks for the support.
Kirti