Notes on ADC
1- the ADC operates within a frequency range of 50kHz to 200kHz. But the CPU clock
frequency is much higher (in the order of MHz). So to achieve it, frequency division must
take place. The prescaler acts as this division factor. It produces desired frequency from
the external higher frequency. There are some predefined division factors – 2, 4, 8, 16,
32, 64, and 128. For example, a prescaler of 64 implies F_ADC = F_CPU/64. For
F_CPU = 16MHz, F_ADC = 16M/64 = 250kHz.
2- There is a trade-off between frequency and accuracy. Greater the frequency, lesser
the accuracy and vice-versa. So, if your application is not sophisticated and doesn’t
require much accuracy, you could go for higher frequencies.
ADC Registers
1- ADMUX – ADC Multiplexer Selection Register
Bits 7:6 – REFS1:0 – Reference Selection Bits – These bits are used to choose the
reference voltage. The following combinations are used.
The ADC needs a reference voltage to work upon. For this we have a three pins
AREF, AVCC and GND. We can supply our own reference voltage across AREF
and GND. For this, choose the first option. Apart from this case, you can either
connect a capacitor across AREF pin and ground it to prevent from noise, or you
may choose to leave it unconnected. If you want to use the VCC (+5V), choose
the second option. Or else, choose the last option for internal Vref.
Let’s choose the second option for Vcc = 5V.
Bit 5 – ADLAR – ADC Left Adjust Result – Make it ‘1’ to Left Adjust the ADC Result.
We will discuss about this a bit later.
Bits 4:0 – MUX4:0 – Analog Channel and Gain Selection Bits – There are 8 ADC
channels (PA0…PA7). Which one do we choose? Choose any one! It doesn’t matter.
How to choose? You can choose it by setting these bits. Since there are 5 bits, it
1- the ADC operates within a frequency range of 50kHz to 200kHz. But the CPU clock
frequency is much higher (in the order of MHz). So to achieve it, frequency division must
take place. The prescaler acts as this division factor. It produces desired frequency from
the external higher frequency. There are some predefined division factors – 2, 4, 8, 16,
32, 64, and 128. For example, a prescaler of 64 implies F_ADC = F_CPU/64. For
F_CPU = 16MHz, F_ADC = 16M/64 = 250kHz.
2- There is a trade-off between frequency and accuracy. Greater the frequency, lesser
the accuracy and vice-versa. So, if your application is not sophisticated and doesn’t
require much accuracy, you could go for higher frequencies.
ADC Registers
1- ADMUX – ADC Multiplexer Selection Register
Bits 7:6 – REFS1:0 – Reference Selection Bits – These bits are used to choose the
reference voltage. The following combinations are used.
The ADC needs a reference voltage to work upon. For this we have a three pins
AREF, AVCC and GND. We can supply our own reference voltage across AREF
and GND. For this, choose the first option. Apart from this case, you can either
connect a capacitor across AREF pin and ground it to prevent from noise, or you
may choose to leave it unconnected. If you want to use the VCC (+5V), choose
the second option. Or else, choose the last option for internal Vref.
Let’s choose the second option for Vcc = 5V.
Bit 5 – ADLAR – ADC Left Adjust Result – Make it ‘1’ to Left Adjust the ADC Result.
We will discuss about this a bit later.
Bits 4:0 – MUX4:0 – Analog Channel and Gain Selection Bits – There are 8 ADC
channels (PA0…PA7). Which one do we choose? Choose any one! It doesn’t matter.
How to choose? You can choose it by setting these bits. Since there are 5 bits, it