Lab 3: Seven-Segment Display and Multiplexing
Multiplexing for multiple displays.

Multiplexing for multiple displays.

2-to-1 Multiplexer

Truth Table

selabout
00X0
01X1
1X00
1X11

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 NameDirectionLocation
selInputPIN_C10
aInputPIN_C11
bInputPIN_D12
out[6]OutputPIN_C17
out[5]OutputPIN_D17
out[4]OutputPIN_E16
out[3]OutputPIN_C16
out[2]OutputPIN_C15
out[1]OutputPIN_E15
out[0]OutputPIN_C14

Output

4-to-1 Multiplexer

Truth Table

sel[1]sel[0]a[1]a[0]b[1]b[0]out (7-segment)
00XXXX0 (off)
01XXXX0 (off)
1000XX0 (off)
1001XX1
1010XX0 (off)
1011XX1
11XX000 (off)
11XX011
11XX100 (off)
11XX111

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 NameDirectionLocation
sel[1]InputPIN_B12
sel[0]InputPIN_A12
a1InputPIN_C12
a0InputPIN_D12
b1InputPIN_C11
b0InputPIN_C10
out[6]OutputPIN_C17
out[5]OutputPIN_D17
out[4]OutputPIN_E16
out[3]OutputPIN_C16
out[2]OutputPIN_C15
out[1]OutputPIN_E15
out[0]OutputPIN_C14

Output

Reference

Lesson 27 - VHDL Example 14: Multiplexing 7-Segment Displays (opens in a new tab)