Microchip® Advanced Software Framework

 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages

Management and configuration functions for the individual ADC channels.

The API functions and definitions can be divided in two groups:

Data Structures

struct  adc_channel_config
 ADC channel configuration. More...
 

Macros

#define CONFIG_ADC_INTLVL   ADC_CH_INTLVL_LO_gc
 Default ADC channel interrupt level. More...
 

Enumerations

enum  adcch_mode {
  ADCCH_MODE_COMPLETE = ADC_CH_INTMODE_COMPLETE_gc,
  ADCCH_MODE_BELOW = ADC_CH_INTMODE_BELOW_gc,
  ADCCH_MODE_ABOVE = ADC_CH_INTMODE_ABOVE_gc
}
 ADC channel interrupt modes. More...
 
enum  adcch_negative_input {
  ADCCH_NEG_PIN0,
  ADCCH_NEG_PIN1,
  ADCCH_NEG_PIN2,
  ADCCH_NEG_PIN3,
  ADCCH_NEG_PIN4,
  ADCCH_NEG_PIN5,
  ADCCH_NEG_PIN6,
  ADCCH_NEG_PIN7,
  ADCCH_NEG_PAD_GND,
  ADCCH_NEG_INTERNAL_GND,
  ADCCH_NEG_NONE
}
 ADC channel negative input. More...
 
enum  adcch_positive_input {
  ADCCH_POS_PIN0,
  ADCCH_POS_PIN1,
  ADCCH_POS_PIN2,
  ADCCH_POS_PIN3,
  ADCCH_POS_PIN4,
  ADCCH_POS_PIN5,
  ADCCH_POS_PIN6,
  ADCCH_POS_PIN7,
  ADCCH_POS_PIN8,
  ADCCH_POS_PIN9,
  ADCCH_POS_PIN10,
  ADCCH_POS_PIN11,
  ADCCH_POS_PIN12,
  ADCCH_POS_PIN13,
  ADCCH_POS_PIN14,
  ADCCH_POS_PIN15,
  ADCCH_POS_TEMPSENSE,
  ADCCH_POS_BANDGAP,
  ADCCH_POS_SCALED_VCC,
  ADCCH_POS_DAC
}
 ADC channel positive input. More...
 

ADC channel configuration

void adcch_write_configuration (ADC_t *adc, uint8_t ch_mask, const struct adc_channel_config *ch_conf)
 Write configuration to ADC channel. More...
 
void adcch_read_configuration (ADC_t *adc, uint8_t ch_mask, struct adc_channel_config *ch_conf)
 Read configuration from ADC channel. More...
 
static uint8_t adcch_get_gain_setting (uint8_t gain)
 Get ADC channel setting for specified gain. More...
 
static void adcch_set_input (struct adc_channel_config *ch_conf, enum adcch_positive_input pos, enum adcch_negative_input neg, uint8_t gain)
 Set ADC channel input mode, multiplexing and gain. More...
 
static void adcch_set_pin_scan (struct adc_channel_config *ch_conf, uint8_t start_offset, uint8_t max_offset)
 Set ADC channel 0 pin scan. More...
 
static void adcch_set_interrupt_mode (struct adc_channel_config *ch_conf, enum adcch_mode mode)
 Set ADC channel interrupt mode. More...
 
static void adcch_enable_interrupt (struct adc_channel_config *ch_conf)
 Enable interrupts on ADC channel. More...
 
static void adcch_disable_interrupt (struct adc_channel_config *ch_conf)
 Disable interrupts on ADC channel. More...
 
#define ADCCH_FORCE_1X_GAINSTAGE   0xff
 Force enabling of gainstage with unity gain. More...
 

#define ADCCH_FORCE_1X_GAINSTAGE   0xff

Force enabling of gainstage with unity gain.

Referenced by adcch_get_gain_setting().

#define CONFIG_ADC_INTLVL   ADC_CH_INTLVL_LO_gc

Default ADC channel interrupt level.

Note
To override the channel interrupt level, define this symbol as the desired level in conf_adc.h.

Referenced by adcch_enable_interrupt().

enum adcch_mode

ADC channel interrupt modes.

Enumerator
ADCCH_MODE_COMPLETE 

Set interrupt flag when conversions complete.

