cancel
Showing results for 
Search instead for 
Did you mean: 

Timer Update Interrupt clarification

STuser2
Senior II

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.

1 ACCEPTED SOLUTION

Accepted Solutions

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?

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

View solution in original post

8 REPLIES 8
KnarfB
Super User

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

TDK
Super User

> 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.

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

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.  

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.

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

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

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?

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

Thank you for the clarification, at present i am trying to understand the code of how input capture works and the speed measurement of the motor, as per the user manual the pre-scaler will be adjusted based on the speed of the motor.

STuser2_0-1756698574687.png

After your explanation i can understand that the pre-scaler register value will be loaded into the pre-scaler buffer after the update event and it is not required to generate interrupt. I was of the impression that event always causes an interrupt.    

> I was of the impression that event always causes an interrupt.

As @TDK said above, if the interrupt is enabled, it will; if it's not enabled, it won't.

It will set TIMx_SR.UIF, though, so you want to clear this bit before interrupts are enabled.

Read the TIM chapter in RM.

JW