I am trying to generate some sequential blocks in Verilog, but the problem is that I need another variable to control double-layer for-loop. For the second layer, the loop bound comparing parameter
should be changed for each iteration of the first loop layer. But, the problem is that I do not know how to set a different loop bound comparing parameter
for each iteration as I get error "par is not a constant" in compiling process.
In below summarized description, I simply showed what I expected. The problem with this is that "par" cannot be set in this way as it is not a C code to perform commands line by line.
parameter sel = 10;
integer par;
...
generate
for ( i = 0 ; i < sel ; i = i + 1)
begin
for ( j = 0 ; j < par ; j = j + 1)
begin
always @(posedge clk) <statement>
par= <a function of par>;
end
end
In the next description, I showed how might be able to do it through an array but here again the error appeared: "parameter 'par' cannot be declared without a default value" while I need to set the values of the constant array through a for-loop, detached from where it is defined!
parameter sel = 10;
parameter integer par[0:sel-1];
initial begin
for ( i = 0 ; i < sel ; i = i + 1)
begin
par[i]= <a function of par>;
end
end
...
generate
for ( i = 0 ; i < sel ; i = i + 1)
begin
for ( j = 0 ; j < par[i] ; j = j + 1)
begin
always @(posedge clk) <statement>
end
end
How can I solve this problem?