2022-02-20 05:21 PM
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
Solved! Go to Solution.
2022-02-21 01:56 AM
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
2022-02-21 01:56 AM
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
2022-02-21 05:21 AM
Thank you that helps out a bunch!