2020-08-26 09:06 PM
Hi,
I'm resetting the timer without disabling it, i clear the counter register by
__HAL_TIM_SET_COUNTER(&htim2, 0);
this will reset the htim2.Instance->CNT, which is the counter period,
however the timer was set to be count up to (prescalar) * (counter period)
I only clear the latter.
In my opinion, I should also clear the former, or may causes an small inaccuracy, but I don't know how to clear it, I can't find the counter register of prescalar, any help??
Thanks!
Solved! Go to Solution.
2020-08-26 09:20 PM
An update event will clear the prescaler:
HAL_TIM_GenerateEvent(&htimx, TIM_EVENTSOURCE_UPDATE);
There's no direct register access to it like there is with CNT. Not sure if disabling/reenabling will clear it.
2020-08-26 09:20 PM
An update event will clear the prescaler:
HAL_TIM_GenerateEvent(&htimx, TIM_EVENTSOURCE_UPDATE);
There's no direct register access to it like there is with CNT. Not sure if disabling/reenabling will clear it.
2020-08-27 12:03 AM
The prescaler counter is not directly accessible.
Do what TDK said, the terms of RM it is setting TIMx_EGR_UG (Reset from the slave-mode controller has the same effect, if you'd need to perform it upon some signal, in hardware without software intervention).
Disabling/enabling the counter using TIMx_CR1.CEN does not influence CNT nor the prescaler counter.
JW