---
title: Tri-state and open-drain outputs
heading: Letting several chips share one wire
eyebrow: C7 · Lesson 10 · Tri-state and open-drain outputs
xp: 40
---

::: hook
An ordinary CMOS output always drives its wire: high or low. Connect two such outputs to one wire and, sooner or later, one drives high while the other drives low, and a large current flows from the supply through both to ground. Buses that several chips share need outputs that can step aside. There are two ways to do it: an output that can turn both its transistors off, and one that only ever pulls down.

::: play
- The curve is an open-drain bus line rising after the last device lets go: a pull-up resistor charges the bus capacitance.
- Raise the resistor or the capacitance and the edge slows. The marked readout is the 30% to 70% rise time that bus standards specify.
- A smaller resistor speeds the edge, but every device pulling low must then sink more current.
:::
:::

```sim plot
view: graph
x: t = 0..3 µs
y: v = 0..3.6 V
slider: R = 0.5..10 = 2.2 kΩ log
slider: C = 50..400 = 200 pF
plot: 3.3*(1 - exp(-t*1e-6/(R*1e3*C*1e-12))) | label: bus voltage | samples: 300
readout: 30% to 70% rise time, ns = log(7/3)/log(2.718281828)*R*1e3*C*1e-12*1e9 | digits: 3
readout: current to hold it low, mA = (3.3 - 0.4)/R | digits: 3
```

::: predict
## Two tri-state drivers on a 3.3 V bus are enabled at once by mistake; one drives high and the other low. Each has 50 Ω of on-resistance. What happens?

- [ ] The bus settles at 1.65 V and nothing else happens
- [x] About 33 mA flows from the supply through both drivers, heating them, while the bus sits near 1.65 V
- [ ] The low driver wins and the bus reads 0
- [ ] Nothing: tri-state outputs can't conflict

::: reveal
$\frac{3.3\text{ V}}{100\ \Omega}$ = 33 mA flows through both outputs, dissipating 0.11 W between them, and the bus sits at an invalid level near the middle. This is **bus contention**. A moment of it is survivable; sustained, it can damage the drivers. Bus protocols are designed so that at most one driver is ever enabled.
:::
:::

::: nameit
## Tri-state outputs

A tri-state driver has an enable: enabled, it drives 0 or 1 like any output; disabled, both its transistors are off and the output floats in a **high-impedance** state (Z). Several drivers can share a bus if exactly one is enabled at a time. If none is enabled the bus floats, so it's usually held by a weak pull-up or a bus keeper; if two are enabled with different values, they fight, with a current of $\frac{V_{DD}}{R_{on1} + R_{on2}}$.

## Open-drain outputs

An open-drain (or open-collector) output has only the pull-down transistor. It can pull the wire low or let go; a **pull-up resistor** $R_p$ returns it high. Any device pulling low wins, so the line computes the AND of all the devices' outputs, a **wired-AND**, and there's never contention. Shared interrupt lines, resets and the I²C bus use it.

## Choosing the pull-up

When the last device lets go, the line rises as an RC charge, from 30% to 70% of $V_{DD}$ in

$$t_r = R_pC_\text{bus}\ln\frac73 = 0.847R_pC_\text{bus}.$$

A bus standard caps $t_r$, which caps $R_p$. Each device must also be able to pull the line below its $V_{OL}$ while sinking the pull-up's current, which sets a minimum:

$$R_p \ge \frac{V_{DD} - V_{OL}}{I_{OL}}.$$

A smaller $R_p$ gives faster edges but more current and power whenever the line is low.
:::

::: example
## An I²C bus on 3.3 V has 400 pF of capacitance, a 1 µs rise-time limit, and devices that can sink 3 mA at 0.4 V. What pull-up resistors are allowed?

::: solution
1. **Rise-time limit.**
   $$\begin{aligned} R_p &\le \frac{1\ \mu\text{s}}{0.847 \times 400\ \text{pF}} \\ &= 2.95\ \text{k}\Omega \end{aligned}$$
