31.3.2 Initialization
The following steps are recommended to initialize ADC operation:
- Configure the ADC voltage reference in the Voltage Reference (VREF) peripheral.
- Optional: Select between Single-Ended or Differential mode by writing to the Conversion Mode (CONVMODE) bit in the Control A (ADCn.CTRLA) register.
- Configure the resolution by writing to the Resolution Selection (RESSEL) bit field in the ADCn.CTRLA register.
- Optional: Configure to left adjust by
writing a ‘
1
’ to the Left Adjust Result (LEFTADJ) bit in the ADCn.CTRLA register. - Optional: Select the Free-Running mode by writing a ‘
1
’ to the Free-Running (FREERUN) bit in the ADCn.CTRLA register. - Optional: Configure the number of samples to be accumulated per conversion by writing to the Sample Accumulation Number Select (SAMPNUM) bit field in the Control B (ADCn.CTRLB) register.
- Configure the ADC clock (CLK_ADC) by writing to the Prescaler (PRESC) bit field in the Control C (ADCn.CTRLC) register.
- Select the positive ADC input by writing to the MUXPOS bit field in the ADCn.MUXPOS register.
- Optional: Select the negative ADC input by writing to the MUXNEG bit field in the ADCn.MUXNEG register.
- Optional: Enable Start Event input by
writing a ‘
1
’ to the Start Event Input (STARTEI) bit in the Event Control (ADCn.EVCTRL) register, and configure the Event System accordingly. - Enable the ADC by writing a
‘
1
’ to the ADC Enable (ENABLE) bit in the ADCn.CTRLA register.
Following these steps will initialize the ADC for basic measurements.
For details about the start-up time of the VREF peripheral, refer to the Electrical Characteristics section.
The ADC does not consume power when the ENABLE bit is ‘0
’. The
ADC generates a 10- or 12-bit result which can be read from the Result (ADCn.RES)
register.
Note: Changing the following registers during a
conversion will give unpredictable results:
- In ADCn.CTRLA:
- Conversion Mode (CONVMODE) bit
- Left Adjust Result (LEFTADJ) bit
- Resolution Selection (RESSEL) bit field
- In ADCn.CTRLB:
- Sample Accumulation Number Select (SAMPNUM) bit field
- In ADCn.CTRLC:
- Prescaler (PRESC) bit field