What is a 2 to 4 line decoder?

A decoder takes in an address and then activates the output line corresponding to it. Pulling that line high or low depending on the decoder.

enter image description here
image source: wikipedia

The 2to4 means it takes a 2 bit address and controls 4 outputs. The number of outputs is always \$2^{inputs}\$.

They typically have an enable input to make it ignore the input and turn all outputs off. That way you can cascade them.


Also called a 2 to 4 demux - it's simply a way of converting a binary number into a selected line. That line alone is asserted (or goes high) while the rest stay low. So

00  -  line 0 goes high
01  -  line 1 goes high
10  -  line 2 goes high
11  -  line 3 goes high

The most common use used to be to convert part of an address from a CPU into a select line to select a particular RAM or ROM chip.


Two input lines can take four different states: 00, 01, 10 and 11. For each of these, a different output line (but always only one) is enabled:

in | out
00 | 1000
01 | 0100
10 | 0010
11 | 0001

This is useful for example when addressing different ICs connected to a shared bus, e.g. for SPI you would connect SCLK, MISO and MOSI to all devices, and the CS for each to one of the decoder outputs, then you could select with two GPIOs which of the four connected devices you want to talk to. Without a decoder, you'd need four GPIOs, and you'd need to take extra care to never activate two devices at the same time.

Tags:

Cpu