8-to-1 Multiplexer

  1. Introduction


    An 8-to-1 multiplexer is a digital device that selects one of the eight inputs lines to the output line by using three-bit selection line. The block diagram of 8-to-1 Mux is shown in Figure 1. A 2n-to-1 multiplexer needs n bit selection line to select one of the 2n inputs to the output.

    Figure 1. Block diagram of 8-to-1 multiplexer

  2. Truth Table


    Figure 2 shows the truth table of the 8-to-1 multiplexer. I1 to I8 are the input lines, S1 - S3 are the selection lines and O is the output line.

    Figure 2. Truth table of  8-to-1 multiplexer

  3. Verilog Module

    Figure 3 shows the Verilog module of the 8-to-1 multiplexer. The 8-bit ports In1 to In8 are input lines of the multiplexer. The Sel port is the 3-bit selection line which is required to select between the eight input lines. 8-bit port Out is the output line of the multiplexer.

    Figure 3. Verilog module of 8-to-1 multiplexer

  4. Verilog Code for the 8-to-1 Multiplexer (mux8to1.v)



    1. module mux8to1( Out,
    2. Sel,
    3. In1,
    4. In2,
    5. In3,
    6. In4,
    7. In5,
    8. In6,
    9. In7,
    10. In8
    11. );
    12. input [7:0] In1,
    13. In2,
    14. In3,
    15. In4,
    16. In5,
    17. In6,
    18. In7,
    19. In8; //The eight 8-bit input lines of the Mux
    20. input [2:0] Sel; //The three bit selection line
    21. output [7:0] Out; //The single 8-bit output line of the Mux
    22. reg [7:0] Out;
    23. //Check the state of the input lines
    24. always @ (In1 or In2 or In3 or In4 or In5 or In6 or In7 or In8 or Sel)
    25. begin
    26. case (Sel)
    27. 3'b000 : Out = In1;
    28. 3'b001 : Out = In2;
    29. 3'b010 : Out = In3;
    30. 3'b011 : Out = In4;
    31. 3'b100 : Out = In5;
    32. 3'b101 : Out = In6;
    33. 3'b110 : Out = In7;
    34. 3'b111 : Out = In8;
    35. default : Out = 8'bx;
    36. //If input is undefined then output is undefined
    37. endcase
    38. end
    39. endmodule
    Figure 4. Verilog Code for 8-to-1 multiplexer

  5. Verilog Test Bench for 8-to-1 Multiplexer (mux8to1_tb.v)



    1. `timescale 1ns / 1ps
    2. module mux8to1_tb;
    3. // Inputs
    4. reg [2:0] Sel;
    5. reg [7:0] In1;
    6. reg [7:0] In2;
    7. reg [7:0] In3;
    8. reg [7:0] In4;
    9. reg [7:0] In5;
    10. reg [7:0] In6;
    11. reg [7:0] In7;
    12. reg [7:0] In8;
    13. // Outputs
    14. wire [7:0] Out;
    15. //temporary variable
    16. reg [2:0] count = 3'd0;
    17. // Instantiate the Unit Under Test (UUT)
    18. mux8to1 uut (
    19. .Out(Out),
    20. .Sel(Sel),
    21. .In1(In1),
    22. .In2(In2),
    23. .In3(In3),
    24. .In4(In4),
    25. .In5(In5),
    26. .In6(In6),
    27. .In7(In7),
    28. .In8(In8)
    29. );
    30. initial begin
    31. // Initialize Inputs
    32. Sel = 0;
    33. In1 = 0;
    34. In2 = 0;
    35. In3 = 0;
    36. In4 = 0;
    37. In5 = 0;
    38. In6 = 0;
    39. In7 = 0;
    40. In8 = 0;
    41. // Wait 100 ns for global reset to finish
    42. #100;
    43. // Add stimulus here
    44. Sel = 3'd0;
    45. In1 = 8'd0;
    46. In2 = 8'd1;
    47. In3 = 8'd2;
    48. In4 = 8'd3;
    49. In5 = 8'd4;
    50. In6 = 8'd5;
    51. In7 = 8'd6;
    52. In8 = 8'd7;
    53. //Selection input generation
    54. for (count = 0; count < 8; count = count + 1'b1)
    55. begin
    56. Sel = count;
    57. #20;
    58. end
    59. end
    60. endmodule
    Figure 5. Verilog Test-Bench for 8-to-1 multiplexer

  6. Timing Diagram

    Figure 6. Timing diagram of 8-to-1 multiplexer