Types in VHDL⚓
There are different types of signals depending on the needs. Each type is defined in a library.
std_logic
⚓
The std_logic
type is used to declare 1-bit signals. It is part of the standard library std_logic_1164
library. This bit can take 9 different states:
Values | Description |
---|---|
'0' |
Low logic state |
'1' |
High logic state |
'Z' |
High impedence |
'U' |
Undefined |
'X' |
Conflict (multiple drivers) |
'W' |
Unknown, Weak |
'H' |
Unknown, probably High |
'L' |
Unknown, probably Low |
'-' |
Don't care… |
However, only the first three states can be synthesized. So if in simulation one of the other states is detected, the design may not behave as expected on FPGA. This is the advantage of this type type, it is thus easier to debug a circuit during simulations.
Declaration :
1 |
|
std_logic_vector
⚓
This type is used to represent signals composed of several bits, for example a bus, or a data signal. It is part of the standard library std_logic_1164
. Each of the bits composing this vector has the same properties as a std_logic
. It is imperative to indicate a size to this vector when declaring it:
1 |
|
As it is an array, it is possible to access each element that composes it, in reading as well as in writing, via indices of type integer :
1 2 3 4 5 6 7 8 |
|
enumerate
⚓
This type is used in particular to describe the different states that an automaton can take (state machine). The declaration is of high level, i.e. it does not involve vector size etc. It is the synthesizer which is in charge of converting the states into physical quantities (ie. electrical signals). Declaration:
1 2 3 4 5 |
|
unsigned
/signed
⚓
These types are used for arithmetic operations. They are defined in the standard library numeric_std
library. Signed signals are represented in 2's complement. In the same way as for vectors std_logic_vector
, it is imperative to indicate a size to these vectors when declaring them:
1 2 |
|
These signals should be used for arithmetic operations, otherwise it is better to use std_logic_vector
. In the same way as for the std_logic_vector
, it is possible to access the bits that make them up via an via an index of type integer.
boolean
⚓
The boolean
type is defined in the standard package. It is an enumerate than can only take two values : true
and false
. It is used for conditional operations. The default value of any object of the boolean type is false.
natural
/integer
⚓
These types of signals can also be used for arithmetic operations, in particular for counter/counter. The type natural
is used for positive data signals, integer
for positive and/or negative data. This time it is not necessary to specify a vector size in number of bits, but a range of values when declaring it. This is the type used as an index of vectors and arrays:
1 2 |
|
If no value range is specified, by default the range is 0 → \(2^{32} -1\) for a natural and \(-2^{31}\) → \(2^{31} -1\) for an integer. It is therefore important, in order to avoid using more resources than necessary, to constrain correctly the possible range of values.
array
⚓
The array
type is used to construct arrays of signals, or arrays (2 or more dimensional arrays). The most often, this type is used to describe memories : 1 dimensional array of signals. In the case of arrays of dimension greater than or equal to 2, the problem of the use of resources arises. Indeed for this type of array a very large number of multiplexers is necessary. Example of declaration:
1 |
|
We define a ram_type
composed of 6 signals of 8 bits. A signal of this type is then addressable as well in reading as in writing. The index used must be of type integer
.
1 2 3 4 5 6 7 8 9 10 11 |
|
For more flexibility, it is possible to declare unconstrain array types, and then set the size at signal declaration:
1 2 3 4 |
|
Record
⚓
The record type is used to build data structures that can be heterogeneous. It is the equivalent of struct in C.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
It is possible to use records in tables:
1 2 3 4 5 6 7 8 9 |
|
line
⚓
It is possible to manipulate text files in VHDL to facilitate simulations. The manipulation of files is obviously not synthesizable, it doesn't make sense on FPGA or ASIC. The line type is the type that allows as its name indicates to manipulate lines.