AnsweredAssumed Answered

TIMER Question

Question asked by b.m.002 on Jan 13, 2016
Latest reply on Jan 14, 2016 by b.m.002

Hi Everyone.

I've looked through some of the older posts re: timer delay function, and I have used one of those posts as a base to what I have implemented. The problem is, when I run the delay function in a loop to test, it runs for about one second then it stops (crashes?).
From what I've read so far, my set up should be a free running 16bit counter.

Can anyone see what the problem is.

      TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
      RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);

      TIM_TimeBaseStructure.TIM_Prescaler = 0x0;
      TIM_TimeBaseStructure.TIM_Period = 0xFFFF;
      TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
      TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
      TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);

      TIM_Cmd(TIM2, ENABLE);

   while(1)
   {
   GPIOC->BRR  = GPIO_Pin_11;
   delay(100);
   GPIOC->BSRR = GPIO_Pin_11;
   delay(100);
   }
     
void delay(uint16_t ticks)
{
  uint16_t start = TIM2->CNT;
  do { } while((TIM2->CNT - start) < ticks);
}

Outcomes