User Manual
Reference
C++ methods are shown in red.
C/C++ functions are shown in green.
static void OrangutanTime::delayMilliseconds(unsigned int milliseconds)
void delay_ms(unsigned int milliseconds)
void delay(unsigned int milliseconds)
Delays for the specified number of milliseconds. Note that if the supplied argument milliseconds has a value
of zero, this function will return execution immediately (unlike delayMicroseconds(0), which will delay for
the maximum time possible of 65536 µs). Because this is a loop delay, the presence of interrupts will extend
the delay period. For example, the Timer 2 overflow interrupt used by OrangutanTime to maintain the system
timers will extend this delay period by approximately 2.5%, so if your system clock is 100% accurate,
delay_ms(1000) will actually delay for approximately 1025 ms.
static void OrangutanTime::delayMicroseconds(unsigned int microseconds)
void delayMicroseconds(unsigned int microseconds)
void delay_us(unsigned int microseconds)
Delays for the specified number of microseconds. Note that if the supplied argument microseconds has a
value of zero, this function will delay for 65536 us (unlike delayMilliseconds(0), which produces no delay
at all). Because this is a loop delay, the presence of interrupts will extend the delay period. For example,
the Timer 2 overflow interrupt used by OrangutanTime to maintain the system timers will extend this delay
period by approximately 2.5%, so if your system clock is 100% accurate, delay_us(1000) will actually delay
for approximately 1025 µs.
static void OrangutanTime::reset()
void time_reset()
Resets the system millisecond timer, but does not reset the system tick counter.
static unsigned long OrangutanTime::ms()
unsigned long get_ms()
unsigned long millis()
Returns the number of elapsed milliseconds since the first time an OrangutanTime function was called or
the last time_reset() call, whichever is shorter. The value can be as high as the maximum value stored in an
unsigned long, 4,294,967,295 ms, which corresponds to a little more than 49 days, after which it starts over at
0. Because the millisecond counter overflows on an even data boundary, differential millisecond calculations
will produce correct results across the millisecond counter overflow.
static unsigned long OrangutanTime::ticks()
unsigned long get_ticks()
Returns the number of elapsed ticks (in units of 0.4 µs) since the first time an OrangutanTime function was
called. The tick counter is not reset by time_reset(). get_ticks() can be used as a high-resolution system
timer that will overflow back to zero after approximately 28.6 minutes of counting. Because the tick counter
overflows on an even data boundary, differential tick calculations will produce correct results across the
tick counter overflow. In order to take advantage of this property, it is important to always perform tick-to-
microsecond conversions of the differential result, not the individual arguments of the differential calculation.
Example
// if the tick counter has overflowed once since we called prev_ticks = get_ticks(),
// the following call will result in a CORRECT measure of the elapsed time in us
unsigned long elapsed_time_us = ticks_to_microseconds(get_ticks() - prev_ticks);
Pololu AVR Library Command Reference © 2001–2015 Pololu Corporation
17. Timing and Delays Page 59 of 65