Chapter 6: Introduction To VHDL
Chapter 6: Introduction To VHDL
Chapter 6: Introduction To VHDL
Ø Introduction
Ø Domain of Description
Ø VHDL Example
Ø Behavioral Description
Ø Procedural Description
Ø Dataflow Description
Ø RTL Behavioral
INTRODUCTION
With the emergence of Integrated Circuit (IC) Technology and it’s development in
allowing more and more components on a single chip, digital systems have grown immensely in
complexity. As a result, detailed designing of the digital systems at the gate and the flip-flop level
has come out to be very tedious and time consuming. Hence, the importance of Hardware
Description Languages in the digital design process. A hardware description language allows a
digital system to be designed and debugged at a higher level before conversion to the gate and flip-
flop level. Use of synthesis computer-aided design tools to do this conversion is becoming more
widespread. An useful analogy would be that of writing software in a high level language like C
and then using a compiler to convert the programs to machine language. VHDL and Verilog are
the two most popular hardware description languages.
· VHDL was initiated in the 1980s by the United States Department of Defence.
· The initial objective of the VHDL was modeling, thus, at that time only a simulator was
envisaged.
· Subsequently, tools for VHDL synthesis were developed.
DOMAINS OF DESCRIPTION
VHDL Description:
VHDL can be used to describe a digital system at several different levels- behavioural, data
flow, and structural.
Ø Behavioural Level: A digital circuit is specified in terms of its input and output behaviour. At
this level, the circuit does not include any implementation details, and can be regarded as a black
box.
Ø Data Flow Level: The circuit is specified in terms of the Boolean Logic equations, relating the
outputs to the inputs.
Ø Structural Level: The circuit is described by specifying what all does it comprise, e.g.
transistors, resistors, etc. and the various interconnections of the gates.
2) Modularity: A system generally consists of one or more components, which are referred
to as entities, having clear interfaces. The interface is what is known as entity declaration. In an
entity declaration, all the input and output ports of the component are clearly specified. The
internals of the component are referred to as the architecture declaration. In an architecture
declaration, we define the internal structure of an entity. The various outputs are declared and
assigned to the output ports. It is important to note that there can be multiple architectures even at
different levels of abstraction associated with the same entity.
3) Concurrency: More often than not the hardware that we synthesize is capable of
running several components simultaneously, i.e. it is concurrent. The idea of concurrency will be
made clearer below.
VHDL Example
The following is the VHDL representation of a two-input AND gate, whose inputs are a
and b, with c as the output.
entity AND is -- the name of entity is AND
port ( a, b: in bit; -- a and b are inputs of one bit each
c: out bit); -- c is a one-bit output
end AND; -- entity declaration ends
The diagram given below shows how a number of active processes run simultaneously, or
concurrently, in VHDL. However the statements inside a process are executed sequentially.
We can say that concurrent statements are processes, which are
always active.
he above diagram shows the parallel running of n active processes. In VHDL, we say that the
processes are running simultaneously or concurrently, though, the statements inside each process
are executed sequentially.
Hierarchy in VHDL
In the figure given below, C0 to C7 are concurrent processes, while S1 to S12 are
sequential processes.
C1, C2 and C3 are concurrent processes which are embedded in another concurrent process
C0. In C1 there are two additional concurrent processes C4 and C5, while C2 has C6 and C7 as
concurrent processes.
In C3 , there are two sequential processes S11 and S12.
In C4, there are two sequential processes S1 and S2.
In C5, there are three sequential processes S3, S4 and S5.
In C6, there is a single sequential process S6.
In C7, there are four sequential processes S7, S8, S9 and S10.
BEHAVIORAL DESCRIPTION IN VHDL
MODELING STYLES
· Structural Description
· Algorithmic Description
· RTL Description
These modeling styles are used separately and there is no need to mix any two of them. The first
three styles have been discussed in the last class. The last two styles that form the behavioral
description will be discussed in this lecture and continued in the next.
CONCURRENT STATEMENTS IN VHDL
Statement Function
entity DFF is
port (D, CLK : in bit ;
Q : out bit ; QN : out bit := '1') ;
end DFF ;
· The default value of instantiation of a signal is '0' so that we could also have written Q :
out bit := '0' ; QN : out bit := '1'
· CLK is just a name used to represent clock and we could use any other name as well.
· The modeling of the design is called simulation. Instantiation is allowed only in simulation
and not in synthesis. The constructs allowed in simulation are more than those allowed in
synthesis.
· The begins in the second and fourth lines match the ends in the last and the but last lines
respectively. The if statement in the fifth line ends with the endif.
· Each process is sensitive to some signals. The list of these signals is mentioned just after
process in parenthesis. The process is executed only when some item in the sensitivity list
changes. Here the process is sensitive to CLK. The CLK signal is also tested within the
process, and if CLK = '1', this means that a rising edge has just occurred on CLK. In this
case, Q is set equal to D, and QN is set to the complement of D. The 10 ns delay represents
the propagation time between the time the clock changes and the flip flop outputs change.
Sensitivity list is allowed only in simulation and not in synthesis.
· There may be several processes running within an architecture. The processes are
concurrent and interact with each other through signals.
CONCURRENT PROCESSES
To model the MUX at the behavioral level, we can use a conditional assignment statement.
This concurrent event is executed whenever an event occurs on a signal used in one of the
expressions or conditions. if condition 1 is true then, sel is set to 0, else if condition 2 is true then ,
sel is set to 1 ,etc.
If a MUX model is used inside a process, a concurrent statement cannot be used. As an alternative,
the MX can be modeled using a case statement.
case sel is
when 0 => y <= x0
when 1 => y <= x1
when 2 => y <= x2
when 3 => y <= x3
end case
The value of sel ( or in general, "expression" ) is found first. If it is equal to 0 ( or the first choice )
then the first statement ( or the first set of sequential statements ) is executed; if it is equal to 1 ( or
the second choice ) then the second statement ( or the second set of sequential statements ) is
executed, etc.
This process will execute the sequential statements until a wait is encountered. Then it will wait
until the specified condition is satisfied ( here an event on trigger occurs ). It will then execute the
next set of sequential statements
until a wait statement is encountered. It will continue in this manner until the end of the process is
reached. Then it starts over again at the beginning of the process.
Note that
process ( trigger )
...
...
is equivalent to
process
...
...
wait on trigger ;
end process ;
Variables are to be defined within the process and are local to the process. It is not allowed to use
both wait and sensitivity list in the same process.wait is used in synthesis in a very limited manner.
A similar architecture declaration using signals instead of variables can be use to distinguish the
signals and variables.
Ø Another Architecture
Architecture sig of dummy is
signal trigger, sum : integer := 0 ;
signal sig1 : integer := 1 ;
signal sig2, sig3 : integer := 2 ;
begin
process
begin
wait on trigger ;
sig3 <= sig1 + sig2 ;
sig1 <= sig3 ;
sum <= sig1 ;
end process ;
end sig ;
The figure illustrates the concept of delta delay. At point A several expressions need to be
evaluated. There is an infinitesimal time delay of delta and the assignments occur simultaneously
at point B after the delta delay.
The variables differ from signals in that they are 'containers', unlike signals that are 'nodes'. When
a variable assignment is executed, the variable is immediately updated without delay, not even a
delta delay. In contrast, when a signal assignment is executed, the signal is scheduled to change
after a delta delay. So in the first case ( in architecture var ), sum will get the value 3 ( equal to
var1 + var3 ) . In the second case ( in architecture sig ), the values of sig3, sig1 and sum are
updated only after a delta delay after an event on trigger. Hence sig1 gets the previous value of
sig3. But the simulation time does not move ahead by delta. So the value of sum is 1.
In the following example, the new value of sig3 is assigned to sig1 since the assignment is
scheduled at time t +1+ delta and takes place at simulation time t +1, till when sig3 has got the new
value.
The definitions and instantiation of signals is outside the process description while variable
definitions is inside.Note that anything between the processes have to go through signals.
Ø Constants
Constants can also be declared. Constants declared at the start of an architecture can be used
anywhere within that architecture, but constants declared within a process are local to the process.
PROCEDURAL DESCRIPTION
Procedures facilitate decomposition of VHDL code into modules. The following statements are
used in procedural description in VHDL. This will be discussed in the next class.
· process statements
The following statements are used in processes and procedures in VHDL. These will be dealt in
the next class.
· assignments
· control statements
· procedure calls
· wait statements
DATAFLOW DESCRIPTION
In a dataflow description we describe the drivers for all the signals in a system using concurrent
assignment statements.
Example:
We start with an example, describing a 1-bit cascadable comparator.
First, we have to make an entity declaration
entity comp1 is
port(a,b,gt,eq,lt:in bit; a_gt_b, a_eq_b, a_lt_b:out bit);
end comp1;
This entity declaration declares an entity ‘comp1’ which has five input ports and three output
ports:
Comp1
A dataflow description of the comparator will use concurrent assignments to describe the drivers
for each of the signals or nodes in the circuit. The dataflow architecture for the 1-bit cascadable
comparator is:
Architecture has to be declared in terms of an entity, that is, architecture always refers to a
particular entity. All the input and output ports declared in the entity are visible within the
architecture. The input ports can be used on the right hand side of the assignments and the output
ports can be used on the left-hand side of concurrent assignments.
In the above example all signals except ‘s’ are input-output ports. ‘s’ is an internal signal of the
entity.
CONCURRENT ASSIGNMENTS IN VHDL
The VHDL signal assignments as in the previous example are called concurrent assignments when
they are not contained in a process or a block. The VHDL simulator monitors the right-hand-side
of each concurrent statement, and every time a signal changes, the expression on the right hand
side is immediately re-evaluated. The new value is assigned to the signal on the left-hand-side after
an appropriate delay. When we are talking in terms of modeling the system, we may not be
concerned about the propagation delays in such a case, simulator assumes an infinitesimal
delay(D). Also, unlike a sequential statement the order of assignments is not important.
Each assignment that we write describes a driver for the signal on the left-hand-side of the
assignment.
a
s<=(a and b) or (not a and not b) s
b
gt
a_gt_b<=(gt and s) or (a and not b) a_gt_b s
a
b
lt
a_lt_b<=(lt and s)or (not a and b) a_lt_b s
a
b
a_eq_b eq
a_eq_b<=eq and s s
The driver need not be implemented explicitly, we can simply state the boolean equation which
describes the driver. All the drivers are acting concurrently.
VHDL also has a mechanism for conditional evaluation of a concurrent assignment by using the
‘guard’. Physically, the guard represents a signal, which is used to control the functioning of a sub-
system, like the enable signal. In terms of modeling the ‘guard’ can also be used to block certain
‘unimportant’ statements, to enable faster simulation. For example, if we have large system in
which all the sub-systems are not required at the same time, we can ignore the sub-system and
enable a faster simulation.
lt
a_lt_b s
a
b
a_eq_b<=guarded eq and s
guard
a_eq_b eq
s
guard
Role of guards
RTL BEHAVIOUR
The RTL behavior description involves specifying the various operations to be performed in a
process. The behavioral description is procedural in which the textual order is also the order of
execution. Behavioral description uses sequential statements and control constructs to alter the
normal sequential flow. For example
process
in_ready: in bit;
while in_ready=’0’ loop
wait until clock’rising;
end loop;
x:=in_port1;
y:=in_port2;
wait until clock’rising;
while x/=y loop
if x>y then
wait until clock’rising;x:=x-y;
else
wait until clock’rising;y:=y-x;
end if;
end loop;
end process;
Note:
1. clock’ represents an attribute of clock and clock’rising is the associated event
attribute of the clock signal.
2. clock‘rising represents (clock’event and clock=’1’)
3. clock is an input signal and not a keyword
In_ready
(asynchronous)
In this example we have a process within which we have specified sequential statements to be
Clock
executed. The signal in_ready is asynchronous, to synchronize the signal we have to
introduce a wait statement.
In_ready (asyncronous)
x:=in_port1;
wait until clock’rising;
The simulator does not require the wait statement the value is assigned to x immediately,
however, physically (in synthesis) the value needs to be stored in a clocked register. Since,
latching occurs only at the rising edge, we have to wait till the rising edge of the clock. An
asynchronous design needs a wait statement within a while loop for the data to actually latch
into the register.
This model assumes that all the associated delays are restricted to within the clock period. However, at
synthesis stages we will need to consider the timing issues. This kind of a description is the “true to the clock
cycle” description of behavior. Prediction can be done upto a clock cycle only.
If we have a process with one statement only we can model it by using a sensitivity list only.
process
begin
-- assignments and conditional constructs
wait until clock’rising;
end process;
process(clock)
begin
if clock=’1’ then
-- assignments and conditional constructs
end process;
In such a process all the statements in the body are executed in a single clock cycle only. We can
control the flow of execution within the process (i.e. doing different computations in each
iteration) by using if-then-else.
We can describe a finite state machine in VHDL by a behavioral description of the state-machine
using the case statement.
process
begin
case state_reg is
when state_0 => -- statements for state_0;
when state_1 => -- statements for state_1;
….
end case;
wait until clock’rising;
end process;
Note :
1. VHDL supports enumerated types so we can use statements like when state_0,
where state_0 is a signal of an enumerated type.
2. Statements for state_i will typically contain statements which perform the action
associated for the ith state and also change the state of the machine as required
3. We have to wait for the rising clock for the state transition to occur.
A finite state machine can also be specified by a dataflow description. For the above example an
equivalent dataflow description would be:
block(clock’rising)
begin
block(state_reg=state_0 and guard)
begin
-- statements for state_0
end block;
block(state_reg=state_1 and guard)
begin
-- statements for state_1
end block;
...
end block;
In this case we have to use the guard for each set of concurrent blocks. The guard determines when
the block is executed, it is used for synchronization, in the above example. In case of nested blocks
the guard refers to the nearest outer guard set. For example, in the above code:
TEST BENCH
The test bench is used to test any design during the testing stages. It is a very useful concept during
the simulation stages. The design under test will have a set of input and a set of output.
Design
Input Under Output
Test
We can declare an entity testbench with no inputs and no outputs. The entity will consist of a test
pattern generator, a clock geenrator and a result check. These three components will be concurrent
processes with the design under test. To test various designs for the same system we can use the
same test bench simply replacing the design under test. We can test the same design with different
designs for the individual components. The test bench is particularly while working with large
designs.
1. Consider a variable pulse generator or VPG. It accepts a 1-digit BCD input and
generates that many number of pulses e.g. if input is \6" then it would generate 6 pulses.
Only exception is that for input \0" it would generate 10 pulses. Write the behavioral
VHDL description of the VPG circuit as two processes.
· First process generates a periodic output “P" which is ON for 400 msec and OFF
for 600 msec.
· The second process takes three inputs; “P", “D0-3" (4-bit) and “dav" and produces
one output “Y". \D0-3" is a BCD input and “dav" is the data valid signal for the BCD
input. “Y" passes on the number of “P" pulses as specified by the “D0-3" input.
(Major –2003)
2. Assume all identifiers a, b, c, d and clk are declared to be bit type signals.
1. Consider the following process. Draw the waveform for c and d.
2. Write the VHDL structural description for two 2-input NAND gates with output of
first connected to one of the inputs of second with a, b and clk as the primary
inputs, c as the output of the first NAND gate and d as the final output.
3. Assuming the same inputs at a,b and clk, draw the waveforms for c and d.
process (clk)
begin
c <= a nand b;
d <= clk nand c;
end process;
(Quiz7 –2003)