In the previous tutorial we learned that a process can be thought of as a program thread. We also learned that a
wait; statement causes the program to pause indefinitely. But is there a way to make a program wait for any other time value than forever?
If we remove the
wait; altogether and try to compile the program, the compiler will complain about an infinite loop. The loop that the compiler is referring to is the process loop. A process thread in VHDL will never terminate, it will loop continuously between the
end process; statements. There has to be a
wait statement somewhere inside of the process loop.
This blog post is part of the Basic VHDL Tutorials series.
wait; will cause the program to pause forever, the
wait for statement can be used to delay the program for any amount of time.
The syntax of the
wait for statement is:
wait for <time_value> <time_unit>;
<time_value> is number and
<time_unit> is one of the following time units:
This tutorial video will show you how to use the
wait for statement to pause the process for a given time.
The code we created in this tutorial:
entity T02_WaitForTb is end entity; architecture sim of T02_WaitForTb is begin process is begin -- This is the start of the process "thread" report "Peekaboo!"; wait for 10 ns; -- The process will loop back to the start from here end process; end architecture;
The output to the simulator console when we pressed the run button in ModelSim:
VSIM 2> run # ** Note: Peekaboo! # Time: 0 ns Iteration: 0 Instance: /t02_waitfortb # ** Note: Peekaboo! # Time: 10 ns Iteration: 0 Instance: /t02_waitfortb # ** Note: Peekaboo! # Time: 20 ns Iteration: 0 Instance: /t02_waitfortb ...
In this example we used
10 ns, meaning 10 nanoseconds. When working with digital logic that runs at MHz clock frequencies, you will usually be working with nanosecond increments.
When we ran the code in the simulator, it printed “Peekaboo!” to the console every 10 ns. Because this is a simulation, the
report statement takes zero time, and so does the looping.
- The process thread will pause at
wait forfor the exact specified time
- All statements other than
waitstatements take zero simulation time