VHDL Example – Wait Statement

The Wait Statement is a powerful tool in VHDL. It can be used in both synthesizable and non-synthesizable code, but is more often used in test benches and models. Wait can be used in the following ways:

wait until condition
wait on sensitivity list
wait for time expression

Wait until will suspend a process until the condition of the wait is true. If the keyword wait is not followed by until the code will wait forever on that line.

Wait on is equivalent to using a sensitivity list in a process. As soon as any of the signals in the wait on list changes, the code will continue to execute.

Wait for is never synthesizable. However it is still very useful for test benches and for bus functional models. Wait for must be followed by some amount of time, for example 10 ns. Ensure that you have a space between your number and your unit of time or your code will not compile.

One additional note: A process that has a sensitivity list can not contain any wait statements.



The example below demonstrates each of the uses for wait described above. It also contains an example usage of the “after” statement. In VHDL after indicates that a signal will received an assigned value after some amount of time has passed. It is not synthesizable.

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity wait_statement is
end wait_statement;

architecture behave of wait_statement is

  constant c_CLK_PERIOD : time := 10 ns;  -- 100 MHz

  signal r_RESET  : std_logic := '1';   -- start in reset
  signal r_CLK_TB : std_logic := '0';
  
begin

  -- Demonstrates: WAIT FOR
  -- Generates a clock that is used by the test bench.
  p_CLK : process
  begin
    r_CLK_TB <= not(r_CLK_TB);
    wait for c_CLK_PERIOD/2;
  end process p_CLK;

  
  -- Demonstrates: WAIT ON
  p_RESET : process 
  begin
    wait on r_CLK_TB;                   -- look for first clock

    wait until r_CLK_TB'event and r_CLK_TB = '1';

    r_RESET <= '0' after 40 ns;         -- relese reset

    wait;                               -- wait forever
  end process;


  -- Main Test Bench Process
  process is
  begin

    -- Demonstrates: WAIT UNTIL
    wait until r_RESET = '0';
    
    wait;                               -- example of a wait forever
  end process;  
  
end behave;

Learn Verilog

Modules

Learn VHDL