Forum Discussion
Altera_Forum
Honored Contributor
13 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 edge variable i: integer :=1; begin if rst_i = '1' ...
Altera_Forum
Honored Contributor
13 years agoc<=c+1; will always give you a synchronous counter, if it's in a synchronous process. Otheriwse you just get a logic loop (that the synthesisor wont like very much).
It really is not a compiler error. While loops do not convert well to hardware. And in your example, i has a range -2^31 to 2^31-1, so the compiler doesnt know what could happen to i. According to your code you never set it to 0 again, so technically it only ever adds 1 on the first clock edge and then never again, whereas the for loop resets i every time it enters the loop. AFAIK, the compilers do not do behavioural analysis, hence why it doesnt know i never goes past 16. It just converts it to a netlist using specific templates. If you had set the size of i as : variable i : integer range 1 to 16; It may have had an easier time.