AnsweredAssumed Answered

STM32F103Z Timer Problem

Question asked by su.sam.001 on Nov 18, 2013
Latest reply on Nov 19, 2013 by Clive One
I have a Timer Problem . I want that my timer every 1ms makes an interrupt .
I testes it here  if (TIM2_Tick >= 1000) but my LED was alway on then I tryied
if (TIM2_Tick >= 1000000) and it was about 1 sec (30 blinks in 34 sec)

My system_clk is 72Mhz .

where is my mistake

void Config_Timer(TIM_TimeBaseInitTypeDef *TIM_TimeBaseStructure, NVIC_InitTypeDef *NVIC_InitStructure)
{
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
    
 /* Enable the Timer2 Interrupt */
  NVIC_InitStructure->NVIC_IRQChannel = TIM2_IRQn;                          //  configure the Timer2 interrupts
  NVIC_InitStructure->NVIC_IRQChannelPreemptionPriority = 0;   //  sets the priority group of the TIMER2 interrupts
  NVIC_InitStructure->NVIC_IRQChannelSubPriority = 1;                    //  set the subpriority inside the group
  NVIC_InitStructure->NVIC_IRQChannelCmd = ENABLE;                            //  TIMER2 interrupts are globally enabled
  NVIC_Init(NVIC_InitStructure);        
    
    /* Configure Timer which is every 1 ms active*/
  TIM_DeInit(TIM2);
  TIM_TimeBaseStructInit(TIM_TimeBaseStructure);
 
  /* Time base configuration */
  TIM_TimeBaseStructure->TIM_Prescaler = 360 - 1; // 72 MHz / 360 = 200 khz
  TIM_TimeBaseStructure->TIM_Period = 200 - 1;    // (1/200khz) * 200 = 1 ms;
  TIM_TimeBaseStructure->TIM_ClockDivision = 0;
  TIM_TimeBaseStructure->TIM_CounterMode = TIM_CounterMode_Up;
  TIM_TimeBaseInit(TIM2, TIM_TimeBaseStructure);
    
 
    
  /* Enable TIM2 Update Interrupt */
  TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
 
  /* Enable TIM2 */
  TIM_Cmd(TIM2,ENABLE);
         
}



void TIM2_IRQHandler(void)
{
    static int TIM2_Tick = 0; 
      
     TIM2_Tick++;

        if (TIM2_Tick >= 1000) // 1 Second
                {
                    if(check == 0)
                    {
                        STM_EVAL_LEDOn(LED1);
                        check=1;
                    }
                    else
                    {
                        STM_EVAL_LEDOff(LED1);
                        check =0;
                    }
                    
                    TIM2_Tick = 0;
        }
}

I set check=0 in my main once

Outcomes