2. **Sink-current limit.**
   $$\begin{aligned} R_p &\ge \frac{3.3 - 0.4}{3\ \text{mA}} \\ &= 967\ \Omega \end{aligned}$$
3. **Pick a value.** Any value between, such as 2.2 kΩ, works.
4. **The faster mode.** At 200 pF and a 300 ns limit, the maximum drops to 1.77 kΩ, so heavily loaded fast buses need stronger pull-ups or current-source drivers.

**Answer:** anything from 967 Ω to 2.95 kΩ, such as 2.2 kΩ.
:::
:::

::: example
## Three devices share an open-drain interrupt line with a pull-up. Device A outputs 1, B outputs 0, C outputs 1. What does the line read, and what if B lets go?

::: solution
1. **B pulls the line low.** B's transistor is on, so the line reads 0:
   $$1 \cdot 0 \cdot 1 = 0$$
   a wired-AND.
2. **B lets go.** No device pulls low, and the pull-up returns the line to 1.
3. **Read it as an interrupt.** Read as an active-low interrupt, the line says "someone needs service" whenever any device pulls it, which is exactly what a shared interrupt needs.

**Answer:** the line reads 0, and returns to 1 when B lets go.
:::
:::

::: example
## How much does the contention in the predict cost, and how much does a pull-up of 2.2 kΩ on 3.3 V cost while a device holds the line low?

::: solution
1. **Contention.** 33 mA flows, and the power is
   $$\begin{aligned} P &= \frac{3.3^2}{100} \\ &= 0.11\ \text{W} \end{aligned}$$
   split between the two fighting outputs.
2. **The pull-up.** While the line is low,
   $$\begin{aligned} I &= \frac{3.3 - 0.4}{2200} \\ &= 1.3\ \text{mA} \end{aligned}$$
   flows, about 4 mW.
3. **Compare.** The open-drain bus spends a little power continuously in exchange for never fighting.

**Answer:** contention costs 0.11 W (33 mA); the pull-up costs about 4 mW (1.3 mA) while the line is held low.
:::
:::

::: check
kind: parts
given: V = 1.8 | 3.3 | 5; R1 = 20 | 50; R2 = 30 | 80

## Two enabled tri-state drivers on a {V} V bus fight: one with {R1} Ω drives high, the other with {R2} Ω drives low.

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

### What current flows?

::: misses
- [V/R1*1000] The two on-resistances are in series.
- [any] $\frac{V_{DD}}{R_{on1} + R_{on2}}$.
:::
:::

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

### What voltage does the bus sit at?

::: misses
- [V*R1/(R1 + R2)] The bus is the divider's tap above the low driver's resistance.
- [any] $V_{DD}\frac{R_{on2}}{R_{on1} + R_{on2}}$.
:::
:::
:::

::: check
kind: parts
given: V = 3.3 | 5; C = 100 | 400; t = 0.3 | 1; I = 3 | 20; Vol = 0.4 | 0.6

## An open-drain bus on {V} V has {C} pF, a {t} µs rise-time limit, and devices that sink {I} mA at {Vol} V.

::: part
answer: t*1e-6/(log(7/3)/log(2.718281828)*C*1e-12)/1000
unit: kΩ
tolerance: 0.5%

### What's the largest pull-up?

::: misses
- [t*1e-6/(C*1e-12)/1000] The 30% to 70% rise takes $0.847RC$, not RC.
- [any] $\frac{t_r}{0.847C_\text{bus}}$.
:::
:::

::: part
answer: (V - Vol)/I
unit: kΩ
tolerance: 0.5%

### What's the smallest?

::: misses
- [V/I] The device only has to reach $V_{OL}$.
- [any] $\frac{V_{DD} - V_{OL}}{I_{OL}}$.
:::
:::
:::

::: check
kind: boolean
vars: A, B, C
answer: A & B & C
ops: and, or, not

## Three open-drain outputs A, B and C share a line with a pull-up. Write the line's value.

::: right
Right: a wired-AND, $ABC$. Any output pulling low makes the line low.
:::

::: misses
- [any] Not yet. The line is high only when no device pulls it low.
:::
:::

