cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H747XI Timer Input Capture Not Working

AWats.4
Associate II

Hello,

I'm trying to use a timer to measure the frequency of an input signal using the callback function:

HAL_TIM_IC_CaptureCallBack(TIM_HandleTypeDef*htim)

The function never seems to be called when a voltage is applied to the input pin.

Here is the timer initialization code, TIM1 interrupts have been enabled. Any suggestions as to why the callback function is not working will be appreciated.

static void MX_TIM1_Init(void)

{

 /* USER CODE BEGIN TIM1_Init 0 */

 /* USER CODE END TIM1_Init 0 */

 TIM_MasterConfigTypeDef sMasterConfig = {0};

 TIM_IC_InitTypeDef sConfigIC = {0};

 /* USER CODE BEGIN TIM1_Init 1 */

 /* USER CODE END TIM1_Init 1 */

 htim1.Instance = TIM1;

 htim1.Init.Prescaler = 8000-1;

 htim1.Init.CounterMode = TIM_COUNTERMODE_UP;

 htim1.Init.Period = 65535;

 htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;

 htim1.Init.RepetitionCounter = 0;

 htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;

 if (HAL_TIM_IC_Init(&htim1) != HAL_OK)

 {

  Error_Handler();

 }

 sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;

 sMasterConfig.MasterOutputTrigger2 = TIM_TRGO2_RESET;

 sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;

 if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)

 {

  Error_Handler();

 }

 sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_RISING;

 sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI;

 sConfigIC.ICPrescaler = TIM_ICPSC_DIV1;

 sConfigIC.ICFilter = 0;

 if (HAL_TIM_IC_ConfigChannel(&htim1, &sConfigIC, TIM_CHANNEL_1) != HAL_OK)

 {

  Error_Handler();

 }

 /* USER CODE BEGIN TIM1_Init 2 */

 /* USER CODE END TIM1_Init 2 */

}

3 REPLIES 3
SPetr.6
Associate II

Have you called the following?

HAL_TIM_IC_Start_IT(&htim1, TIM_CHANNEL_1)

Did you generate this code with CubeMx?

AWats.4
Associate II

Yes I have called that, and yes this was generated with CubeMx, no luck however. I've attached the .ioc file.

TDK
Guru

Try getting an example to work:

https://github.com/STMicroelectronics/STM32CubeH7/blob/ccb11556044540590ca6e45056e6b65cdca2deb2/Projects/STM32H743I-EVAL/Examples/TIM/TIM_InputCapture/Src/main.c

> The function never seems to be called when a voltage is applied to the input pin.

Note that the pin needs to be low first, then transition high in order for the callback to work. If it's already high, nothing happens.

If you feel a post has answered your question, please click "Accept as Solution".