Get ready for the STM32 Summit 2026 | Online, November 3
..
Hi,
ARR value should be one less than the desired value. In your case instead of 250 use 249.
TIM4_TimeBaseInit(TIM4_PRESCALER_64, 249);
I accidentally posted it blank.
I'm using TIM4 to develop a prototype product application, and the interval between interrupt events is about 0.4%.
With the minimum required implementation as shown below, the interrupt event occurrence interval was 1.004 ms (The ideal is just 1 ms).
For a 15 minute timer, there will be a large gap of +3.6 seconds.
INTERRUPT_HANDLER(TIM4_UPD_OVF_IRQHandler, 23) { GPIO_WriteReverse(GPIOD, GPIO_PIN_5); TIM4_ClearITPendingBit(TIM4_IT_UPDATE); } void main(void) { CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSE, DISABLE, CLK_CURRENTCLOCKSTATE_ENABLE); GPIO_Init(GPIOD, GPIO_PIN_5, GPIO_MODE_OUT_PP_LOW_FAST); TIM4_DeInit(); TIM4_TimeBaseInit(TIM4_PRESCALER_64, 250); TIM4_ITConfig(TIM4_IT_UPDATE, ENABLE); TIM4_Cmd(ENABLE); enableInterrupts(); while (1) { } }
The MCU is STM8S003F3U6TR.
I am using a 16MHz external oscillator with a deviation of ± 30ppm.
What causes this gap? Can software handle it?
Regards,
Gotoda
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.