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.
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 at | en | sel | din | y0 | y1 | y2 | Expected selection hit |
|---|---|---|---|---|---|---|---|
| 0 ns | 1 | 00 | 52 | 52 | 00 | 00 | 001 |
| 10 ns | 1 | 10 | 52 | 00 | 00 | 52 | 100 |
| 20 ns | 1 | 01 | 52 | 00 | 52 | 00 | 010 |
| 30 ns | 1 | 01 | 00 | 00 | 00 | 00 | 010 |
| 40 ns | 1 | 11 | 52 | 00 | 00 | 00 | 000 |
| 50 ns | 0 | 00 | 52 | 00 | 00 | 00 | 000 |
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.
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?
| Channel | Data output (hex) | Decoder hit |
|---|---|---|
| 0 | y0 = 52 | hit[0] = 1 |
| 1 | y1 = 00 | hit[1] = 0 |
| 2 | y2 = 00 | hit[2] = 0 |
hit[2:0] = 001
Teaching film
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)