Skip to content
Tutorials Center
My learning

Topics

Lesson 12 of 57 ยท Logic Gates

Tri-State Buffers, Open-Collector Outputs and Buses

Learn how tri-state buffers share a bus using the high-impedance state, what bus contention does, and how open-collector outputs make a wired-AND, with Python models.

A normal gate output is always either 1 or 0. It drives its wire hard to the supply voltage or to ground, and that is exactly why you must never connect two ordinary gate outputs to the same wire. If one gate says 1 and the other says 0, they fight, and the wire ends up at some uncertain voltage while a large current flows between the two gates. Yet a computer needs exactly this kind of sharing: a memory chip, a CPU and a few peripherals all need to put data on the same set of wires, one at a time.

Two special output styles solve the problem. A tri-state output has a third state, disconnected, in which the gate lets go of the wire. An open-collector (or open-drain) output can only pull the wire low and never drives it high. This lesson shows how both work, what goes wrong when a rule is broken, and how to model a bus in Python.

The third state: high impedance

A tri-state buffer has one data input A, one output Y and an enable input EN. When EN = 1, it behaves like a simple buffer: Y = A. When EN = 0, the output is in the high-impedance state, written Z or "high-Z". In this state the output is electrically disconnected: it neither pulls the wire to 1 nor to 0, as if there were an open switch between the buffer and the wire.

EN A Y
0 0 Z
0 1 Z
1 0 0
1 1 1

Z is not a logic value you can compute with. It means "nobody is driving". Some buffers have an active-low enable (written EN' or OE', output enable). The idea is the same, with the enable polarity inverted.

Sharing a wire: the bus

A bus is a group of wires shared by several devices. Each device connects to the bus through tri-state buffers. The rule of a bus is simple: at most one driver may be enabled at any time, while every device may listen all the time. A small decoder or a controller makes sure only one enable line is active.

flowchart LR
    R1["Register A"] --> B1["Tri-state buffer EN_A"]
    R2["Register B"] --> B2["Tri-state buffer EN_B"]
    R3["Memory"] --> B3["Tri-state buffer EN_M"]
    B1 --> BUS(("Shared bus"))
    B2 --> BUS
    B3 --> BUS
    BUS --> L1["Register C input"]
    BUS --> L2["ALU input"]

Three sources can drive the bus, only one at a time. Every listener sees the same value.

A bus replaces a tangle of point-to-point wires and a big multiplexer. Instead of routing every source to every destination, you give each source an enable and run one set of wires past everybody. The price is speed, because the bus must carry the load of many connections, and discipline, because two enabled drivers create a conflict.

Bus contention and floating buses

Two things can go wrong, and both are classic debugging stories.

Bus contention means two or more drivers are enabled at once. If they drive the same value, nothing visible happens (though the design is still wrong). If they drive opposite values, a strong output pulling high meets another one pulling low. The wire sits at a voltage somewhere in the forbidden zone between 0 and 1, the current through both output stages is large, the chips get hot, and the logic that reads the bus sees garbage. In simulators the result is shown as X (unknown).

A floating bus happens when no driver is enabled. The wire has no source, so it picks up noise from the surroundings. A listener might read 0, 1 or oscillate between them, and a CMOS input left at a middle voltage can draw excess current. Designers fix this with a pull-up or pull-down resistor, a weak connection to the supply or ground that sets a default value when everyone is in Z. A weak resistor loses to any active driver, so it never causes contention.

Contention can also happen for a very short time during a hand-over. If one buffer is turned off and another turned on at the same moment, the switching speeds may overlap for a few nanoseconds. Careful designs leave a small dead time between turning one driver off and the next one on.

Modeling a bus

A bus resolves the values of all its drivers using four rules. Z contributes nothing. One active driver sets the value. Two active drivers that agree keep that value. Two that disagree produce X. If no driver is active, the value is Z, or the pull-up value if there is a pull-up.

Python Resolving a shared bus

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The case "A and M (both 1)" shows that agreement is accepted. The case "A and B" is a true conflict, and a pull-up cannot hide it. The decoder at the end is the standard defense: with a 2-bit select code, exactly one enable is high, so contention cannot happen as long as the select lines themselves are glitch-free.

