2019-03-13 08:24 AM
Hello
I have TIM3 set up like so:
This gives me a timer interrupt every 1 second. But it appears as though the callback HAL_TIM_PeriodElapsedCallback is called immediately after I call HAL_TIM_Base_Start_IT(&htim3) and then in intervals of 1 second thereafter.
Why does the period elapse immediately after starting the timer? Is there a way to get around this?
Solved! Go to Solution.
2019-03-13 09:13 AM
UPDATE is CNT==0
So both the initial load, and the clock after CNT=ARR will trigger
Not sure it is avoidable, short of clearing and waiting for CNT>0 and then enabling the interrupt, or special casing the first interrupt call.
2019-03-13 09:13 AM
UPDATE is CNT==0
So both the initial load, and the clock after CNT=ARR will trigger
Not sure it is avoidable, short of clearing and waiting for CNT>0 and then enabling the interrupt, or special casing the first interrupt call.
2019-03-13 02:36 PM
The "library" functions for setting up timers tend to set TIMx_EGR.UG to force any prescaler change to apply immediately (see for example TIM_Base_SetConfig() called from all the HAL_TIM_XXXX_Init() functions; but the same could be found in the respective functions of SPL too).. This of course has the effect of setting TIMx_SR.UIF thus the interrupts gets fired as soon as it's enabled.
The solution is to clear TIMx_SR after calling the _Init() function and before enabling the interrupts. I don't use Cube so can't help with the exact Cube/HAL incantation for that.
JW