XMEGA DAC Calibration application Main File.
This is an example on how to calibrate the XMEGA DAC by using the internal ADC.
Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.
#include <asf.h>
#include <conf_board.h>
Macros | |
#define | ADC_CH_TO_DAC_CH0 ADC_CH0 |
#define | ADC_CH_TO_DAC_CH1 ADC_CH1 |
#define | ADC_DAC_GAIN_TARGET ((uint16_t)((2048*1.6)/4)) |
#define | ADC_DAC_OFFSET_TARGET ((uint16_t)((2048*1.6)/2)) |
#define | AVG_SAMPLES 32 |
#define | CALIBRATION_ADC ADCA |
#define | DAC_OUTPUT_FOR_GAIN_CALIB ((uint16_t)(4096/4)) |
#define | DAC_OUTPUT_FOR_OFFSET_CALIB ((uint16_t)(4096/2)) |
Functions | |
static int16_t | adc_get_sample (uint8_t adc_ch) |
Wrapper function for getting and ADC sample. More... | |
static int16_t | adc_get_sample_avg (uint8_t adc_ch, uint8_t samples) |
Wrapper function for getting averaged ADC measurements. More... | |
static void | configure_adc (void) |
Configure the ADC for DAC calibration. More... | |
static void | configure_dac (void) |
Configure the DAC for calibration. More... | |
static void | configure_pins (void) |
Configure the DAC pins for analog operation only and as output. More... | |
static void | dac_calibrate (void) |
Function for calibration the DAC using the internal ADC. More... | |
static void | dac_calibrate_gain (uint8_t dac_ch) |
Gain calibrate a DAC channel. More... | |
static void | dac_calibrate_offset (uint8_t dac_ch) |
Offset calibrate the DAC channel. More... | |
static void | dac_set_channel_gain (DAC_t *dac, uint8_t dac_ch, uint8_t gain) |
Function for setting the gain calibration value. More... | |
static void | dac_set_channel_offset (DAC_t *dac, uint8_t dac_ch, uint8_t offset) |
Function for setting the offset calibration value. More... | |
int | main (void) |
Main application rutine. More... | |
Variables | |
int16_t | adc_offset = 0 |
#define ADC_CH_TO_DAC_CH0 ADC_CH0 |
Referenced by configure_adc(), dac_calibrate_gain(), and dac_calibrate_offset().
#define ADC_CH_TO_DAC_CH1 ADC_CH1 |
Referenced by configure_adc(), dac_calibrate_gain(), and dac_calibrate_offset().
#define ADC_DAC_GAIN_TARGET ((uint16_t)((2048*1.6)/4)) |
Referenced by dac_calibrate_gain().
#define ADC_DAC_OFFSET_TARGET ((uint16_t)((2048*1.6)/2)) |
Referenced by dac_calibrate_offset().
#define AVG_SAMPLES 32 |
Referenced by dac_calibrate_gain(), and dac_calibrate_offset().
#define CALIBRATION_ADC ADCA |
Referenced by adc_get_sample(), configure_adc(), and dac_calibrate().
#define DAC_OUTPUT_FOR_GAIN_CALIB ((uint16_t)(4096/4)) |
Referenced by dac_calibrate_gain().
#define DAC_OUTPUT_FOR_OFFSET_CALIB ((uint16_t)(4096/2)) |
Referenced by dac_calibrate_offset().
|
static |
Wrapper function for getting and ADC sample.
adc_ch | which channel to get the ADC samples from /returns 16-bit signed ADC result |
References adc_clear_interrupt_flag(), adc_get_result, adc_start_conversion(), adc_wait_for_interrupt_flag(), CALIBRATION_ADC, and result.
Referenced by adc_get_sample_avg().
|
static |
Wrapper function for getting averaged ADC measurements.
adc_ch | which ADC channel to get samples from e.g. ADC_CH0, ADC_CH1 |
samples | number of samples to average over /returns 16-bit signed result of the averaged ADC samples |
References adc_get_sample(), and result.
Referenced by configure_adc(), dac_calibrate_gain(), and dac_calibrate_offset().
|
static |
Configure the ADC for DAC calibration.
References ADC_CH_TO_DAC_CH0, ADC_CH_TO_DAC_CH1, adc_disable(), adc_enable(), adc_get_sample_avg(), adc_offset, adc_read_configuration(), ADC_REF_VCC, ADC_RES_12, adc_set_clock_rate(), adc_set_conversion_parameters(), adc_set_conversion_trigger(), ADC_SIGN_ON, ADC_TRIG_MANUAL, adc_write_configuration(), ADCCH_NEG_PAD_GND, ADCCH_NEG_PIN1, ADCCH_POS_PIN1, ADCCH_POS_PIN10, ADCCH_POS_PIN11, adcch_read_configuration(), adcch_set_input(), adcch_write_configuration(), and CALIBRATION_ADC.
Referenced by dac_calibrate().
|
static |
Configure the DAC for calibration.
References DAC_ADJ_RIGHT, DAC_CH0, DAC_CH1, dac_enable(), dac_read_configuration(), DAC_REF_AVCC, dac_set_active_channel(), dac_set_conversion_parameters(), and dac_write_configuration().
Referenced by dac_calibrate().
|
static |
Configure the DAC pins for analog operation only and as output.
References ioport_configure_pin(), IOPORT_DIR_OUTPUT, and IOPORT_INPUT_DISABLE.
Referenced by dac_calibrate().
|
static |
Function for calibration the DAC using the internal ADC.
This function will calibrate the DAC using the internal ADC, please be aware that signals will be outputted on the DAC pins.
When calibrating always start with the offset then do gain calibration.
References adc_disable(), CALIBRATION_ADC, configure_adc(), configure_dac(), configure_pins(), dac_calibrate_gain(), dac_calibrate_offset(), DAC_CH0, and DAC_CH1.
Referenced by main().
|
static |
Gain calibrate a DAC channel.
dac_ch | which DAC channel to calibrate, valid values are DAC_CH0 and DAC_CH1. |
References ADC_CH_TO_DAC_CH0, ADC_CH_TO_DAC_CH1, ADC_DAC_GAIN_TARGET, adc_get_sample_avg(), adc_offset, Assert, AVG_SAMPLES, DAC_CH0, DAC_CH1, DAC_OUTPUT_FOR_GAIN_CALIB, dac_set_channel_gain(), dac_set_channel_value(), delay_us, and result.
Referenced by dac_calibrate().
|
static |
Offset calibrate the DAC channel.
dac_ch | which DAC channel to calibrate, valid values are DAC_CH0 and DAC_CH1. |
References ADC_CH_TO_DAC_CH0, ADC_CH_TO_DAC_CH1, ADC_DAC_OFFSET_TARGET, adc_get_sample_avg(), adc_offset, Assert, AVG_SAMPLES, DAC_CH0, DAC_CH1, DAC_OUTPUT_FOR_OFFSET_CALIB, dac_set_channel_offset(), dac_set_channel_value(), delay_us, and result.
Referenced by dac_calibrate().
|
static |
Function for setting the gain calibration value.
dac | pointer to the DAC hardware module. |
dac_ch | which channel to set gain calibration for (DAC_CH0, DAC_CH1) |
gain | the calibration value to write. |
References DAC_CH0, and DAC_CH1.
Referenced by dac_calibrate_gain().
|
static |
Function for setting the offset calibration value.
dac | pointer to the DAC hardware module. |
dac_ch | which channel to set gain calibration for (DAC_CH0, DAC_CH1) |
offset | the calibration value to write. |
References DAC_CH0, and DAC_CH1.
Referenced by dac_calibrate_offset().
int main | ( | void | ) |
Main application rutine.
References board_init(), dac_calibrate(), DAC_CH0, DAC_CH1, dac_set_channel_value(), dac_wait_for_channel_ready(), and sysclk_init.
int16_t adc_offset = 0 |
Referenced by adc_oversampled(), configure_adc(), dac_calibrate_gain(), dac_calibrate_offset(), and init_adc().