【发布时间】:2021-02-17 14:36:41
【问题描述】:
我在运行模拟以确保我的计数器正常工作时遇到了一些问题。我的计数器的代码是:
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
不幸的是,当我运行模拟时,它显示输出从未初始化。知道为什么吗?
【问题讨论】:
-
else if(clk) counter <= counter+1'b1;应该是else counter <= counter +1'b1;除了回答工具提到你需要在设计模块中进行此更改以防止综合错误。
标签: verilog simulation