yeolyi.comSeongyeol's CS

Multiplexer

The circuits we have built so far always process their inputs the same way. The go-straight circuit always computes Green ∧ ¬Obstacle, and the safe always computes (Key1 ∧ Key2) ∨ Card. But a calculator shows the sum when you press + and the difference when you press −. Computers often need to pick one of several values like this, depending on the situation. What kind of circuit makes this choice possible?

Multiplexer

Imagine a calculator that computes both the sum and the difference in advance, then sends only one of them to the screen depending on which button was pressed. A circuit that picks one of several inputs and outputs it like this is a multiplexer (MUX).

The simplest MUX is the 2-to-1 MUX, which picks one of two inputs. When the select signal S is 0 it outputs A, and when it is 1 it outputs B.

Out
0000
0010
0101
0111
1000
1011
1100
1111

Set S to 0 and change A and B. Which input does Out follow? Then switch S to 1 and try again.

In the rows where S is 0, Out always equals A, and in the rows where S is 1, it always equals B. As a logical expression, that is (¬S ∧ A) ∨ (S ∧ B).

  1. Set S to 0 and change A and B. Only A shows up at Out.
  2. Switch S to 1. Now B shows up instead. S is the select signal that picks the input.

We will use the MUX often, so from now on we will hide the gates inside and draw it as a single box, as below. Just like the circuit above, it sends out A, coming in at D0, when S is 0, and B, coming in at D1, when S is 1.

Change S, A, and B and check that it behaves the same as the circuit above.

What if there are four inputs? Just widen the select signal to 2 bits (S1, S0). A 4-to-1 MUX picks the first input for 00, the second for 01, the third for 10, and the fourth for 11. You can build one by chaining three of the 2-to-1 MUXes above. The two MUXes on the left use S0 to pick one of A and B and one of C and D, and the MUX on the right uses S1 to make the final choice between those two.

  1. Set S1·S0 to 10 and change C. Out follows C. Changing A, B, or D now has no effect on Out.
  2. Switch S1·S0 to 00, 01, and 11, and check that A, B, and D each come out.

Wrapping up

A MUX uses a few bits of select signal to pick one of several inputs. In the next post, let’s build a decoder, which uses a number to turn on just one of several outputs.

Challenge

Using two 2-to-1 MUXes, build a circuit that outputs 1 when X and Y differ. You can connect X, Y, the constants 0 and 1, or the output of the other MUX to each MUX's select signal and its two data inputs.