31.3.1 Initialization
The following steps are recommended to initialize the ADC operation:
- Configure the resolution by writing to the Resolution Selection (RESSEL) bit in the Control A (ADCn.CTRLA) register.
- Optional: Enable the Free-Running mode by writing a ‘
1
’ to the Free-Running (FREERUN) bit in ADCn.CTRLA. - Optional: Configure the number of samples to be accumulated per conversion by writing the Sample Accumulation Number Select (SAMPNUM) bits in the Control B (ADCn.CTRLB) register.
- Configure a voltage reference by writing to the Reference Selection (REFSEL) bit in the Control C (ADCn.CTRLC) register. The default is the internal voltage reference of the device (VREF, as configured there).
- Configure the CLK_ADC by writing to the Prescaler (PRESC) bit field in the Control C (ADCn.CTRLC) register.
- Configure an input by writing to the MUXPOS bit field in the MUXPOS (ADCn.MUXPOS) register.
- Optional: Enable Start Event input by
writing a ‘
1
’ to the Start Event Input (STARTEI) bit in the Event Control (ADCn.EVCTRL) register. Configure the Event System accordingly. - Enable the ADC by writing a
‘
1
’ to the ENABLE bit in ADCn.CTRLA.
Following these steps will initialize the ADC for basic measurements, which can
be triggered by an event (if configured) or by writing a ‘1
’ to the Start
Conversion (STCONV) bit in the Command (ADCn.COMMAND) register.