---
title: The ADC's input
heading: Sampling capacitors, source resistance, dividers and references
eyebrow: C12 · Lesson 17 · The ADC's input
xp: 40
---

::: hook
The code that reads an ADC is two lines; the circuit in front of it decides whether the reading is right. Inside a microcontroller's converter, a switch connects the pin to a small capacitor for a short **acquisition time**, then opens and converts whatever voltage the capacitor reached. If the source can't charge that capacitor in time, the reading comes out low, and no amount of code fixes it. This lesson sizes the parts around the pin: how much resistance a sensor may have, when a capacitor at the pin helps, how to scale a voltage that's too big, and where the reference fits in.
:::

::: play
- The curve is how far the sampling capacitor is from its final voltage, in 12-bit codes, as the acquisition goes on. The dashed line is half a code, the usual target.
- Raise the source resistance: the time constant grows and the curve crosses half a code later. A 100 kΩ divider needs about 9 µs, which is most of a conversion.
- The readout is the acquisition time needed: $(R_s + R_\text{sw})C_s \ln 2^{13}$.
:::

```sim plot
view: graph
x: t = 0..10 µs
y: e = 0.01..10000 codes log
slider: R = 100..100000 = 10000 Ω log
slider: C = 2..30 step 1 = 10 pF
plot: 4096*exp(-t*1e-6/((R + 1000)*C*1e-12)) | label: error
plot: 0.5 + 0*t | dashed | label: half a code
readout: acquisition time needed (µs) = (R + 1000)*C*1e-12*ln(8192)*1e6 | digits: 3
```

::: predict
## A thermistor divider has a Thévenin resistance of 50 kΩ. The ADC samples onto 10 pF for 1 µs. Roughly how far off is a reading of a full-scale step?

- [ ] Less than one code
- [ ] About 10 codes
- [x] Hundreds of codes
- [ ] The ADC compensates automatically

::: reveal
The time constant is 51 kΩ × 10 pF = 0.51 µs, so 1 µs is only about two time constants: the capacitor gets to $1 - e^{-1.96} = 86\%$ of the step, about 580 codes short of 4096 (only when the voltage has just changed a lot, as when switching channels). Either lengthen the acquisition, lower the source resistance, or put a capacitor at the pin.
:::
:::

::: nameit
## Settling

The sampling capacitor $C_s$ charges through the switch resistance $R_\text{sw}$ and the source's Thévenin resistance $R_s$. To settle within half a code of an N-bit converter from a full-scale step:

$$t_\text{acq} \ge (R_s + R_\text{sw})\,C_s \ln 2^{N+1}$$

For 12 bits, $\ln 8192 = 9.01$ time constants.

## A capacitor at the pin

A capacitor $C_\text{ext}$ much bigger than $C_s$ supplies the charge directly. When the switch closes, the two share charge, and the pin dips by $\Delta V\,C_s/(C_\text{ext} + C_s)$, where $\Delta V$ is the difference between the capacitor's old voltage and the pin's. Keeping that under half a code needs $C_\text{ext} \ge (2^{N+1} - 1)C_s$, about 82 nF for 10 pF at 12 bits. The source then has a whole sample period, not just the acquisition time, to recharge it, which also makes $R_s C_\text{ext}$ a low-pass filter: good against aliasing and noise, slow for fast signals.

## Dividers

A divider scales a large voltage into range: $V_\text{pin} = V\,R_2/(R_1 + R_2)$. Its Thévenin resistance $R_1 \parallel R_2$ is the source resistance the ADC sees, and $V/(R_1 + R_2)$ is a current it draws all the time, which matters for battery devices.

## References

The ADC reads $V/V_\text{ref}$. A reference that's 1% high makes every reading 1% low. A **ratiometric** sensor (a thermistor or potentiometer powered from the same rail as the reference) cancels the reference: both scale together.
:::

::: example
## A 10 kΩ source drives an ADC that samples onto 10 pF through 1 kΩ. What acquisition time does 12 bits need?

::: solution
1. **Time constant.** The source and the 1 kΩ switch add in series:
   $$\begin{aligned} \tau &= 11\ \text{k}\Omega \times 10\ \text{pF} \\ &= 110\ \text{ns} \end{aligned}$$
2. **Settle to 12 bits.** That takes 9.01 time constants:
   $$9.01\tau = 991\ \text{ns}$$
   about 1 µs.
3. **A weaker source.** A 100 kΩ source would need 9.1 µs.

**Answer:** about 1 µs (991 ns).
:::
:::

::: example
## A 12 V battery is measured through 100 kΩ over 33 kΩ. What does the pin see, how much current flows, and what is one code worth at the battery?

::: solution
1. **Divider ratio.**
   $$\frac{33}{133} = 0.248$$
2. **Pin voltage.**
   $$12\ \text{V} \times 0.248 = 2.98\ \text{V}$$
   safely under 3.3 V.
