2024-05-03 08:34 AM
HI,
I set TIM5 up to trigger every 1us (APB1 42MHz) with the below function and I expect HAL_TIM_PeriodElapsedCallback() to be invoked every 1us but that's not the case. How do I make sure that the callback gets invoked properly?
My init function:
static void manual_TIM5_Init(void)
{
__HAL_RCC_TIM5_CLK_ENABLE(); // start the Timer5 clock
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
TIM_MasterConfigTypeDef sMasterConfig = {0};
htim5.Instance = TIM5;
htim5.Init.Prescaler = 1;
htim5.Init.CounterMode = TIM_COUNTERMODE_UP;
htim5.Init.Period = 20;
htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim5) != HAL_OK)
{
Error_Handler();
}
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if (HAL_TIM_ConfigClockSource(&htim5, &sClockSourceConfig) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
}
Solved! Go to Solution.
2024-05-03 08:43 AM
Hi,
seems same "problem" ... :)
see:
>How do I make sure that the callback gets invoked properly?
Make it 100x slower...
2024-05-03 08:41 AM
I missed to mention that it does get started with:
HAL_TIM_Base_Start_IT(&htim5);
2024-05-03 08:43 AM
Hi,
seems same "problem" ... :)
see:
>How do I make sure that the callback gets invoked properly?
Make it 100x slower...
2024-05-03 09:38 AM
Prescaler and Period as set as N-1
So 20 is DIV21
Interrupting at 1us / 1MHz is impractical, even without the excess baggage of HAL with it's call-ins and call-backs. The processor will saturate with not productive work.
Use a maximal TIM clocking the CNT at 1 MHz, such that you can count off elapsed time.
Clocking fast will improve your ability to resolve
2024-05-03 02:45 PM
Yes for a work around, I have timer every 1 second and it just gets the microsecond timer value TIM5->CNT.