Skip to main content
SWenn.1
Senior III
February 21, 2022
Solved

Clear Tim1 --- STM32L476RG?

  • February 21, 2022
  • 1 reply
  • 984 views

Hello All....

Simple question. I am using the functions(HAL_TIM_Base_Stop_IT and HAL_TIM_Base_Start_IT). Basically I set a timer to count to a value and an interrupt occurs. The timer starts on a GPIO edge. I would like the timer to always zero out at the edge first. I have looked at the Start_IT function and cannot find where in this function the counter is first cleared before starting (maybe it is not). I then looked at the manual and cannot identify which bit or for that matter which register I should use to clear the counter of Tim1. Can someone tell me where this bit is? Does it exist in RCC or something?

I would like to add I am using the callback void HAL_TIM_PeriodElapsedCallback

Thanks

This topic has been closed for replies.
Best answer by KnarfB

The counter is not reset by that. But, you can (over)write the counter value at any time using

__HAL_TIM_SET_COUNTER(&htim1, 0);

Doing so after HAL_TIM_Base_Stop_IT or before the next HAL_TIM_Base_Start_IT will start next time at 0.

Note that you can trigger a timer start without using an interrupt handler. This avoids sw delays but limits you to dedicated pins. If that's usefull/neccessary depends on you performance requirements. Keywords are. Combined reset trigger slave mode. There is a 30.3.8 PWM input mode example in the ref. man.

hth

KnarfB

1 reply

KnarfB
KnarfBBest answer
Super User
February 21, 2022

The counter is not reset by that. But, you can (over)write the counter value at any time using

__HAL_TIM_SET_COUNTER(&htim1, 0);

Doing so after HAL_TIM_Base_Stop_IT or before the next HAL_TIM_Base_Start_IT will start next time at 0.

Note that you can trigger a timer start without using an interrupt handler. This avoids sw delays but limits you to dedicated pins. If that's usefull/neccessary depends on you performance requirements. Keywords are. Combined reset trigger slave mode. There is a 30.3.8 PWM input mode example in the ref. man.

hth

KnarfB

SWenn.1
SWenn.1Author
Senior III
February 21, 2022

Thank you that helps out a bunch!