cancel
Showing results for 
Search instead for 
Did you mean: 

HAL Timer Module - read & set counter value

rajpaged
Associate II
Posted on July 16, 2014 at 12:22

In the old standard drivers, you could use TIM_GetCounter(TIM2) and  TIM_SetCounter(TIM2, 0) to read or modify the timer counter values. Is there a similar thing within the HAL drivers? I can't seem to find any replacement functions for these. Should I just access the register directly? TIM2->CNT

#hal-diver #timers #stm32f4
1 REPLY 1
Posted on July 16, 2014 at 14:12

Hi h.hammer,

You can use the following Macros available under stm32f4xx_hal_tim.h file in order to Set/Get the TIM Counter Register value:

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

With regards.