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 begin
and 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.
While wait;
will cause the program to pause forever, and 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>;
where <time_value>
is number and <time_unit>
is one of the following time units:
fs | femtoseconds |
ps | picoseconds |
ns | nanoseconds |
us | microseconds |
ms | milliseconds |
sec | seconds |
min | minutes |
hr | hours |
Exercise
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 ...
Analysis
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.
Get free access to the Basic VHDL Course
Download the course material and get started.
You will receive a Zip with exercises for the 23 video lessons as VHDL files where you fill in the blanks, code answers, and a link to the course.
By submitting, you consent to receive marketing emails from VHDLwhiz (unsubscribe anytime).
Takeaway
- The process thread will pause at
wait for
for the exact specified time - All statements other than
wait
statements take zero simulation time