简体   繁体   English

iverilog testbench错误:输入被声明为wire,但不是

[英]iverilog testbench error: input is declared as wire, but it isn't

I am very new to iverilog and am creating a counter to reduce a 100Mhz clock frequency to something easier to work with, as part of a larger project. 我是iverilog的新手,并且正在创建一个计数器,将一个100Mhz的时钟频率降低到更容易使用的水平,这是大型项目的一部分。 I found some code that does that and so I tried to write a testbench for it. 我找到了执行此操作的代码,因此我尝试为其编写测试平台。 Here is the code I found: 这是我发现的代码:

    module slowClock(clk, reset, clk_1Hz);
input clk, reset;
output clk_1Hz;

reg clk_1Hz;
reg [27:0] counter;

always@(posedge reset or posedge clk)
begin
     if (reset == 1'b1)
         begin
             clk_1Hz <= 0;
             counter <= 0;
         end
     else
         begin
             counter <= counter + 1;
             if ( counter == 25_000_000)
                 begin
                     counter <= 0;
                     clk_1Hz <= ~clk_1Hz;
                 end
         end
end
endmodule   

and here is the testbench I wrote: 这是我写的测试台:

module slowClock_tb(clk, reset, clk_1Hz);
    input  clk;
    input  reset;
    output  clk_1Hz;

initial 
begin
    clk = 1'b0; 
    reset = 1'b0;
#2 reset = ~reset;

end

    always #3 clk = ~clk;

slowClock clock_generator(clk, reset, clk_1Hz);


endmodule

Here are the error messages: 这是错误消息:

$ iverilog  slowClock.v slowClock_tb.v 
slowClock_tb.v:8: error: clk is not a valid l-value in slowClock_tb.
slowClock_tb.v:2:      : clk is declared here as wire.
slowClock_tb.v:9: error: reset is not a valid l-value in slowClock_tb.
slowClock_tb.v:3:      : reset is declared here as wire.
slowClock_tb.v:10: error: reset is not a valid l-value in slowClock_tb.
slowClock_tb.v:3:      : reset is declared here as wire.
slowClock_tb.v:14: error: clk is not a valid l-value in slowClock_tb.
slowClock_tb.v:2:      : clk is declared here as wire.
4 error(s) during elaboration.

The first error message: clk is declared here as wire. 第一个错误消息:clk在这里声明为wire。 But it hasn't been declared as a wire in either the original code or the testbench. 但是在原始代码或测试平台中都没有将其声明为导线。 Same goes for reset. 重置也一样。 I have tried getting help from the on-campus tutors, but they didn't know why this is happening or were able to advise on how to fix it. 我曾尝试从校园内的导师那里寻求帮助,但他们不知道为什么会这样,或者无法就如何解决这一问题提供建议。

Can anyone suggest how to fix this? 谁能建议如何解决这个问题?

When you don't include a type all variables/signals are inferred as wires. 当您不包含类型时,所有变量/信号都被推断为导线。 You haven't given them a type, so they're assumed to be wires. 您尚未给它们指定类型,因此假定它们为电线。

You've also defined clk and reset as inputs in your testbench module, but then you're assigning to them inside the testbench so that's why they're not valid l-values. 您还已经在testbench模块中将clkreset定义为输入,但是随后在testbench中将它们分配给它们,这就是为什么它们不是有效的l值的原因。

Try this: 尝试这个:

module slowClock(
    input  wire clk,
    input  wire reset,
    output reg clk_1Hz
    );

    reg [27:0] counter;

    always@(posedge reset or posedge clk) begin
        if (reset == 1'b1) begin
            clk_1Hz <= 0;
            counter <= 0;
        end else begin
            counter <= counter + 1;
            if ( counter == 25_000_000) begin
                counter <= 0;
                clk_1Hz <= ~clk_1Hz;
            end
        end
    end
endmodule
module slowClock_tb;
    reg clk = 1'b0;
    reg reset = 1'b0;
    integer counter = 0;
    wire clk_1Hz;

    initial begin
        #2 reset <= ~reset;
    end

    always #3 clk <= ~clk;

    slowClock clock_generator(clk, reset, clk_1Hz);

    always @(posedge clk) begin
        counter <= counter + 1;
        $display("%0d", counter);

        if (counter > 100) $finish;
    end

endmodule

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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