WebbotLib AVR library
WebbotLib It just does it
  C++ documentation  C documentation

clock.h

Use the clock for delays and to test for time intervals.

 

Function

 


TICK_COUNT clockGetus()

Get the current time in µS.
Note that this number will wrap around so a later reading may give a smaller value.
This happens every 0xffffffff or 4,294,967,295 microseconds ie every 4295 seconds or every 72 minutes (approx).
This means that the longest time difference you can sense by subtracting two values is about 72 minutes - this should not be a problem since if you are trying to do that then your program is probably wrong.
Note that, even with wrap around, you can always subtract two values to get a duration (so long as it's less than 72 minutes) ie:
TICK_COUNT start = clockGetus();
... do something ...
TICK_COUNT end = clockGetus();
TICK_COUNT duration = end - start; // the number of uS up to a maximum of 72 minutes
NB if this is called from app_init then it will have unknown results as the clock has not yet been created.

boolean clockHasElapsed(TICK_COUNT usStart, TICK_COUNT usWait)

Test if a given duration has elapsed.
Returns TRUE if it has or FALSE if not.
Whilst I wouldn't recommend doing this: here is an example that pauses for 10mS.
TICK_COUNT start = clockGetus(); // Get the start time
TICK_COUNT wait = 10000; // 10ms = 10000us
while(clockHasElapsed(start, wait)==FALSE){
    ... still waiting ...
}
NB if this is called from app_init then it will have unknown results as the clock has not yet been created.

boolean clockHasElapsedGetOverflow(TICK_COUNT usStart, TICK_COUNT usWait, TICK_COUNT* overflow)

Similar to 'clockHasElapsed' but returns the number of µS left to go if the duration has not elapsed, or the number of µS we have exceeded the duration if is has elapsed.
For example:
TICK_COUNT start = clockGetus();
TICK_COUNT wait = 10000; // wait for 10ms
TICK_COUNT overflow;
while(clockHasElapsedGetOverflow(start, wait, &overflow)==FALSE){
    // There are still 'overflow' µS left
}
// overflow has the number of µS in excess of 'wait' that we have actually waited for
NB if this is called from app_init then it will have unknown results as the clock has not yet been created.

clockWaitms(TICK_COUNT ms)

Pause for the given number of milliseconds.
So to wait for 1 second we could use:-
clockWaitms(1000);
NB The granularity of the clock is such that you should not assume that this waits for exactly 1 second- but rather that it waits for 'at least' one second.
NB if this is called from app_init then it will have unknown results as the clock has not yet been created.

clockWaitus(TICK_COUNT us)

Pause for the given number of microseconds.
So to wait for 100 microseconds we could use:-
clockWaitus(100);
NB The granularity of the clock is such that you should not assume that this waits for exactly 100 micro seconds- but rather that it waits for 'at least' that time.
NB if this is called from app_init then it will have unknown results as the clock has not yet been created.

Valid XHTML 1.0 Transitional