Skip to main content
Graduate II
August 30, 2025
Solved

Timer Update Interrupt clarification

  • August 30, 2025
  • 3 replies
  • 570 views

This is a line of code i don't understand, 

 /* Force the TIMx prescaler with immediate access (gen update event)
 */
 LL_TIM_SetPrescaler(TIMx, pHandle->HALLMaxRatio);
 LL_TIM_GenerateEvent_UPDATE(TIMx);

The code is part of the __weak void HALL_Init(HALL_Handle_t *pHandle) function

when the second line of code is executed does it mean that i get the interrupt timer over flow interrupt immediately. Please clarify. The TIM4 is configured in XOR / Hall mode.

    This topic has been closed for replies.
    Best answer by TDK

    If the interrupt is not enabled, it won't go to the interrupt. It doesn't need to enter an interrupt to reset the prescaler.

     

    Are you debugging a larger problem? What is the larger context here? Why are we talking about the interrupt at all?

    3 replies

    Super User
    August 31, 2025

    The timer pre-scaler register is buffered. The pre-scaler value set in line 3 is only effective after an update event.

    Line 4 generates that update event.

    hth

    KnarfB

    Super User
    August 31, 2025

    > does it mean that i get the interrupt timer over flow interrupt immediately

    Generating an update event will cause an interrupt if the update interrupt is enabled.

    STuser2Author
    Graduate II
    September 1, 2025

    Thank you for your time and clarification

    If i verify the complete code (MCSDK) for enabling the interrupts 

    /* Force the TIMx prescaler with immediate access (gen update event)
     */
     LL_TIM_SetPrescaler(TIMx, pHandle->HALLMaxRatio);
     LL_TIM_GenerateEvent_UPDATE(TIMx);
    
     /* Clear the TIMx's pending flags */
     WRITE_REG(TIMx->SR, 0);
    
     /* Selected input capture and Update (overflow) events generate interrupt */
    
     /* Source of Update event is only counter overflow/underflow */
     LL_TIM_SetUpdateSource(TIMx, LL_TIM_UPDATESOURCE_COUNTER);
    
     LL_TIM_EnableIT_CC1(TIMx);
     LL_TIM_EnableIT_UPDATE(TIMx);
     LL_TIM_SetCounter(TIMx, HALL_COUNTER_RESET);
    
     LL_TIM_CC_EnableChannel(TIMx, LL_TIM_CHANNEL_CH1);
     LL_TIM_EnableCounter(TIMx);

    The update interrupt is enabled in line 15. So, i really don't understand why line 4 is written? Does the reason is as suggested by @KnarfB is to update the pre-scaler but still not generate the interrupt as the interrupt is not enabled. Please clarify.  

    Super User
    September 1, 2025

    Line 4 is written to do the thing it says it does in the comments.

    /* Force the TIMx prescaler with immediate access (gen update event)
     */

     

    In other words: to update the prescaler. event is generated because prescaler is preloaded.

    STuser2Author
    Graduate II
    September 1, 2025

    But the interrupt is not enabled, does it go to the interrupt as well? Please help.