VHDL Programming

(C. Jardin) #1

52 Chapter Three


another variable of the same name exists in the process, function, or
procedure, then these two variables are treated as separate variables
and are accessed by context. Let’s look at an example to illustrate this
point:

PROCESS(i)
BEGIN

x <= i + 1; -- x is a signal

FOR i IN 1 to a/2 LOOP
q(i) := a; -- q is a variable
END LOOP;

END PROCESS;

Whenever the value of the signal i in the process sensitivity list
changes value, the process will be invoked. The first statement schedules
the value i + 1on the signal x. Next, the FORloop is executed. The index
value iis not the same object as the signal ithat was used to calculate
the new value for signal x. These are separate objects that are each
accessed by context. Inside the FORloop, when a reference is made to i,
the local index is retrieved. But outside the FORloop, when a reference is
made to i, the value of the signal iin the sensitivity list of the process
is retrieved.
The values used to specify the range in the FORloop need not be specific
integer values, as has been shown in the examples. The range can
be any discrete range. A discrete_range can be expressed as a
subtype_indicationor a range statement. Let’s look at a few more exam-
ples of how FORloops can be constructed with ranges:

PROCESS(clk)
TYPE day_of_week IS (sun, mon, tue, wed, thur, fri,
sat);
BEGIN
FOR i IN day_of_week LOOP
IF i = sat THEN
son <= mow_lawn;
ELSIF i = sun THEN
church <= family;
ELSE
dad <= go_to_work;
END IF;
END LOOP;
END PROCESS;
Free download pdf