cancel
Showing results for 
Search instead for 
Did you mean: 

Best way of implementing stopwatch

paramasivan
Associate II
Posted on March 31, 2015 at 08:20

Hi,

Which one is the best way of implementing stopwatch in stm32f429? Currently i am using soft timers for stopwatch. But it has time  drift in long period when compared into my mobile stopwatch. I have using RTC also. Is there any method using with RTC module for stopwatch. Thanks in advance.

#timer #stm32 #interrupt #!stm32f4-disco #exti
6 REPLIES 6
Posted on March 31, 2015 at 15:03

Neither the LSI or HSI are particularly accurate, use crystals?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
paramasivan
Associate II
Posted on April 02, 2015 at 09:50

Hi Clive,

i am using external crystal 8MHz and my system core clock is 180MHZ. Even I have tried timer 2 for stopwatch. But still my stopwatch is little bit faster than mobile stopwatch.

 TIM_TimeBaseStructure.TIM_Prescaler = 1799; //timer input

  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

  TIM_TimeBaseStructure.TIM_Period = 1000;

  TIM_TimeBaseStructure.TIM_ClockDivision = 0;

  TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;

  TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);

  

  NVIC_SetPriority(TIM2_IRQn,0);

  

  TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE); 

TIM_ARRPreloadConfig(TIM2, ENABLE);

void TIM2_IRQHandler(void)

{

   TIM2->SR &=0xFFFE;

   

 SW_Update = 1;

 SW_MSecs ++;

   if(SW_MSecs == 100)

   {

     SW_MSecs =0;

     

     if(GPIO_ReadOutputDataBit(GPIOB,GPIO_Pin_12))      // for test, its exactly switch                                                                                                          1secs

         GPIOB->BSRRH = GPIO_Pin_12;

       else

           GPIOB->BSRRL = GPIO_Pin_12;

     

     SW_Secs ++;

     if(SW_Secs == 60)

     {

       SW_Secs =0;

       SW_Mins ++;

       if(SW_Mins == 60)

       {

         SW_Mins =0;

       }

     }

   }

 //}

}

paramasivan
Associate II
Posted on April 02, 2015 at 13:07

I have also tried in the following manner

 TIM_TimeBaseStructure.TIM_Prescaler = 1799; //timer input

  TIM_TimeBaseStructure.TIM_Period = 1000 -1;

timer has generate interrupt at every 9.900 ms only. I couldn't understand why the timer did't get 10 ms interrupt.

AvaTar
Lead
Posted on April 02, 2015 at 13:23

10 ms isn't really very demanding.

I usually handle such tasks with the SysTick timer:

RCC_ClocksTypeDef RCC_Clocks;
/* SysTick event each 10ms */
RCC_GetClocksFreq (&RCC_Clocks);
SysTick_Config (RCC_Clocks.HCLK_Frequency / 100);

Posted on April 02, 2015 at 15:23

Round here we'd use an oscilloscope.

Would confirm the input HSE clock, and PLL/CPU clock, via the MCO (PA8) pin.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
paramasivan
Associate II
Posted on April 07, 2015 at 14:11

I am getting 181.4 MHZ output on MCO2 pin.

I am using 32.768 Mhz crystal for RTC. Shall i create timer interupt using the LSE clock input? or any other way to calibrate the HSE with LSE crystal clock?

What about the sub seconds in RTC? Is it create any interrupt to update my sub seconds in my stopwatch?