Verilog:总是在里面循环

Joh*_*ath 0 verilog

我正在尝试实现一个在always块中使用for循环的模块我们使用0和1的数组来记录在特定时间内收到的信号数.

不幸的是,我们收到了这样的错误:

ERROR:Xst:2636 - "Tourniquet.v" line 54: Loop has iterated 10000 times. Use "set -loop_iteration_limit XX" to iterate more.
Run Code Online (Sandbox Code Playgroud)

似乎for循环不允许在always块内(n似乎没有重置).我看过各种网站和论坛,但没有找到任何解决方案.

这是我的代码:

  module Tourniquet(
    input t0,
    input mvt,
     input clk,
    output init
    );

reg initialisation;
reg [0:99] memoire;
reg count = 0;
reg compteur = 0;
reg n;

assign init = initialisation;

always @(posedge clk) 
begin
    if (count==99) 
    begin 
            if (mvt)
            begin 
            memoire[count]=1;
            count=0;
            end

            else
            begin 
            memoire[count]=0;
            count=0;
            end
    end 

    else
    begin 
            if (mvt)
            begin 
            memoire[count]=1;
            count = count + 1;
            end

            else
            begin 
            memoire[count]=0;
            count = count + 1;
            end
    end
end

always @(posedge clk) 
begin
initialisation = 0;
for (n=0; n<99; n=n+1) compteur = compteur + memoire[n];
if (compteur>10) initialisation = 1;
compteur = 0;
end

endmodule
Run Code Online (Sandbox Code Playgroud)

我找不到解决方案,也不确定问题是什么,欢迎任何提示或帮助.非常感谢你 !

sha*_*111 5

你需要循环迭代100次.为此,您需要至少8位计数器变量.

但在这里,n被声明为reg n一个单位计数器变量.所以,n+1给予1和再做n+1一次0.

因此,for循环条件这n<100永远满意.并且for循环永远不会终止.

这是你的for循环多次迭代的主要原因.

通常,integer数据类型用于这些类型的计数器.integer类似于32位reg.声明ninteger nreg [7:0] n具有适当的计数器增量和正确的循环终止.