Like everyone else with the ATMega, I too am playing with the ADC on the ATMega to measure voltage as a learning exercise.
This is some info I collected that some may found useful: The ATMega328 ADC voltage compared against UT61E.
Here is the collection environment:
- Since I found the USB's power quality makes a huge difference, I should point out this Arduino is powered via USB (@5.008V) connected to a laptop.
- An Arduino UNO hosts the ATMega328. A large capacitor discharges and feed the voltage into a simple OpAmp voltage follower and a .1uF as decoupler cap at OpAmp output to the Arduino. No other circuit involved.
- The UT61E reference reads at the point it enters the Arduino.
- The Arduino does not average or anything fancy - wait 229ms, read analog ports, report back at 19200, and wait till the clock ticks again.
- The conversion is the standard formula 5*adcCount/1023. As basic and native as it gets.
- The data is collected via a Java program. The JAVA program reads both the Arduino and the UT61E.
- The Arduino reports data every 229ms - a prime number so the other little things I do (like key debounce) will not be evenly divided into it reporting cycle.
- The Java program understands UT61E's overshoot and will skip a cycle when the UT61E just changed range.
- A big source of error I discovered was the time delta between the UT61E's reading and the Arduino's reading. So the dV/dT is made as small as possible. Minimum 20 data point is collected per count (>10 seconds per ADC count since UT61E samples at about 1/2 seconds).
- The Java program will wait for the next report if the one last read is too old. "How old is too old" is based on experience from the data collected thus far in the run. Total time delta Sum(time of UT61E's number - time of Arduino's number) for all records is under 700ms.
- The error plotted is the average of AbsoluteValue(error percentage) of that ADC count. So, a +10% is not going to cancel out a -10%. Which ever ADC (A0-A3) reports the worst error is the one plotted.
My comment:
With a good USB power source, it does very well on the high ranges but too dependent on the quality of the USB power. At over 2.5 volt, you can count on better than 1% if USB power is very near but over 5V. I cannot get consistent results (when USB powered) between different machines or even different ports. My PCI powered USB/firewire card compared to the USB ports on the mother board has a 100mV USB voltage difference. The mother board USB power is also different than the USB power on my laptops. That little delta shows up in the results.
At the low end, it is hopeless unless something is done about it. Averaging and other techniques, I have achieved better results in my learning exercise. I collected this native328 results as the base line to see if the results my learning exercise is better, and if so, how much better.
Just thinking some may be interested in how well the native-ATMega328 ADC numbers look.