3. **Current.**
   $$\frac{12\ \text{V}}{133\ \text{k}\Omega} = 90\ \mu\text{A}$$
   all the time, more than the whole sleeping board in the power lesson.
4. **One code at the battery.** One code is 0.806 mV at the pin, so at the battery it's
   $$\frac{0.806\ \text{mV}}{0.248} = 3.25\ \text{mV}$$
5. **Acquisition.** The Thévenin resistance is 24.8 kΩ, so the ADC needs about 2.3 µs of acquisition, or a capacitor at the pin.

**Answer:** the pin sees 2.98 V, the divider draws 90 µA all the time, and one code is worth 3.25 mV at the battery.
:::
:::

::: example
## What capacitor at the pin makes the charge-sharing error under half a code, for a 10 pF sampling capacitor and 12 bits?

::: solution
1. **Size the capacitor.**
   $$\begin{aligned} C_\text{ext} &\ge 8191 \times 10\ \text{pF} \\ &= 82\ \text{nF} \end{aligned}$$
   so a 100 nF part works.
2. **The filter it makes.** With the 24.8 kΩ divider above, the corner is
   $$\begin{aligned} f_c &= \frac{1}{2\pi RC} \\ &= \frac{1}{2\pi (24\,800)(10^{-7})}\ \text{Hz} \\ &= 64\ \text{Hz} \end{aligned}$$
3. **What it's good for.** That's fine for a battery voltage, and far too slow for audio.

**Answer:** at least 82 nF, so a 100 nF part; with the 24.8 kΩ divider its corner is 64 Hz.
:::
:::

::: check
kind: parts
given: R = 1 | 10 | 47 | 100; C = 5 | 10 | 20; N = 10 | 12

## A source of {R} kΩ drives an {N}-bit ADC that samples onto {C} pF through 1 kΩ.

::: part
answer: (R + 1)*1000*C*1e-12*1e9
unit: ns
tolerance: 0.5%

### What is the time constant?

::: misses
- [R*1000*C*1e-12*1e9] Include the 1 kΩ switch.
- [any] $(R_s + R_\text{sw})C_s$.
:::
:::

::: part
answer: (R + 1)*1000*C*1e-12*ln(2^(N + 1))*1e6
unit: µs
tolerance: 0.5%

### What acquisition time settles a full-scale step to half a code?

::: misses
- [(R + 1)*1000*C*1e-12*ln(2^N)*1e6] Half a code is $2^{-(N+1)}$ of full scale.
- [any] $\tau \ln 2^{N+1}$.
:::
:::
:::

::: check
kind: parts
given: Rs = 10 | 50; C = 10 | 20; t = 0.5 | 1 | 2

## A {Rs} kΩ source (plus 1 kΩ switch) charges {C} pF for {t} µs after a full-scale step on a 12-bit ADC.

::: part
answer: 4096*exp(-t*1e-6/((Rs + 1)*1000*C*1e-12))
tolerance: 0.5%

### How many codes short is the reading?

::: misses
- [any] $4096\,e^{-t/\tau}$.
:::
:::

::: part
answer: (1 - exp(-t*1e-6/((Rs + 1)*1000*C*1e-12)))*100
unit: %
tolerance: 0.5%

### What fraction of the step did it reach?

::: misses
- [any] $1 - e^{-t/\tau}$.
:::
:::
:::

::: check
kind: parts
given: V = 5 | 12 | 24; R1 = 100 | 470; R2 = 10 | 22 | 33

## A {V} V supply is measured through {R1} kΩ over {R2} kΩ.

::: part
answer: V*R2/(R1 + R2)
unit: V
tolerance: 0.5%

### What does the pin see?

::: misses
- [V*R1/(R1 + R2)] The pin is across the lower resistor.
- [any] $V R_2/(R_1 + R_2)$.
:::
:::

::: part
answer: V/(R1 + R2)*1000
unit: µA
tolerance: 0.5%

### What current does the divider draw?

::: misses
- [any] $V/(R_1 + R_2)$.
:::
:::

::: part
answer: R1*R2/(R1 + R2)
unit: kΩ
tolerance: 0.5%

### What source resistance does the ADC see?

::: misses
- [R1 + R2] The Thévenin resistance is the two in parallel.
- [any] $R_1 \parallel R_2$.
:::
:::
:::

::: check
kind: parts
given: C = 5 | 10 | 20; N = 10 | 12 | 14

## An {N}-bit ADC samples onto {C} pF.

::: part
answer: (2^(N + 1) - 1)*C/1000
unit: nF
tolerance: 0.5%

### What pin capacitor keeps the charge-sharing error under half a code?

::: misses
- [any] $(2^{N+1} - 1)C_s$.
:::
:::

::: part
answer: C/((2^(N + 1) - 1)*C + C)*2^N
tolerance: 0.5%

### With exactly that capacitor, how many codes does a full-scale charge share dip the pin?

::: misses
- [any] $2^N C_s/(C_\text{ext} + C_s)$: half a code.
:::
:::
:::

