Pages: [1]   Go Down
Author Topic: Micros function implementation  (Read 394 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So at the moment, the Arduino Due I am using has micros() specified as the following in the wiring.c file:

uint32_t micros( void )
    uint32_t ticks ;
    uint32_t count ;

    do {
        ticks = SysTick->VAL;
        count = GetTickCount();
    } while (SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk);

    return count * 1000 + (SysTick->LOAD + 1 - ticks) / (SystemCoreClock/1000000) ;

What is the purpose of calling SysTick->CTRL before the do-while loop is used?

Additionally, this implementation waits for the internal SysTick Current Value Register to tick to zero, then determines the number of microseconds that have elapsed based on this. This seems to lower the resolution of the returned value. Is it possible to get the number of nanoseconds that have elapsed with a similar function to micros() that doesn't wait for SysTick->VAL to count down without sacrificing much performance? I understand the resolution of the function wouldnt be overly impressive as there is ~12ns per clock tick.

Laguna Hills, CA 92653
Offline Offline
Full Member
Karma: 0
Posts: 112
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It appears that many programmers are allergic to comments.

Is it necessary for this while loop to be there at all?

Cheers, Gary
Due for controlling Electric car charging.
Nissan LEAF - Mini Quick Charge (mQC)

Pages: [1]   Go Up
Jump to: