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:

fsfemtoseconds
pspicoseconds
nsnanoseconds
usmicroseconds
msmilliseconds
secseconds
minminutes
hrhours

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
...

Need the Questa/ModelSim project files?

Let me send you a Zip with everything you need to get started in 30 seconds

How does it work?

Tested on Windows and Linux Loading Gif.. How it works

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.

Takeaway

  • The process thread will pause at wait for for the exact specified time
  • All statements other than wait statements take zero simulation time

Go to the next tutorial »

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *