cancel
Showing results for 
Search instead for 
Did you mean: 

Clear Tim1 --- STM32L476RG?

SWenn.1
Senior III

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

1 ACCEPTED SOLUTION

Accepted Solutions
KnarfB
Principal III

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

View solution in original post

2 REPLIES 2
KnarfB
Principal III

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

Thank you that helps out a bunch!