Associate II
April 15, 2026
Solved
HAL_TIM_IC_ReadChannelCapturedValue returns 0
- April 15, 2026
- 2 replies
- 154 views
Hello,
I used STM32CubeMX2 to configure a timer (timer 2, channel 4) for input capture. I'm starting the timer and then applying the signal on the timer input pin. Since I configured the TIM interrupt, the interrupt callbacks do occur.
void HAL_TIM_InputCaptureCallback(hal_tim_handle_t *htim,
hal_tim_channel_t channel) {
if (htim == mx_tim2_gethandle() && channel == HAL_TIM_CHANNEL_4) {
uint32_t value = HAL_TIM_IC_ReadChannelCapturedValue(htim,
HAL_TIM_CHANNEL_4);
#ifdef DEBUG
SWD_printf("ICTIM: %d\n", value);
#endif
}
}
The problem that I am having is that HAL_TIM_IC_ReadChannelCapturedValue always returns 0. The number of callbacks is actually correct (it matches the number of positive and negative edges of the signal). The timer frequency is 10,000Hz (the period is 0.1ms) and the signal pulses are between 2ms and 9ms so the timer is not overflowing. I would expect timer readings to be between 20 and 90.
I attached the timer configuration screenshots.
I wonder what am I doing wrong,
-Gil
