[英]Output from a counter not showing as initialized in Verilog simulation
我在运行模拟以确保我的计数器工作时遇到了一些麻烦。 我的计数器的代码是:
module counter(
input clk, rst,
output reg [16:0] counterout
);
always @(posedge(clk), posedge(rst))
begin
if (rst) counterout <= 0;
else if (clk) counterout <= counterout + 1;
end
endmodule
和我的测试代码:
`timescale 1ns / 1ps
module testbench();
reg clock;
reg rst;
wire [16:0] out;
counter test(
.clk(clock),
.rst(rst),
.counterout(out)
);
integer k = 0;
initial
begin
rst = 0;
clock = 0;
#100 ;
for(k = 0; k < 1000; k = k+1)
begin
#5 clock = clock + 1;
end
#5 $finish;
end
endmodule
不幸的是,当我运行模拟时,它显示输出从未初始化。 知道为什么吗?
您的计数器仍然未知,因为您没有重置它。 计数器需要将rst
信号设为 1 才能重置,但您的测试平台始终将rst
驱动为 0。这是更改测试平台以重置计数器的一种方法。
initial
begin
rst = 1; // Assert reset
clock = 0;
#100 ;
rst = 0; // Release reset
for(k = 0; k < 1000; k = k+1)
begin
#5 clock = clock + 1;
end
#5 $finish;
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.