This file contains the function implementations for XMEGA ADC Oversampling Application.It shows how to use oversampling to increase the resolution.In this example configuration has been been selected for oversampling from 12 bit signed to 16 bit signed result.
Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.
#include <compiler.h>
#include <sleepmgr.h>
#include <sysclk.h>
#include <conf_oversampling.h>
#include <adc_oversampling.h>
#include <asf.h>
Functions | |
static void | adc_handler (ADC_t *adc, uint8_t ch_mask, adc_result_t result) |
Callback function for ADCB-CH0 interrupts. More... | |
static int8_t | adc_offset_get_signed (void) |
This function get the offset of the ADCB when it is configured in signed mode. More... | |
void | adc_oversampled (void) |
This function processes sampled ADC values and calculate the oversampling result. More... | |
static void | convert_to_ascii (uint8_t *buf_index, uint64_t dec_val) |
This Function converts a decimal value to ASCII. More... | |
void | display_adccount (uint64_t adc_rawcount, uint8_t x_cordinate, uint8_t sign_flag) |
This Function Display ADC count on LCD. More... | |
void | init_adc (void) |
This function initialize the ADCB,gets ADCB-CH0 offset and configure ADCB-CH0 for oversampling. More... | |
Variables | |
static struct adc_channel_config | adc_ch_conf |
static struct adc_config | adc_conf |
static int16_t | adc_offset = 0 |
Static variable to store total ADC Offset value for total number of sample. More... | |
static int8_t | adc_offset_one_sample = 0 |
volatile bool | adc_oversampled_flag = false |
Global variable/flag to indicate that one set of oversampling is done for start processing. More... | |
static int64_t | adc_result_accum_processed = 0 |
static volatile int64_t | adc_result_accumulator = 0 |
static volatile int64_t | adc_result_one_sample = 0 |
static int64_t | adc_result_one_sample_processed = 0 |
static volatile uint16_t | adc_samplecount = 0 |
static int64_t | v_input = 0 |
Static variable to find analog value at ADC input after oversampling process. More... | |
static uint8_t | v_input_ascii_buf [ASCII_BUFFER_SIZE] = {"+1.123456"} |
Static buffer variable to store ASCII value of calculated input voltage for display. More... | |
static int64_t | v_input_one_sample = 0 |
Static variable to find analog value at ADC Input without oversampling process. More... | |
|
static |
Callback function for ADCB-CH0 interrupts.
adc | Pointer to ADC module. |
ch_mask | ADC channel mask. |
result | Conversion result from ADC channel. |
References ADC_CH0, adc_ch_conf, adc_clear_interrupt_flag(), adc_oversampled_flag, adc_result_accumulator, adc_result_one_sample, adc_samplecount, adcch_disable_interrupt(), adcch_write_configuration(), and result.
|
static |
This function get the offset of the ADCB when it is configured in signed mode.
References ADC_CH0, adc_get_result, adc_start_conversion(), and adc_wait_for_interrupt_flag().
Referenced by init_adc().
void adc_oversampled | ( | void | ) |
This function processes sampled ADC values and calculate the oversampling result.
Function to process sampled ADC values.
References abs, ADC_CH0, adc_ch_conf, adc_offset, adc_offset_one_sample, adc_result_accum_processed, adc_result_accumulator, adc_result_one_sample, adc_result_one_sample_processed, adc_samplecount, adcch_enable_interrupt(), ADCCH_MODE_COMPLETE, adcch_set_interrupt_mode(), adcch_write_configuration(), ASCII_BUFFER_SIZE, convert_to_ascii(), display_adccount(), gfx_mono_draw_string(), sysfont, v_input, v_input_ascii_buf, and v_input_one_sample.
Referenced by main().
|
static |
This Function converts a decimal value to ASCII.
buf_index | Pointer to buffer used to store ASCII value. |
dec_val | Decimal to be converted as ASCII. |
References NUMBER_OF_DIGITS_IN_RESULT.
Referenced by adc_oversampled().
void display_adccount | ( | uint64_t | adc_rawcount, |
uint8_t | x_cordinate, | ||
uint8_t | sign_flag | ||
) |
This Function Display ADC count on LCD.
Function to display raw ADC count on LCD.
adc_rawcount | ADC raw count value to be displayed. |
x_cordinate | X-coordinate where display should end. |
sign_flag | Sign of ADC count.If negative sign_flag is set. |
References gfx_mono_draw_char(), NUMBER_OF_DIGITS_IN_ADCCOUNT, and sysfont.
Referenced by adc_oversampled().
void init_adc | ( | void | ) |
This function initialize the ADCB,gets ADCB-CH0 offset and configure ADCB-CH0 for oversampling.
Function to initialize the ADC.
References ADC_CH0, adc_ch_conf, adc_conf, adc_disable(), adc_enable(), adc_handler(), adc_offset, adc_offset_get_signed(), adc_offset_one_sample, adc_read_configuration(), ADC_REF_AREFB, ADC_RES_12, adc_set_callback(), adc_set_clock_rate(), adc_set_conversion_parameters(), adc_set_conversion_trigger(), ADC_SIGN_ON, ADC_TRIG_FREERUN_SWEEP, ADC_TRIG_MANUAL, adc_write_configuration(), adcch_enable_interrupt(), ADCCH_MODE_COMPLETE, ADCCH_NEG_PIN3, ADCCH_POS_PIN3, adcch_read_configuration(), adcch_set_input(), adcch_set_interrupt_mode(), and adcch_write_configuration().
Referenced by main().
|
static |
Referenced by adc_handler(), adc_oversampled(), and init_adc().
|
static |
Referenced by init_adc().
|
static |
Static variable to store total ADC Offset value for total number of sample.
|
static |
Referenced by adc_oversampled(), and init_adc().
Global variable/flag to indicate that one set of oversampling is done for start processing.
Static variable/flag to indicate that one set of oversampling is done for start processing.
Referenced by adc_handler(), and main().
|
static |
Referenced by adc_oversampled().
|
static |
Referenced by adc_handler(), and adc_oversampled().
|
static |
Referenced by adc_handler(), and adc_oversampled().
|
static |
Referenced by adc_oversampled().
|
static |
Referenced by adc_handler(), and adc_oversampled().
|
static |
Static variable to find analog value at ADC input after oversampling process.
Referenced by adc_oversampled().
|
static |
Static buffer variable to store ASCII value of calculated input voltage for display.
Referenced by adc_oversampled().
|
static |
Static variable to find analog value at ADC Input without oversampling process.
Referenced by adc_oversampled().