Verilog is case-sensitive. shiftin
is a different signal from shiftIn
(capital "I"). In the testbench you declared shiftin
, but you did not declare shiftIn
. By default Verilog considers undeclared signals as type wire
, and the default value of a wire
is z
. This means that the input to your design module is undriven. The simulator I used gave me a warning message about this. You can also try your code on different simulators on edaplayground to get more helpful messages.
Change all shiftIn
to shiftin
in your testbench module, and that clears up most of your z
and x
:
time= 0shiftin=0 reset =0 shiftout =x
time= 50shiftin=0 reset =0 shiftout =0
time= 100shiftin=1 reset =0 shiftout =0
time= 150shiftin=1 reset =0 shiftout =1
time= 200shiftin=0 reset =1 shiftout =0
You still get x
at time 0 because reset is not asserted at time 0; reset is asserted at time 200. Typically, you would assert reset at time 0 (reset=1;
), then deassert it (reset=0;
) after a few clock cycles, say at time 100.
module tb_shiftReg();
reg shiftin;
reg clk;
reg reset;
wire shiftOut;
shiftReg SR(shiftin,clk,reset,shiftOut);
initial begin
clk=0;
forever #10 clk = ~clk;
end
initial begin
$monitor("time=",$time, "shiftin=%b reset =%d shiftout =%b",shiftin,reset,shiftOut);
$dumpfile("test.vcd");
$dumpvars;
reset=1;
shiftin <= 0;
#100;
reset=0;
shiftin <= 1;
#100;
shiftin <= 0;
#100;
shiftin <= 0;
#100 $finish;
end
endmodule
With the above changes, all signals show 0/1:
time= 0shiftin=0 reset =1 shiftout =0
time= 100shiftin=1 reset =0 shiftout =0
time= 150shiftin=1 reset =0 shiftout =1
time= 200shiftin=0 reset =0 shiftout =1
time= 250shiftin=0 reset =0 shiftout =0
Note: Your reset signal is asynchronous, not synchronous, because you included reset
in the sensitivity list:
always @(posedge clk or posedge reset)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…