2.2 Single Conversion Mode
Task: Single Conversion on ADC channel 0
In this program the initialize()
routine is used to
initialize the ADC module. The convert()
routine has to be called
whenever the application needs an ADC conversion.
- Set the MUX bit fields (MUX3:0) in ADC’s MUX register (ADMUX) equal to 0000 to select ADC Channel 0.
- Set the ADC Enable bit (ADEN) in ADC Control and Status Register A (ADCSRA) to enable the ADC module.
- Set the ADC Pre-scalar bit fields (ADPS2:0) in ADCSRA equal to 100 to prescale the system clock by 16.
- Set the Voltage Reference bit fields (REFS1:0) in ADMUX equal to 11 to select Internal 1.1V reference.
- Set the Start Conversion bit (ADSC) in ADCSRA to start a single conversion.
- Poll (wait) for the Interrupt Flag (ADIF) bit in the ADCSRA register to be set, indicating that the conversion is completed.
- After the ADIF bit becomes high, read the ADC data register pair (ADCL/ADCH) to get the 10-bit ADC result.