cancel
Showing results for 
Search instead for 
Did you mean: 

How to reset counter value ?

LHerm.1
Associate III

Hello everyone, i would like to know the HAL function that allows to reset the value of a simple counter. I don't find the HAL function to reset my counter to 0 before a next counting.

So all i want to do is to count, read my counter value and reput it to zero for the next count.

Thank for your help !

1 ACCEPTED SOLUTION

Accepted Solutions

TIM2->CNT = 0;

There's probably a macro, try grep

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

5 REPLIES 5
Javier1
Principal

there is some info missing here. "counter" is ambiguous.

Are you reffering to the counter of a timer?

TIM2->CNT = 0;

There's probably a macro, try grep

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Yes sorry, it's the value of my timer.

I use a Nucleo board (F401RE) and i would like to know if a function "HAL_TIM_......" to reset the value of the counter to zero exists or not.

But the solution proposed by "Tesla Delorean" just behind works very well : TIMx ->CNT = 0;

It's not the most proper solution but it works.

Best regards

It works !

Thank very much

/**

 * @brief Set the TIM Counter Register value on runtime.

 * @param __HANDLE__ TIM handle.

 * @param __COUNTER__ specifies the Counter register new value.

 * @retval None

 */

#define __HAL_TIM_SET_COUNTER(__HANDLE__, __COUNTER__) ((__HANDLE__)->Instance->CNT = (__COUNTER__))

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..