## Support » Pololu AVR Library Command Reference »## 2. Orangutan Analog-to-Digital ConversionThe OrangutanAnalog class and the C functions in this section make it easy to use to the analog inputs and integrated analog hardware on the Orangutan robot controllers (LV, SV, SVP, X2, and Baby Orangutan) and 3pi robot. These functions take care of configuring and running the analog-to-digital converter. For a higher level overview of this library and example programs that show how this library can be used, please see ## ChannelsThe tables below give a summary of the analog inputs available on your AVR. Some of these pins are hardwired or jumpered to the battery voltage or sensors or trimpots built in to your device, while other pins are available for you to connect your own sensors to. Please refer to the pin assignment table in the user’s guide for your device for more information.
*Reading the analog channels on the Orangutan SVP that are measured by the auxiliary processor requires the auxiliary processor to be in the correct mode. See the documentation for the Orangutan SVP
*Pins PA6 and PA7 on the Orangutan X2 are connected by default through SMT jumpers to the a battery voltage divider circuit and the user trimpot, respectively. You should not make external connections to these pins without first breaking the default SMT jumper connections, which are located on the underside of the main board and labeled in the silkscreen “ADC6=BATLEV” and “ADC7=TRIMPOT”.
## Function Reference
static void OrangutanAnalog:: void Used to set the ADC for either 8-bit or 10-bit conversions. The ## Example:// run the ADC in 10-bit conversion mode OrangutanAnalog::setMode(MODE_10_BIT); // run the ADC in 10-bit conversion mode set_analog_mode(MODE_10_BIT); static unsigned char OrangutanAnalog:: unsigned char Returns the current ADC mode. The return value will be static unsigned int OrangutanAnalog:: unsigned int Performs a single analog-to-digital conversion on the specified analog input channel and returns the result. In 8-bit mode, the result will range from 0 to 255 for voltages from 0 to 5 V. In 10-bit mode, the result will range from 0 to 1023 for voltages from 0 to 5 V. The static unsigned int OrangutanAnalog:: unsigned int This function is just like analog_read() except the result is returned in millivolts. A return value of 5000 indicates a voltage 5 V. In most cases, this function is equivalent to static unsigned int OrangutanAnalog:: unsigned int Performs static unsigned int OrangutanAnalog:: unsigned int 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 static unsigned int OrangutanAnalog:: unsigned int 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:: void 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 static unsigned int OrangutanAnalog:: unsigned int 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 static unsigned int OrangutanAnalog:: unsigned int This function is just like read_trimpot() except the result is returned in millivolts. On the Orangutan SVP, this function is more efficient than static int int 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. static int int Performs ten 10-bit analog-to-digital conversions on the battery voltage sensing circuit (a 1/3 voltage divider of VIN) of the Orangutan SV and returns the average measured battery voltage in millivolts. A result of 9153 would mean a battery voltage of 9.153 V. This function will only return the correct result when there is a short across the “ADC6=VBAT/3” SMT jumper on the bottom side of the PCB. The SV ships with this SMT jumper shorted with a solder bridge, 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. static int int Returns the measured Orangutan SVP battery voltage in millivolts. The battery voltage on the SVP is measured by the auxiliary microcontroller, so this function just asks the auxiliary MCU for the most recent measurement; it does not use the ADC on the user MCU. static int int Performs ten 10-bit analog-to-digital conversions on the battery voltage sensing circuit (a 5/16 voltage divider of VIN) of the Orangutan X2 and returns the average measured battery voltage in millivolts. A result of 9153 would mean a battery voltage of 9.153 V. This function will only return the correct result when there is a short across the “ADC6=BATLEV” SMT jumper on the bottom side of the PCB. The X2 ships with this SMT jumper shorted with a solder bridge, 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. static int OrangutanAnalog:: int Performs 20 10-bit analog-to-digital conversions on the output of the temperature sensor on the Orangutan LV and returns average result in tenths of a degree Farenheit, so a result of 827 would mean a temperature of 82.7 degrees F. The temperature sensor is on analog input 6 on the Orangutan LV, so this method is equivalent to static int int This method is the same as readTemperatureF() above, except that it returns the temperature in tenths of a degree Celcius. This function will only return correct results when used on an Orangutan LV, and it requires a short across the “ADC6=TEMP” SMT jumper (this short is present by default). static void OrangutanAnalog:: void Initiates an ADC conversion that runs in the background, allowing the CPU to perform other tasks while the conversion is in progress. The static unsigned char OrangutanAnalog:: unsigned char Returns a 1 if the ADC is in the middle of performing an analog-to-digital conversion, otherwise it returns a 0. The AVR is only capable of performing one conversion at a time. static unsigned int unsigned int Returns the result of the previous analog-to-digital conversion. In 8-bit mode, the result will range from 0 to 255 for voltages from 0 to 5 V. In 10-bit mode, the result will range from 0 to 1023 for voltages from 0 to 5 V. static unsigned int unsigned int This function is just like analog_conversion_result() except the result is returned in millivolts. A return value of 5000 indicates a voltage 5 V. In most cases, this function is equivalent to static unsigned int unsigned int Converts the result of an analog-to-digital conversion to millivolts. By default, this assumes an analog reference voltage of exactly 5000 mV. The analog reference voltage used by this function can be changed using the set_millivolt_calibration() function. ## Example:OrangutanAnalog::toMillivolts(OrangutanAnalog::read(0)); // e.g. returns 5000 if analog input 0 is at 5 V to_millivolts(analog_read(0)); // e.g. returns 5000 if analog input 0 is at 5 V |

Log In | Wish Lists | BIG Order Form | Shopping Cart
US toll free: 1-877-7-POLOLU ~
(702) 262-6648 |
||||||||||||||||

Catalog | Forum | Blog | Support | Ordering | Distributors | About | Contact |
---|