cancel
Showing results for 
Search instead for 
Did you mean: 

callback not getting triggered by 1us timer (TIM5)

debug
Associate III

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();

}

}
1 ACCEPTED SOLUTION

Accepted Solutions
AScha.3
Chief III

Hi,

seems same "problem" ... :)

see:

https://community.st.com/t5/stm32-mcus-products/stm32g474re-general-purpose-timer-tim16/m-p/669419#M242931

 

>How do I make sure that the callback gets invoked properly?

Make it 100x slower...

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

View solution in original post

4 REPLIES 4
debug
Associate III

I missed to mention that it does get started with:

HAL_TIM_Base_Start_IT(&htim5);

 

AScha.3
Chief III

Hi,

seems same "problem" ... :)

see:

https://community.st.com/t5/stm32-mcus-products/stm32g474re-general-purpose-timer-tim16/m-p/669419#M242931

 

>How do I make sure that the callback gets invoked properly?

Make it 100x slower...

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

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

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Yes for a work around, I have timer every 1 second and it just gets the microsecond timer value TIM5->CNT.