VHDL Programming

(C. Jardin) #1

Predefined Attributes 153


END PROCESS;

END behave;

Package ohms_lawdeclares three physical types used in this example.
Types current,voltage, and resistanceare used to show how physical
types can be converted to type INTEGERand back to a physical type.
Whenever ports ior ehave an event occur on them, process ohm_proc
is invoked and calculates a new value of resistance (r) from the current (i)
and the voltage (e). Variables conve,convi, and int_rwere not necessary
in this example but were added for ease of understanding. The commented-
out assignment to output rshows an example where the internal variables
are not needed.
The first statement of the process assigns the position number of the
input value to variable convi. If the input value is 10 ua, then 10 is
assigned to variable convi.
The second statement assigns the position number of the value of
input eto variable conve. The base unit of type voltage is uv (microvolts);
therefore, the position number of any voltage value is determined based
on how many uv the input value is equal to.
The last line in the process converts the resistance value calculated
from the previous line to the appropriate ohms value in type resistance.
The ’VALattribute is used to convert a position number to a physical type
value of type resistance.
The preceding example illustrates how ’POSand ’VALwork, but not
’SUCC,’PRED,’RIGHTOF, and ’LEFTOF. Following is a very simple example
using these attributes:

PACKAGE p_color IS
TYPE color IS ( red, yellow, green, blue, purple,
orange );

SUBTYPE reverse_color is color RANGE orange downto red ;

END p_color;

Assuming the preceding types, the following results are obtained:

color’SUCC(blue) returns purple.

color’PRED(green) returns yellow.

reverse_color’SUCC(blue) returns green.

reverse_color’PRED(green) returns blue.
Free download pdf