ATmega16/32 ADC Registers
In AVR ADC, we need to understand four main register -
- ADCH: Holds digital converted data higher byte
- ADCL: Holds digital converted data lower byte
- ADMUX: ADC Multiplexer selection register
- ADCSRA: ADC Control and status register
ATmega 16
₹299.00Price
Excluding Taxes
Steps to Program ATmega16/32 ADC
- Make the ADC channel pin as an input.
- Set ADC enable bit in ADCSRA, select the conversion speed using ADPS2 : 0. For example, we will select devisor 128.
- Select ADC reference voltage using REFS1: REFS0 in ADMUX register, for example, we will use AVcc as a reference voltage.
- Select the ADC input channel using MUX4 : 0 in ADMUX, for example, we will use channel 0.
- So our value in register ADCSRA = 0x87 and ADMUX = 0x40.
- Start conversion by setting bit ADSC in ADCSRA. E.g.ADCSRA |= (1<<ADSC);
- Wait for conversion to complete by polling ADIF bit in ADCSRA register.
- After the ADIF bit gone high, read ADCL and ADCH register to get digital output.
- Notice that read ADCL before ADCH; otherwise result will not be valid.