Learn › Topic 8
Multiplexers, decoders and encoders explained
8 min read · bitGateLab Team
Medium-scale combinational blocks are the parts from which almost any digital system is built: the multiplexer picks one data item out of several, the demultiplexer routes a data item to one destination, the decoder activates a single line according to a binary number and the encoder does the opposite. Here you will see their equations, their truth tables and two applications that show up in every exam: implementing a logic function with a multiplexer and designing a decoder for a 7-segment display.
The multiplexer (MUX)
A multiplexer with 2n data inputs has n select inputs and one output. The binary number on the select lines says which data input is passed to the output. The simplest one is the 2-to-1 MUX:
Y = S·I0 + S·I1
With S = 0 the output copies I0; with S = 1 it copies I1. The 4-to-1 MUX uses two select lines S1 S0, and each data input is multiplied by its corresponding select minterm:
Y = S1·S0·I0 + S1·S0·I1 + S1·S0·I2 + S1·S0·I3
| S1 | S0 | Y |
|---|---|---|
| 0 | 0 | I0 |
| 0 | 1 | I1 |
| 1 | 0 | I2 |
| 1 | 1 | I3 |
Each term is an AND of the data input with the select lines (true or complemented), and all of them are combined in an OR.
Implementing a function with a MUX
Since the MUX already contains all the minterms of its select variables, it works as a "programmable function". With a MUX of 2n inputs you can implement any function of n variables by putting a 0 or a 1 on each data input. Better still: with the same MUX you can implement a function of n + 1 variables if you connect the leftover variable (or its complement) to the data inputs.
Example: implement F(A, B, C) = Σm(1, 2, 6, 7) with a 4-to-1 MUX, using A and B as the select lines (A = S1, B = S0).
- Group the truth table into pairs with the same value of A B and see how F depends on C.
- AB = 00: m0 = 0 (C = 0), m1 = 1 (C = 1). F = C, so I0 = C.
- AB = 01: m2 = 1 (C = 0), m3 = 0 (C = 1). F = C, so I1 = C.
- AB = 10: m4 = 0, m5 = 0. I2 = 0.
- AB = 11: m6 = 1, m7 = 1. I3 = 1.
Check with A = 0, B = 1, C = 0 (minterm 2): the select value 01 picks I1 = C = 1. Correct, m2 belongs to the function.
The demultiplexer and the decoder
The 1-to-4 demultiplexer (DEMUX) takes a data input D and sends it to one of four outputs according to S1 S0; the others stay at 0: Y0 = D·S1·S0, Y1 = D·S1·S0, Y2 = D·S1·S0, Y3 = D·S1·S0.
If you fix D = 1 in the DEMUX and call it "enable", you get a decoder: n inputs and 2n outputs, of which only one is active, the one that corresponds to the input number. A 3-to-8 decoder generates the 8 minterms of three variables. That is why any three-variable function can be built with a decoder and an OR gate that collects the outputs of its minterms.
Example: a full adder with a 3-to-8 decoder. Inputs A, B and Cin.
- Sum S = Σm(1, 2, 4, 7): a 4-input OR with the outputs Y1, Y2, Y4, Y7.
- Carry Cout = Σm(3, 5, 6, 7): a 4-input OR with Y3, Y5, Y6, Y7.
Check one case: A = 1, B = 1, Cin = 0 is the number 110 = 6. Only Y6 is activated; Y6 is not in the OR for S (S = 0) but it is in the one for Cout (Cout = 1). Indeed, 1 + 1 + 0 = 10 in binary.
The priority encoder
The encoder performs the inverse operation: from 2n lines it outputs the n-bit binary number of the active line. The problem is what to do if two are active at the same time; the practical solution is the priority encoder, which outputs the number of the highest active line. For 4 inputs D3 (the highest priority) to D0:
Y1 = D3 + D2, Y0 = D3 + D2·D1, V = D3 + D2 + D1 + D0
The output V ("valid") indicates that at least one input is active; without it you could not tell "D0 active" from "none active", because both give Y1 Y0 = 00. Try it with D2 = D1 = 1: Y1 = 1 and Y0 = 0 + 0·1 = 0, that is, 10 = 2. D2 wins, as it should.
BCD to 7-segment decoder
A 7-segment display has one LED per segment. The decoder receives a BCD digit (A B C D, with A as the most significant bit) and lights the segments that draw that digit. For a common-cathode display, 1 means the segment is on:
| Digit | ABCD | a | b | c | d | e | f | g |
|---|---|---|---|---|---|---|---|---|
| 0 | 0000 | 1 | 1 | 1 | 1 | 1 | 1 | 0 |
| 1 | 0001 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
| 2 | 0010 | 1 | 1 | 0 | 1 | 1 | 0 | 1 |
| 3 | 0011 | 1 | 1 | 1 | 1 | 0 | 0 | 1 |
| 4 | 0100 | 0 | 1 | 1 | 0 | 0 | 1 | 1 |
| 5 | 0101 | 1 | 0 | 1 | 1 | 0 | 1 | 1 |
| 6 | 0110 | 1 | 0 | 1 | 1 | 1 | 1 | 1 |
| 7 | 0111 | 1 | 1 | 1 | 0 | 0 | 0 | 0 |
| 8 | 1000 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| 9 | 1001 | 1 | 1 | 1 | 1 | 0 | 1 | 1 |
The codes 1010 to 1111 are not valid BCD, so they are treated as don't-care conditions (X) on the Karnaugh map. This simplifies each segment a great deal.
Segment a: it is 0 only for digits 1 and 4. On the 4-variable map, with X's in 10 to 15, the largest groups are: A (8 cells including the X's), C (8 cells), B·D (minterms 5, 7, 13, 15) and B·D (the four corners: 0, 2, 8, 10).
a = A + C + B·D + B·D
Check digit 4 (0100): A = 0, C = 0, B·D = 1·0 = 0, B·D = 0·1 = 0. Result 0: segment a stays off, which is correct.
If the display is common-anode, each segment lights with a 0, so all the outputs are inverted.
Common mistakes
- Reversing the order of the select lines: if S1 and S0 are swapped, input I1 trades places with I2 and the function comes out wrong.
- Forgetting that many decoders have active-low outputs and using an OR where a NAND belongs.
- Designing an encoder with no priority and no valid output, which gives 00 both for "D0 active" and for "nothing active".
- Mixing the common-cathode table with a common-anode display: exactly the opposite segments light up.
- Not taking advantage of the combinations 1010 to 1111 as don't cares and ending up with equations twice as large.
Try it in the simulator
Compare the truth table of the function with the version built from a multiplexer.
- Create a truth table with three inputs A, B, C and set F = 1 in rows 1, 2, 6 and 7.
- In the editor, place a 4-to-1 multiplexer (or build it from four AND gates, two NOT gates and a four-input OR) and connect A and B to the select lines.
- Connect C, the complement of C, a constant 0 and a constant 1 to the data inputs, in that order.
- Step the inputs through all eight combinations and watch that the output matches the table.
- Repeat with segment a of the display: enter its column in a 4-variable table, mark rows 10 to 15 as X and review the groups proposed by the Karnaugh map.
Exercises
- Implement F(A, B, C) = Σm(0, 3, 5, 6) with a 4-to-1 MUX using A and B as the select lines.
Answer
AB = 00: m0 = 1, m1 = 0, I0 = C. AB = 01: m2 = 0, m3 = 1, I1 = C. AB = 10: m4 = 0, m5 = 1, I2 = C. AB = 11: m6 = 1, m7 = 0, I3 = C. It is the even-parity function (it is 1 when there is an even number of ones): F = A ⊕ B ⊕ C.
- How many select lines does a 16-input MUX need, and what is the largest number of variables the function it implements can have?
Answer
4 select lines (24 = 16). By connecting the leftover variable to the data inputs it can implement any function of up to 5 variables.
- Find the equation of segment e using the combinations 10 to 15 as don't cares.
Answer
e = 1 for 0, 2, 6 and 8. Groups: B·D (0, 2, 8, 10) and C·D (2, 6, 10, 14). Result: e = B·D + C·D = D·(B + C).
- In the 4-input priority encoder, what output do you get for D3 = 0, D2 = 0, D1 = 1, D0 = 1?
Answer
Y1 = 0 + 0 = 0, Y0 = 0 + 1·1 = 1, V = 1. Output 01: D1 wins over D0.