ADCCH_MODE_BELOW 

Set interrupt flag when conversion result is below compare value.

ADCCH_MODE_ABOVE 

Set interrupt flag when conversion result is above compare value.

ADC channel negative input.

Identifies the signals that can be used as negative input to the ADC channels in differential mode. Some of the input signals are only available with certain gain settings, e.g., 1x gain.

Note
The ADC must be set in signed mode to use differential measurements. For single-ended measurements, ADDCH_NEG_NONE should be specified as negative input.
Pad and internal GND are not available on all devices. See the device manual for an overview of available input signals.
Enumerator
ADCCH_NEG_PIN0 

ADC0 pin.

ADCCH_NEG_PIN1 

ADC1 pin.

ADCCH_NEG_PIN2 

ADC2 pin.

ADCCH_NEG_PIN3 

ADC3 pin.

ADCCH_NEG_PIN4 

ADC4 pin.

ADCCH_NEG_PIN5 

ADC5 pin.

ADCCH_NEG_PIN6 

ADC6 pin.

ADCCH_NEG_PIN7 

ADC7 pin.

ADCCH_NEG_PAD_GND 

PAD ground.

ADCCH_NEG_INTERNAL_GND 

Internal ground.

ADCCH_NEG_NONE 

Single ended mode.

ADC channel positive input.

Identifies the external and internal signals that can be used as positive input to the ADC channels.

Enumerator
ADCCH_POS_PIN0 
ADCCH_POS_PIN1 
ADCCH_POS_PIN2 
ADCCH_POS_PIN3 
ADCCH_POS_PIN4 
ADCCH_POS_PIN5 
ADCCH_POS_PIN6 
ADCCH_POS_PIN7 
ADCCH_POS_PIN8 
ADCCH_POS_PIN9 
ADCCH_POS_PIN10 
ADCCH_POS_PIN11 
ADCCH_POS_PIN12 
ADCCH_POS_PIN13 
ADCCH_POS_PIN14 
ADCCH_POS_PIN15 
ADCCH_POS_TEMPSENSE 

Temperature sensor.

ADCCH_POS_BANDGAP 

Bandgap reference.

ADCCH_POS_SCALED_VCC 

VCC scaled down by 10.

ADCCH_POS_DAC 

DAC output.

static void adcch_disable_interrupt ( struct adc_channel_config ch_conf)
inlinestatic

Disable interrupts on ADC channel.

Parameters
ch_confPointer to ADC channel configuration.

References adc_channel_config::intctrl.

Referenced by differential_signed_average(), main(), and single_ended_unsigned_average().

static void adcch_enable_interrupt ( struct adc_channel_config ch_conf)
inlinestatic

Enable interrupts on ADC channel.

Parameters
ch_confPointer to ADC channel configuration.

References CONFIG_ADC_INTLVL, and adc_channel_config::intctrl.

Referenced by main().

static uint8_t adcch_get_gain_setting ( uint8_t  gain)
inlinestatic

Get ADC channel setting for specified gain.

Returns the setting that corresponds to specified gain.

Parameters
gainValid gain factor for the measurement.
Returns
Gain setting of type ADC_CH_GAIN_t.

References ADC_CH_GAIN_DIV2_gc, ADCCH_FORCE_1X_GAINSTAGE, and Assert.

Referenced by adcch_set_input().

void adcch_read_configuration ( ADC_t *  adc,
uint8_t  ch_mask,
struct adc_channel_config ch_conf 
)

Read configuration from ADC channel.

Reads out the current configuration from the ADC channel to the specified buffer.

Parameters
adcPointer to ADC module.
ch_maskMask of ADC channel(s):
  • ADC_CHn , where n specifies the channel. (Only a single channel can be given in mask)
ch_confPointer to ADC channel configuration.

References ADC_CH0, adc_disable_clock(), adc_enable_clock(), adc_get_channel(), cpu_irq_restore(), cpu_irq_save(), adc_channel_config::ctrl, adc_channel_config::intctrl, adc_channel_config::muxctrl, and adc_channel_config::scan.

Referenced by main().

static void adcch_set_input ( struct adc_channel_config ch_conf,
enum adcch_positive_input  pos,
enum adcch_negative_input  neg,
uint8_t  gain 
)
inlinestatic