Open-collector and open-drain outputs

The second style of shared-wire output can only do half the job. An open-collector output (in CMOS, open-drain) has a transistor that pulls the output to ground when its input says 0, and does nothing otherwise. It cannot drive high. Without outside help, the output is either 0 or floating.

The help is a pull-up resistor from the shared wire to the supply voltage. When every open-collector output is off, the resistor pulls the wire up to 1. When any output turns on, its transistor pulls the wire to 0, overpowering the resistor.

That behavior makes a natural AND: the wire is 1 only if all outputs are off (each sends a 1), and 0 as soon as any output sends 0. Connecting outputs together to get this function is called a wired-AND (you also see "wired-OR" for the same thing in negative logic). No gate is needed. Two outputs shorted together, with one pull-up resistor, do the work of an AND gate.

flowchart TB
    VCC["+V"] --> RP["Pull-up resistor"]
    RP --> W(("Shared wire"))
    O1["Open-collector 1: pulls low if input is 0"] --> W
    O2["Open-collector 2: pulls low if input is 0"] --> W
    O3["Open-collector 3: pulls low if input is 0"] --> W

The wire is high only when no device pulls it down.

Open-collector outputs are used in places where several devices must be able to raise an alarm or request attention on the same wire:

  • A shared interrupt request line, where any device can pull the line low.
  • The I2C serial bus, where both the clock and the data wire are open-drain with pull-ups, so a slow device can hold the clock low to say "wait".
  • Level shifting, because the pull-up can connect to a different supply voltage than the chip uses.
  • Driving LEDs and relays that need more current or voltage than a normal output.

Open-collector buses are slower on rising edges, because the resistor has to charge the wire's capacitance, and larger resistors make this slower. Their advantage is safety: shorting two outputs can never create a contention, because nobody ever drives high.

Python Wired-AND with open-collector outputs

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Which one should you use?

Ordinary output Tri-state Open-collector / open-drain
States 0, 1 0, 1, Z 0, Z (the resistor makes the 1)
Can share a wire? Never Yes, one enabled driver at a time Yes, any number of drivers
Contention risk Not applicable High if enables are wrong None
Rising edge Fast Fast Slow (resistor and wire capacitance)
Typical use Everything else Data buses, memory Interrupt lines, I2C, wired-AND

In FPGA and ASIC design, tri-state buses inside the chip are rare because internal multiplexers are easier to analyze. Tri-state pins on the chip boundary, for connecting to external memory or shared data lines, are still common.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. What does the Z state of a tri-state buffer mean?

    High impedance means the buffer neither pulls the wire high nor low. It is like an open switch. An unknown value after a conflict is written X, not Z.
  2. 2. Two enabled tri-state drivers on one bus output 1 and 0. What happens?

    Both drivers are strong, so neither wins. The wire sits at an uncertain voltage and the output stages heat up. A designer prevents this with one-hot enable signals.
  3. 3. What is the job of the pull-up resistor in an open-collector circuit?

    An open-collector output can only pull low. The resistor raises the wire to 1 when every output has released it.
  4. 4. Three open-collector outputs share a wire with one pull-up. Which function does the wire compute?

    The wire is 1 only if all three outputs release it, and any 0 pulls it low, which is exactly AND.
  5. 5. How do designers usually prevent contention on a shared data bus?

    A decoder produces a one-hot code, so only one driver is ever enabled. Pull resistors only set the default when nobody drives.

Summary

  • An ordinary gate output always drives the wire, so two of them on one wire fight each other.
  • A tri-state buffer adds a high-impedance (Z) state controlled by an enable input, so many drivers can share a bus when only one is enabled.
  • Bus contention (two active drivers disagreeing) gives an undefined voltage and excess current. A floating bus (no driver) picks up noise, so buses often have pull-up or pull-down resistors.
  • An open-collector or open-drain output can only pull low. With a pull-up resistor, several of them form a wired-AND on one wire, which is safe against contention but slower to rise.
  • Decoders produce one-hot enables, the standard way to guarantee a single driver.

Continue with what the gates are made of in Logic Families: TTL vs CMOS, Fan-out and Propagation Delay.