Skip to main content
Olly Kao
Associate II
August 27, 2020
Solved

timer reset by clearing counter register

  • August 27, 2020
  • 2 replies
  • 2100 views

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.
Best answer by TDK

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.

2 replies

TDK
TDKBest answer
August 27, 2020

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
August 27, 2020

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