Forum Discussion

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

while loop iteration error

Hi all again!

I'm trying to use a while-loop statement in my code, but it wouldn't compile. I created a separate project to simplify the loop statement but it didn't help.

Here is the code:

library IEEE; 
use IEEE.std_logic_1164.all; 
use IEEE.std_logic_unsigned.all; 
 
entity whiler is 
port( clk:in std_logic; 
      reset:in std_logic; 
      outer:out std_logic); 
end whiler; 
 
architecture behavior of whiler is 
begin 
     
    process 
        variable index : integer := 0; 
    begin 
        wait until rising_edge(clk); 
        if (reset = '1') then 
            outer <= '0'; 
        elsif (reset = '0') then 
            while index < 6 loop 
                outer <= '1'; 
                index := index + 1; 
            end loop; 
        end if; 
    end process; 
end behavior;

I get an error stating that the loop must end within 10k iterations, but as far as I can tell this loop should only run through 6 times, so i can't tell whats throwing this error.

Sorry if this seems a simple problem, i'm still pretty new to this language.

Thanks for your time,

Zammy

14 Replies

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

    --- Quote Start ---

    ser_out <= sr(6); can go after the end if; (associated rising_edge(clk)) before end process; and not infer a register.

    --- Quote End ---

    Then you'd get a missmatch between simulation and synthesis. because the process is only sensitive to the clock, in simulation it would only change on any edge of the clock. Because sr(6) will have only been scheduled for a change on the rising edge, and not actually changed yet, ser_out would only get set to the new sr(6) on the falling edge.

    You would have to make the process sensitive to sr(6) too to fix this.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    Then you'd get a missmatch between simulation and synthesis.

    --- Quote End ---

    And a Quartus warning about sr missing in the sensitivity list. I didn't think about this detail, when writing the snippet. Basically I'm used to place combinational code in the concurrent architecture part, except for case statements and similar constructs, that need a process.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    And a Quartus warning about sr missing in the sensitivity list. I didn't think about this detail, when writing the snippet. Basically I'm used to place combinational code in the concurrent architecture part, except for case statements and similar constructs, that need a process.

    --- Quote End ---

    Same here

    When I see clk and reset in the sensitivity list with other signals, I get scared someones puting the clock through gates.