我正在建模一个由三个 D 触发器组成的移位寄存器。有三个输入(clk、reset、shiftIn)和一个输出(shiftOut)。复位为同步高电平有效并复位所有触发器。
设计
module shiftReg(shiftIn,clk,reset,shiftOut);
input shiftIn, clk, reset;
output shiftOut;
reg Q1,Q2,shiftOut;
always @(posedge clk or posedge reset)
begin
if(reset == 1'b1) begin
Q1 <= 1'b0;
Q2 <= 1'b0;
shiftOut <= 1'b0;
end
else begin
Q1 <= shiftIn;
Q2 <= Q1;
shiftOut <= Q2;
end
end
endmodule
试验台
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=0;
shiftin <= 0;
#100;
reset=0;
shiftin <= 1;
#100;
reset =1;
shiftin <= 0;
#100;
reset =1;
shiftin <= 0;
#100 $finish;
end
endmodule
当我使用以下模拟它时,我得到以下输出iverilog
:
vu2swz@PPDP01:~$ iverilog Shiftregister.v
vu2swz@PPDP01:~$ ./a.out
VCD info: dumpfile test.vcd opened for output.
time= 0shiftin=z reset =0 shiftout =x
time= 50shiftin=z reset =0 shiftout =z
time= 200shiftin=z reset =1 shiftout =0
为什么我得到 z 和 x 而不是 1 和零?