Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ADC Calibration example for XMEGA-A1 Xplained Documentation

Introduction

This example demonstrates a method for offset and gain calibration for single-ended measurements with the Analog to Digital Converter (ADC).

Main files:

ADC driver API

The ADC driver API can be found here.

Device Info

All AVR XMEGA devices with an ADC can be used.

Description of the example

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 configured input pin (INPUT_PIN). An external voltage supply, capable of giving 0 to 1.0 V, must be connected to this input pin.

In addition to the ADC input pin, three I/O pins are used for LED control (LED1_PIN and LED2_PIN) and button input (BUTTON_PIN, active low).

When the example starts, the first LED lights up. This indicates that the example is waiting for the external voltage supply to be set to 0 Volts. Once this has been done, the button must be pressed to trigger measurement of the total offset error.

After this, the second LED lights up. This indicates that the example is waiting for the external voltage supply to be set to 0.9 Volts. Once this has been done, the button must once again be pressed to trigger measurements for gain compensation.

Oversampling is used to improve the accuracy of the calibration measurements. This means that a mean sample value is computed. The amount of oversampling is configurable (see OVERSAMPLING_FACTOR).

Once the calibration has been done, both LEDs are turned off and the device continuously samples from the input pin. The calibration data are then used to compute a calibrated sample value according to the following equation (U = voltage, R = ADC result):

\[ U_\textnormal{now} = \frac{(R_\textnormal{now} - R_\textnormal{offset}) \cdot R_\textnormal{gain,ideal}}{R_\textnormal{gain,calibration} - R_\textnormal{offset}} \]

The calibrated sample value is stored in the global variable last_sample, which can, e.g., be watched during debugging.

Compilation Info

This software was written for the GNU GCC and IAR for AVR. Other compilers may or may not work.

Contact Information

For further information, visit Microchip.