high precision system time

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
deadlyboy
Posts: 27
Joined: Wed Nov 26, 2014 9:27 am

high precision system time

Post by deadlyboy »

hi every body

for creating a real time system i need to have system time which has microsecond precision.

i used halGetCounterValue() and halGetCounterFrequency(). but it will reset every 25 second.

my code is lke this :

Code: Select all

uint32_t tnow = getSystemTimeInMicroSecond();
while(true)
{
   
   if(getSystemTimeInMicroSecond() - tnow => 13333)
   {       tnow = getSystemTimeInMicroSecond();
      dojobOne();
   }
   if(getSystemTimeInMicroSecond() - tnow  >= 25555)
   {      tnow = getSystemTimeInMicroSecond();
      dojobTwo();
   }
   
}


so i cannot use chThdSleepMicrosecond().
chTimeNow() gives me a 1 millisecond precision.if i had a counter which counts every 168 ticks of micro (stm32f4-168mhz) i will have a system time in micro second.

is it possible to implement this ?? if yes how ??
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: high precision system time

Post by Giovanni »

ChibiOS/RT 3.0 supports high resolution time in the kernel, you can have system tick with 1uS resolution.

You may also consider the GPT driver but only for delays.

Giovanni
Post Reply