ENع
→Inside an ADC
الدرس 13 · Sampling and conversion

Inside an ADC: flash and successive approximation

لم يُترجم بعد؛ يُعرض باللغة الإنجليزية

14 دقيقة10 خطوات5 أسئلةBeginner
عن هذا الدرس

An analog-to-digital converter (ADC) turns a held voltage into a whole number. Follow one input, Vin = 1.30 V, through two 3-bit designs that both answer 5 (binary 101). A flash ADC compares Vin with seven thresholds from a resistor ladder all at once and counts the ones. A successive-approximation (SAR) ADC holds Vin still and finds one bit per clock tick with a single comparator and a DAC: a binary search. It helps to know the Quantization and bit depth lesson, the Circuits lesson on voltage dividers and the lesson on binary numbers.

ستتعلّم

حدّد ما تشعر بأنك أتقنته. هذا التقييم الذاتي لا يؤثر في درجة الدرس.

شكل 13 · تفاعلي
01 / 10

The job: a voltage becomes a number

An ADC (analog-to-digital converter) turns a voltage into a whole number. Here Vin = 1.30 V, the reference is 2.00 V and we want 3 bits: 8 codes, one per 0.25 V step. The answer should be 5, binary 101.

Vref = 2.00 V    N = 3 bits
2^N = 8 codes: 0 .. 7
one step (LSB) = Vref / 2^N
               = 2.00 / 8 = 0.25 V

Vin = 1.30 V
whole steps below Vin: 1.30 / 0.25 = 5.2
code = 5  ->  binary 101
(5 × 0.25 = 1.25 V ≤ 1.30 V < 1.50 V)

plot: the code for every input from 0 to 2 V
جارٍ تحميل الرسم…
أو ← →
اقرأ الدرس خطوة بخطوة
  1. The job: a voltage becomes a number

    An ADC (analog-to-digital converter) turns a voltage into a whole number. Here Vin = 1.30 V, the reference is 2.00 V and we want 3 bits: 8 codes, one per 0.25 V step. The answer should be 5, binary 101.

    Vref = 2.00 V    N = 3 bits
    2^N = 8 codes: 0 .. 7
    one step (LSB) = Vref / 2^N
                   = 2.00 / 8 = 0.25 V
    
    Vin = 1.30 V
    whole steps below Vin: 1.30 / 0.25 = 5.2
    code = 5  ->  binary 101
    (5 × 0.25 = 1.25 V ≤ 1.30 V < 1.50 V)
    
    plot: the code for every input from 0 to 2 V
  2. The comparator: one yes-or-no

    A comparator has two inputs, + and −. Its output is 1 when the + input is higher, otherwise 0. It answers one yes-or-no question, so it is a 1-bit converter. Both designs here are built from comparators.

    comparator
      + input higher than − input  ->  1
      otherwise                    ->  0
    
    one comparator = one question
      "is Vin above this voltage?"
    
    flash ADC: 7 comparators, all at once
    SAR ADC:   1 comparator, asked 3 times
  3. A ladder of thresholds

    Eight equal resistors share the 2.00 V reference equally, 0.25 V each. The joins between them sit at 0.25, 0.50 ... 1.75 V: seven thresholds, one for each comparator's − input.

    8 equal resistors in series across Vref
    each one drops 2.00 / 8 = 0.25 V
    
    join k (from the bottom) = k × 0.25 V
      k = 1:  0.25 V
      k = 2:  0.50 V
      k = 3:  0.75 V
      k = 4:  1.00 V
      k = 5:  1.25 V
      k = 6:  1.50 V
      k = 7:  1.75 V
    
    (equal resistors share a voltage equally:
     see the Circuits lesson on voltage dividers)
  4. Flash: all seven compare at once

    Vin reaches the + input of all seven comparators at the same moment. The 5 whose threshold is below 1.30 V output 1; the 2 above output 0. Read from the highest down: 0011111, ones below Vin and zeros above, like a thermometer.

      1.30 > 1.75 ?  no  -> 0
      1.30 > 1.50 ?  no  -> 0
      1.30 > 1.25 ?  yes -> 1
      1.30 > 1.00 ?  yes -> 1
      1.30 > 0.75 ?  yes -> 1
      1.30 > 0.50 ?  yes -> 1
      1.30 > 0.25 ?  yes -> 1
    
    read top to bottom: 0011111
    a "thermometer code": all ones below,
    all zeros above the level of Vin
  5. The encoder counts the ones

    An encoder counts the ones: 5, which is 101 in binary. One comparison time and done. The price: 2^N − 1 comparators. 3 bits need 7; 8 bits need 255, so flash is rarely used much past 8 bits.

    ones counted: 5  ->  101
    
    # Python 3 with numpy
    import numpy as np
    vin = 1.30
    thr = 0.25 * np.arange(1, 8)  # taps
    ones = vin > thr        # 7 at once
    code = int(np.count_nonzero(ones))
    print(code, format(code, "03b"))
    # 5 101
    
    comparators = 2^N − 1
      N = 3: 7     N = 8: 255
  6. SAR: first, hold the input still

    Successive approximation (SAR) uses one comparator several times instead. That takes several clock ticks (beats of the chip's timer), so a sample-and-hold copies Vin onto a capacitor, then opens its switch. The held 1.30 V stays still while the bits are found.

    sample-and-hold (S/H)
      switch closed: the capacitor follows Vin
      switch open:   it keeps 1.30 V
    
    why: the SAR needs 3 clock ticks;
    a changing input would move the target
    in the middle of the search
  7. Tick 1: try the top bit

    The register tries the top bit: 100. The DAC (digital-to-analog converter) turns 100 into 4 × 0.25 = 1.00 V, half the range. Is 1.30 V higher? Yes, so the 1 stays.

    trial  100  = 4
    DAC    4 × 0.25 = 1.00 V
    compare 1.30 > 1.00 ?  yes -> keep 1
    
    code so far: 100
    Vin lies between 1.00 and 2.00 V
  8. Tick 2: try the middle bit

    Next it tries 110, which the DAC makes 1.50 V. Is 1.30 V higher? No, so that bit goes back to 0. The code is 100 and the answer lies between 1.00 and 1.50 V.

    trial  110  = 6
    DAC    6 × 0.25 = 1.50 V
    compare 1.30 > 1.50 ?  no -> clear
    
    code so far: 100
    Vin lies between 1.00 and 1.50 V
  9. Tick 3: the last bit, done

    Last, it tries 101: 1.25 V. 1.30 V is higher, so the bit stays. Three ticks, three bits: 101, the same 5 the flash found. Each tick halved the range left: a binary search.

    trial  101  = 5
    DAC    5 × 0.25 = 1.25 V
    compare 1.30 > 1.25 ?  yes -> keep 1
    result 101 = 5
    
    # Python 3
    code = 0
    for bit in (4, 2, 1):
        trial = code | bit
        if vin > trial * 0.25:  # DAC
            code = trial          # keep
    print(code, format(code, "03b"))
    # 5 101
  10. Flash or SAR?

    Flash: 7 comparators, one step. SAR: one comparator, 3 steps (N steps for N bits). Flash wins on speed; SAR on size and power. That is why microcontrollers usually carry a SAR ADC.

                 flash        SAR
    comparators  2^N − 1      1
    steps        1            N
    
    N = 3:       7 comps      3 ticks
    N = 8:       255 comps    8 ticks
    
    flash: the very fastest converters
    SAR:   small and low power,
           common inside microcontrollers

اختبار يتاح بعد الخطوة الأخيرة.