This simple example shows how to use the Analog to Digital Converter (ADC) for temperature measurement with the internal sensor.
The ADC driver API can be found here.
All AVR XMEGA devices with an ADC can be used.
ADC A is configured for unsigned, 12-bit conversions using the internal 1 V voltage reference. The conversions are configured for manual triggering. Channel 0 of the ADC is configured for single-ended measurements from the internal temperature sensor.
An ADC interrupt callback function is used to handle the conversion results, from which the current temperature, in kelvin, is computed. The computation requires the factory calibration measurement, and is done according to the following formula (T = temperature, R = ADC result):
\[ T_\textnormal{now} = \frac{(R_\textnormal{now} \cdot T_\textnormal{calibration})}{R_\textnormal{calibration}} \]
The computed temperature is stored in the global variable last_temperature, which can, e.g., be watched during debugging.
This software was written for the GNU GCC and IAR for AVR. Other compilers may or may not work.
For further information, visit Microchip.