2X1 Multiplexer
Boolean Equation
Y = I0 if {S = 0}
Y = I1 if {S = 1}
Truth Table
input I0,I1,S;
output Y;
assign Y = (S)?I1:I0;
endmodule
Behavioral Modeling
module mux_21(I0,I1,S,Y);
input I0,I1,S;
output Y;
reg Y;
always@(I0 or I1 or S)
begin
if(S == 1'b1)
Y = I1;
else
Y = I0;
end
endmodule
Case Statement
module mux_21(I0,I1,S,Y);
input I0,I1,S;
output Y;
reg Y;
always@(I0 or I1 or S)
begin
case(S)
1'b1 : Y = I1;
1'b0 : Y = I0;
endcase
end
endmodule
Testbench
module mux_21_tb;
reg t_I0,t_I1,t_S;
wire t_Y;
mux_21 mux_21_tb(.I0(t_I0),.I1(t_I1),.S(t_S),.Y(t_Y));
initial
begin
t_I0 = 1'b0;
t_I1 = 1'b0;
t_S = 1'b0;
end
always #10 t_s = ~t_s;
always #20 t_I0 = ~t_I0;
always #40 t_I1 = ~t_I1;
always@(t_I0 or t_I1 or t_S)
begin
$monitor("%t,t_S=%d,t_I0=%d,t_I1=%d,t_Y=%d",$time,t_S,t_I0,t_I1,t_Y);
end
endmodule

.jpg)
Comments
Post a Comment