简体   繁体   English

计数器的输出未显示为在 Verilog 模拟中初始化

[英]Output from a counter not showing as initialized in Verilog simulation

I'm having some trouble running a simulation to make sure my counter works.我在运行模拟以确保我的计数器工作时遇到了一些麻烦。 The code for my counter is:我的计数器的代码是:

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

and my testbech code:和我的测试代码:

`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

Unfortunately, when I run the simulation, it shows the output as never initialized.不幸的是,当我运行模拟时,它显示输出从未初始化。 Any idea why?知道为什么吗?

在此处输入图片说明

Your counter remains unknown because you did not reset it.您的计数器仍然未知,因为您没有重置它。 The counter needs the rst signal to be 1 to be reset, but your testbench always drives rst as 0. Here is one way to change the testbench to reset the counter.计数器需要将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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM