我不明白为什么我的程序什么都不返回。我正在尝试制作一个简单的 6 位递增计数器,它可以按按钮计数。
module top (CLK, BTN_RST, LED, BTN_C);
input CLK, BTN_RST, BTN_C;
output [5:0]LED;
reg [5:0]LED;
always @(posedge CLK or posedge BTN_RST) begin
if (BTN_RST) begin
LED <= 6'b000000;
end
else begin: COUNT
while (BTN_C) begin
LED <= LED + 1'b1;
disable COUNT;
end
end
end
endmodule
测试台是:
module top_test;
reg CLK;
reg BTN_RST;
reg BTN_C;
reg [5:0]LED;
initial begin
CLK = 0;
BTN_RST = 0;
BTN_C = 0;
#1 BTN_RST = 1;
#5 BTN_RST = 0;
#10 BTN_C = 1;
#50;
end
always
begin
#5 CLK=~CLK;
end
endmodule
此代码编译并运行(正如我在 iSim 上看到的那样),但
LED
输出给我 XXXXXX。我想我不仅在这里犯了一些错误,而且我也无法理解测试台是如何工作的以及如何对输入和输出进行正确的分配。谁能帮帮我?
您需要在测试台中添加您的设计实例。现在,LED不再是X;我看到它从 0 开始计数。
module top_test;
reg CLK;
reg BTN_RST;
reg BTN_C;
wire [5:0]LED;
initial begin
CLK = 0;
BTN_RST = 0;
BTN_C = 0;
#1 BTN_RST = 1;
#5 BTN_RST = 0;
#10 BTN_C = 1;
#50;
end
always
begin
#5 CLK=~CLK;
end
top dut (
// Inputs:
.BTN_C (BTN_C),
.BTN_RST (BTN_RST),
.CLK (CLK),
// Outputs:
.LED (LED)
);
endmodule
我将 reg 更改为 top_test 中的 LED 接线。当我使用 VCS 作为模拟器时,我看到 LED 从 0 开始增加。但是,当我切换到 Incisive 时,LED 保持在 0.
我认为您的 while/disable 代码导致了问题。我已经重新编码它看起来更标准一点:
module top (CLK, BTN_RST, LED, BTN_C);
input CLK, BTN_RST, BTN_C; //
output [5:0]LED;
reg [5:0]LED;
always @(posedge CLK or posedge BTN_RST) begin
if (BTN_RST) begin
LED <= 6'b000000;
end else if (BTN_C) begin
LED <= LED + 1'b1;
end
end
endmodule