AnsweredAssumed Answered

How to achieve max. accuracy for static timing event

Question asked by Neiro on Nov 17, 2013
Latest reply on Nov 18, 2013 by Neiro
Hello :)

I want a timer to execute ISR all 4 ms but for academic reasons (interest) I want it as accurate as possible. So I chose TIM_Prescaler = 0 and TIM_ClockDivision = 0.
Is there anything else that could increase accuracy? Here's the code: 
  /* Timer2 (250 Hz) initialization */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
  /* Prescaler of 1 */
  TIM_TimeBaseStructure.TIM_Prescaler = 0;
  /* To get 250ms */
  TIM_TimeBaseStructure.TIM_Period = 0x52080;
  /* No preprescaler */
  TIM_TimeBaseStructure.TIM_ClockDivision = 0;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
  /* Timer2 IRQ */
  NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_Init(&NVIC_InitStructure);
  TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
  /* Timer2 enable counter */
  TIM_Cmd(TIM2, ENABLE);


void TIM2_IRQHandler(void)
{
    TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
   ...
}

Thank you!!

Outcomes