VHDL Data Types
VHDL Data Types
DATA TYPES
Every data object in VHDL can hold a value that belongs to a set
of values. This set of values is specified by using a type
declaration.
A type is a name that has associated with it a set of values and a
set of operations.
The language also provides the facility to define new types by
using type declarations and also to define a set of operations on
these types by writing functions that return values of this new
type.
All the possible types that can exist in the language can be
categorized into the following four major categories:
1. Scalar types: Values belonging to these types appear in a
sequential order.
2. Composite types: These are composed of elements of a single
type (an array type) or elements of different types (a record type).
3. Access types: These provide access to objects of a given type
(via pointers).
4. File types: These provides access to objects that contain a
sequence of values of a given type.
SUBTYPES
A subtype is a type with a constraint.
The constraint specifies the subset of values for the type.
The type is called the base type of the subtype.
An object is said to belong to a subtype if it is of the base type
and if it satisfies the constraint.
Subtype declarations are used to declare subtypes.
An object can be declared to either belong to a type or to a
subtype.
Examples of subtypes are
subtype MY_INTEGER is INTEGER range 48 to 156 ;
type DIGIT is ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9') ;
subtype MIDDLE is DIGIT range '3' to '7' ;
A subtype need not impose a constraint. In such a case, the
subtype simply gives another name to an already existing type.
For example:
subtype NUMBER is DIGIT;
SCALAR TYPES
The values belonging to this type are ordered, that is, relational
operators can be used on these values.
For example, BIT is a scalar type and the expression '0' < 1' is
valid.
There are four different kinds of scalar types:
1. enumeration,
2. integer,
3. physical,
4. floating point.
Integer types, floating point types, and physical types are
classified as numeric types since the values associated with
these types are numeric.
Further, enumeration and integer types are called discrete types
since these types have discrete values associated with them.
Enumeration Types
An enumeration type declaration defines a type that has a set of
user-defined values consisting of identifiers and character
literals.
Examples are
type MVL is ('U','0','1','Z);
type MICRO_OP is (LOAD, STORE, ADD, SUB, MUL, DIV);
subtype ARITH_OP is MICRO_OP range ADD to DIV;
Examples of objects defined for these types are
signal CONTROL_A: MVL;
signal CLOCK: MVL range '0' to '1';
variable IC: MICRO_OP := STORE;
variable ALU: ARITH_OP;
Contd…
The order of values appearing in an enumeration type declaration
defines the lexical order for the values.
When using relational operators, a value is always less than a
value that appears to its right in the order.
For instance, in the MICRO_OP type declaration, STORE < DIV is
true, and SUB > MUL is false.
Values of an enumeration type also have a position number
associated with them.
The position number of the leftmost element is 0.
The position number of any particular element is one more than
the position number of the element to its left.
The values of an enumeration type are called enumeration
literals.
Contd…
If the same literal is used in two different enumeration type
declarations, the literal is said to be overloaded.
In such a case, whenever such a literal is used, the type of the
literal is determined from its surrounding context. The following
example clarifies this.
type MVL is ('U', '0', '1 ', 'Z);
type TWO_STATE is ('0', '1');
...
variable CLOCK: TWO_STATE;
variable LATCH_CTRL: MVL;
...
CLOCK := '0‘:
LATCH_CTRL := LATCH_CTRL xor '0';
Contd…
The predefined enumeration types of the language are
CHARACTER, BIT, BOOLEAN, and SEVERITY_LEVEL.
Values belonging to the type CHARACTER constitute the 128
characters of the ASCII character set. These values are called
character literals and are always written between two single
quotes (' ').
Examples are
'A', '_', '" (the single quote character itself),
'3' (the character literal 3)
The predefined type BIT has the literals '0' and 1’
BOOLEAN has the literals FALSE and TRUE
Type SEVERITY_LEVEL has the values NOTE, WARNING,
ERROR, and FAILURE
Integer Types
An integer type defines a type whose set of values fall within a
specified integer range.
Examples of integer type declarations are
type INDEX is range 0 to 15;
type WORD_LENGTH is range 31 downto 0;
subtype DATA_WORD is WORD_LENGTH range 15
downto 0;
type MY_WORD is range 4 to 6;
Some object declarations using these types are
constant MUX_ADDRESS: INDEX := 5;
signal DATA_BUS: DATA_WORD;
Contd…
Values belonging to an integer type are called integer literals.
Examples of integer literals are
56349 6E2 0 98_71_28
Literal 6E2 refers to the decimal value 6 * (10^2) = 600.
The underscore ( _ ) character can be used freely in writing
integer literals and has no impact on the value of the literal;
98_71_28 is same as 987128.
INTEGER is the only predefined integer type of the language.
The range of the INTEGER type is implementation dependent but
must at least cover the range -(2^ 31 - 1) to +(2^31 - 1).
Floating Point Types
A floating point type has a set of values in a given range of real
numbers. Examples of floating point type declarations are
type TTL_VOLTAGE is range -5.5 to -1.4;
type REAL_DATA is range 0.0 to 31.9;
An example of an object declaration is
variable LENGTH: REAL_DATA range 0.0 to 15.9;
...
variable L1, L2, L3: REAL_DATA range 0.0 to 15.9;