cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_TIM_IC_ReadChannelCapturedValue returns 0

gil_dobjanschi
Associate III

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

1 ACCEPTED SOLUTION

Accepted Solutions
gil_dobjanschi
Associate III

The problem was that I called HAL_TIM_IC_StartChannel_IT:

 

HAL_TIM_IC_StartChannel_IT(mx_tim2_gethandle(), HAL_TIM_CHANNEL_4)

 but I did not call:

HAL_TIM_Start(mx_tim2_gethandle());

 

The example from TIM input capture Github was very useful.

 

Sorry for the trouble,

Gil

View solution in original post

2 REPLIES 2
gil_dobjanschi
Associate III

The problem was that I called HAL_TIM_IC_StartChannel_IT:

 

HAL_TIM_IC_StartChannel_IT(mx_tim2_gethandle(), HAL_TIM_CHANNEL_4)

 but I did not call:

HAL_TIM_Start(mx_tim2_gethandle());

 

The example from TIM input capture Github was very useful.

 

Sorry for the trouble,

Gil

Sara BEN HADJ YAHYA
ST Employee

Hello,

this thread has been moved to the STM32 MCUs Embedded software forum because it relates only to HAL2, not STM32CubeMX2. This will help improve visibility and ensure the right experts are involved.

Regards,

Sara.


In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.