seeking help in writing the synthesizable "for loop" code in verilog

Status
Not open for further replies.

ranga4a2

Newbie level 2
Joined
Dec 29, 2011
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
vellore
Activity points
1,295
hi everybody,
code:

reg [0:250]primset[0:200];
input p;
integer i;

for(i=1;i<p-1;i=i+1)
begin
primset;=i;
end


while i am writing this for loop in xilinx. i am getting this error "For loop stop condition should depend on loop variable or be static".

can any one help me in solving this error.
 

the example itself doesn't make sense, but you can solve
the problem this way:
Code:
localparam max = 201;

reg [x:0] primset[0:max-1];

integer i;

 always @(posedge clk)
    for( i=0; i<max; i=i+1 )
      if ( i<p )      primset[i] <= i;
      else            primset[i] <= primset[i];

J.A
 

    V

    Points: 2
    Helpful Answer Positive Rating
Loops get unrolled in synthesis and are implemented as parallel hardware. They are not used the same way you would use them in software. They are used to generate multiple instances of a circuit. Therefore, the bounds on the loop must be known at 'build time'.
 

yes, you would need to do the loop over the maximum length, and then add an "if loopvar < inputvar".
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…