Problem with timer and input capture, timer does not run
Does anyone have experience with getting the timer to run with input capture, I am unable to make the input capture function.
I have a working system with STM32F03 (M0) devices initialization generated by CubeMX. Now I am testing an identical system with STM32G07 instead also initialization from CubeMX.
Same setup of timers but I am unable to make input capture work.
I am using TIM15 and PA2 input.
What I need is the timer to interrupt on both edges when input changes and I want to read out the time between edges. (Again functionallity was fine in STM32F03).
I configure counter mode as UP.
Prescale 10 and no internal clock division
Repetiotion counter is 0 and auto reload is disabled.
Polarity selection as both edges.
IC selection direct
No input filter (0)
To me it seems that the timer is not running, I can see from registers that edge signal is triggered and also I get an interrupt. But the timer value is always 0.
htim15.Instance = TIM15;
htim15.Init.Prescaler = 10;
htim15.Init.CounterMode = TIM_COUNTERMODE_UP;
htim15.Init.Period = 0;
htim15.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim15.Init.RepetitionCounter = 0;
htim15.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim15) != HAL_OK)
{
Error_Handler();
}
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if (HAL_TIM_ConfigClockSource(&htim15, &sClockSourceConfig) != HAL_OK)
{
Error_Handler();
}
if (HAL_TIM_IC_Init(&htim15) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim15, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_BOTHEDGE;
sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI;
sConfigIC.ICPrescaler = TIM_ICPSC_DIV1;
sConfigIC.ICFilter = 0;
if (HAL_TIM_IC_ConfigChannel(&htim15, &sConfigIC, TIM_CHANNEL_1) != HAL_OK)
{
Error_Handler();
}
And in MSP i have:
__HAL_RCC_TIM15_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
/**TIM15 GPIO Configuration
PA2 ------> TIM15_CH1
PA3 ------> TIM15_CH2
*/
GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF5_TIM15;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* TIM15 interrupt Init */
HAL_NVIC_SetPriority(TIM15_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(TIM15_IRQn);
Anyone able to spot why the timer does not seem to run???
Please help :)