::: check
given: R = 1 | 2.2 | 4.7 | 10; C = 50 | 200 | 400
answer: log(7/3)/log(2.718281828)*R*1e3*C*1e-12*1e9
unit: ns
tolerance: 0.5%

## What's the 30% to 70% rise time of an open-drain line with a {R} kΩ pull-up and {C} pF?

::: right
Right. $0.847R_pC$ = {answer}.
:::

::: misses
- [R*1e3*C*1e-12*1e9] From 30% to 70% takes $\ln\frac73$ time constants.
- [any] $R_pC\ln\frac73$.
:::
:::

::: check
kind: choice

## Several chips share a bus where any of them may need to signal a fault at any moment, without coordination. Which output type should drive it?

- [ ] Ordinary push-pull outputs
- [ ] Tri-state outputs, each enabled when it has a fault
- [x] Open-drain outputs with a pull-up
- [ ] Any type; the bus will sort it out

::: right
Right. Open-drain outputs can all pull at once without contention, so they need no coordination.
:::

::: misses
- [1] Push-pull outputs would fight whenever two disagree.
- [2] Two chips signaling at once would both be enabled, and might drive different values.
- [4] Conflicting drivers waste power and can be damaged.
:::
:::

::: check
kind: python

## Write `pullup_range(V, C, tr, Vol, Iol)` returning `(Rmin, Rmax)` in ohms for an open-drain bus: the smallest pull-up the drivers can overcome and the largest that meets the 30% to 70% rise time `tr`.

```python starter
def pullup_range(V, C, tr, Vol, Iol):
    return V / Iol, tr / C

print(pullup_range(3.3, 400e-12, 1e-6, 0.4, 3e-3))
```

```python solution
import math

def pullup_range(V, C, tr, Vol, Iol):
    return (V - Vol) / Iol, tr / (math.log(7 / 3) * C)

print(pullup_range(3.3, 400e-12, 1e-6, 0.4, 3e-3))
```

```python tests
lo, hi = pullup_range(3.3, 400e-12, 1e-6, 0.4, 3e-3)
assert abs(lo - 966.667) < 0.01 and abs(hi - 2950.56) < 0.1, f"Expected 967 Ω and 2.95 kΩ; got {lo}, {hi}"
lo2, hi2 = pullup_range(3.3, 200e-12, 300e-9, 0.4, 20e-3)
assert abs(hi2 - 1770.33) < 0.1 and lo2 < hi2, "Fast mode at 200 pF: up to 1.77 kΩ."
```

::: right
Right. A workable bus needs Rmin below Rmax; if not, the bus has too much capacitance for its drivers.
:::
:::

::: explain
## Why can't two ordinary CMOS outputs share a wire, while two open-drain outputs can?

::: model
An ordinary CMOS output always connects its wire either to the supply or to ground through a transistor. If two such outputs disagree, one connects the wire to the supply and the other to ground, so current flows straight through both transistors, wasting power and leaving the wire at an invalid voltage in between. An open-drain output can only connect the wire to ground or let go; nothing in it ever drives the wire high. A shared pull-up resistor does that, weakly. When several open-drain outputs disagree, the ones pulling low simply win against the resistor, with only the resistor's small current flowing, so the wire reads the AND of all the outputs and nothing fights.
:::
:::

::: practice

::: check
given: V = 2.5 | 5; R1 = 25 | 60; R2 = 25 | 90
answer: V/(R1 + R2)*1000
unit: mA
tolerance: 0.5%

## Contention on {V} V through {R1} Ω and {R2} Ω. Current?

::: misses
- [any] $\frac{V}{R_1 + R_2}$.
:::
:::

::: check
given: V = 3.3 | 5; Vol = 0.3 | 0.4; I = 3 | 6
answer: (V - Vol)/I
unit: kΩ
tolerance: 0.5%

## {V} V bus, devices sink {I} mA at {Vol} V. Smallest pull-up?

::: misses
- [any] $\frac{V - V_{OL}}{I_{OL}}$.
:::
:::
:::
