In Sample Accumulator mode the ADC can add up to 64 samples in an accumulator register,
thus filtering the signal and reducing the noise. It is useful when reading analog
sensor data where a smooth signal is required. By using a hardware accumulator instead
of adding those readings in software, it reduces the CPU load. To activate this mode,
the Sample Accumulation Number in the ADC0.CTRLB register must be set in addition to the
normal ADC initialization.Figure 5-1. ADC0.CTRLB - Set the SAMPNUM
Bit
ADC0.CTRLB = ADC_SAMPNUM_ACC64_gc;
The ADC conversion is started by setting the STCONV bit in the ADC0.COMMAND
register.
ADC0.COMMAND = ADC_STCONV_bm;
The samples will be added up in the ADC0.RES register. The ADC_RESRDY flag is set after
the number of samples specified in ADC0.CTRLB is
acquired.
while (!(ADC0.INTFLAGS & ADC_RESRDY_bm))
{
;
}
The user can read that value and divide it by the number of samples, to get an average
value.