VHDL Tech Intro
VHDL Tech Intro
Shawki Areibi
School of Engineering
University of Guelph,
Albert Thornbrough Bld #159
Guelph, Ontario,
Canada, N1G 2W1
sareibi@uoguelph.ca
(http://www.uoguelph.ca/∼sareibi)
This technical report series allows faculty of the School of Engineering at the University of
Guelph to publish detailed and recent research results in a timely manner. It is not intended
that these technical reports duplicate outside publications. However, due to the time lag
in publishing results in formal, peer reviewed venues, many of these technical reports will
be submitted for review and publication elsewhere. In such cases, it is intended that the
technical reports will contain additional details and results that cannot be included elsewhere
due to space limitations.
In addition to technical reports pertaining to research conducted within the School of
Engineering, the technical report series may also be used to publish ”pedagogical” results
and methods. Guelph has a strong tradition and committment to high-quality teaching and
teaching methods. Many of our faculty are actively engaged in developing new pedagogical
techniques, including the use of multi-media and Web-based tools for instructional purposes.
We believe that it is equally important to make these results available to the academic and
education community.
While all reports will be numbered sequentially, a research report will be identified by the
technical report number and the code R. Likewise, a pedagogical report will be identified by
the technical report number followed by the code P.
For more information about this technical report series, please contact:
Shawki Areibi sareibi@uoguelph.ca
Publication History
This manual is meant to give students a “first look” at the hardware description language
VHDL (namely 2nd year students taking ENGG*2410 Digital Design at the University of
Guelph School of Engineering). It is a derivative of the original SOE Technical Report
VHDL for Digital Design. The pages herein are not meant to be exhaustive; the goal is for
the student to develop an understanding of some of the fundamental concepts of the VHDL
language, necessary to pursue further (more advanced) studies in this area. Some
knowledge of digital systems design will be assumed, although only at a moderate level.
Notably, the most influential book used in the creation of this text is the VHDL Starter’s
Guide by Sudhakar Yalamanchili [1] (highly recommended for a more complete
understanding of the VHDL language). Some examples may also be based (at least in part)
on examples from the book VHDL for Programmable Logic by Kevin Skahill [2]. Other
important references include [3] and [4].
This work may not be copied or reproduced in whole or in part for any commercial purpose.
Permission to copy in whole or in part without payment of fee is granted for nonprofit
educational and research purposes provided that all such whole or partial copies include the
following: a notice that such copying is by permission of the School of Engineering, University
of Guelph, Guelph, Canada; an acknowledgement of the authors and individual contributors
to the work; an all applicable portions of the copyright notice. Copying, reproducing, or
republishing for any other purpose shall require a license with payment of fee to the School
of Engineering. All rights reserved.
TR 2023-01P
Contents
1 Introduction 1
1.1 Overview of VHDL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Power of HDLs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.3 Using VHDL in the Design Process . . . . . . . . . . . . . . . . . . . . . . . 3
1.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2 First Concepts 4
2.1 Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.2 Entity Declaration & Architecture Body . . . . . . . . . . . . . . . . . . . . 5
2.3 Return to Signal Assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.3.1 Simple . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.3.2 Conditional . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.3.3 Selected . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3 Behavioural Description 12
3.1 Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.2 Order of Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.2.1 If Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.2.2 Case Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.2.3 Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.3 Wait Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
4 Structural Description 20
4.1 Describing Connections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
4.2 Hierarchy & Abstraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
4.3 Generics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
4.4 Configurations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
4.5 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
A Quick Reference 27
A.1 Reserved Words . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
A.2 Declarations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
A.2.1 Entity Declaration . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
A.2.2 Architecture Body . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
A.2.3 Library Declarations . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
A.2.4 Package Declarations . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
A.2.5 Component Declarations . . . . . . . . . . . . . . . . . . . . . . . . . 28
A.2.6 Signal Declarations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
A.2.7 Constant Declarations . . . . . . . . . . . . . . . . . . . . . . . . . . 29
iv
TR 2023-01P
v
TR 2023-01P
List of Figures
1 Design Views and Corresponding Levels of Abstraction . . . . . . . . . . . . 2
2 Half-Adder Circuit & Entity Declaration . . . . . . . . . . . . . . . . . . . . 6
3 4 to 1, 8 Bit Multiplexer Symbol & Entity Declaration . . . . . . . . . . . . 7
4 Half-Adder Code Using Concurrent Signal Assignments . . . . . . . . . . . . 8
5 Full-Adder Circuit & Code Using Concurrent Signal Assignments . . . . . . 9
6 4 to 1, 8 Bit Multiplexer Code Using Conditional Signal Assignment . . . . . 10
7 4 to 1, 8 Bit Multiplexer Code Using Selected Signal Assignment . . . . . . . 11
8 Half-Adder Code Using Process with If and Case Statements . . . . . . . . . 14
9 Simple For Loop, Initializing an 8-bit Vector . . . . . . . . . . . . . . . . . . 15
10 Simple While Loop, Initializing an 8-bit Vector . . . . . . . . . . . . . . . . 15
11 Positive Edge-Triggered D Flip-Flop Symbol, Truth Table & Code . . . . . . 18
12 Full-Adder Code Using Structural Description . . . . . . . . . . . . . . . . . 21
13 Hierarchy of Full-Adder Structural Model . . . . . . . . . . . . . . . . . . . . 22
14 Generic Exclusive-Or Gate . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
15 Half-Adder Code Using Structural Description and Generic Exclusive-Or Gate 24
16 Full-Adder Configuration Specified in Architecture Declarations . . . . . . . 25
List of Tables
1 IEEE 1164 Standard Signal Value System . . . . . . . . . . . . . . . . . . . 4
2 Most Common Signal Attributes . . . . . . . . . . . . . . . . . . . . . . . . . 17
3 Most Common Value Attributes . . . . . . . . . . . . . . . . . . . . . . . . . 17
4 Reserved Words . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
vi
TR 2023-01P
1 Introduction
The term “VHDL” is a very popular buzz word in industry, especially in the search for
qualified engineers who are familiar with it. But what is VHDL, and why all the fuss?
1
TR 2023-01P
set of tools in their development and data sharing among these tools became extremely
important.
VHDL is capable of representing multiple levels of abstraction in the process. This fur-
ther encourages standardization and use, since different design tools (with different design
methodologies) using a standardized HDL can create portable models, reducing the com-
plexity of data sharing among designs. In the rapidly developing technology sector of digital
systems, design philosophy will be frequently changing, and it is therefore desirable that the
HDL language used be flexible enough to accommodate these changes, something for which
VHDL is seemingly well suited for.
Due to VHDL’s rich language subset, it is also technology independent. Designs can
be synthesized to Field Programmable Gate Arrays (FPGAs) or Complex Programmable
Logic Devices (CPLDs) using specialized CAD tools. CAD tools also exist for Application
Specific Integrated Circuit (ASIC) designs in order to simulate operations before physically
implementing them. Once a physical design is available, the timing and performance can
also be verified in simulation.
As previously alluded to, with the ability to create portable models among CAD tools, it
is not a far leap for VHDL to permit the re-use of designs. Libraries of digital models are
available across a diverse range of platforms, and additional ones can be created within a
particular group. It is also possible to mix hardware and software in the process of a design!
2
TR 2023-01P
1.4 Summary
VHDL is a powerful language used to describe hardware structures and behaviour. As a
standard of the IEEE, it is commonly used among CAD vendors and digital designers in
general. Its power and appeal are derived in part from its ability to represent different levels
of abstraction in a digital design, coupled with a rich language set that allows it to be used
in a diverse range of design philosophies. The point is this: VHDL ⇒ Large cost savings in
the design of digital systems.
Among HDLs, VHDL is also accompanied by another popular language named Verilog.
Verilog is also an approved IEEE standard and therefore most CAD tools support it as well
as VHDL. This standardization gives HDLs another advantage over schematics, namely that
HDLs are portable across CAD tools whereas schematic capture tools are typically unique
to a particular vendor.
1
At the same time we may also optimize the design, so that it will perform better for a given device
architecture. We will probably also concern ourselves with placing and routing the design, that is, making
the VHDL design fit within the constraints of a programmable logic device or a field-programmable gate
array.
3
TR 2023-01P
2 First Concepts
Upon first encounter, VHDL can seem overly complicated and intimidating. Not only does
it provide a very rich language set capable of describing a variety of levels of abstraction,
but the language is also meant to describe physical systems. This makes programming in
VHDL much different than in conventional languages such as C or Java. Rather than develop
algorithms and sequences of manipulations on data in order to achieve a certain goal, the
intent in a VHDL program is to model a physical system, to mimic its behaviour. The first
and most obvious example of these differences is the use of parallel operations in VHDL.
Programming in VHDL will require a different approach and way of thinking to problems
compared to the conventional programming languages most are familiar with.
Nonetheless, these differences just described can also be of great aide to the new-comer.
Since VHDL is meant to described physical systems, many of the language constructs that
will be introduced in this text can be paralleled with real physical objects, removing a great
deal of abstractness. In this section, some of the most fundamental language constructs will
be introduced in order to start building the necessary knowledge required to develop any
VHDL program.
2.1 Signals
In digital circuits we concern ourselves with signals, and likewise in VHDL. To accommodate
all the possible signal values that could occur in a digital circuit, dependent in part on design
style, the IEEE approved a 9 value system in order to construct a standard that would allow
for portable models. This value system is termed the IEEE 1164 standard, can can be seen
in Table 1 (the meaning of each signal value will not be discussed here as most are evident
and there importance will be seen as the student develops greater knowledge of VHDL and
digital simulation).
Value Meaning
U Uninitialized
X Forcing Unknown
0 Forcing 0
1 Forcing 1
Z High Impedance
W Weak Unknown
L Weak 0
H Weak 1
- Don’t Care
4
TR 2023-01P
In order to furnish these signal values and simulate the behaviour of digital signals, VHDL
introduces the signal object type2 . Signals can be of different types, such as integer or real
(used at a more abstract level), but the most common and useful to be introduced as new
material at this point are std_logic and std_logic_vector (defined in the IEEE library
package std_logic_1164). Both signal types provide the values in Table 1 on the previous
page, except that the latter allows the initialization of a “bank” of std_logic signals.
Included in the IEEE 1164 standard is a means of dealing with conflicting signals. For
example, say a signal is being driven to both 0 and 1 simultaneously. In this case, the IEEE
1164 standard defines the resulting signal to be X, forcing unknown. As another example,
take the case where a signal is being driven to both 1 and Z (high impedance). Here the
resulting signal would be 1. These results are determined by a resolution function, and the
signals which are defined with such a function are said to be of a resolved type.
Signal declaration is best demonstrated by example, as it differs in two contexts to be
discussed shortly. Nonetheless, it is generally of the form:
5
TR 2023-01P
At this point it is important to note that bold face type is used in the VHDL code
presented in this document for reserved words, a list of which can be seen in Table 4 on page
27. So for the code just presented, the key words entity, is, port, and end are all reserved
by the VHDL language, and therefore they can not be used as labels in the code (such as
for the name of an entity or a signal). Also, VHDL is not generally case sensitive, so the
following are equivalent:
The first two lines in the above example are typically used in VHDL code, the latter to
distinguish key words, but it is really just a matter of style (of course the last line of the
example is only meant to show that case in not important, it has no real use other than
this).
Now consider the 4 to 1, 8 Bit Multiplexer Circuit and Entity Declaration in Figure 3
on the following page. The entity is named mux and in this case the input and output
signals are declared to be std_logic_vector’s, meaning that each encompasses a group of
std_logic signals (which adhere to the IEEE 1164 value system). For example, the input
signals In0 to In3 each contain 8 std_logic signals, numbered from 7 down to 0. Basically
a std_logic_vector is a bus, grouping several signals into one for convenience and clarity.
The rest of this entity declaration should now seem straight-forward.
Having described the entity declaration — the interface — we must now move on to
describing the behaviour of these entities. This is done using an architecture body. The
basic syntax is:
The architecture name is just another label, in this called arch_type, usually given to
distinguish it from other possible variants. Examples could be behavioural, structrural,
6
TR 2023-01P
high_speed, low_power, etc. The architecture will describe the inner workings of the entity,
which is associated to it by placing its name after the key word of, in this case called
the_entity. Obviously then the architecture follows from the entity, but the entity is
meaningless without an architecture, hence one usually speaks of an entity-architecture pair.
Architecture bodies differ greatly due to the various levels of abstraction for which VHDL
is capable of modeling. Hence, these will be discussed in the sections that follow.
2.3.1 Simple
Consider a full implementation of the half-adder in Figure 4 on the next page. The CSAs
shown here are as straight forward as can be. However, being the first full piece of code
presented, its description will require more detail than in following examples.
First notice the libary clause, which identifies the library to be used. On the other
hand it is coupled with a use clause, which identifies the packages or design units to be
used in the current design. Here the package name is std_logic_1164 and all components
in it will be used. This can be regarded as a standard declaration for the purpose of this
document and any designs created subsequent to the information gathered from it should
include this library and package. Next is the entity declaration previously seen in Figure 2
on the preceding page (and therefore need not be discussed further). The architecture has
been called concurrent_behaviour, and is linked to the half_adder entity.
Although the CSAs themselves are simple enough (the statements contained within the
begin and end of the concurrent_behaviour architecture), it is important not to loose
sight of the fact that they are concurrent, so that each statement is evaluated concurrently,
7
TR 2023-01P
regardless of order. Hence, the sum and carry signal assignments could be reversed and the
model would be unaffected (albeit not the greatest example since either way order is not
relevant to this example). So,
CSAs are evaluated when a term on the right hand side changes, in this case the signals a
or b (which in this example both CSAs are dependent upon, although this will not always
be the case).
Now consider a more complicated example, that of the full-adder in Figure 5 on the next
page. For clarity, both the digital circuit and a full implementation in VHDL have been
included together. Of course, the ieee library and std_logic_1164 package have been
included, now considered standard for out purposes. Notice that the full_adder entity
includes only the input and output signals to the design unit, those necessary for interfacing
purposes.
In the dataflow architecture described, internal signals have been declared before the
architecture body, namely s1 to s3, which are also present in the circuit. These internal
signals are then used to link various components in the design, and thus complete the physical
model of the circuit. As a result, this architecture contains 5 CSA statements, one for
each signal. Again recall that the order of the signal assignments is irrelevant, as they are
evaluated not in order but concurrently. Whenever a signal changes, if it is contained on the
right hand side of a CSA, that CSA will be evaluated. The sequence of execution could be
considered for some change in input signals, but as one can see from this example, a change
in one signal can set off a whole chain of events!
8
TR 2023-01P
library ieee;
use ieee.std_logic_1164.all;
Figure 5: Full-Adder Circuit (top) and Code Using Concurrent Signal Assignments (bottom)
2.3.2 Conditional
In the previous 2 examples boolean expressions were used with CSAs to model the circuits.
Although the models are legitimate, not all circuits can be described in this fashion without
great tedium. Wherefore more complex constructs are now introduced.
Examine the code for the 4-to-1, 8 bit multiplexer using a conditional signal assignment
in Figure 6 on the following page. The entity is no different than that presented in Figure 3
on page 7, thus only the architecture need be discussed. A conditional signal assignment is
one statement, and thus if there were additional signal assignments in the architecture body
besides it they would operate concurrently. Consider it one long CSA, with added flavour.
As in the simple CSAs presented in the preceding section, any change on the right hand
side of the signal assignment (i.e. on the right hand side of the <=) will cause it to be
9
TR 2023-01P
library ieee;
use ieee.std_logic_1164.all;
updated. Thus, if the signals In0 to In3 or Sel change, Out will be evaluated. The most
important factor to remember when dealing with conditional signal assignments is that the
conditional expressions are evaluated in order. Therefore, when updated, each conditional
expression is evaluated from first to last, and once one of the expressions is found to be valid,
evaluation terminates (hence the proceeding conditional expressions are not evaluated).
Perhaps now it should be mentioned that when specifying a grouping of bits, such as in
a std_logic_vector, quotation marks are used ("..."). On the other hand, if only one
bit where being specified, as for a std_logic signal, single quotations are used (‘.’). Take
for example the Sel signal above, used to select the input to be directed to the output. If
“Sel = "10"” then Out is connected to In2. If this signal were instead split up into two , say
Sel1 and Sel0, then for the same results “Sel1 = ‘1’ and Sel0 =‘0’” would be required.
2.3.3 Selected
A selected signal assignment is very similar to a conditional signal assignment. Consider
the code for the 4-to-1, 8 bit multiplexer using a selected signal assignment in Figure 7
on the following page. As in the previous case, this signal assignment is evaluated as one
statement, except that here the order in which the select expressions appear is irrelevant,
i.e. select expressions are evaluated concurrently.
One element may seem strange in the architecture body, that of the others word present
in the last select expression. The keyword others is used to denote the remaining signal
values not yet defined. This brings up a tremendously important aspect of a selected sig-
10
TR 2023-01P
library ieee;
use ieee.std_logic_1164.all;
nal assignment, that the full range of signal values must be covered. Recall that the IEEE
1164 standard defines a 9 value system (Table 1 on page 4). Attempting to define a select
expression for every possible combination would be exhaustive, thus the use of the others
keyword.
2.4 Summary
Basic building blocks have now been put in place for creating simple VHDL models. The
following topics should now be considered essential and basic knowledge:
11
TR 2023-01P
3 Behavioural Description
This section will be mainly concerned with presenting a more in depth knowledge of language
constructs (as will be the following), focused on behavioural descriptions. Programming a
behavioural description of a model will seem more natural to those with previous program-
ming experience (than in the following section regarding structural descriptions). Language
constructs presented in this section will follow closely with conventional programming lan-
guages. This is mainly since behavioural models can be described in terms of the processing
performed on input signals and the output signals produced. Hence an introduction to the
process construct wherein signal assignments are sequential rather than concurrent.
3.1 Process
Using sequential statements within the process construct, more abstract behavioural models
will be possible3 . Take for example the modeling of a CPU or memory module. Approaching
such a task using only the CSAs presented thus far would be overwhelming. However, using
more conventional programming techniques such as if statements, loops, etc. (to be discussed
shortly), the task is greatly simplified.
A process is declared inside an architecture body in two general forms, the first to be
discussed being:
Note that the process label is optional, although recommended for clarity.
A sensitivity list identifies the signals that will cause the process to execute. Whenever
an event occurs on a signal in the sensitivity list, the process is executed sequentially until
completion. This is similar to CSAs whereas they are executed when an event occurs on a
signal on the right hand side of the assignment. Process declarations will be the variables
that are to be used locally (whose declaration will been seen shortly in an example), which
can be standard data types such as integers, characters, and real numbers. Moreover, the
process can contain assignments to signals declared externally.
3
Synthesizing these abstract models into real digital circuits is a complex task still being researched and
optimized today and thus not suitable for discussion in this introductory manual.
12
TR 2023-01P
Although statements are strictly sequential within a process, it is possible to modify the
order of execution using more advanced constructs. Introducing these constructs now will
allow for some much needed examples.
3.2.3 Loops
And of course this section would be incomplete without the all too familiar loop, necessary to
perform repetitive operations. There are two general loops in VHDL, a for and a while loop.
However, there are some distinct features to these loops not usually seen elsewhere. Let us
begin with some very simple examples, say initializing the elements of a std_logic_vector
for some unknown architecture, seen in Figures 9 and 10 on page 15.
In order to clarify the examples, some points should be first considered. Notice that an
entity has not been explicitly defined here and is being assumed. This is merely intended to
simplify the examples and should not be a point of confusion. Also, note that the 8 bit vector
could also be initialized using one statement, namely “sum <= "00000000"” and therefore
these are trivial examples only intended to demonstrate the use of such loops. And finally,
13
TR 2023-01P
library ieee;
use ieee.std_logic_1164.all;
14
TR 2023-01P
15
TR 2023-01P
note the method upon which vector elements are accessed, using parentheses and the bit
number to access with the vector name (i.e. vector_name(bit_number)).
First consider the for loop in Figure 9 on the preceding page. Notice that the index i has
not been declared in advance. In VHDL a for loop index is implied and thus only a name
need be provided. As the index is implied for the loop, it is only local to it. However, unlike
most conventional languages, the for loop index may not be modified inside of the loop. It
is only an index, and nothing more.
Now we turn our attention to the while loop in Figure 10 on the previous page. In this
case a loop index is not implied and instead the while loop relies on a condition, like that
used in an if statement. In this example the condition relies on an unimplied index, created
to act like the previous for loop. This then introduces a new construct, the variable.
Note however that a variable need not have an initial value. Observe also that a variable
assignment uses the “:=” operator, and that it is local to the process.
Using such statements not only can a process be made to wait for specific events, such as
the rising edge of a clock, but the process can also be suspended at various points inside of
the process (as opposed to just at the beginning).
In order to present the workings of the wait statement we need first discuss the function
attributes in Table 2 and the value attributes in Table 3 on the following page. Since the
tables give brief descriptions of each attribute, they will not be discussed in greater detail
here, but rather will be seen in examples that follow.
Now take the simple example of the code for a positive edge-triggered D flip-flop in
Figure 11 on page 18. Here it can be noted that the process does not contain a sensitivity
list, but instead has been replaced by a wait statement. This wait statement is rather
important as it designates a positive edge to trigger the D flip-flop. Such a condition is also
sometimes used in an if statement when asynchronous set and reset signals exist (in which
case a sensitivity list would be required, since they are not limited by the clock).
Recall that an IEEE 1164 signal may have up to 9 distinct values, and hence the wait
statement used here is somewhat flawed. Any event that ends with the Clk being the value
1 will cause the D flip-flop to trigger, whereas we would like it to trigger only when the Clk
16
TR 2023-01P
17
TR 2023-01P
library ieee;
use ieee.std_logic_1164.all;
Figure 11: Positive Edge-Triggered D Flip-Flop Symbol, Truth Table (top) and Code (bot-
tom)
changes from 0 to 1. Hence, the reason for which the ieee library defines two functions to
simplify this problem, namely rising_edge(Clk) and falling_edge(Clk) (of course Clk
can be any desired signal). These functions return Boolean values and thus are used in a
condition (in this case replacing the attributes used for the wait until construct).
Further examples of the use of attributes and wait statements can be found in other texts.
Nonetheless their importance and use should be understood.
3.4 Summary
The constructs needed to create behavioural models in VHDL have been described in this
section, including:
18
TR 2023-01P
statement;
• If statement — if condition then, elsif (only one ‘e’), else, end if;
• Case statement — Several branches of execution, must cover full range;
• Loops:
– for — Implied index, cannot modify index;
– while — Relies on condition, usually uses a declared variable local to the process;
• Attributes — Function and signal attributes, often used in wait statements.
19
TR 2023-01P
4 Structural Description
A structural description of a digital circuit provides a representation of the connections
between various components. The behaviour of each component is not dealt with, rather the
focus is on the connections themselves. Considering the previous section, this type of model
could be regarded as less abstract, and we soon realize that several structural models can be
conceived from a single behavioural model. Nonetheless, down the chain of hierarchy (say
for example that each component is also modeled using structural descriptions), at some
point the models must be behavioural, even if this must be attained at the gate level. This
is much like the actual wiring of digital circuits, whereas chips are created and then used in
a design, and then this design may be packaged and then used in another design, and so on.
The task of this section will be to introduce such structural models in VHDL.
20
TR 2023-01P
library ieee;
use ieee.std_logic_1164.all;
then specified with their name, and then port map’s are made. The latter is nothing more
than the specification of the ports connecting to interconnections, using ‘=>’ to specify the
connection from the component to the signal which will provide the interconnection between
it and other components.
21
TR 2023-01P
architecture pairs for a 2-input and gate and a 2 input xor gate (see the original circuit for
the half-adder in Figure 2 on page 6). The resulting hierarchy for the full-adder would be
that shown in Figure 13.
Although simple in structure, it is evident that for large designs the connections in a
structural model could be substantially complex and numerous, the reason for which a hier-
archical approach is most often taken. I.e. the top-level design is broken up into large blocks
(components) and interconnections are made, then the process is repeated iteratively for
each block (component) until the final descriptions provided are behavioural. The point at
which behavioural descriptions would be provided is dependent on the current desired level of
abstraction of the design. As the design progresses and comes closer to being implemented,
the behavioural descriptions can be replaced with structural descriptions decreasing the level
of abstraction until, perhaps, the design attains a gate level representation (of course, the
hierarchical representation ends at behavioural models, hence the gate level models would
have to be behavioural).
One last point that should be obvious, once considered. Since the structural models
depend on components not described in that model, the components must be analyzed
in advance (i.e. the entity-architecture pairs of components must be analyzed in advance).
Analyzing a structural model without having defined the entity-architecture pairs for each
component would result in errors, since the model would have no meaning. Interconnections
22
TR 2023-01P
4.3 Generics
Now would be an appropriate time to introduce the generic construct. This is a convenient
feature used to parameterize a model. Figure 14 shows a generic behavioural model of an
exclusive-or gate. The number of inputs are parameterized by the value n, whose default value
is 2. The rest of the code need not be described as it should be somewhat self explanatory.
Nonetheless, examine the code to ensure that it is clear and well understood.
library ieee;
use ieee.std_logic_1164.all;
Now we continue with an example of using the generic exclusive-or gate in Figure 15 on
the next page. In this example the generic_xor component instantiation is the same as
the entity declaration for the generic_xor except that the value of n is unspecified, and a
generic map is used to declare the value of n to be 2. Note that this is the same as the
default value specified in the generic_xor entity declaration, and is somewhat redundant.
If the generic and generic map constructs had not been included in the half-adder code,
this default value would have been used. However, not only does this code demonstrate how
to use the generic map to specify the value of n but it also ensures that changes in the
default value of n in the generic_xor entity declaration will not affect the half-adder model.
23
TR 2023-01P
The value of n could also have been specified in the component declaration by changing the
generic parameter such that:
generic(n: positive:=2);
which thus would make it match the generic_xor entity declaration exactly, but of course
the value of n specified (i.e. 2) could differ4 .
library ieee;
use ieee.std_logic_1164.all;
Figure 15: Half-Adder Code Using Structural Description and Generic Exclusive-Or Gate
4.4 Configurations
Since many variations in model type are possible in VHDL, it is important to know how to
bind models together. For example, one architecture could be optimized for speed whereas an
other for lower power consumption. If several architectures exist for the same component,
then a configuration must be specified. This can become quite complicated as there is a
4
Actually, it is also possible to pass down generic values from multiple levels of hierarchy, but to alleviate
any further possible confusion our discussion will not go any further than it already has.
24
TR 2023-01P
substantial amount of flexibility and options available and hence only one simple method of
combining components will be discussed herein, once default configurations are discussed.
In the structural model of the full-adder previously discussed (See Figure 12 on page 21),
no configuration was specified. It was assumed that the component declarations would
match entity declarations (found in the working directory). However, if there were multiple
architectures for an entity then the architecture most recently analyzed would be used to
analyze the structural model. On the other hand, if it were desired that another architecture
be used (rather than the last one analyzed), or if the component did not have a matching
entity (which should of course be avoided for the sake of clarity), then a configuration would
have to be specified.
A configuration can be specified among the architecture declarations (before the begin
clause). The general syntax is:
This should be fairly straight-forward and thus not require additional explanation (if not
clear the following example should alleviate confusion).
Take for example the structural description of the full-adder again. Added to the ar-
chitecture declarations could have been the lines shown in Figure 16. Although the first
half-adder is expected to be found in the library work according to the first configuration,
this is actually a keyword usually used to specify the current working directory. The two
half-adders differ in only the fact that the first will use the behavioural architecture and
the second the structural architecture. On the other hand, the 2-input or gate will be ex-
pected to be found in the or_gates library with the entity name or and architecture named
structural.
-- (standard) ieee library; full_adder entity declaration
-- see Figure 12 on page 21
25
TR 2023-01P
4.5 Summary
This section has introduced the constructs needed to created structural models in VHDL,
including:
26
TR 2023-01P
A Quick Reference
This section is not meant to cover all possible declarations, but hopefully the most relevant
are present. Note that terms surrounded by square braces ([...]) in the code presented are
optional, and therefore are not required (the square braces themselves are not to be included
in the code).
27
TR 2023-01P
A.2 Declarations
A.2.1 Entity Declaration
entity entity_name is port(
-- interface signal declarations
);
end entity_name;
28
TR 2023-01P
Concurrent statements are recalculated every time the expression on the right-hand side of
the equation changes.
Variables can only be declared within a process (for our purposes) and are local to the process
in which they are declared. Variables are updated immediately.
29
TR 2023-01P
A.4.2 with-select-when
with select expression select
signal <= expression1 when condition1 ;
expression2 when condition2 ;
...
[expressionN when others ];
Process labels are used to identify the functionality of the process; a process label is not
mandatory but is strongly recommended.
A.5.2 if-then-else
if condition1 then
-- sequential statements
[elsif condition2 then
-- sequential statements]
[else
-- sequential statements]
endif;
A.5.3 case-when
case expression is
30
TR 2023-01P
A.5.4 for-loop
for index in range loop
-- sequential statements
end loop;
A.5.5 while-loop
while condition loop
-- sequential statements
end loop;
A.6 Modes
A.6.1 in
Used to describe a signal that is an input to an entity. Such signals can ONLY be used as
inputs.
A.6.2 out
Used to describe signals that may ONLY be used as outputs from an entity. The out signals
are not required internally within an entity.
31
TR 2023-01P
A.6.3 inout
Used to describe signals that may be used as inputs and outputs to an entity. Useful when
hierarchically creating components or dealing with bi-directional signals (such as feedback
signals).
A.6.4 buffer
A buffer signal is an output signal, where the signal’s values are also required internal to an
entity.
32
TR 2023-01P
References
[1] S. Yalamanchili. Introductory VHDL From Simulation to Synthesis. Prentice Hall, Upper
Saddle River, New Jersey, 2001.
[2] K. Skahill. VHDL for Programmable Logic. Addison Wesley, Reading, Massuchusetts,
1996.
[3] Charles H. Roth. Digital Systems Design Using VHDL. ITP Nelson, New York, New
York, 1997.
[4] M.M. Mano and C. Kime. Logic And Computer Design Fundamentals. Prentice Hall,
New York, New York, 2000.
33