Altera_Forum
Honored Contributor
12 years agoprocesses: while loop does not work, for loop does work. Why?
I want to write this code for a basic synchronous counter more efficiently...
u_count: process(rst_i, clk_i) -- generated on rising edgevariable i: integer :=1;
begin
if rst_i = '1' then
c <= "00000000000000000";
elsif (clk_i ='0' and clk_i'event) then
c(0) <= c(0) xor cyi;
c(1) <= c(1) xor t(0); -- t(n) terms are propagate terms defined earlier as dataflow statements.
c(2) <= c(2) xor t(1);
..
c(16) <= c(16) xor t(15);
end if;
end process;
This code below for a loop counter works (good to know) u_count: process(rst_i, clk_i) -- generated on rising edge
variable i: integer range 1 to 16;
begin
if rst_i = '1' then
c <= "00000000000000000";
elsif (clk_i ='0' and clk_i'event) then
c(0) <= c(0) xor cyi;
for i in 1 to 16 loop
c(i) <= c(i) xor t(i-1);
end loop;
end if;
end process;
--------------------------------------------------------------------- And this code below with the most basic while loop does not Error (10536): loop must terminate within 10,000 iterations u_count: process(rst_i, clk_i) -- generated on rising edge
variable i: integer :=1;
begin
if rst_i = '1' then
c <= "00000000000000000";
elsif (clk_i ='0' and clk_i'event) then
c(0) <= c(0) xor cyi;
while (i <= 16) loop
c(i) <= c(i) xor t(i-1);
i:=i+1; -- how can i get past 16 to 10,000?
end loop;
end if;
end process;
Lots of people get this error, but they don't present a simple, bullet-proof example that does not have some other quirk that obfuscates this issue, so I never could find an explanation for the error. Thanks.