Circuit 3D

Multiplexer and decoder

A multiplexer (mux) is a switch made of logic: it connects one of several inputs to a single output, chosen by a binary number on its select lines. A decoder does the reverse job, turning a binary number into one active output among many, and either way n lines choose between 2n options, so 3 lines choose between 8.

2n options

where n is the number of select or input lines, so 3 lines choose between 8.

A demultiplexer sends one input out to one of several outputs.

What is a multiplexer?

A multiplexer is a digital switch with several data inputs, one output, and select lines whose binary number chooses which input is connected through.

With 2 select lines it chooses between 4 inputs, with 3 between 8. In Figure 1 the select number picks one of four fixed data bits. Built from logic gates, a mux can even act as any logic function: put the truth table on its inputs and use the select lines as the function’s inputs.

D0 1 D1 0 D2 0 D3 1 Y 1 S1 1 S0 1

Select 11: binary 11 is 3, so the multiplexer connects D3 to the output, and Y = 1. The other three inputs are ignored.

Figure 1. A 4-to-1 multiplexer with the data 1, 0, 0, 1 on its inputs. The two select lines, S1 and S0, choose which input reaches the output Y.

What is a demultiplexer?

A demultiplexer works the other way: one data input, several outputs, and select lines that choose which output the data goes to.

Together, a multiplexer and a demultiplexer can send several signals down one wire by taking turns, which is where the name comes from: telephone networks used it to share lines. Analog multiplexers, such as the 74HC4051 and 74HC4067, pass voltages either way, so one chip works as both.

What is a decoder?

A decoder turns a binary number on its n inputs into a signal on exactly one of its 2n outputs, so each number lights or enables its own line.

Figure 2’s 2-to-4 decoder has active-high outputs; many chips, like the 3-to-8 74HC138, use active-low outputs instead, pulling the chosen one to 0 V. An enable input switches every output off, and feeding data into it turns the decoder into a demultiplexer. Computers use decoders to select which memory chip answers an address.

A1 1 A0 0 2 → 4 enable Y0 Y1 Y2 Y3

Input 10: binary 10 is 2, so output Y2 goes HIGH and the other three stay LOW: exactly one output for each input number.

Figure 2. A 2-to-4 decoder with active-high outputs: the two-bit input number picks which one output goes HIGH.

What is an encoder?

An encoder does a decoder’s job in reverse: it has many inputs and outputs the binary number of whichever one is active.

A priority encoder, such as the 74HC148, reports the highest-numbered input if several are active at once, which suits keypads and interrupt lines. An 8-to-3 encoder turns eight buttons into a 3-bit number on three wires.

How does a seven-segment decoder work?

A BCD to seven-segment decoder takes a decimal digit as a 4-bit binary number and turns on the segments that draw it, so four pins can show any digit from 0 to 9.

The CD4511 drives a common-cathode seven-segment display this way, with a resistor on each segment. Figure 3 shows the segments it lights for each digit.

0 D 1 C 1 B 1 A BCD to 7-seg

7 in BCD is 0111: the decoder turns those four bits into seven segment outputs, lighting a, b, c and leaving d, e, f, g dark.

Figure 3. A BCD to seven-segment decoder, such as a CD4511, turning a 4-bit binary digit into the segments that draw it.

What are multiplexers and decoders used for?

Multiplexers and decoders let a few wires or pins reach many signals: reading more sensors than a microcontroller has inputs, driving displays and LED matrices, and selecting memory and peripherals by address.

An Arduino with a 16-channel analog mux can read 16 sensors through one analog pin and four digital ones. Inside processors, multiplexers route data between registers on every clock cycle.

How many select lines or outputs do you need?

To find a mux’s select lines, take the smallest n with 2n at least the number of inputs, so 8 inputs need 3; a decoder with n inputs has 2n outputs.

Example 1: a multiplexer’s select lines

How many select lines does a multiplexer with 8 inputs need?

Given
a multiplexer choosing between 8 inputs
Find
how many select lines it needs
Solution
n select lines can count 2n choices, so find n with 2n = 823 = 8, so n = 3
Answer
3 select lines

Example 2: a decoder’s outputs

A microcontroller has 3 spare pins to drive a decoder. How many outputs can it choose between, one at a time?

Given
3 microcontroller pins driving a 3-to-8 decoder
Find
how many outputs it can pick between
Solution
Outputs = 23 = 8
Answer
8 outputs, one at a time, as on a 74HC138

Summary

Key equations

  • choices = 2n n select lines
  • n = log2(inputs) select lines needed
  • Y = DS a mux’s output

Key terms

Select lines
The binary number that chooses.
Enable
Turns the chip’s outputs on.
Active low
On means 0 V.
BCD
Each decimal digit in 4 bits.

Practice problems

  1. A 4-to-1 multiplexer has S1 S0 = 10. Which input reaches the output?

  2. How many select lines does a 16-input multiplexer need?

  3. A 3-to-8 decoder gets the input 101. Which output is active?

  4. What does a demultiplexer do?

  5. What does a BCD to seven-segment decoder do with 0111?

FAQ

What is the difference between a multiplexer and a decoder?

A multiplexer passes one of many data inputs to its output; a decoder turns a binary number into one active output among many.

Is a decoder the same as a demultiplexer?

Nearly: a decoder with an enable input becomes a demultiplexer when the data goes into that enable.

What is a 74HC138?

A 3-to-8 line decoder: three inputs choose which of eight active-low outputs goes to 0 V, with three enable inputs.

Can a multiplexer pass analog signals?

Analog multiplexers such as the 74HC4051 can, using switches that pass voltages either way. Logic multiplexers only pass digital levels.

Why is it called multiplexing?

Because it lets many signals share one path by taking turns, as telephone lines did long before chips.

What is BCD?

Binary-coded decimal: each decimal digit stored separately as four bits, so 7 is 0111 and 12 is 0001 0010.

How do I read more analog sensors on an Arduino?

Use an analog multiplexer: set its select pins from digital outputs, then read the chosen sensor through one analog pin.

What is a shift register?

A chain of flip-flops that moves data one place along at each clock pulse, so a 74HC595 turns 3 microcontroller pins into 8 outputs.