4X1 Multiplexer

 


Truth Table









Dataflow Modeling

    module mux_41(I0,I1,I2,I3,S1,S0,Y)

        input I0,I1,I2,I3,S1,S0;

        output Y;

        assign Y=S1?(S0?I3:I2):(S0?I1:I0);

    endmodule


 Case Statement

module mux_41(I0,I1,I2,I3,S1,S0,Y);

    input I0,I1,I2,I3,S1,S0;

    output Y;

     reg     Y;

     always@(I0 or I1 or I2 or I3 or S1 or S0)

     begin

          case(S1 or S0)

              2'b00 : Y = I0;

              2'b01 : Y = I1;

              2'b10 : Y = I2;

              2'b11 : Y = I3;

             endcase

        end

endmodule

Structural Modeling










2X1 Multiplexer

    module mux_21(I0,I1,S,Y);

        input I0,I1,S;

         output Y;

         assign Y=S?I1:I0;

     endmodule 

   4X1 Multiplexer

   module mux_41(I0,I1,I2,I3,S0,S1,Y);

       input I0,I1,I2,I3S0,S1;

      output Y;

       mux_21 logic1(.I0(I0),

                                 .I1(I1),

                                 .S(S0),

                                 .Y(temp1)

                                );

       mux_21 logic2(.I0(I0),

                                 .I1(I1),

                                 .S(S0),

                                 .Y(temp2)

                                );

         mux_21 logic3(.I0(temp1),

                                 .I1(temp2),

                                 .S(S1),

                                 .Y(Y)

                                );

endmodule

Testbench

module mux_41_tb;

    reg t_I0,t_I1,t_I2,t_I3,t_S1,t_S0;

    wire t_Y;

     mux_41 mux_41_tb(.I0(t_I0),

                                        .I1(t_I1),

                                         .I2(t_I2),

                                          .I3(t_I3),

                                          .S1(t_S1),

                                          .S0(t_S0),

                                           .Y(t_Y)

                                            );

          initial

               begin

                   t_I0 = 1'b0;

                   t_I1 = 1'b0;

                   t_I2 = 1'b0;

                   t_I3 = 1'b0;

                   t_S1 = 1'b0;

                   t_S0 = 1'b0;

                   #500 $finish;

            end

          always #10 t_I0 = ~t_I0; 

           always #10 t_I1 = ~t_I1;

           always #10 t_I2 = ~t_I2;

           always #10 t_I3 = ~t_I3;

           always #10 t_s1 = ~t_s1;

           always #10 t_s0 = ~t_s0;

            always@(t_I0 or t_I1 or t_I2 or t_I3 or t_S1 or t_S0)

             begin

                    $monitor("%t,t_I0 = %d,t_I1=%d,t_I2 =%d,t_I3 

                                      =%d,t_s1=%d,t_s0=%d",$time,t_I0,t_I1,t_I2,t_I3,t_s1,t_s0);

               end

endmodule

Comments

Popular posts from this blog

2X1 Multiplexer