Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
14 years ago

While loop error

I am writing some VHDL code that will take an integer and do some calculations and caonditional operations, and I keep getting this error:

Error (10536): VHDL Loop statement error : Loop must terminate within 10,000 iterations

Here is my code below...the error refers to the WHILE synchro_gear <= 16383 LOOP.

synchro_gear <= gear_calc*36;

IF synchro_gear < 16383 THEN

Synchro_36 <= synchro_gear;

ELSIF synchro_gear >=16383 THEN

i <= 0;

WHILE synchro_gear >= 16383 LOOP

i <= i + 1;

synchro_gear <= synchro_gear - 16383;

END LOOP;

WHILE i > 0 LOOP

full_range <= 0;

j <= 0;

FOR j IN 0 to 16383 LOOP

Synchro_36 <= full_range;

full_range <= j + 1;

END LOOP;

i <= i - 1;

END LOOP;

Synchro_36 <= synchro_gear;

END IF;

Please help me figure this one out. Thanks

1 Reply

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    short answer - dont use while loops for synthesisable VHDL. You have tried to write VHDL as if it is C. VHDL is NOT a programming language. I suggest you delete all your VHDL, draw out your circuit and only re-write the VHDL when you fully understand the circuit first.

    long answer - loops are unrolled to produce parrallel hardware. So you always have to assume the worst case, which here means that (im going to assume that synchro_gear is not constrained) the worst case is synchro_gear is 2^31. This means it will take a lot of loops to exit, and it is trying to place over 10,000 adders and subtractors. This is very poor design. The way to fix it is as I said above for the short version.