In digital electronicsthree-state, tri-state, or 3-statelogic allows an output port to assume a high impedance state, effectively removing the output from the circuit, in addition to the 0 and 1 logic levels. This allows multiple circuits to share the same output line or lines. Three-state outputs are implemented in many registers, bus drivers, and flip-flops in the 7400 and 4000 series as well as in other types, but also internally in many integrated circuits. Other typical uses are internal and external buses in microprocessors, computer memory, and peripherals. Many devices are controlled by an active-low input called which dictates whether the outputs should be held in a high-impedance state or drive their respective loads. The term tri-state should not be confused with ternary logic.
Uses
The basic concept of the third state, high impedance, is to effectively remove the device's influence from the rest of the circuit. If more than one device is electrically connected to another device, putting an output into the Hi-Z state is often used to prevent short circuits, or one device driving high against another device driving low. Three-state buffers can also be used to implement efficient multiplexers, especially those with large numbers of inputs. Three-state buffers are essential to the operation of a shared electronic bus. Three-state logic can reduce the number of wires needed to drive a set of LEDs.
Many memory devices designed to connect to a bus have both and pins, which superficially appear to do the same thing. If is not asserted, the outputs are high impedance. The difference lies in the time needed to output the signal. When chip select is deasserted, the chip does not operate internally, and there will be a significant delay between providing an address and receiving the data. When chip select is asserted, the chip internally performs the access, and only the final output drivers are disabled by deasserting output enable. This can be done while the bus is in use for other purposes, and when output enable is finally asserted, the data will appear with minimal delay. A ROM or static RAM chip with an output enable line will typically list two access times: one from chip select asserted and address valid, and a second, shorter time beginning when output enable is asserted.
Use of pull-ups and pull-downs
When outputs are tri-stated their influence on the rest of the circuit is removed, and the circuit node will be "floating" if no other circuit element determines its state. Circuit designers will often use pull-up or pull-down resistors to influence the circuit when the output is tri-stated. The PCI local bus provides pull-up resistors, but they would require several clock cycles to pull a signal high given the bus's large distributed capacitance. To enable high-speed operation, the protocol requires that every device connecting to the bus drive the important control signals high for at least one clock cycle before going to the Hi-Z state. This way, the pull-up resistors are only responsible for maintaining the bus signals in the face of leakage current. Intel refers to this convention as "sustained tri-state", and also uses it in the Low Pin Count bus.
The open collector input/output is a popular alternative to three-state logic. For example, the I²C bus protocol specifies the use of pull-up resistors on the two communication lines. When devices are inactive, they "release" the communication lines and tri-state their outputs, thus removing their influence on the circuit. When all the devices on the bus have "released" the communication lines, the only influence on the circuit is the pull-up resistors, which pull the lines high. When a device wants to communicate, it comes out of the Hi-Z state and drives the line low. Devices communicating using this protocol either let the line float high, or drive it low – thus preventing any bus contention situation where one device drives a line high and another low. Early microcontrollers often have some pins that can only act as an input, other pins that can only act as a push–pull output, and a few pins that can only act as an open collector input/output. A typical modern microcontroller has many three-state general-purpose input/output pins that can be programmed to act as any of those kinds of pins. A three-state bus is typically used between chips on a single printed circuit board, or sometimes between PCBs plugged into a common backplane. Usage of three-state logic is not recommended for on-chip connections but rather for inter-chip connections. Three-state buffers used to enable multiple devices to communicate on a data bus can be functionally replaced by a multiplexer. That will help select output from a range of devices and write one to the bus.