Microchip® Advanced Software Framework

Quickstart guide for SAM ADCIFE driver

This is the quickstart guide for the SAM ADCIFE driver, with step-by-step instructions on how to configure and use the driver in a selection of use cases.

The use cases contain several code fragments. The code fragments in the steps for setup can be copied into a custom initialization function, while the steps for usage can be copied into, e.g., the main application function.

Basic use case

In this basic use case, the ADCIFE module and single channel are configured for:

  • 12-bit, unsigned conversions
  • Internal bandgap as 1.0 V reference
  • ADC clock rate of at most 1.8 MHz and maximum sample rate is 300 KHz
  • Software triggering of conversions
  • Interrupt-based conversion handling
  • Single channel measurement
  • ADC_CHANNEL_13 as positive input

Prerequisites

  1. System Clock Management (Sysclock)

Setup steps

Example code

Add to application C-file:

void adcife_read_conv_result(void)
{
// Check the ADC conversion status
if ((adc_get_status(&g_adc_inst) & ADCIFE_SR_SEOC) == ADCIFE_SR_SEOC){
g_adc_sample_data[0] = adc_get_last_conv_value(&g_adc_inst);
adc_clear_status(&g_adc_inst, ADCIFE_SCR_SEOC);
}
}
struct adc_config adc_cfg = {
// System clock division factor is 16
// The APB clock is used
.clksel = ADC_CLKSEL_APBCLK,
// Max speed is 150K
.speed = ADC_SPEED_150K,
// ADC Reference voltage is internal 1.0V
.refsel = ADC_REFSEL_0,
// Enables the Startup time
.start_up = CONFIG_ADC_STARTUP
};
struct adc_seq_config adc_seq_cfg = {
// Select Vref for shift cycle
// Pad Ground
.muxneg = ADC_MUXNEG_1,
// DAC internal
.muxpos = ADC_MUXPOS_3,
// Enables the internal voltage sources
.internal = ADC_INTERNAL_3,
// Disables the ADC gain error reduction
.gcomp = ADC_GCOMP_DIS,
// Disables the HWLA mode
.hwla = ADC_HWLA_DIS,
// 12-bits resolution
// Enables the single-ended mode
};
void adc_setup(void)
{
adc_init(&g_adc_inst, ADCIFE, &adc_cfg);
adc_ch_set_config(&g_adc_inst, &adc_ch_cfg);
adc_set_callback(&g_adc_inst, ADC_SEQ_SEOC, adcife_read_conv_result,
ADCIFE_IRQn, 1);
}

Workflow

  1. Define the interrupt service handler in the application:
  2. Initialize ADC Module:
  3. Enable ADC Module:
  4. Configure ADC single sequencer with specified value.:
  5. Set callback for ADC:

Usage steps

Example code

Add to, e.g., main loop in application C-file:

Workflow

  1. Start ADC conversion on channel: