我对verilog来说是全新的,我很快就会对我上大学的课程有所了解。因此,我正在使用我的altera DE2板和quartis2,并学习细节。
我正在尝试制作一个通过开关打开和关闭的计数器。 到目前为止,计数器根据按键计数和重置。
这是我的错误:
Error (10119): Verilog HDL Loop Statement error at my_first_counter_enable.v(19): loop with non-constant loop condition must terminate within 250 iterations
我理解我被要求提供一个循环变量,但即使这样做我也会收到错误。 这是我的代码:
module my_first_counter_enable(SW,CLOCK_50,LEDR,KEY);
input CLOCK_50;
input [17:0] SW;
input KEY;
output [17:0] LEDR;
reg [32:0] count;
wire reset_n;
wire enable;
assign reset_n = KEY;
assign enable = SW[0];
assign LEDR = count[27:24];
always@ (posedge CLOCK_50 or negedge reset_n) begin
if(enable)
if(!reset_n)
count = 0;
else
count = count + 1;
end
endmodule
我希望有人可以在循环中指出我的错误并允许我继续。
谢谢!
答案 0 :(得分:3)
我认为你不想在那里使用while
循环。怎么样:
always@ (posedge CLOCK_50 or negedge reset_n) begin
if(!reset_n)
count <= 0;
else if (enable)
count <= count + 1;
end
我还添加了非阻塞分配<=
,它们更适合于同步逻辑。
答案 1 :(得分:2)
每当时钟有一个上升沿时,该块就会触发。你有while
循环的地方并不代表硬件中的任何东西,它仍然需要一个时钟来驱动触发器。
虽然可以在测试笔中使用循环来驱动刺激
integer x;
initial begin
x = 0;
while (x<1000) begin
data_in = 2**x ; //or stimulus read from file etc ...
x=x+1;
end
end
我发现for
循环或repeat
更有用:
integer x;
initial begin
for (x=0; x<1000; x=x+1) begin
data_in = 2**x ; //or stimulus read from file etc ...
end
end
initial begin
repeat(1000) begin
data_in = 'z; //stimulus read from file etc (no loop variable)...
end
end
注意:个人我也会在每件事情上添加开头,以避免以后添加额外的行,并想知道为什么他们总是或永远不会被执行,特别是在语言新手时。它还具有使缩进看起来更好的附加好处。
always@ (posedge CLOCK_50 or negedge reset_n) begin
if(!reset_n) begin
count <= 'b0;
end
else if (enable) begin
count <= count + 1;
end
end
答案 2 :(得分:0)
<强>标题强>
错误(10119):Verilog HDL循环语句错误:具有非常量循环条件的循环必须在迭代内终止 描述
当合成通过Verilog HDL中的循环迭代超过合成循环限制时,Quartus®II软件中可能会出现此错误。此限制可防止合成潜在地进入无限循环。默认情况下,此循环限制设置为250次迭代。
解决方法/修复
要解决此错误,可以使用Quartus II设置文件(.qsf)中的VERILOG_NON_CONSTANT_LOOP_LIMIT选项设置循环限制。例如:
set_global_assignment -name VERILOG_NON_CONSTANT_LOOP_LIMIT 300