AnsweredAssumed Answered

[stm32f407][TIM5] Overflow interrupt-unexpected low frequency

Question asked by PatLas on Oct 15, 2014
Latest reply on Oct 15, 2014 by Clive One
Hi,

I've got some problem with my code that should run timer5 to overflow and generate interrupt it should appear each 500ms but appears each approx. 3s.

code:

void TimerInit(void){
      RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5, ENABLE);
    TIM_TimeBaseInitTypeDef timerInitStructure; 

//generated timer interrupt freq. 168MHz/(16800*5000) = 2Hz
    timerInitStructure.TIM_Prescaler = 16799;
    timerInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
    timerInitStructure.TIM_Period = 4999;
    timerInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
    timerInitStructure.TIM_RepetitionCounter = 0;
    TIM_TimeBaseInit(TIM5, &timerInitStructure);
     
     
    TIM_Cmd(TIM5, ENABLE);
     
          NVIC_InitTypeDef nvicStructure;
    nvicStructure.NVIC_IRQChannel = TIM5_IRQn;
    nvicStructure.NVIC_IRQChannelPreemptionPriority = 0;
    nvicStructure.NVIC_IRQChannelSubPriority = 1;
    nvicStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&nvicStructure);
}

void SystemClock_Config(void)
{
     //HSE: 8MHz pll set to achieve core and tim5 freq. 168MHz 
     RCC_HSEConfig(RCC_HSE_ON);
     RCC_PLLConfig(RCC_PLLSource_HSE , 8, 336, 2, 7);
     RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK );
     RCC_PLLCmd(ENABLE);
     
     RCC_HCLKConfig(RCC_SYSCLK_Div1);
     RCC_PCLK1Config(RCC_HCLK_Div4);
     RCC_PCLK2Config(RCC_HCLK_Div2);
}

extern void TIM5_IRQHandler(void)
{
     if(TIM_GetITStatus(TIM5, TIM_IT_Update) != RESET)
     {
          TIM_ClearITPendingBit(TIM5, TIM_IT_Update);
          GPIOD->ODR ^= 1<<15; //led here
     }
}

Could someone help me to deal with that problem?

Outcomes