Multiplexing for multiple displays.
2-to-1 Multiplexer
Truth Table
| sel | a | b | out | 
|---|---|---|---|
| 0 | 0 | X | 0 | 
| 0 | 1 | X | 1 | 
| 1 | X | 0 | 0 | 
| 1 | X | 1 | 1 | 
Code
module mux_2to1(
    input wire a, b,   // Boolean inputs
    input wire sel,    // Selector input
    output wire [6:0] out   // 7-segment output (A-G)
);
    wire mux_out;  // Intermediate wire for multiplexer output
    // 2-to-1 Multiplexer Logic
    assign mux_out = (sel) ? b : a;
    // Mapping multiplexer output to 7-segment display
    assign out = (sel & ~b) ? 7'b1000000 :   // 0 when sel=1 and b=0
                 (sel | a) ? 7'b1111001 :    // 1 when sel=0 and a=1, or sel=1 and b=1
                              7'b1111111;    // Otherwise, turn off all segments
endmodule
Pin Planner
| Node Name | Direction | Location | 
|---|---|---|
| sel | Input | PIN_C10 | 
| a | Input | PIN_C11 | 
| b | Input | PIN_D12 | 
| out[6] | Output | PIN_C17 | 
| out[5] | Output | PIN_D17 | 
| out[4] | Output | PIN_E16 | 
| out[3] | Output | PIN_C16 | 
| out[2] | Output | PIN_C15 | 
| out[1] | Output | PIN_E15 | 
| out[0] | Output | PIN_C14 | 
Output
4-to-1 Multiplexer
Truth Table
| sel[1] | sel[0] | a[1] | a[0] | b[1] | b[0] | out (7-segment) | 
|---|---|---|---|---|---|---|
| 0 | 0 | X | X | X | X | 0 (off) | 
| 0 | 1 | X | X | X | X | 0 (off) | 
| 1 | 0 | 0 | 0 | X | X | 0 (off) | 
| 1 | 0 | 0 | 1 | X | X | 1 | 
| 1 | 0 | 1 | 0 | X | X | 0 (off) | 
| 1 | 0 | 1 | 1 | X | X | 1 | 
| 1 | 1 | X | X | 0 | 0 | 0 (off) | 
| 1 | 1 | X | X | 0 | 1 | 1 | 
| 1 | 1 | X | X | 1 | 0 | 0 (off) | 
| 1 | 1 | X | X | 1 | 1 | 1 | 
Code
module mux_4to1(
    input wire [1:0] sel,     // Selector input
    input wire a1, a0,        // Input bits for a
    input wire b1, b0,        // Input bits for b
    output reg [6:0] out      // 7-segment output (A-G), changed to 'reg'
);
    // Enhanced mapping using truth table for multiplexer output to 7-segment display
    always @(*) begin
        case (sel)
            2'b00: out = 7'b1000000; // Output 0
            2'b01: out = 7'b1000000; // Output 0
            2'b10: begin
                case ({a1, a0})
                    2'b00: out = 7'b1000000; // Output 0
                    2'b01: out = 7'b1111001; // Output 1
                    2'b10: out = 7'b1000000; // Output 0
                    2'b11: out = 7'b1111001; // Output 1
                endcase
            end
            2'b11: begin
                case ({b1, b0})
                    2'b00: out = 7'b1000000; // Output 0
                    2'b01: out = 7'b1111001; // Output 1
                    2'b10: out = 7'b1000000; // Output 0
                    2'b11: out = 7'b1111001; // Output 1
                endcase
            end
        endcase
    end
endmodule
Pin Planner
| Node Name | Direction | Location | 
|---|---|---|
| sel[1] | Input | PIN_B12 | 
| sel[0] | Input | PIN_A12 | 
| a1 | Input | PIN_C12 | 
| a0 | Input | PIN_D12 | 
| b1 | Input | PIN_C11 | 
| b0 | Input | PIN_C10 | 
| out[6] | Output | PIN_C17 | 
| out[5] | Output | PIN_D17 | 
| out[4] | Output | PIN_E16 | 
| out[3] | Output | PIN_C16 | 
| out[2] | Output | PIN_C15 | 
| out[1] | Output | PIN_E15 | 
| out[0] | Output | PIN_C14 | 
Output
Reference
Lesson 27 - VHDL Example 14: Multiplexing 7-Segment Displays (opens in a new tab)