Set ADC channel input mode, multiplexing and gain.

Sets up an ADC channel's input mode and multiplexing according to specified input signals, as well as the gain.

Parameters
ch_confPointer to ADC channel configuration.
posPositive input signal.
negNegative input signal:
  • ADCCH_NEG_NONE for single-ended measurements.
  • ADCCH_NEG_PINn , where n specifies a pin, for differential measurements.
  • ADDCH_x_GND , where x specified pad or internal GND, for differential measurements.
gainGain factor for measurements:
  • 1 for single-ended or differential with pin 0, 1, 2 or 3, pad or internal GND as negative input.
  • 0 (0.5x), 1, 2, 4, 8, 16, 32 or 64 for differential with pin 4, 5, 6 or 7, pad or internal GND as negative input.
  • ADCCH_FORCE_1X_GAINSTAGE to force the gain stage to be enabled with unity gain for differential measurement.
Note
The GND signals are not available on all devices. Refer to the device manual for information on available input signals.
With unity (1x) gain, some input selections may be possible both with and without the gain stage enabled. The driver will default to the configuration without gainstage to keep the current consumption as low as possible unless the user specifies ADCCH_FORCE_1X_GAINSTAGE as gain.

References ADC_CH_MUXNEG_MODE10_GND_gc, ADC_CH_MUXNEG_MODE10_INTGND_gc, ADC_CH_MUXNEG_MODE11_GND_gc, ADC_CH_MUXNEG_MODE11_INTGND_gc, adcch_get_gain_setting(), ADCCH_NEG_INTERNAL_GND, ADCCH_NEG_NONE, ADCCH_NEG_PAD_GND, ADCCH_NEG_PIN3, ADCCH_NEG_PIN4, ADCCH_NEG_PIN7, ADCCH_POS_TEMPSENSE, Assert, adc_channel_config::ctrl, and adc_channel_config::muxctrl.

Referenced by differential_signed_average(), main(), and single_ended_unsigned_average().

static void adcch_set_interrupt_mode ( struct adc_channel_config ch_conf,
enum adcch_mode  mode 
)
inlinestatic

Set ADC channel interrupt mode.

Parameters
ch_confPointer to ADC channel configuration.
modeInterrupt mode to set.

References adc_channel_config::intctrl.

Referenced by differential_signed_average(), main(), and single_ended_unsigned_average().

static void adcch_set_pin_scan ( struct adc_channel_config ch_conf,
uint8_t  start_offset,
uint8_t  max_offset 
)
inlinestatic

Set ADC channel 0 pin scan.

Sets the parameters for pin scan, which enables measurements on multiple, successive input pins without any reconfiguration between conversions.

Pin scan works by adding a offset to the positive MUX setting to get the current input pin. The offset is incremented for each conversion, and is reset to 0 once a conversion with the maximum offset is done.

Parameters
ch_confPointer to the ADC channel configuration structure
start_offsetInitial offset to start pin scan at
  • 0 - max_offset
max_offsetMaximum offset for the pin scan
  • 0 to disable
  • 1 - 15 to enable
Note
Only the AVR XMEGA AU family features this setting.
Pin scan is only available on ADC channel 0.

References ADC_CH_OFFSET_gp, Assert, and adc_channel_config::scan.

void adcch_write_configuration ( ADC_t *  adc,
uint8_t  ch_mask,
const struct adc_channel_config ch_conf 
)

Write configuration to ADC channel.

Writes the specified configuration to the ADC channel.

Parameters
adcPointer to ADC module.
ch_maskMask of ADC channel(s):
  • ADC_CHn , where n specifies the channel. (Only a single channel can be given in mask)
ch_confPointer to ADC channel configuration.
Note
The specified ADC's callback function must be set before this function is called if callbacks are enabled and interrupts are enabled in the channel configuration.

References ADC_CH0, adc_disable_clock(), adc_enable_clock(), adc_get_channel(), Assert, cpu_irq_restore(), cpu_irq_save(), adc_channel_config::ctrl, adc_channel_config::intctrl, adc_channel_config::muxctrl, and adc_channel_config::scan.

Referenced by differential_signed_average(), main(), and single_ended_unsigned_average().