::: check
kind: parts
given: R = 4.7 | 10 | 25; C = 10 | 100 | 470

## A source of {R} kΩ feeds a {C} nF capacitor at the pin.

::: part
answer: 1/(2*pi*R*1000*C*1e-9)
unit: Hz
tolerance: 0.5%

### What corner frequency does it make?

::: misses
- [any] $1/(2\pi RC)$.
:::
:::

::: part
answer: R*1000*C*1e-9*ln(8192)*1000
unit: ms
tolerance: 0.5%

### How long does a full-scale change take to settle to half a 12-bit code?

::: misses
- [any] $9.01RC$.
:::
:::
:::

::: check
kind: parts
given: e = 0.5 | 1 | 2; V = 1 | 2.5

## The 3.3 V reference is actually {e}% high, and the input is {V} V.

::: part
answer: round(V/(3.3*(1 + e/100))*4095)
tolerance: 0

### What code does the ADC give?

::: misses
- [round(V/3.3*4095)] The code is relative to the actual reference.
- [any] $V \times 4095/V_\text{ref}$.
:::
:::

::: part
answer: (V/(1 + e/100) - V)*1000
unit: mV
tolerance: 2%

### What error results if the program assumes 3.3 V?

::: misses
- [any] The reading is low by a factor $1 + e$.
:::
:::
:::

::: check
kind: choice

## A thermistor divider is powered from the same 3.3 V rail the ADC uses as its reference. The rail is 2% low. How much does the temperature reading change?

- [x] Almost nothing: the divider's output and the reference both scale with the rail
- [ ] 2%
- [ ] 4%
- [ ] It depends on the temperature

::: misses
- [2] That's the error for a sensor whose output doesn't scale with the rail.
- [3] The errors cancel instead of adding.
- [4] The ratio is independent of the rail at every temperature.
:::
:::

::: check
kind: python

## Write `acq_time(rs, rsw, cs, bits)`: the acquisition time in seconds that settles a full-scale step to half a code, and `divider(v, r1, r2)`: a tuple (pin voltage, current in amperes, Thévenin resistance).

```python starter
import math

def acq_time(rs, rsw, cs, bits):
    return 0.0

def divider(v, r1, r2):
    return (0.0, 0.0, 0.0)
```

```python solution
import math

def acq_time(rs, rsw, cs, bits):
    return (rs + rsw) * cs * math.log(2 ** (bits + 1))

def divider(v, r1, r2):
    return (v * r2 / (r1 + r2), v / (r1 + r2), r1 * r2 / (r1 + r2))
```

```python tests
assert abs(acq_time(10e3, 1e3, 10e-12, 12) - 991.2e-9) < 1e-10, "10 kΩ + 1 kΩ, 10 pF, 12 bits: 991 ns."
assert abs(acq_time(0, 1e3, 10e-12, 16) - 1e-8 * math.log(2 ** 17)) < 1e-15, "16 bits: ln 2^17 time constants."
v, i, r = divider(12, 100e3, 33e3)
assert abs(v - 2.977) < 1e-3, "12 V through 100k over 33k: 2.977 V."
assert abs(i - 90.2e-6) < 1e-7, "90.2 µA."
assert abs(r - 24812) < 1, "100k ∥ 33k = 24.8 kΩ."
```

::: right
Right. With these two you can check any sensor's connection to the ADC before building it.
:::
:::

::: explain
## Why can a capacitor at the ADC pin let a high-resistance sensor be read accurately, and what does it cost?

::: model
The sampling capacitor needs a burst of charge in a short acquisition time, and a high-resistance source can't deliver it fast enough, so the reading comes out short. A much larger capacitor at the pin holds that charge ready: when the switch closes, it shares charge with the sampling capacitor and its voltage barely dips. The source then has the whole time between samples to top it back up. The cost is speed: the source resistance and the pin capacitor form a low-pass filter, so the reading follows changes only as fast as that time constant allows, and sampling too often can drain it faster than the source refills it.
:::
:::

::: practice
::: check
given: R = 5 | 22 | 68
answer: (R + 1)*1000*10e-12*ln(8192)*1e6
unit: µs
tolerance: 0.5%

## Acquisition time for a {R} kΩ source, 1 kΩ switch, 10 pF, 12 bits?

::: misses
- [any] $9.01(R_s + R_\text{sw})C_s$.
:::
:::

::: check
given: V = 6 | 15; R1 = 68 | 150; R2 = 22 | 47
answer: V*R2/(R1 + R2)
unit: V
tolerance: 0.5%

## Pin voltage for {V} V through {R1} kΩ over {R2} kΩ?

::: misses
- [any] $VR_2/(R_1 + R_2)$.
:::
:::

::: check
given: C = 4 | 8 | 16
answer: 8191*C/1000
unit: nF
tolerance: 0.5%

## Pin capacitor for half-a-code charge sharing with {C} pF at 12 bits?

::: misses
- [any] $8191C_s$.
:::
:::
:::
