Chapter 32 of 32

DAC & ADC

Everything in this tutorial so far has lived in a world of clean 0s and 1s. The real world is analog: temperature, sound pressure, light intensity and battery voltage change smoothly and can take any value. To measure a sensor, a microcontroller must turn a voltage into a number. To play music, a phone must turn numbers back into a voltage for the speaker. These two jobs are done by the ADC (analog-to-digital converter) and the DAC (digital-to-analog converter).

In this chapter we start with DACs, because most ADCs contain a DAC inside. We build the binary-weighted and R-2R ladder DACs, define the specifications (resolution, accuracy, monotonicity, settling time), and then study sampling, quantisation and the main ADC types: flash, counter-ramp, successive approximation, dual-slope and sigma-delta, with worked numerical examples of the kind asked in university exams and GATE.


The Big Picture

  analog input                                                       analog output
 (sensor, mic) ──► [anti-alias filter] ──► [ADC] ══ n-bit codes ══►
                                                                 [processor / DSP]
               ◄── [smoothing filter] ◄── [DAC] ◄═ n-bit codes ══
 (speaker, motor)

DAC: a circuit that converts an n-bit digital code D into a proportional analog voltage or current. ADC: a circuit that converts an analog input into the n-bit code whose value best represents it.


DAC Fundamentals

An ideal n-bit DAC produces an output proportional to the input code:

Vout = K × D, where D = bn−12n−1 + ... + b121 + b020 and K is the step size (the output change for one LSB, also called the resolution in volts).

Two conventions appear in books, so read questions carefully:

  • Reference-based (how R-2R DACs behave): step = Vref / 2n, and the maximum output (all 1s) is Vref(2n − 1) / 2n, one step short of Vref.

  • Full-scale-based (common in exam problems): if the question says "full-scale output is VFS" meaning the output at all 1s, then step = VFS / (2n − 1).

Percentage resolution = step / full-scale output × 100% = 100 / (2n − 1) %. It depends only on the number of bits.

Bits nLevels 2n% resolutionStep for Vref = 10 V (Vref/2n)
82560.392%39.06 mV
1010240.0978%9.77 mV
1240960.0244%2.44 mV
1665 5360.00153%0.153 mV

Binary-Weighted Resistor DAC

The simplest idea: one resistor per bit, with values R, 2R, 4R, ..., each switched between Vref and ground, all feeding the inverting input of an op-amp summing amplifier. The MSB has the smallest resistor, so it contributes the largest current.

          b3 (MSB)  ──/── R   ───┐
          b2        ──/── 2R  ───┤
          b1        ──/── 4R  ───┤          Rf
          b0 (LSB)  ──/── 8R  ───┤    ┌───/\/\/───┐
                                 │    │           │
  each switch connects its       └────┤−  \       │
  resistor to Vref (bit = 1)          │    >──────┴──► Vout
  or to ground (bit = 0)         GND ─┤+  /
                                      (op-amp: the − input is a virtual ground)

Because the op-amp holds its inverting input at 0 V (virtual ground), each resistor carries a current that depends only on its own bit. The currents add and flow through Rf:

Vout = −Rf × Vref × (b3/R + b2/2R + b1/4R + b0/8R) = −(Rf/R) × Vref × D / 8 (for 4 bits).

Example. Vref = 5 V, Rf = R/2, D = 1011 (11). Vout = −(1/2) × 5 × 11/8 = −5 × 11/16 = −3.4375 V. With Rf = R/2 the formula becomes Vout = −Vref × D / 16, so each step is 5/16 = 0.3125 V.

The problem. An n-bit version needs resistors from R to 2n−1R. For 12 bits that is R to 2048R, and each must be precise relative to the others: the MSB resistor must be accurate to better than about 1 part in 4096, or the MSB's error will be larger than the whole LSB. Precise resistors over such a wide range are very hard to make on a chip. That is why practical DACs use the R-2R ladder.

R-2R Ladder DAC

