Measuring speed with Input Capture Mode [STM32 & CubeMx]

Xavier Pacheco Paulino

Joined Oct 21, 2015
728
I'm trying to measure low speeds with a 1 PPR (pulse per revolution) sensor. For low PPRs, using the Period Measurement Method is suggested. If I get the period of the signal, then I can apply the formula:

RPM = 6000/(Pulse Period)

This is what I have:

In CubeMx I've set Timer 2, Channel 3 Input Capture Mode. My APB2 frequency is 1 MHz. The TIM2 prescaler is 1000 and the counter period is 10000. Everytime a pulse is given, a falling edge occurs.

Now, in code I have:

Code:
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
{

if(htim->Instance == TIM2){
inputCaptureVal = __HAL_TIM_GetCounter(htim);
__HAL_TIM_SetCounter(htim,0);
}
}

I'm pretty new using the Input Capture Mode, so I'm not sure of this. Does __HAL_TIM_GetCounter(htim) actually tell the period of the input signal? So I can simply say RPM = 6000/inputCaptureVal?