Combinational Logic Design
Multiplexers & Demultiplexers
A multiplexer, or mux, is a digital switch. It has several data inputs but only one output, and a set of select lines decides which input is passed through. A demultiplexer, or demux, does the opposite: it takes one data input and sends it to one of several outputs. Together they are the standard way to route data inside a chip, from a CPU register file to a communications link.
In this lesson you will write the truth tables and Boolean equations of 2:1 and 4:1 multiplexers, see how a demultiplexer works, and learn the useful trick of building a logic function from a multiplexer. You should know SOP expressions and minterms from earlier lessons.
Learning objectives
After this lesson you will be able to:
- Explain what select lines do and how many a mux needs.
- Write the output equation of a 2:1 and a 4:1 multiplexer.
- Describe how a demultiplexer routes its data input.
- Implement a three-variable function with a 4:1 multiplexer.
- Relate a demultiplexer to a decoder.
The 2:1 multiplexer
The simplest multiplexer has two data inputs, I0 and I1, one select line S and one output Y. When S = 0 the output follows I0, and when S = 1 it follows I1.
| S | Y |
|---|---|
| 0 | I0 |
| 1 | I1 |
As an equation, this is Y = S'I0 + S I1. Each product term lets one input through only when the select line has the right value. It is the same SOP idea you have used before, with the data inputs acting as the "enable" for each term.
The 4:1 multiplexer
With four data inputs you need two select lines, S1 and S0, because two bits give four combinations. In general a mux with 2^n data inputs needs n select lines. So an 8:1 mux has 3 select lines and a 16:1 mux has 4.
| S1 | S0 | Y |
|---|---|---|
| 0 | 0 | I0 |
| 0 | 1 | I1 |
| 1 | 0 | I2 |
| 1 | 1 | I3 |
The equation has one product term per input:
Y = S1'S0'I0 + S1'S0 I1 + S1 S0'I2 + S1 S0 I3
Only one of the four terms can be 1 at a time, because the select lines pick exactly one combination. That is why the output is simply the chosen input.
Example 1: reading a 4:1 mux
A 4:1 mux has data inputs I0 = 1, I1 = 0, I2 = 1 and I3 = 0. Find Y for every value of the select lines.
| S1 | S0 | Selected input | Y |
|---|---|---|---|
| 0 | 0 | I0 | 1 |
| 0 | 1 | I1 | 0 |
| 1 | 0 | I2 | 1 |
| 1 | 1 | I3 | 0 |
Result: Y = 1 when S1S0 is 00 or 10, and Y = 0 when it is 01 or 11. In other words, Y = S0'. The mux has turned a pattern of constants into a Boolean function of its select lines.
The demultiplexer
A 1:4 demultiplexer has one data input D, two select lines S1 and S0 and four outputs Y0 to Y3. The selected output copies D, and every other output stays at 0.
| S1 | S0 | Y0 | Y1 | Y2 | Y3 |
|---|---|---|---|---|---|
| 0 | 0 | D | 0 | 0 | 0 |
| 0 | 1 | 0 | D | 0 | 0 |
| 1 | 0 | 0 | 0 | D | 0 |
| 1 | 1 | 0 | 0 | 0 | D |
The equations are Y0 = D S1'S0', Y1 = D S1'S0, Y2 = D S1 S0' and Y3 = D S1 S0. Look closely: if you tie D to 1, each output becomes a single minterm of the select lines. A demultiplexer with D = 1 is exactly a decoder, which you will meet in the next lesson. Because of this, many chips sell one part labelled both "decoder" and "demultiplexer".
Example 2: implementing a function with a 4:1 mux
A multiplexer can implement any function, which makes it a useful building block. Implement F(A,B,C) = m(1, 2, 6, 7) using a 4:1 mux.
The truth table of F is:
| A | B | C | F |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 1 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 |
Step 1: choose the select lines. Connect A and B to S1 and S0. That leaves one variable, C, to feed the data inputs.
Step 2: look at each pair of rows. For each value of AB, look at the two rows where C = 0 and C = 1 and decide what F is in terms of C.
| AB | Minterms | F in terms of C | Mux input |
|---|---|---|---|
| 00 | m0, m1 | C | I0 = C |
| 01 | m2, m3 | C' | I1 = C' |
| 10 | m4, m5 | 0 | I2 = 0 |
| 11 | m6, m7 | 1 | I3 = 1 |
Step 3: connect the inputs. I0 = C, I1 = C', I2 = 0 (ground) and I3 = 1 (supply voltage).
Result: a single 4:1 mux plus one inverter implements F, with no other gates. The same method works for any three-variable function, and an 8:1 mux can implement a four-variable function the same way.
Example 3: a 2:1 mux as an XOR gate
Connect A to the select line, I0 to B and I1 to B'. When A = 0 the output is B, and when A = 1 it is B'. That is exactly Y = A XOR B.
Result: one 2:1 multiplexer and an inverter build an XOR gate.
Common mistakes
- Counting select lines wrongly. A mux with N data inputs needs log2(N) select lines, so 4 inputs need 2 and not 4.
- Mixing up the bit order of S1 and S0. S1 is the most significant bit, so S1S0 = 10 selects I2.
- Leaving unused data inputs floating. An unconnected input has an unknown value. Tie it to 0 or 1.
- Forgetting the inverter. Implementing a function with a mux often needs C' on a data input.
- Confusing mux and demux. A mux has many inputs and one output. A demux has one input and many outputs.
Practice problems
Check your answers with the truth table generator.
-
A 2:1 mux has I0 = 0 and I1 = 1. Write Y as a function of S.
Answer: Y = S.
-
A 4:1 mux has I0 = 0, I1 = 1, I2 = 1 and I3 = 0. Which function of S1 and S0 does it produce?
Answer: Y = S1 XOR S0, which equals S1'S0 + S1 S0'.
-
Implement F(A,B,C) = m(0, 1, 5, 7) with a 4:1 mux, using A and B as the select lines.
Answer: I0 = 1, I1 = 0, I2 = C and I3 = C.
-
How many select lines do a 16:1 multiplexer and a 1:8 demultiplexer have?
Answer: 4 for the 16:1 mux (2^4 = 16) and 3 for the 1:8 demux (2^3 = 8).
Frequently asked questions
What are multiplexers used for? They select between data sources: choosing which register feeds an arithmetic unit, sharing one wire between several signals, or converting parallel data to serial data. They are also used to implement logic functions directly.
What is the difference between a multiplexer and a demultiplexer? A multiplexer selects one of many inputs and sends it to one output. A demultiplexer takes one input and sends it to one of many outputs.
Can a multiplexer implement any Boolean function? Yes. An n-variable function can be built with a mux that has n select lines by tying the data inputs to the truth table values. Using one fewer select line, as in Example 2, saves hardware but needs the remaining variable on the data inputs.
To explore a function before building it, try the Boolean calculator or the K-map tool.
Next lesson: Encoders and Decoders