2.4 ADC Burst Mode

With the setup from Single mode, configuring the ADC to Burst mode requires only a few lines of code to be changed.

Todo: Edit adc_init() to configure the ADC as listed below:
  • 1024 sample accumulation with free running
  • ADC sampling in bursts
  1. Configure the SAMPNUM bit field in the Control F (ADC0.CTRLF) register:
    ADC0.CTRLF = ADC_SAMPNUM_ACC1024_gc | ADC_FREERUN_bm;
    Info: When the ADC is in Burst mode, a configurable number of samples are accumulated into a single ADC result (Sample Accumulation). The RESULT register holds the sum of these accumulations and can be used as an average result of the sample.
  2. Configure the mode of operation for the ADC to Burst by writing to the MODE bit field in the COMMAND (ADC0.COMMAND) register:
    ADC0.COMMAND = ADC_MODE_BURST_gc;
  3. Verify that the solution builds with no errors by selecting Build → Build Solution from the top menu bar in Microchip Studio or pressing the F7 key.
Result: Code for initializing the ADC is complete, and the expected result is listed below:
void adc_init()
{
	ADC0.CTRLA = ADC_ENABLE_bm;
	ADC0.CTRLB = ADC_PRESC_DIV4_gc;
	ADC0.CTRLC = ADC_REFSEL_VDD_gc | TIMEBASE_VALUE << ADC_TIMEBASE_gp;
	ADC0.CTRLE = 3;
	ADC0.CTRLF = ADC_SAMPNUM_ACC1024_gc | ADC_FREERUN_bm ;
	ADC0.MUXPOS = ADC_MUXPOS_AIN5_gc;
	ADC0.COMMAND = ADC_MODE_BURST_gc;   
}