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