[英]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.