VHDL Programming

(C. Jardin) #1

58 Chapter Three


Let’s look at a practical example of an ASSERTstatement to illustrate
how it works. The example performs a data setup check between two
signals that control a D flip-flop. Most flip-flops require the din(data)
input to be at a stable value a certain amount of time before a clock edge
appears. This time is called the setup time and guarantees that the din
value will be clocked into the flip-flop if the setup time is met. This is
shown in the following model. The assertion example issues an error
message to the designer if the setup time is violated (assertion is false):

PROCESS(clk, din)
VARIABLE last_d_change : TIME := 0 ns;
VARIABLE last_d_value : std_logic := ‘X’;
VARIABLE last_clk_value : std_logic := ‘X’;
BEGIN
IF (last_d_value /= din) THEN — /= is
last_d_change := NOW; — not equal
last_d_value := din;
END IF;

IF (last_clk_value /= clk) THEN
last_clk_value := clk;

IF (clk = ‘ 1 ’) THEN
ASSERT (NOW - last_d_change >= 20 ns)
REPORT “setup violation”
SEVERITY WARNING;
END IF;
END IF;
END PROCESS;

The process makes use of three local variables to record the time and
last value of signal dinas well as the value of the clksignal. By storing
the last value of clkand din, we can determine if the signal has changed
value or not. By recording the last time that dinchanged, we can measure
from the current time to the last dintransition to see if the setup time
has been violated or not. (An easier method using attributes is shown in
Chapter 5,“Subprograms and Packages.”)
Whenever dinor clkchanges, the process is invoked. The first step in
the process is to see if the dinsignal has changed. If it has, the time of
the transition is recorded using the predefined function NOW. This function
returns the current simulation time. Also, the latest value of dinis stored
for future checking.
The next step is to see if signal clkhas made a transition. If the
last_clk_valuevariable is not equal to the current value of clk, then
we know that a transition has occurred. If signal clkis a ‘ 1 ’value,
Free download pdf