AnsweredAssumed Answered

TIM3 interrupt occasionally fires too early

Question asked by maddox.rich on May 20, 2013
Latest reply on May 25, 2013 by Danish Ali
I am using TIM3 as an event timer to trigger external ADC conversions.  I am having an issue where the timer interrupt fires too early and causes an out of range conversion result from the ADC.  I notice that when the interrupt is enabled, the TIM3 isr immediately fires followed by another one approximately 24.9ms later.  After that, the isr fires correctly (26.66ms) for a period of time until i get spurious interrupts that, again, fire at the 24.9ms interval.  The spurious interrupts occur anywhere from every few minutes to every few hours...

Using Keil Microvision 4.6 on a STM32F103ZE.  Using the Standard peripheral driver 3.5.0.  Code is as follows...

/* Enable the TIM3 Interrupt */
 NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQChannel;
 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
 NVIC_Init(&NVIC_InitStructure);
 /* TIM3 Peripheral Configuration */
TIM_DeInit(TIM3);
TIM_TimeBaseStructure.TIM_Period = 2666;
TIM_TimeBaseStructure.TIM_Prescaler = 719;
TIM_TimeBaseStructure.TIM_ClockDivision = 1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
 TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
 TIM_SetCounter(TIM3,0x0000);//clear counter reg
 TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);//enable isr
 TIM_Cmd(TIM3, ENABLE);//enable the counter
Here is the ISR...

void TIM3_IRQHandler(void){
 static int iTicks240Milliseconds = 0;
 static int iTicks10Seconds = 0;
 TIM_ClearITPendingBit(TIM3, (TIM_IT_Update|TIM_IT_CC1|TIM_IT_CC2|TIM_IT_CC3|TIM_IT_CC4));
 b30Milliseconds = TRUE;
 if(iTicks240Milliseconds++ >= 6){
   b240Milliseconds = TRUE;
   iTicks240Milliseconds = 0;
 }
 if(iTicks10Seconds++ > 333){
   bInitComplete = TRUE;//allow relays, analog out...etc to function
 }
}

Any ideas what might be going on?

thanks




Outcomes