2. Timing and Delays

The following timing and delay functions are designed for the Orangutans and 3pi, 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. For the functions in this section only, the C functions are also available from C++.

The timing functions use an interrupt on Timer2, which is configured when time_reset(), get_ms(), or an equivalent function is called. This means that the timing code will conflict with other code that uses Timer2. However, the functions here are compatible with the other uses of Timer2 within the Pololu library.

Reference

C++ methods are shown in red.

C/C++ functions are shown in green.

static unsigned char OrangutanTime::delayMilliseconds(unsigned int milliseconds)

unsigned char delay_ms(unsigned int milliseconds)

unsigned char delay(unsigned int milliseconds)

Delays for the specified number of milliseconds.

static unsigned char OrangutanTime::delayMicroseconds(unsigned int microseconds)

static unsigned char delayMicroseconds(unsigned int microseconds)

unsigned char delay_us(unsigned int microseconds)

Delays for the specified number of microseconds.

static void OrangutanTime::reset()

void time_reset()

Starts/resets the system timer. This begins using an interrupt on Timer2 to record the elapsed time since reset.

static void OrangutanTime::ms()

unsigned long get_ms()

unsigned long millis()

Returns the number of elapsed milliseconds since reset. 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.