User Manual
17. Timing and Delays
The following timing and delay functions are designed for the Orangutans and 3pi robot, which run at 20 MHz.
They will give different results at other processor frequencies. These functions are not available within the
Arduino environment, which has its own delay functions.
The timing functions use a Timer 2 overflow interrupt (TIMER2_OVF), and Timer 2 is automatically
configured when any OrangutanTime function is called. This means that the timing code will conflict with other
code that uses Timer 2 in an incompatible way. However, the functions here are compatible with the other uses
of Timer 2 within the Pololu library.
The Timer 2 overflow ISR is written in assembly to make it as short as possible. When the Timer 2 overflow
interrupt occurs, your code will be interrupted for a total span of 2.65 µs (this includes the time it takes to jump
into the ISR and the time it takes to return from it) once every 102.4 µs. Once every millisecond, the Timer 2
overflow ISR will take a little bit longer: 3.85 µs instead of the usual 2.65 µs. So in all, maintaining the system
timers takes up approximately 2.5% of your available processing time.
General Note about Timers: The functions in Pololu AVR library will conflict with code that
tries to reconfigure the hardware timers it is relying upon, so if you want to use a timer for some
custom task, you cannot use the portion of the library that relies on that timer. The Pololu AVR
library only uses Timer 0 for motor PWM generation, and it is only used for this purpose on
the Orangutan LV, SV, Baby Orangutan, and 3pi robot, so the Orangutan SVP and X2 can safely
use Timer 0 for any custom task. Timer 1 is used by OrangutanBuzzer for sound generation on
all devices, and it is used by OrangutanServos for servo pulse generation on all devices. Timer
2 is used for motor PWM generation on all devices except Orangutan X2, and it is used by
OrangutanTime to run the system timer on all devices. Additionally, the Orangutan SVP-1284
has a second 16-bit timer, Timer 3, that can safely be used for any custom task (the Pololu AVR
library does not use Timer 3 for anything).
Pololu AVR Library Command Reference © 2001–2015 Pololu Corporation
17. Timing and Delays Page 58 of 65