The R-2R ladder uses only two resistor values, R and 2R, however many bits there are:

  Vref ──┬────── R ──────┬────── R ──────┬────── R ──────┬
         │               │               │               │
         2R              2R              2R              2R          2R
         │               │               │               │           │
        [S3]            [S2]            [S1]            [S0]        GND
        b3 (MSB)        b2              b1              b0 (LSB)  (termination)

   each switch Si sends its 2R leg either to the op-amp's virtual ground (bit = 1)
   or to real ground (bit = 0); both are at 0 V, so the ladder currents never change.
   The currents of the "1" legs are summed by the op-amp with feedback resistor Rf.

Why it works. Look into the ladder from any node towards the right: you always see 2R (the last node has 2R to the termination in parallel with 2R in the leg: 2R ∥ 2R = R, plus the series R = 2R, and this repeats at every node). So at each node the current splits equally: half down the leg, half onwards. The leg currents are therefore I/2, I/4, I/8, I/16 from MSB to LSB, a perfect binary weighting made from two resistor values. The node voltages halve too: Vref, Vref/2, Vref/4, Vref/8.

R-2R output (n bits, feedback resistor Rf): Vout = −(Rf/R) × Vref × D / 2n. With Rf = R: Vout = −Vref × D / 2n.

Example. An 8-bit R-2R DAC with Vref = 10 V and Rf = R receives D = 10110100 (180). Vout = −10 × 180/256 = −7.03125 V. The step size is 10/256 = 39.0625 mV and the largest output (D = 255) is −9.961 V.

PointBinary-weightedR-2R ladder
Resistor valuesn different (R to 2n−1R)Only R and 2R
Resistors for n bitsnAbout 2n
Matching difficultyVery hard for n > 8Easy to match two values on a chip
UseTeaching, very low resolutionStandard in integrated DACs

DAC Specifications

  • Resolution: the number of bits, or the step size in volts.

  • Accuracy: how far the actual output can be from the ideal, often given as ±½ LSB or as a percentage of full scale.

  • Offset error: the output when D = 0 (should be 0 V).

  • Gain error: the full-scale output is too large or too small, so all steps are scaled wrongly.

  • Differential non-linearity (DNL): how much each actual step differs from the ideal 1 LSB. Integral non-linearity (INL): the worst deviation of the output curve from a straight line.

  • Monotonicity: the output never decreases when the code increases. If DNL is worse than −1 LSB, a step goes backwards and the DAC is non-monotonic, which is disastrous inside control loops and inside ADCs.

  • Settling time: the time for the output to settle within ±½ LSB of its final value after a code change. It limits the conversion rate.

A classic weak spot is the major carry transition, 0111...1 → 1000...0: every bit switches, so any mismatch between the MSB and the sum of all lower bits shows up as a large DNL error (and switching skew causes a glitch).


ADC Fundamentals: Sampling and Quantisation

Sampling

An ADC measures the input at discrete instants, at a sampling rate fs. To capture a signal without losing information, the sampling theorem (Nyquist-Shannon) requires:

fs > 2 × fmax, where fmax is the highest frequency in the signal. 2fmax is called the Nyquist rate.

If a component above fs/2 is present, it is aliased: it appears in the samples as a false lower frequency, and nothing afterwards can remove it. That is why an analog anti-aliasing low-pass filter sits before the ADC. Example: audio up to 20 kHz is sampled at 44.1 kHz (CD) or 48 kHz, leaving room for a practical filter.

Many ADC types need the input to stay still during conversion, so a sample-and-hold (S/H) circuit (a switch and a capacitor plus a buffer) captures the voltage and holds it while the conversion runs.

Quantisation

An n-bit ADC has 2n output codes. Each code represents a band of input voltages one step wide:

Step size (1 LSB): Q = Vref / 2n. The difference between the true input and the value represented by the code is the quantisation error. For an ADC whose thresholds are placed for rounding, it is at most ±Q/2 (±½ LSB); for a truncating ADC it is between 0 and 1 LSB.

For a full-scale sine wave, quantisation noise limits the signal-to-noise ratio of an ideal n-bit ADC to:

SQNR ≈ 6.02 n + 1.76 dB: each extra bit adds about 6 dB. 8 bits ≈ 49.9 dB, 12 bits ≈ 74.0 dB, 16 bits ≈ 98.1 dB.

