I'm new to verilog and modelsim. I'm having trouble with my AND and OR modules in this particular testbench. The output is always Z(hi impedance)
module mux2to1_tb();
reg[1:0] r0,r1;
reg r2;
wire[1:0] out;
initial
begin
r0=1;
r1=3;
r2=0;
#10;
r2=1;
#10;
end
mux tm(r0,r1,r2,out);
endmodule
here is the mux module
module mux(d0,d1,s0,out);
input[1:0]d0,d1;
input s0;
output[1:0] out;
wire [1:0]w1,w2,w3,w4;
assign w4[0]=s0;
assign w4[1]=s0;
inv2bit M0(w4,w3);
and2bit M1(d0,w3,w1);
and2bit M2(d1,w4,w2);
or2bit M3(w1,w2,out);
endmodule
/*assign w3= ~w4;
assign w1= d0&w3;
assign w2= d1&w4;
assign out= w1|w2;*/
this is the or module
module or2bit(iA,iB,out);
input iA,iB;
output out;
assign out= iA|iB;
endmodule
this is the inverter module
module inv2bit(i1,out);
input i1;
output out;
assign out= ~i1;
endmodule
Best Answer
You declared the
out
signal as awire
in your testbench, and you connected it to theout
output
port of yourmux
module. However, theout
signal inmux
is undriven (it is not connected to anything else). In Verilog,wire
signals default to thez
value.In
mux
you have an undeclared signal namedoutX
. Is thisX
a typo? In other words,out
andoutX
are two different signals. If you renameoutX
asout
everywhere, theout
will be connected.UPDATE: You have confirmed the
X
was a typo, and updated the Question accordingly. That problem is solved.Since you added the inv/and/or module code to the Question, we can see that you try to connect 2-bit signals to 1-bit ports in your submodules. For example:
w4[1:0]
toi1
ininv2bit
. You need to change the port declarations to be 2-bit wide, such as: