Analog-to-digital converters (ADCs) are incredibly useful for turning real-world phenomena into values we can use in programming projects. But how can an ADC convert analog signals into digital ones we can use anywhere?

What Are ADCs Used For?

You’ll find ADCs just about everywhere. They’re on your phone, converting your voice into a string of binary values. They’re in your car, measuring the rotation of your wheels. They’re in oscilloscopes, helping to capture signals and represent them. Yet, the place most people will have used them is the world of video and audio, where getting light and sound into a digital space is fundamental.

What Is a Sample Rate? How Does Sample Rate Affect an ADC?

One of the most critical headline metrics of an ADC is the sample rate: the number of readings taken every second.

A very high-end oscilloscope might take ten billion samples per second. The plucky little MCP3008 ADC can take a relatively modest two hundred thousand. In the audio world, a sample rate of 44,100 per second (44.1 kHz) is typical.

animation illustrating how bit depth works

The more samples we take, the more accurately we can represent a signal. Sometimes, this is essential; sometimes, it’s not. Let’s say we’re building a fader bank (designed to control electronics, like you’d see on a lighting or audio desk) with a few dozen potentiometers. In this case, the values we need to measure are unlikely to change millions of times per second since our fingers can’t move that quickly. We just need enough samples for the result to be smooth and responsive.

What Is Bitrate? Does Bitrate Affect the Quality of an ADC?

We should also think about the quality of the sample we’re getting. This is largely determined by the bitrate, which tells us how many on-off states we can use to digitally represent the voltage. The more bits we have, the more possible values we can record in any given sample and the smoother and more precise the end result.

We’ve written about binary and how it works, so if you’re unsure, that’s a good place to get started. How many bits do we need? Again, it depends on what we’re trying to accomplish. Sometimes, we might be limited by the protocol we’re using. For example, the MIDI 1.0 protocol is limited to seven-bit (and occasionally fourteen-bit) values. In other cases, the limiting factor might be human perception. If the increased fidelity doesn’t produce any perceptible improvement in the result, it might not be worthwhile.

a graph demonstrating SAR adc works

How Does Multiplexing Improve ADC Quality?

Popular ADC chips like theADS1115and theMCP3008offer many inputs. But under the hood, they really only contain a single ADC. This is possible because of the multiplexers built into these devices. Multiplexers are absolutely everywhere in the world of electronics and telecommunications. They’re digital switches that act as traffic control for your ADC. The ADC might sample one channel, and then the next, and then the next. So, if you have eight channels and a sample rate of 200,000, you can rotate through all of them, taking 25,000 samples per channel.

What Types of ADC Are There?

ADCs work in various ways, depending on the cost and capabilities required.

AFlash ADCworks via a very complex voltage divider. A bank of resistors divides the reference voltage into increments, which are then tested against the input via a bank of comparators. Flash ADCs are lightning quick, but they’re limited when it comes to bit depth because of the number of comparators required. They’re also power-hungry for the same reason.

animation illustrating phase shift flattening waveform

ASubranging ADCseeks to offset these weaknesses by splitting the work between two separate units: one to roughly work out the voltage and then a second to work it out precisely. By splitting things up, we can decrease the number of comparators. Some subranging ADCs will split the work into three stages, with error correction built in along the way.

SAR (Successive Approximation Register) ADCs do their work viaa kind of binary search. Suppose we have eight bits to fill. The SAR will start from 10000000, which is the middle value (00000000 being the bottom and 11111111 being the top). If the voltage exceeds this midpoint, the SAR will keep the leftmost digit as 1; if it doesn’t, the SAR will set the leftmost digit to 0. We can repeat the process with the next digit and so on recursively. This will cause the guessed value to move toward the actual value gradually:

animation showing aliasing

In this way, we continually narrow the search, splitting the possibilities in half and asking whether the result is higher or lower than the mid-point. In this case, the value is somewhere between 0 and 255; after a few iterations, the ADC has worked out that it’s around 77.

Sigma-deltaconverters are probably the most difficult to understand. They’re used for high-precision musical and signal-measuring applications. They work by oversampling a signal and refining the result using fiendishly complicated filtering and mathematics. This process effectively reduces the sample rate while increasing precision. These ADCs are great when noise and precision matter more than speed.

animation showing how more samples creates a better waveform

Finally, we haveIntegrating ADCs, which are even slower than sigma-delta ones. They work with the help of a capacitor, the rate of whose charge can be used to determine the input voltage. The sample rate here is often synchronized with the power supply frequency, which can be used to keep noise to an absolute minimum.

What Is Nyquist-Shannon Theory?

Let’s say we want to describe an analog signal digitally. To do this, we need at least two points for every given cycle: one at the top and one at the bottom. Thus, our sampling frequency must be at least twice the highest frequency we expect to measure.

This is known as the Nyquist frequency, after Swedish-American physicist Harry Nyquist. The theory is named after Nyquist and Claude Shannon (a preeminent mathematician and cryptographer) but not after Edmund Whittaker, who came up with the idea before either of them.

Whoever we credit with the theory, there’s a problem with it. It’s impossible to know in advance when the top and bottom of a waveform will arrive. What if we take our samples midway up the incoming waveform? Observe how a shift in the incoming signal might flatten our captured result out completely:

Or even hallucinate new waveforms that didn’t even exist before:

These hallucinations are known asaliases.

The Problem With Aliasing

You’ll probably be familiar with the “wagon wheel” illusion that sometimes occurs when a spinning object is filmed. The wheels on a car, or the blades on a helicopter, appear to be turning backward—only very slowly. In some cases, the blades might stop entirely (with frankly weird results—check out the video below!).

While playing an older video game, you might also have noticed that parallel lines sometimes produce strange warping artifacts. Fences, staircases, and stripey jumpers begin to look very peculiar indeed. Or what about those strange whistling sounds you sometimes get when listening to someone speak over a poor-quality digital connection? It’s distortion, but a particular kind of distortion. What’s with all of those ugly frequencies emerging from the noise? If you’re listening to harmonically rich content, like a drumkit, the effect is even more obvious—especially in the high end.

If you understand the cause of one of these, you’re on your way to understanding all of them. In the case of the wagon wheel, the fixed frame rate means that we can’t capture the motion properly. If something rotates 350° every frame, it’s only natural to perceive that it’s actually moved backward by 10°. In other words, there isn’t enough information to faithfully represent what’s happening. The samples we’re taking are misaligned with what we’re trying to measure.

This isn’t a problem that’s unique to analog-digital conversion. In many of these cases, we’re converting one kind of digital signal to another.

So, what’s the solution? There are several. We could apply a special filter to deal with these artifacts, which is what many ADCs do under the hood. Or, we can take many, many more samples than we need. The more samples we take, the more accurate our picture of the wave becomes:

Sample With Greater Quality For the Best Results

If you find this sort of thing interesting, the good news is that we’ve barely dipped our toe into this subject. There are depths to plumb here: ADCs are extremely complicated.

But from the point of view of the end user or of the average Arduino enthusiast, they’re also very simple. Voltages go in, and numbers come out. So, whatever you’re seeking to measure—whether it’s the moisture content of a patch of soil, the oscillations of a human voice box, or a stream of photons refracting through a lens—the chances are good there’s an ADC that will do the job.