Many microcontrollers contain internal on-chip ADC. Typical devices would be Atmel Atmega series microcontrollers like Atmega8 and further. Internal ADC is a successive way to integrate the analog world into your embedded systems using only one microcontroller die. Many applications don’t require high speed or high accuracy ADC conversions; thus, on-chip ADC is the best choice.
Let’s look at Atmega8. It contains a 10-bit approximation ADC with an analog input multiplexer of 8-single-ended input voltage (refers to 0V) channels.
Atmega microcontrollers have separate analog supply voltage pins – AVCC (Atmega8 has known bug – digital and analog grounds are interconnected inside a chip).
The reference voltage is provided inside the chip. It is nominally 2.56V or AVCC. AREF pin is used to decouple voltage reference by a capacitor for better noise performance.
The reference voltages nay be selected between:
- Internal reference 2.56V;
- AVCC (must not differ from VCC more than ±0.3V);
- Or reference voltage can be connected to external pin AREF.
If we have 8 bit ADC, then our conversion would look like this:
Digital Code = ( Vin / Vref ) x 256
Lets say we use 5V reference and we measure 3.2V input signal. So result:
Result =( Vin * 256 ) / Vref = ( 3.2V * 256 ) / 5V = 163 = 0xA3
Just remember that on-chip ADC accuracy isn’t perfect. Atmega8 datasheet states that absolute accuracy is ±2LSB. This means that the last two bits give an error. So same our calculated result may vary. It can be like 0xA0 or 0x0xA2.
Another issue is supply voltage stability and accuracy. Let us say that voltage is 1% higher than we expect. It would be 5.05V. Then our calculation will give:
Result = ( Vin * 256 ) / Vref = ( 3.2V * 256 ) / 5.05V = 162 = 0xA2
So 1% change in voltage will change conversion result in one bit. Typically voltage may vary by 2 or 3%.
The voltage variation may occur because of supply source instability, temperature changes, loads. It is hard to avoid this. But absolute accuracy can be increased by selecting external ADC like MAX1242.