cancel
Showing results for 
Search instead for 
Did you mean: 

Timer error

gocchan
Associate III
 
1 ACCEPTED SOLUTION

Accepted Solutions
AA1
Senior III

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

View solution in original post

2 REPLIES 2
gocchan
Associate III

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

AA1
Senior III

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