Microchip® Advanced Software Framework

adc.c File Reference

SAM Peripheral Analog-to-Digital Converter Driver.

Copyright (c) 2012-2018 Microchip Technology Inc. and its subsidiaries.

#include "adc.h"

Macros

#define PIN_INVALID_ADC_AIN   0xFFFFUL
 

Functions

static void _adc_configure_ain_pin (uint32_t pin)
 
static enum status_code _adc_set_config (struct adc_module *const module_inst, struct adc_config *const config)
 
void adc_get_config_defaults (struct adc_config *const config)
 Initializes an ADC configuration structure to defaults. More...
 
enum status_code adc_init (struct adc_module *const module_inst, Adc *hw, struct adc_config *config)
 Initializes the ADC. More...
 
void adc_regular_ain_channel (uint32_t *pin_array, uint8_t size)
 Initializes the ADC channel sequence. More...
 
void adc_set_window_mode (struct adc_module *const module_inst, const enum adc_window_mode window_mode, const int16_t window_lower_value, const int16_t window_upper_value)
 Sets the ADC window mode. More...
 

#define PIN_INVALID_ADC_AIN   0xFFFFUL

Referenced by _adc_configure_ain_pin().

static void _adc_configure_ain_pin ( uint32_t  pin)
inlinestatic

Configure MUX settings for the analog pins

This function will set the given ADC input pins to the analog function in the pinmux, giving the ADC access to the analog signal

Parameters
[in]pinAINxx pin to configure

References Assert, system_pinmux_config::input_pull, system_pinmux_config::mux_position, PIN_INVALID_ADC_AIN, system_pinmux_get_config_defaults(), SYSTEM_PINMUX_PIN_PULL_NONE, and system_pinmux_pin_set_config().

Referenced by _adc_set_config(), and adc_regular_ain_channel().

static enum status_code _adc_set_config ( struct adc_module *const  module_inst,
struct adc_config *const  config 
)
static

Writes an ADC configuration to the hardware module

Writes out a given ADC module configuration to the hardware module.

Parameters
[out]module_instPointer to the ADC software instance struct
[in]configPointer to configuration struct
Returns
Status of the configuration procedure
Return values
STATUS_OKThe configuration was successful
STATUS_ERR_INVALID_ARGInvalid argument(s) were provided

References _adc_configure_ain_pin(), adc_config::accumulate_samples, ADC_ACCUMULATE_DISABLE, ADC_ACCUMULATE_SAMPLES_16, ADC_ACCUMULATE_SAMPLES_256, ADC_ACCUMULATE_SAMPLES_4, ADC_ACCUMULATE_SAMPLES_64, ADC_DIVIDE_RESULT_16, ADC_DIVIDE_RESULT_2, ADC_DIVIDE_RESULT_4, ADC_DIVIDE_RESULT_8, ADC_DIVIDE_RESULT_DISABLE, ADC_RESOLUTION_10BIT, ADC_RESOLUTION_12BIT, ADC_RESOLUTION_13BIT, ADC_RESOLUTION_14BIT, ADC_RESOLUTION_15BIT, ADC_RESOLUTION_16BIT, ADC_RESOLUTION_8BIT, ADC_RESOLUTION_CUSTOM, ADC_WINDOW_MODE_DISABLE, adc_config::clock_prescaler, adc_config::clock_source, adc_config::correction, adc_correction_config::correction_enable, adc_config::differential_mode, adc_config::divide_result, adc_config::event_action, adc_config::freerunning, adc_correction_config::gain_correction, adc_config::gain_factor, adc_pin_scan_config::inputs_to_scan, adc_config::left_adjust, adc_config::negative_input, adc_correction_config::offset_correction, adc_pin_scan_config::offset_start_scan, adc_config::pin_scan, adc_config::positive_input, adc_config::reference, adc_config::reference_compensation_enable, adc_config::resolution, adc_config::run_in_standby, adc_config::sample_length, system_gclk_chan_config::source_generator, STATUS_ERR_INVALID_ARG, STATUS_OK, system_gclk_chan_enable(), system_gclk_chan_get_config_defaults(), system_gclk_chan_set_config(), adc_config::window, adc_window_config::window_lower_value, adc_window_config::window_mode, and adc_window_config::window_upper_value.

Referenced by adc_init().

void adc_regular_ain_channel ( uint32_t *  pin_array,
uint8_t  size 
)

Initializes the ADC channel sequence.

Like SAMD and SAMR21 the INPUTOFFSET register will be incremented one automatically after a conversion done, causing the next conversion to be done with the positive input equal to MUXPOS + INPUTOFFSET, it is scanning continuously one by one even ADC channels are not continuous.

Initializes the ADC channel sequence by the sequence of pin_array.

Parameters
[in]pin_arrayThe array of the Mux selection for the positive ADC input
[in]sizeThe size of pin_array

References _adc_configure_ain_pin().