158 Chapter Six
changed, then a rising edge must have occurred. (When a synthesis tool
is applied to the preceding example, a flip-flop results.)
What the preceding example ignores is the fact that an ’X’value to a
’ 1 ’value also looks like a rising edge when it is not. The next example
shows how to correct this problem using the ’LAST_VALUEattribute. The
IFstatement from the preceding example is rewritten here:
IF ( clk = ’ 1 ’ ) AND ( clk’EVENT )
and ( clk’LAST_VALUE = ’ 0 ’) THEN
q <= d;
END IF;
In this example, one more check is made to make certain that the last
value of the clkinput was a ’ 0 ’before the new event occurred.
In both examples, the ’EVENTattribute was not really needed, because
the process statement had only clkas its sensitivity list. The only way
that the process statement could be executed would be because of an
event on signal clk. This is a true statement, but it is a good modeling
practice to check for the event anyway. Some time in the future, the model
may be modified to include an asynchronous preset or clear, and these
signals will be added to the sensitivity list for the process statement. Now,
when an event occurs on any of the inputs, the process is invoked. Using
the ’EVENTattribute, the process can determine which input caused the
process to be invoked.
Attribute ’LAST_EVENT
Attribute ’LAST_EVENTreturns the time since the previous event occurred
on the signal. This attribute is very useful for implementing timing
checks, such as setup checks, hold checks, and pulse width checks. An
example of a setup time and a hold time are shown in Figure 6-1.
The rising edge of signal clkis the reference edge to which all checks
are performed. A setup time check guarantees that the data input does
not change during the setup time, and the hold time check guarantees
that the data input does not change during the time equal to the hold time
after the reference edge. This ensures correct operation of the device.
Following is an example of the setup time check using the ’LAST_EVENT
attribute:
LIBRARY IEEE;
USE IEEE.std_logic_1164.ALL;
ENTITY dff IS