cancel
Showing results for 
Search instead for 
Did you mean: 

timer reset by clearing counter register

Olly Kao
Associate III

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!

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

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".

View solution in original post

2 REPLIES 2
TDK
Guru

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".

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