Saturday 4 July 2015

Combinational circuits- Mux4to1 using Mux2:1 and testbench

MUX 4 TO 1 USING MUX 2 TO 1 AND ITS TESTBENCH

MUX 2 TO 1
module mux2to1(out,s,a,b);
output out;
input s,a,b;
wire w1,w2,w3;
not n1(w1,s);
and a1(w2,w1,a);
and a2(w3,s,b);
or o1(out,w2,w3);
endmodule

MUX 4 TO 1
module mux4(out,s1,s0,a,b,c,d);
output out;
input s1,s0;
input a,b,c,d;
wire w1,w2;
mux2to1 m1(w1,s0,a,b);
mux2to1 m2(w2,s0,c,d);
mux2to1 m3(out,s1,w1,w2);

endmodule

TEST BENCH
module muxtest;
reg a,b,c,d,s1,s0;
wire out;
mux4 m1(out,s1,s0,a,b,c,d);
initial
begin
a=1;b=0;c=1;d=0;
s1=0;s0=0;
a=1;b=0;c=1;d=0;
#75 s1=0;s0=1;
a=1;b=0;c=1;d=0;
#75 s1=1;s0=0;
a=1;b=0;c=1;d=0;
#75 s1=1;s0=1;
end
endmodule

No comments:

Post a Comment