ideal 3-bit ADC transfer curve (rounding thresholds at ½ LSB)

 code
 111 |                                        ┌─────
 110 |                                  ┌─────┘
 101 |                            ┌─────┘
 100 |                      ┌─────┘
 011 |                ┌─────┘
 010 |          ┌─────┘
 001 |    ┌─────┘
 000 |────┘
     +────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬──► Vin
          ½     1½    2½    3½    4½    5½    6½    (in LSB)
          thresholds: each code covers a band 1 LSB wide

Flash (Parallel) ADC

The fastest approach: compare the input with every threshold at the same time.

  • A resistor divider makes the 2n − 1 threshold voltages.

  • 2n − 1 comparators each compare Vin with one threshold.

  • The comparator outputs form a thermometer code (all 1s below the input level, all 0s above). A priority encoder (from Decoders & Encoders) converts it to binary.

3-bit flash ADC (7 comparators). Example: Vin between thresholds 5 and 6

 threshold 7 ── C7 ── 0
 threshold 6 ── C6 ── 0
 threshold 5 ── C5 ── 1     thermometer code 0011111
 threshold 4 ── C4 ── 1  ─────────────────────────────►  priority   ──► 101
 threshold 3 ── C3 ── 1                                  encoder
 threshold 2 ── C2 ── 1
 threshold 1 ── C1 ── 1

Conversion time: one comparator delay plus the encoder: essentially one clock. Cost: comparators double with each bit. 8 bits need 255 comparators, 10 bits need 1023. Flash ADCs are therefore used for very high speed at modest resolution (6 to 8 bits): oscilloscopes, radar, and as building blocks inside pipelined ADCs.


Counter-Ramp (Counting) ADC

The simplest approach: a counter drives a DAC, and a comparator watches whether the DAC output has passed Vin.

  1. Reset the counter to 0.

  2. On each clock, count up by 1. The DAC output rises as a staircase.

  3. When the DAC output exceeds Vin, the comparator flips and stops the counter. The count is the result.

Conversion time depends on the input: up to 2n − 1 clocks for a full-scale input, about half that on average. For 8 bits with a 1 MHz clock, the worst case is 255 µs. A tracking (servo) ADC improves this with an up/down counter that follows the input instead of restarting from 0 each time.


Successive-Approximation (SAR) ADC

The SAR ADC is the workhorse of microcontrollers (for example 10 or 12-bit ADCs on most MCUs). It replaces the counter with a binary search, finding one bit per clock, starting from the MSB:

  1. Set the MSB to 1 (all other bits 0). The DAC outputs half of Vref.

  2. If the DAC output is above Vin, the guess was too high: clear the bit. Otherwise keep it.

  3. Move to the next bit and repeat until the LSB is decided.

Conversion time = n clocks, whatever the input (plus sampling time). An 8-bit SAR needs 8 clocks where a counter-ramp ADC may need 255.

Worked Example and Simulation

An 8-bit SAR ADC with Vref = 10 V (DAC output = 10 × D / 256) converts Vin = 6.3 V. Here is a model of the algorithm in Python, together with a counter-ramp ADC for comparison:

# Successive-approximation ADC model
def sar_adc(vin, vref, n):
    """Return the n-bit code chosen by a SAR ADC (truncating type)."""
    code = 0
    for bit in reversed(range(n)):          # MSB first
        trial = code | (1 << bit)           # tentatively set this bit
        vdac = vref * trial / 2**n          # DAC output for the trial code
        keep = vdac <= vin                  # comparator decision
        print(f"bit {bit}: try {trial:0{n}b}  DAC = {vdac:7.4f} V  "
              f"{'<=' if keep else '> '} {vin} V  -> {'keep 1' if keep else 'clear to 0'}")
        if keep:
            code = trial
    return code

def counting_adc(vin, vref, n):
    """Counter-ramp ADC: count up until the DAC output exceeds vin."""
    clocks = 0
    code = 0
    while code < 2**n - 1 and vref * (code + 1) / 2**n <= vin:
        code += 1
        clocks += 1
    return code, clocks

vin, vref, n = 6.3, 10.0, 8
code = sar_adc(vin, vref, n)
print(f"SAR result: {code:08b} = {code}, DAC({code}) = {vref*code/2**n:.4f} V, "
      f"after {n} clocks")
c, k = counting_adc(vin, vref, n)
print(f"Counting ADC result: {c:08b} = {c}, after {k} clocks")

Output:

