Demultiplexer (demux)

Route one sensor reading to one of three channels. When the reading itself is zero, what can the receiver tell from its data pins?

The collector has an eight-bit report, hexadecimal 52, to send to one of three processing blocks. A demultiplexer, or demux, routes that one word to a selected output. The collector supplies one data input. Each processing block has its own output connection.

Which output gets the word?

The input din is eight bits wide, as are the three outputs y0, y1, and y2. When enable en is one, the two-bit selector sel uses codes 00, 01, and 10 for outputs zero, one, and two. Unselected outputs carry 00. The fourth code, 11, has no output assigned to it. It makes all three outputs zero, just as disabling en does.

Eight-bit din 52 enters the demultiplexer. With en high and sel 01, y1 gets 52 while y0 and y2 are zero.
Output one is selected. It carries all eight input bits. The other two outputs carry the idle value 00.

In the combinational block, give all three outputs a zero default, then override the selected one. The case examines the concatenation of the one enable bit and the two select bits. For example, 101 means enable is high and output one is selected. Every other combination uses the defaults from this evaluation, so every branch has defined outputs.

module demux3 (
    input  logic [7:0] din,
    input  logic       en,
    input  logic [1:0] sel,
    output logic [7:0] y0, y1, y2
);
    always_comb begin
        {y2, y1, y0} = '0;
        case ({en, sel})
            3'b100: y0 = din;
            3'b101: y1 = din;
            3'b110: y2 = din;
            default: ;
        endcase
    end
endmodule

This RTL depends on the current inputs. If a branch leaves a previous output unassigned, synthesis may infer a latch to hold the old value. The zero defaults give unselected outputs a value on each evaluation.

Can you tell which output was selected when all three are zero?

Keep din=52 and select outputs zero, two, and one at 0, 10, and 20 ns. Follow 52 across the outputs. At 30 ns, keep output one selected and change din to 00. Output one gets the new data. Its value now matches the idle values on the other outputs.

At 40 ns, restore 52 on the input and use the unused select code 11. At 50 ns, bring sel back to the legal code 00 and disable en. Neither setting selects an output, and all three outputs still show 00. Looking only at the data cannot distinguish the selected zero at 30 ns from the two idle cases.

Change atenseldiny0y1y2Expected selection hit
0 ns10052520000001
10 ns11052000052100
20 ns10152005200010
30 ns10100000000010
40 ns11152000000000
50 ns00052000000000

The data is shown in hexadecimal. The testbench checks the outputs 1 ns after each change, at 1, 11, 21, 31, 41, and 51 ns. The hit column follows the selection contract below and is separate from the demux data outputs.

The Icarus waveform shows 52 at y0, y2, and y1 at 0, 10, and 20 ns. At 30 ns output one is still selected and all outputs become 00. At 40 ns the code is unused and at 50 ns the block is disabled, so the outputs stay zero even with din at 52.
Output one is still selected in the shaded interval. It carries the data value 00. The plot comes from a functional Icarus VCD. The testbench delay schedules the observation.

Add a decoder to indicate the selected output

Pass the same en and sel to a decoder. It produces three selection bits, hit[2:0]. Output zero corresponds to the lowest bit, and output two to the highest. The three valid selections produce 001, 010, and 100. A disabled or unused selection produces 000.

Selection is unchanged at 20 and 30 ns, so hit=010 at both times. The receiver on output one can use hit[1] to tell it was selected and then read y1. The hit signal indicates the current route. The receiving interface defines when to sample or accept the word.

Replay the example and check every combination

Download the runnable SystemVerilog example. Icarus checks the six directed data cases above and all 2,048 binary combinations of enable, select, and eight-bit data. The reference shifts the incoming data into the appropriate lane of a 24-bit expected word. Comparing the full word catches both a wrong route and an unselected output that remains nonzero.

Interactive lab

Send 52 to channel 1 and then change the byte to 00. Compare the three data outputs with the companion decoder’s select lines. Now turn enable off. Can the data outputs distinguish these two cases?

Data at each output and the companion decoder result for the same en and sel
ChannelData output (hex)Decoder hit
0y0 = 52hit[0] = 1
1y1 = 00hit[1] = 0
2y2 = 00hit[2] = 0

hit[2:0] = 001

Teaching film

Read the transcript

Run the RTL yourself

Extract the lab and follow the commands in its README. Compare the simulated outputs and waveform with your predictions from the interactive lab.

Download Demultiplexer (demux) RTL (.zip)

Check your understanding

1. With en = 1, sel = 2 and din = 52, where does 52 appear?
2. With en high and sel held at 1, din changes from 52 to 00. Which lane is still selected?
3. All three data outputs read 00. What else tells you which lane was selected?
4. With en high, sel at binary 11 and din at FF, what appears on the outputs?
5. Why set all three outputs to 00 first in an always_comb demux?