Documents » Pololu AVR Library Command Reference »3. Orangutan Analog-to-Digital ConversionThe OrangutanAnalog class and the C functions in this section allow easy access to the analog inputs on 3pi and the Orangutan controllers. These functions take care of configuring and running the analog-to-digital converters, but they do not automatically set the ports to be inputs or enable/disable the pull-up resistors. By default, all ports on the Orangutan are set to inputs, and the pull-ups are turned off, so no additional configuration is needed for most applications. For a higher level overview of this library and example programs that show how this library can be used, please see Section 5.a of the guide to Programming Orangutans and the 3pi Robot from the Arduino Environment or Section 6.c of the Pololu AVR C/C++ Library User’s Guide. ReferenceC++ and Arduino methods are shown in red. C functions are shown in green. static void OrangutanAnalog::setMode(unsigned char mode) void set_analog_mode(unsigned char mode) Used to set the ADC for either 8-bit or 10-bit conversions. The library defines the keywords MODE_8_BIT and MODE_10_BIT, which can be used as the argument to this method. When the ADC is in 8-bit mode, conversion results will range from 0 – 255 for voltages ranging from 0 – 5 V. When the ADC is in 10-bit mode, conversion results will range from 0 – 1023 for voltages ranging from 0 – 5 V. Example:// run the ADC in 10-bit conversion mode OrangutanAnalog::setMode(MODE_10_BIT); static unsigned char OrangutanAnalog::getMode() unsigned char get_analog_mode() Returns the current ADC mode. The return value will be MODE_8_BIT (1) if the ADC is in 8-bit conversion mode, otherwise it will be MODE_10_BIT (0). static unsigned int OrangutanAnalog::read(unsigned char channel) unsigned int analog_read(unsigned char channel) 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 – 255 for voltages from 0 – 5 . In 10-bit mode, the result will range from 0 – 1023 for voltages from 0 – 5 V. The channel argument should be 0 – 7. This function will occupy program execution until the conversion is complete (approximately 100 us). static unsigned int OrangutanAnalog::readAverage(unsigned char channel, unsigned int numSamples) unsigned int analog_read_average(unsigned char channel, unsigned int numSamples) Performs numSamples analog-to-digital conversions on the specified analog input channel and returns the average value of the readings. In 8-bit mode, the result will range from 0 – 255 for voltages from 0 – 5 . In 10-bit mode, the result will range from 0 – 1023 for voltages from 0 – 5 V. The channel argument should be 0 – 7. This function will occupy program execution until all of the requested conversions are complete (approximately 100 us per sample). static unsigned int OrangutanAnalog::readTrimpot() unsigned int read_trimpot() Performs 20 analog-to-digital conversions on the output of the trimmer potentiometer on the 3pi, Orangutan LV-168 or Baby Orangutan B and returns the average result. In 8-bit mode, the result will range from 0 – 255 for voltages from 0 – 5 . In 10-bit mode, the result will range from 0 – 1023 for voltages from 0 – 5 V. The trimpot is on analog input 7, so this method is equivalent to readAverage( static int OrangutanAnalog::readTemperatureF() int read_temperature_f() Performs 20 analog-to-digital conversions on the output of the temperature sensor on the Orangutan LV-168 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, so this method is equivalent to readAverage( static int readTemperatureC() int read_temperature_c() This method is the same as readTemperatureF() above, except that it returns the temperature in tenths of a degree Celcius. static int readBatteryMillivolts() int read_battery_millivolts() Performs 10 analog-to-digital conversions on the battery voltage sensing circuit of the 3pi and returns the average result 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. static void OrangutanAnalog::startConversion(unsigned char channel) void start_analog_conversion(unsigned char channel) Initiates an ADC conversion that runs in the background, allowing the CPU to perform other tasks while the conversion is in progress. The procedure is to start a conversion on an analog input with this method, then poll isConverting() in your main loop. Once isConverting() returns a zero, the result can be obtained through a call to conversionResult() and this method can be used to start a new conversion. static unsigned char OrangutanAnalog::isConverting() unsigned char analog_is_converting() Returns a 1 if the ADC is in the middle of performing a conversion, otherwise it returns a 0. The ATmega168 is only capable of performing one analog-to-digital conversion at a time. static unsigned int conversionResult() unsigned int analog_conversion_result() Returns the result of the previous analog-to-digital conversion. In 8-bit mode, the result will range from 0 – 255 for voltages from 0 – 5 . In 10-bit mode, the result will range from 0 – 1023 for voltages from 0 – 5 V. static unsigned int toMillivolts(unsigned int adcResult) static unsigned int to_millivolts(unsigned int adc_result) Converts the result of an analog-to-digital conversion to millivolts. This assumes a board power level of exactly 5000 mV. Example:OrangutanAnalog::toMillivolts(OrangutanAnalog::read(0)); // e.g. will return 5000 if analog input 0 is at 5 V |
|
Home
|
Contact
|
About
|
Forum
|
US toll free: 1-877-7-POLOLU |