在monitor语句之后删除#2 reset会使代码无效。输出仅为0 x。包括它工作正常。为什么呢?
module counter(out,clock,reset);
input clock,reset;
wire clock,reset;
output [3:0]out;
reg [3:0]out;
always @(posedge clock or negedge clock)
begin
if(reset)
out<=1'b0;
else
out<=out+1;
end
endmodule
module tb();
reg clock,reset;
output [3:0]out;
counter c(out,clock,reset);
initial
begin
clock=0;
reset=1;
end
initial
begin
$monitor("%d %d",$time,out);
#2 reset=0;
end
always
#1 clock=~clock;
initial
#100 $finish;
endmodule
答案 0 :(得分:2)
删除#2
即可在reset
上创建竞争条件:
initial reset = 1;
initial reset = 0;
模拟器的最终值通常为编译顺序中读取的最后一个赋值reset
。尝试合并你的初始块:
initial
begin
$monitor("%d %d",$time,out);
clock=0;
reset=1;
#2 // <-- optional (and still recommened) if you make the below change
// @(clk) //<-- if you truely want a dual edge triggered flip-flop with synchronous reset
reset=0;
end
双边沿触发触发器非常罕见,许多合成器和FPGA不支持它们。我猜你打算用一个带有高有效异步复位的负边沿触发触发器。在这种情况下,替换:
always @(posedge clock or negedge clock)
使用:
always @(negedge clock or posedge reset)