The limitations of the ADC Apr 2016
The Analog-to-Digital-Converter (ADC) we all know from Arduinos and other µCs is a marvel of integration and electronics engineering. Able to measure at rates of over a million samples per second (depending on the µC), you can just select an I/O pin, start an ADC conversion, wait briefly, and then you get a reading back - usually either 0..1023 for a 10-bit ADC or 0..4095 for a 12-bit ADC, representing input signals from 0..3.3V or 0..5V. On a chip stuffed with mostly digital logic gates, that’s close to sheer magic.
Internally, an ADC is usually implemented as follows (image from EEWeb):
I.e. some electronics “in front” of the µC, then inside a multiplexer which connects a specified pin to the actual ADC, then a sampling capacitor, and then an ADC based on a Successive Approximation register. This diagram can explain many properties of an ADC, as you will see.
But first, the input: being part of a µC chip powered at 3.3V (or 5V), means that the input signal must stay within that 0..3.3V range at all times - anything beyond that can damage the entire chip. Everything below assumes a 3.3V supply, by the way - as is common for ARM-based chips. Note that even if some of a chip’s pins are “5V tolerant”, this doesn’t apply when using the ADC!
Limitation #1 - Whatever you do, never connect a raw voltage < 0V or > 3.3V to an ADC pin.
Next: the multiplexer. Most lower-end ARM chips have one, sometimes two, ADC converters. They can still read analog voltages on many pins, because of the multiplexer, but never at the same time. An ADC busy with one measurement can’t do another measurement at the same time. You can measure N voltages one after the other, but that’ll take N times as much time.
Limitation #2 - An ADC can only be used with one pin at a time. Voltages on multiple pins need to be measured one after the other (this is usually not such a big deal if the ADC is fast).
The third element in the circuit is the sampling capacitor, and the resistance of the input circuit and multiplexer feeding it. Together, these form a low-pass filter which limits the rate of change of the signal seen by the ADC. This can have surprising effects. for example when the input comes from a resistor divider with values in the MΩ range. When reading different channels, that sampling capacitor needs to charge or discharge again when the multiplexer changes - so that even a constant voltage may require some time to accurately show up on the ADC.
Limitation #3 - Switching channels can take time, especially when the switching needs to be very frequent or when the input source has a relatively high input resistance / impedance. Sometimes it’s better to switch to a channel, and simply throw away the first reading(s).
The final issue is a complex theoretical one, but nevertheless one you need to be aware of. The Nyquist–Shannon sampling theorem can be boiled down to a very simple guideline: you need to sample at least twice as fast as the highest frequency present in the input signal. If you don’t know what frequencies are present, you have to insert a low-pass filter to keep high ones out.
So for DC, i.e. more or less constant voltages, we can simply ignore the issue. And if the input source is a microphone for example, we just need to sample at twice the maximum frequency picked up by the mike, probably sampling somewhere in the range 10..50 KHz will be fine. If the input is derived from AC mains, with no extreme spikes, then sampling at 1000 Hz will be fine.
Just don’t expect to get anything meaningful out of an ADC by reading at say 50 or even 100 samples per second, when the input might have a certain amount of AC mains “hum” pickup.
Limitation #4 - ADC’s can’t report anything meaningful if the signal can change faster than half the sampling rate. If you measure a signal 60 times per second, and the signal is a pure 50 Hz sine wave, the ADC will “see” a (pure!) 10 Hz sine wave - this effect is called aliasing.
So how do we measure voltages which might be either positive or negative? - Coming up next!