Skip to main content
Olly Kao
Associate II
Aug 27, 2020 4:06 AM UTC
Solved

timer reset by clearing counter register

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!

This topic has been closed for replies.
TDK
TDKBest answer
Aug 27, 2020 4:20 AM UTC

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.

"If you feel a post has answered your question, please click ""Accept as Solution""."

2 replies

TDK
TDKBest answer
Aug 27, 2020 4:20 AM UTC

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.

"If you feel a post has answered your question, please click ""Accept as Solution""."
waclawek.jan
Super User
Aug 27, 2020 7:03 AM UTC

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