2025-08-30 7:31 AM
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.
Solved! Go to Solution.
2025-08-31 8:19 PM
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?
2025-08-31 12:05 AM
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
2025-08-31 3:32 PM
> 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.
2025-08-31 7:43 PM
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.
2025-08-31 7:47 PM
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.
2025-08-31 8:03 PM
But the interrupt is not enabled, does it go to the interrupt as well? Please help.
2025-08-31 8:19 PM
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?
2025-08-31 8:52 PM
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.
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.
2025-08-31 11:24 PM
> 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