bit 7: try 10000000  DAC =  5.0000 V  <= 6.3 V  -> keep 1
bit 6: try 11000000  DAC =  7.5000 V  >  6.3 V  -> clear to 0
bit 5: try 10100000  DAC =  6.2500 V  <= 6.3 V  -> keep 1
bit 4: try 10110000  DAC =  6.8750 V  >  6.3 V  -> clear to 0
bit 3: try 10101000  DAC =  6.5625 V  >  6.3 V  -> clear to 0
bit 2: try 10100100  DAC =  6.4062 V  >  6.3 V  -> clear to 0
bit 1: try 10100010  DAC =  6.3281 V  >  6.3 V  -> clear to 0
bit 0: try 10100001  DAC =  6.2891 V  <= 6.3 V  -> keep 1
SAR result: 10100001 = 161, DAC(161) = 6.2891 V, after 8 clocks
Counting ADC result: 10100001 = 161, after 161 clocks

Both reach code 161 (6.3 × 256 / 10 = 161.28, truncated), but the SAR needs 8 clocks and the counter 161. The remaining error, 6.3 − 6.2891 = 0.0109 V, is less than one LSB (39.06 mV), as expected for a truncating converter. (The value 6.40625 is printed as 6.4062 because Python rounds the exact half to even.)

The SAR's weakness: its DAC must be accurate to the full resolution, and the input must be held constant during all n steps (hence the sample-and-hold).


Dual-Slope (Integrating) ADC

Used in digital multimeters, where accuracy and noise rejection matter more than speed:

  1. Run-up: integrate Vin for a fixed time T1 (a fixed number of clock counts N1). The integrator output ramps to a level proportional to Vin.

  2. Run-down: switch the integrator input to a reference of opposite polarity, −Vref, and count clocks until the output returns to zero. This takes T2 (N2 counts).

The integrator's slope in run-up is proportional to Vin and in run-down to Vref, and it travels the same height both ways:

Vin × T1 = Vref × T2, so N2 = N1 × Vin / Vref.

integrator output (magnitude)
      │
      │                   / \
      │               /       \
      │           /             \
      │       /                   \
      │   /                         \
      └───────────────────────────────────► time
        |<------ T1 ------>|<-- T2 -->|
              fixed           measured (∝ Vin)

  run-up slope ∝ Vin (larger Vin → higher peak, longer T2)
  run-down slope is fixed by Vref

Why it is so accurate: the R and C values of the integrator and the clock frequency appear on both sides and cancel; only Vref matters. And because the input is integrated over T1, any noise whose period divides T1 averages to zero. Choosing T1 = 20 ms (or a multiple) rejects 50 Hz mains hum, the supply frequency in India; 100 ms rejects both 50 Hz and 60 Hz.

Example. N1 = 1000 counts, Vref = 2 V, Vin = 1.234 V. N2 = 1000 × 1.234 / 2 = 617 counts. The disadvantage is speed: a conversion takes tens to hundreds of milliseconds.


Sigma-Delta (ΔΣ) ADC

A sigma-delta ADC uses a very simple 1-bit quantiser (a comparator) running at a rate many times higher than the Nyquist rate (oversampling). A feedback loop with an integrator makes the density of 1s in the output bit stream track the input. A digital decimation filter then averages this stream into high-resolution samples at a lower rate. The loop also pushes ("shapes") quantisation noise to high frequencies, where the filter removes it.

Sigma-delta converters give 16 to 24 bits of resolution and are used in audio codecs, precision measurement and sensor interfaces. Their limitation is bandwidth and latency: they suit signals from DC up to the audio range and somewhat beyond, not very fast signals.


Comparing ADC Types

TypeConversion time (n bits)HardwareTypical resolutionTypical use
Flash1 clock2n − 1 comparators6 to 8 bitsOscilloscopes, radar, very high speed
Counter-rampUp to 2n − 1 clocks (varies with input)Counter, DAC, 1 comparator8 to 12 bitsTeaching, simple slow systems
Successive approximationn clocks (fixed)SAR register, DAC, 1 comparator8 to 18 bitsMicrocontrollers, data acquisition
Dual-slopeLong: about 2 × 2n clocks or moreIntegrator, comparator, counter12 to 20+ bits (digits)Digital multimeters, panel meters
Sigma-deltaMany oversampled clocks per output sampleIntegrator, 1-bit quantiser, digital filter16 to 24 bitsAudio, precision sensors

