计数器的输出未在 Verilog 仿真中显示为已初始化

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