Sunday, January 12, 2014

MUX 2:1





Mux Code
module mymux2_1(in1,in2,sel,y);
  input in1,in2,sel;
  output y;
  reg y;

 always@(in1,in2,sel)
  case (sel)
    1'b0: y = in1;
    1'b1: y = in2;
  endcase
endmodule

Test Bench

`timescale 1ns/1ns

module tb();
reg in1,in2,sel;
wire y;
mymux2_1 U1(
             .in1(in1),
             .in2(in2),
             .sel(sel),
             .y(y));
             
             initial
  begin 
    sel=1;
    in1=0;
    in2=1;
    
    #10;
    sel=0;
    in1=0;
    in2=1;
    #10;
    sel=1;
    in1=1;
    in2=0;
    #100;
    sel=0;
    in1=1;
    in2=1;
    #100;
  //  $finish;
  end
  endmodule  

No comments:

Post a Comment