Rule of thumb: faster means fewer bits; more bits means slower. Flash is fastest, dual-slope and sigma-delta are most precise, and SAR sits in the middle, which is why it is everywhere.


Common Mistakes

  • Mixing up step-size conventions. Vref/2n (reference-based) vs VFS/(2n − 1) (full-scale output at all 1s). Check what the question calls "full scale".

  • Wrong comparator count for flash ADCs. It is 2n − 1, not 2n and not n.

  • Assuming the counter-ramp ADC takes n clocks. That is the SAR. The counter-ramp takes up to 2n − 1.

  • Forgetting the minus sign of inverting op-amp DACs.

  • Using fs = 2 fmax exactly. The theorem needs fs strictly greater than 2 fmax, and real filters need a margin.

  • Thinking more bits always means more accuracy. Resolution is the number of bits; accuracy also depends on offset, gain, linearity and noise.


GATE and Interview Questions

Q1. A 10-bit DAC has a full-scale output of 10.23 V (at all 1s). What is the step size and the output for D = 0101101001?

Step = 10.23 / (210 − 1) = 10.23 / 1023 = 10 mV. D = 0101101001 = 256 + 64 + 32 + 8 + 1 = 361. Vout = 361 × 10 mV = 3.61 V.

Q2. How many comparators does a 6-bit flash ADC need?

26 − 1 = 63.

Q3. A 12-bit SAR ADC uses a 2 MHz clock. Ignoring sampling time, what is its conversion time? What is the worst case for a 12-bit counter-ramp ADC with the same clock?

SAR: 12 clocks × 0.5 µs = 6 µs. Counter-ramp: (212 − 1) × 0.5 µs = 4095 × 0.5 µs = 2047.5 µs (about 2 ms).

Q4. What is the quantisation step and maximum quantisation error (rounding ADC) of an 8-bit ADC with Vref = 5.12 V?

Q = 5.12 / 256 = 20 mV; maximum error = ±Q/2 = ±10 mV.

Q5. A signal contains frequencies up to 15 kHz. What is the minimum sampling rate? What happens if it is sampled at 20 kHz?

Must exceed 2 × 15 = 30 kHz. At 20 kHz, components above 10 kHz alias: a 15 kHz tone appears as 20 − 15 = 5 kHz, a false frequency that cannot be removed afterwards.

Q6. In a dual-slope ADC, N1 = 2000 counts and Vref = 1 V. The run-down takes 1450 counts. Find Vin. Does the clock frequency matter?

Vin = Vref × N2/N1 = 1 × 1450/2000 = 0.725 V. The clock frequency (and the integrator's RC) cancel out, as long as they are stable during one conversion.

Q7. Why do integrated DACs use R-2R ladders rather than binary-weighted resistors?

An R-2R ladder needs only two resistor values, which are easy to match accurately on a chip, regardless of the number of bits. A binary-weighted DAC needs a range of R to 2n−1R with ratio accuracy better than 1 LSB, which is impractical beyond about 8 bits.


Summary

  • A DAC outputs V = K × D. Step = Vref/2n (or VFS/(2n − 1) when VFS is the output at all 1s); % resolution = 100/(2n − 1).

  • Binary-weighted DAC: resistors R to 2n−1R, hard to match. R-2R ladder: two values, currents halve at each node, Vout = −(Rf/R) Vref D/2n.

  • DAC specs: resolution, accuracy, offset and gain error, DNL/INL, monotonicity, settling time.

  • ADC basics: sample at fs > 2fmax (anti-aliasing filter, sample-and-hold); step Q = Vref/2n; quantisation error ±½ LSB; SQNR ≈ 6.02n + 1.76 dB.

  • Flash: 2n − 1 comparators, 1 clock. Counter-ramp: up to 2n − 1 clocks. SAR: binary search, n clocks. Dual-slope: Vin = Vref N2/N1, slow but accurate with mains-noise rejection. Sigma-delta: oversampling + digital filtering, 16 to 24 bits.

  • This completes the Digital Logic tutorial: from gates and Boolean algebra, through combinational and sequential design, to memories, logic families and the bridge to the analog world.