FR
FR
is probably not going to help you write better VHDL code, it will only be
will provide more information for those who are interested. Regarding
the VHDL acronym, the V is short for yet another acronym: VHSIC
Description Language. Clearly, the state of technical affairs these days has
done away with the need for nested acronyms. VHDL is a true computer
language with the accompanying set of syntax and usage rules. But, as
describe hardware. The tendency for most people familiar with a higher level computer language such
as C or Java is to view VHDL as just another
VHDL was invented to describe hardware and in fact VHDL is a con current language. What this means
is that, normally, VHDL instructions
are all executed at the same time (concurrently), regardless of the size of
difference should necessarily encourage you to re-think how you write your
circuits that generally do not work correctly and have bugs that are nearly
impossible to trace. And if the circuit does actually work, it will most likely
be inefficient due to the fact that the resulting hardware was unnecessarily
large and overly complex. This problem is compounded as the size and
There are two primary purposes for hardware description languages such
as VHDL. First, VHDL can be used to model digital circuits and systems.
Although the word “model” is one of those overly used words in engineering,
a certain level of detail. The nice thing about VHDL is that the level
of detail is unambiguous due to the rich syntax rules associated with it.
circuit model allows for the subsequent simulation and/or testing of the
circuit. The VHDL model can also be translated into a form that can be
There are other logic languages available to model the behavior of digital
circuit designs that are easy to use because they provide a graphical
method to model circuits. For them, the tendency is to prefer the graphical
approach because it has such a comfortable learning curve. But, as you can
design is to start with a system that is able to describe exactly how your
digital circuit works (in other words, modeling it) without having to worry
working knowledge of VHDL will provide you with the tools to model
Finally, you will be able to use your VHDL code to create actual func tioning circuits. This allows you to
implement relatively complex circuits
using allows you to dedicate more time to designing your circuits and less
VHDL is a very exciting language that can allow the design and imple mentation of functions capable of
processing an enormous amount of data
what is really impressive is that, via simple VHDL modules, you can
complexity
description of what the final logic circuit should do and a language compiler,
in this case called a synthesizer, attempts to “infer” what the actual final
physical logic circuit should be. Novice programmers are not always able to
attempt to reach the same objective. This approach is not only very time
now is to learn how to properly use VHDL to describe what you want to
implement.
Before you start, here are a couple of points that you should never forget
language, these skills are only indirectly applicable to VHDL. When you
are working with VHDL, you are not programming, you are “designing
hardware”. Your VHDL code should reflect this fact. What does this mean?
It means that unless you are inside certain constructs, your code lines will
be executed almost all at once. If your VHDL code appears too similar to
the most complicated programming at any level can be broken down into
design in that even the most complicated digital circuits can be described
in terms of basic digital constructs. In other words, if you are not able to
roughly envision the digital circuit you are trying to model in terms of
basic digital circuits, you will probably misuse VHDL, thus angering the
to be.
is probably the most common device that you can use for your VHDL
implementations. If you want to do VHDL coding for FPGAs you will have
to play within the rules that current major FPGA manufacturers have
drawn up to help you (rules which also ensure their continued existence in
the market).
for the following steps: VHDL code writing, compiling, simulation and
hardware tools that you can use to perform the mentioned steps. Most of
these software tools are free of charge but are not open-source. Nevertheless,
the same tools follow a license scheme, whereby paying a certain amount
32-bit processor) that you can easily include in your own project.
. At the time
will show you how to get up and running with the VHDL language. For
further tasks such as synthesis and upload of your code into an FPGA, the
free of charge Xilinx Vivado7 or the Altera equivalent tool Quartus, can
be employed.
There are several features of VHDL that you should know before moving
you should memorize the basic concepts presented in this section. This
programming language and lay the foundation that will enable you to
VHDL is not case sensitive. This means that the two statements shown
in Listing 2.1 have the exact same meaning (don’t worry about what the
statement actually means though). Keep in mind that Listing 2.1 shows an
example of VHDL case sensitivity and not good VHDL coding practices.
VHDL is not sensitive to white space (spaces and tabs) in the source
document. The two statements in Listing 2.2 have the exact same meaning.
Once again, Listing 2.2 is not an example of good VHDL coding style.
Note that Listing 2.2 once again indicates that VHDL is not case sensitive.
2.3 Comments
Comments in VHDL begin with the symbol “--” (two consecutive dashes).
The VHDL synthesizer ignores anything after the two dashes and up to
the end of the line in which the dashes appear. Listing 2.3 shows two types
(comments that span multiple lines but do not require comment marks on
line or section of code that may not be clear to a reader of your code
too few comments so don’t be shy: use lots of comments. Research has
shown that using lots of appropriate comments is actually a sign of high
intelligence.
2.4 Parentheses
VHDL is relatively lax on its requirement for using parentheses. Like other
computer languages, there are a few precedence rules associated with the
all these rules and write clever VHDL source code that will ensure the
readers of your code are left scratching their heads, a better idea is to
source code understands the purpose of the code. Once again, the two
statements appearing in Listing 2.4 have the same meaning. Note that
extra white space has been added along with the parentheses to make the
is terminated with a semicolon. This fact helps when attempting to re move compiling errors from your
code since semicolons are often omitted
during initial coding. The main challenge then is to know what constitutes
As you will soon find out, the VHDL language contains if, case and
loop statements. A common source of frustration that occurs when learn ing VHDL are the classic
mistakes involving these statements. Always
remember the rules stated below when writing or debugging your VHDL
code and you will save yourself a lot of time. Make a note of this section as
one you may want to read again once you have had a formal introduction
In general, you should not worry too much about memorizing code syntax
as chances are you will use an editor sophisticated enough to have code
2.7 Identifiers
names and port names (all of which will be discussed soon). Listed below
are the hard and soft rules (i.e. you must follow them or you should follow
names make for better reading code, but longer names present more
length.
ˆ Identifiers must not end with an underscore and must never have two
consecutive underscores.
ˆ The best identifier for a function that calculates the position of the Earth
ˆ The best identifier for a variable that stores the age of your car is
Remember, intelligent choices for identifiers make your VHDL code more
family and friends. A few examples of both good and bad choices for
There is a list of words that have been assigned special meaning by the
reserved words that you may be inclined to use appears in Listing 2.7. A
from Listing 2.7 are standard operator names such as AND, OR, XOR,
Coding style refers to the appearance of the VHDL source code. Obviously,
such as C and Java where you have the ability to make the document more
Instead of stating here a bunch of rules for you to follow as to how your
code should look, you should instead strive to simply make your source
code readable. Listed below are a few thoughts on what makes readable
source code.
ˆ Chances are that if your VHDL source code is readable to you, it will
other people may include someone who is helping you get the code
someone who signs your paycheck at the end of the day. These are
the people you want to please. These people are probably very busy
and more than willing to make a superficial glance at your code. Nice
other VHDL document that you find organized and readable. Any code
Emulate the good parts of their style while on the path to creating an
ˆ Adopting a good coding style helps you write code without mistakes.
As with other compilers you have experience with, you will find that
error but a marginal job at telling you where or what the error is.
Using a consistent coding style enables you to find errors both before
This is par ticularly true when using proper indentation and sufficient comments
higher level. Once this is done, the module is referred to by its inherently
more simple black-box representation rather than by the details of the
circuitry that actually performs that functionality. This approach has two
number of logic gates. Second, the black-box approach allows for the reuse
Not surprisingly, VHDL descriptions of circuits are based on the black box approach. The two main parts
of any hierarchical design are the black
box and the stuff that goes in the black box (which can of course be other
black boxes). In VHDL, the black box is referred to as entity and the
stuff that goes inside it is referred to as the architecture. For this reason,
the VHDL entity and architecture are closely related. As you can probably
the VHDL coding time is spent on properly writing the architecture. Our
describing the entity and then moving on to the details of writing the
architecture. Familiarity with the entity will hopefully aid in your learning
3.1 Entity
lower-level circuitry. This wrapper effectively describes how the black box
interfaces with the outside world. Since VHDL describes digital circuits, the
entity simply lists the various inputs and outputs of the underlying circuitry.
my entity defines the name of the entity. The next section is nothing
more than the list of signals from the underlying circuit that are available
to the outside world, which is why it is often referred to as an interface
various signals. The next keyword (the keyword in) specifies the direction
of the signal relative to the entity where signals can either enter, exit or do
both. These input and output signals are associated with the keywords in,
refers to the type of data that the port will handle. There are several data
types available in VHDL but we will primarily deal with the std logic
type and derived versions. More information regarding the various VHDL
When you attempt to write fairly complicated VHDL code, you will need
to split your code into different files, functions and packages constructors
which will help you better deal with your code. In this scenario, the entity
body will not only host the port definition statements but, most likely,
other procedures as well. We will talk about this later in the book.
Listing 3.2 shows an example of a black box and the VHDL code used to
describe it. Listed below are a few points to note about the code in List ing 3.2. Most of the points deal
with the readability and understandability
ˆ Each port name is unique and has an associated mode and data type.
This is a requirement.
single line. Port names are separated by commas. Always strive for
readability.
for readability. Remember that white spaces are ignored by the compiler.
some type of diagram helps with any VHDL code that you may be
Hopefully, you are not finding these entity specifications too challenging.
In fact, they are so straightforward, we will throw in one last twist before
we leave the realm of VHDL entities. Most of the more meaningful circuits
that you will be designing, analyzing and testing have many similar and
closely related inputs and outputs. These are commonly referred to as “bus
signals” in computer lingo. Bus lines are made of more than one signal
separate signal in the bus name contains the bus name plus a number to
separate it from other signals in the bus. Individual bus signals are referred
to as elements of the bus. As you would imagine, buses are often used
the word “bundle” to refer to a set of similar signals and bus to refer to a
protocol.
Bundles are easily described in the VHDL entity. All that is needed is a
new data type and a special notation to indicate when a signal is a bundle
or not. A few examples are shown in Listing 3.3. In these examples note that
the mode remains the same but the type has changed. The std logic
data type has now been replaced by the word std logic vector to
indicate that each signal name contains more than one signal. There are
As you can see by examining Listing 3.3, there are two possible methods
to describe the signals in a bundle. These two methods are shown in the
argument lists that follow the data type declaration. The signals in the
bundle can be listed in one of two orders which are specified by the to and
downto keywords. If you want the most significant bit of your bundle to
be the first bit on the left you use the downto keyword. Be sure not to
forget the orientation of signals when you are using this notation in your
VHDL model.
In the black box of Listing 3.3 you can see the formal notation for a bundle.
Note that the black box uses a slash-and-number notation. The slash across
the signal line indicates the signal is a bundle and the associated number
the black box relative to Listing 3.3 is that the input lines sel1 and sel0
could have been made into one bundle containing the two signals
The data type std logic and the data type std logic vector is
what the IEEE has standardized for the representation of digital signals.
Normally, you should consider that these data types assume the logic value 1
or the logic value 0. However, as specified in the std logic 1164 package,
the implementation of the std logic type (and the std logic vector
0,1,U,X,Z,W,L,H,-.
The data type std logic becomes available to you soon after the dec laration library IEEE; use IEEE.std
logic 1164.all; at the
The reason for all these values is the desire for modeling three-state
drivers, pull-up and pull-down outputs, high impedance state and a few
others types of inputs/outputs. For more details refer to the IEEE 1164
Standard2.
Alternatively to the std logic data type, VHDL programmers some times use the much simpler data type
bit which has only the logic values
1 and 0.
The VHDL language as many other computer languages, has gone through
a long and intense evolution. Among the most important standardization
steps we can mention are the release of the IEEE Standard 1164 pack age as well as some child
standards that further extended the functionality
feature of VHDL you just need to import the two main library packages
Once these packages have been included, you will have access to a very
conversion functions, math functions and so on. For instance, the inclusion
of the package numeric std.all will give you the possibility of using the
unsigned data type and the function to unsigned shown in Listing 3.4.
3.3 Architecture
what the circuit actually does. In other words, the VHDL architecture
much easier than describing how the circuit is intended to operate. This
statement becomes even more important as the circuits you are describing
entity. As you will eventually discover, the VHDL coding style used inside
the architecture body has a significant effect on the way the circuit is
device). This gives the VHDL programmer the flexibility of designing sys tems with specific positive or
negative features such as particular physical
size (measuring the number of needed basic digital elements) or operational
speed.
For various reasons, such as facilitating code re-usability and connectibil ity, an architecture can be
modeled in different ways. Understanding the
plus any combination of these three. There is the data-flow model, the
These models will be described throughout the book. Listing 3.5 gives a
sneak preview of what a simple but complete VHDL code block looks like.
In VHDL there are several object types. Among the most frequently used
we will mention the signal object type, the variable object type and the
wire. The variable type, like in C or Java, is used to store local information.
The constant is like a variable object type, the value of which cannot
example, that a signal object can be of type std logic or of other types
like integer, custom types, etc. The same applies for variable objects.
Signals are declared at the top of the architecture body, just before the
As seen in line 19 and line 20 of Listing 3.5 when you want to assign a new
value to an object of type signal you use the operator “<=”. Alternatively,
when you want to assign a new value to an object of type variable you will
This has important consequences for the updated values of variables and
signals. This means that you should never assume that a signal assignment
can happen instantly and it also means that you can take advantage of
the process construct, a construct that you are not yet familiar with. We
will see more in details later on in the book that any time we need a
after the other (like in C or Java), we will be using the process construct.
bottom. However the process itself will be executed concurrently with the
the execution of the process, are not executed consecutively but instead
concurrently (all at the same time). Any hope that the execution of line
24 will happen before or after the execution of the process will only result
in great disappointment.
As a final note, let us to remind that the type std logic only exists if
Listing 3.5.
3.5 Summary
ˆ The entity declaration describes the inputs and outputs of your circuit.
since these signals are what the circuitry, external to the entity, uses
see later on, even an inout) while the type is either a std logic or
ˆ The word bundle is preferred over the word bus when dealing with
multiple signals that share a similar purpose. The word bus has other
these are always easier to work with in VHDL compared to scalar types
ˆ The architecture describes what your circuit actually does and what
behavior are possible in VHDL. These are the data-flow model, the
3.6 Exercises
diagrams?
diagrams
The previous chapter introduced the idea of the basic design units of VHDL:
the entity and the architecture. Most of the time was spent describing
the entity simply because there is so much less involved compared to the
back for a moment and remember what it is we are trying to do with VHDL.
this is very important. The tendency for young VHDL programmers with
computer programming backgrounds is to view VHDL as just another pro gramming language they want
or have to learn. Although many university
students have used this approach to pass the basic digital classes, this is
languages. The main similarity is that they both use a syntactical and rule based language to describe
something abstract. But, the difference is that
they are describing two different things. Most programming languages are
in a concurrent manner1
once. Realizing this fact will help you to truly understand the VHDL
by the processor. Once the processor finishes one action, it moves onto the
next action specified somewhere in the associated source code. This makes
we are generally only capable of doing one thing at a time. This description
lays the foundation for an algorithmic method where the processor does
a great job of following a set of rules which are essentially the direction
provided by the source code. When the rules are meaningful, the processor
one by one through a set of statements, VHDL has the ability to execute
concurrent manner (in other words, in parallel). Once again, the key
had any introduction to basic digital hardware, you are most likely already
both familiar and comfortable with the concept of parallelism, albeit not
As you know, the output of the gates are a function of the gate inputs.
Any time that any gate input changes, there is a possibility that, after an
opportune delay, the gate output will change. This is true of all the gates
in Figure 4.1 or in any digital circuit in general. Once changes to the gate
inputs occur, the circuit status is re-evaluated and the gate outputs may
change accordingly. Although the circuit in Figure 4.1 only shows a few
gates, this idea of concurrent operation of all the elements in the circuit is
the same in all digital circuits no matter how large or complex they are.
Since most of us are human, we are only capable of reading one line of
when we try to write some text, not to mention enter some text into
a computer. So how then are we going to use text to describe a circuit
that is inherently parallel? We did not have this problem when discussing
The VHDL programming paradigm is built around the concept of ex pression parallelism and
concurrency with textual descriptions of circuits.
statements that look a lot like the statements in algorithmic languages but
Listing 4.1 shows the code that implements the circuit shown in Figure 4.1.
true that we cannot write these four statements at the same time but we can
If you feel that the algorithmic style of thought is creeping into your soul,
three chunks of code appearing below are 100% equivalent to the code
shown in Listing 4.1. Once again, since the statements are interpreted as
better idea to describe the circuit as shown in Listing 4.1 since it somewhat
the assignment operator signifies a transfer of data from the right-hand side
of the operator to the left-hand side. VHDL uses two consecutive characters
words, the signal on the left-hand side of the signal assignment operator is
With these new insights into VHDL, you should be able to understand the
code of Listing 4.1 and its relationship to its schematic shown in Figure 4.1.
The statement “G <= A AND B;” indicates that the value of the signal
There are four types of concurrent statements that are examined in this
statement which we will soon examine further and put it into the context
In essence, the four types of statements represent the tools that you will
adds a fair amount of steepness to the learning curve. As you know from
pieces of code can actually produce the same result. The same is true
for VHDL code: several considerably different pieces of VHDL code can
actually generate the exact same hardware. Keep this in mind when you
look at any of the examples given in this tutorial. Any VHDL code used to
solve a problem is more than likely one of many possible solutions to that
problem. Some of the VHDL models in this tutorial are presented to show
that something can be done a certain way, but that does not necessarily
Listing 4.5. In this case, the target is a signal that receives the values of
This example contains a few new ideas that are worth further clarifica tion.
ˆ There are header files and library files that must be included in your
VHDL code in order for your code to correctly compile. These few lines
of code are listed at the top of the code in Listing 4.6. The listed lines
are more than what is needed for this example but they will be required
ˆ This example highlights the use of several logic operators. The logic
operators available in VHDL are AND, OR, NAND, NOR, XOR and
the left and right-hand side of the operator. The NOT operator is a
unary operator and for that, it only operates on the value appearing to
ˆ In this solution, the entity only has one associated architecture. This is
fairly common practice in most VHDL design.
But since there is only one CSA statement, the concept of concurrency is
not readily apparent. The idea behind any concurrent statement in VHDL
is that the output is changed any time one of the input signals changes.
VHDL, so you may want to read that sentence a few more times. The idea
Listing 4.8 uses some special statements in order to implement the circuit.
The intermediate signals must be declared within the body of the archi tecture because they have no
link to the outside world and thus do not
appear in the entity declaration. Note that the intermediate signals are
declared in the architecture body but appear before the begin statement.
Despite the fact that the architectures f3 2 and f3 1 of Listing 4.7 and
Listing 4.8 appear different, they are functionally equivalent. This is because
for this example, their use brings up some good points. First, the use
of intermediate signals is the norm for most VHDL models. The use of
intermediate signals was optional in Listing 4.8 due to the fact that the
used. Secondly, intermediate signals are something of a tool that you will
often need to use in your VHDL models. The idea here is that you are
will often need to use intermediate signals in order to accomplish your goal
of modeling the circuit. The use of intermediate signals allows you to more
easily model digital circuits but does not make the generated hardware
there is more text written on your page, the circuit you are describing
not true. The main theme of VHDL is that you should use the VHDL
tools at your disposal in order to model your circuits in the simplest way
into VHDL code was almost trivial. Then again, the function in Example 2
there are a few other types of concurrent construct that can ease its
implementation.
describe statements that have only one target but can have more than one
evaluated and assigned to the target. Only one assignment is applied per
assignment statement.
The target in this case is the name of a signal. The condition is based
upon the state of some other signals in the given circuit. Note that there is
only one signal assignment operator associated with the conditional signal
assignment statement.
The conditional signal assignment statement is probably easiest to un derstand in the context of a
circuit. For our first example, let us simply
signal assignment.
ˆ If you look carefully at this code you will notice that there is in fact
expressions are the single digits surrounded by single quotes; the as sociated conditions follow the
when keyword. In other words, there is
only one signal assignment operator used for each conditional signal
assignment statement.
ˆ The solution uses relational operators. There are actually six different
relational operators are the “=” and “/=” relational operators which
are the “is equal to” and the “is not equal to” operators, respectively.
There are more intelligent uses of the conditional signal assignment state ment. One of the classic uses
is for the implementation of a multiplex
The next example is a typical conditional signal assignment imple mentation of a MUX
There are a couple of things to note in the solution provided in List ing 4.11.
logic that would have been required if CSA statements were used. The
VHDL code looks good and is pleasing to the eye, qualities required
for readability.
this case, the values on the bundle SEL are accessed using double
quotes around the specified values. In other words, single quotes are
for the SEL signal plus a catch-all else statement. We could have
changed the line containing ’0’ to D0 and removed the line associated
Generally speaking, you should clearly provide all the options in the code
any time a change occurs in the conditional signals (the signals listed in
statement is executed any time there is a change in any of the signals listed
Though it is still early in the VHDL learning game, you have been
is maybe a bit less intuitive than the concurrent signal assignment. There
touch more upon this relationship once we start talking about sequential
statements.
The concept of working with bundles is very important in VHDL. Gener ally speaking, if you can use a
bundle as opposed to individual signals, you
should. You will often need to access individual signals within a bundle.
When this is the case, a special syntax is used (e.g. SEL(1)). Note that
the code shown in Listing 4.12 is equivalent to but probably not as clear
as the code shown in Listing 4.11. Be sure to note the similarities and
differences.
Selected signal assignment statements are the third type of signal assign ment that we will examine.
As with conditional signal assignment state ments, selected signal assignment statements only have
one assignment
of one expression. The syntax for the selected signal assignment statement
the when others clause as the final entry in the selected signal assignment
statement. In reality, the middle clause ’0’ when ’0’ could be removed
diagram for this example is the same as before and is not repeated here.
Once again, there are a few things of interest in the solution for Example 6
The general appearance is the same. Both solutions are also much more
pleasing to the eye than the one where the MUX was modeled using
output is assigned the constant value of ’0’ when the other listed
ˆ The circuit used in this example was a 4:1 MUX. In this case, each of
requirement. The only requirement here is that the line containing the
The only comment for the solution of Example 7 is that the vertical bar
time there is a change in the chooser expression listed in the first line of
much more depth once we are ready to talk about sequential statements.
with the previous solutions to this example is that they required the
modern day of digital circuit design, you score the most points when you
allow the VHDL synthesizer to do the work for you. The solution to this
example hopefully absolves you from ever again having to use a Karnaugh
The process statement is the final signal assignment type we will look at.
Before we do that, however, we need to take a few steps back and explore
usually many different and varied solutions to the same problem. This is
So, now is not the time to learn about the process statement. We will do
that right after we pick up a few more VHDL concepts. Now just remember
sequentially. In other words, the process statement is a tool that you can
sequential manner (one instruction after the other, from top to bottom).
statement and therefore will be executed together with the other concurrent
4.7 Summary
ˆ The main design consideration in VHDL modeling supports the fact that
each other. This is the major difference between VHDL and higher-level
ˆ The architecture body can contain any or all of the mentioned concurrent statements.
can be used to describe the same circuit. The designer should strive for
clarity in digital modeling and allow the VHDL synthesizer to sort out
the details.