User Manual

static unsigned int OrangutanAnalog::readAverageMillivolts(unsigned char channel, unsigned int
numSamples)
unsigned int analog_read_average_millivolts(unsigned char channel, unsigned int numSamples)
This function is just like analog_read_average() except the result is returned in millivolts. A return value
of 5000 indicates a voltage of 5 V. This function is equivalent to
to_millivolts(analog_read_average(channel, numSamples)).
static unsigned int OrangutanAnalog::readVCCMillivolts()
unsigned int read_vcc_millivolts()
Performs ten 10-bit analog-to-digital conversions on the fixed internal 1.1V bandgap voltage and computes
the analog reference voltage, VCC, from the results. On the Orangutans and 3pi, VCC is regulated to a steady
5 V, but VCC will fall below 5 V on all devices except the Orangutan LV if VIN drops to around 5 V or lower.
On the LV, VCC will rise above 5 V if VIN exceeds 5 V. This function can be used to monitor VCC and catch
when it is lower or higher than it should be. It can also be used as an argument to the set_millivolt_calibration()
function to ensure that millivolt conversions of analog voltage readings stay accurate when the ADC reference
voltage, VCC, cannot be regulated to 5 V. Note that this function performs 10-bit conversions regardless of
the analog mode, but it restores the analog mode to its previous state before the function returns.
static void OrangutanAnalog::setMillivoltCalibration(unsigned int referenceMillivolts)
void set_millivolt_calibration(unsigned int referenceMillivolts )
This function updates the value of the reference voltage used by the to_millivolts() function (and all other
functions that return conversion results in millivolts) to be referenceMillivolts. The default callibration
value is 5000 mV, which is accurate when VCC is 5 V, as it is during normal operation for all devices.
If VCC is not 5 V and the analog reference voltage value is not adjusted to the new VCC, however,
millivolt conversions of analog readings performed by this library will be inaccurate. An easy way to
ensure that your conversions remain accurate even when VCC falls below 5 V is to call
set_millivolt_calibration(read_vcc_millivolts()) in your main loop.
static unsigned int OrangutanAnalog::readTrimpot()
unsigned int read_trimpot()
Performs 20 analog-to-digital conversions on the output of the trimmer potentiometer on the Orangutan
(including the SVP) or 3pi robot. In 8-bit mode, the result will range from 0 to 255 for voltages from 0 to 5 .
In 10-bit mode, the result will range from 0 to 1023 for voltages from 0 to 5 V. This method is equivalent to
readAverage(TRIMPOT, 20).
static unsigned int OrangutanAnalog::readTrimpotMillivolts()
unsigned int read_trimpot_millivolts()
This function is just like read_trimpot() except the result is returned in millivolts. On the Orangutan SVP, this
function is more efficient than to_millivolts(read_trimpot()). On all other devices the two are equivalent.
static int readBatteryMillivolts_3pi()
int read_battery_millivolts_3pi()
Performs ten 10-bit analog-to-digital conversions on the battery voltage sensing circuit (a 2/3 voltage divider
of VIN) of the 3pi and returns the average measured battery voltage in millivolts. A result of 5234 would mean
a battery voltage of 5.234 V. For rechargeable NiMH batteries, the voltage usually starts at a value above 5 V
and drops to around 4 V before the robot shuts off, so monitoring this number can be helpful in determining
when to recharge batteries. This function will only return the correct result when the ADC6 shorting block
is in place on the front-left side of the robot. The 3pi ships with this shorting block in place, so this function
will return the correct result by default. Note that this function performs 10-bit conversions regardless of the
analog mode, but it restores the analog mode to its previous state before the function returns.
Pololu AVR Library Command Reference © 2001–2015 Pololu Corporation
2. Orangutan Analog-to-Digital Conversion Page 10 of 65