Unit V
Unit V
• We are familiar with the design of a digital system. The basic steps involved in
this process are,
• But as the size and complexity of digital systems increase, they can not be
designed manually; their design becomes highly complex. At their most detailed
level, they may consists of millions of elements, i.e. transistors or logic gates.
So Computer Aided Design (CAD) tools are used in the design of such systems.
One such a tool is a Hardware Description Language (HDL).
■ The HDL provides the digital designer with a means of describing a digital
system at a wide range of levels of abstraction and at the same time, provides
access to computer-aided design tools to aid in the design process at these
levels.
■ The HDL, represents digital systems in the form of documentation which can
be understood by human as well as computers.
■ The HDL makes it easy to exchange the ideas between the designers.
■ The most prominent modem HDLs in industry are Verilog and VHDL.
Verilog is one of the two major Hardware Description Languages (HDLs) used
by hardware designers in industry and academia. Of course, VHDL is the other
one.
■ Verilog is very C-like and liked by electrical and computer engineers as most
learn the C language in college. VHDL is very Ada-like and most engineers
have no experience with Ada.
■ Package (optional)
■ Entity
■ Architecture
■ Configuration (optional)
• The Fig. 10.2.1 shows the relationship of these basic blocks of VHDL
program. A design may include any number of package, entity, architecture and
configuration declarations. It is important to note that the entity and architecture
blocks are compulsorily required; however, the package and configuration
blocks are optional.
1. Entity Declaration
• It gives the specification of input/output signals to external circuitry. An entity
is modeled using an entity declaration and at least one architecture body. An
entity X, when used in another entity Y, becomes a component for the entity Y.
Entity gives interfacing between device and the other peripherals. An entity
usually has one or more ports, which are analogous to the pins on a schematic
symbol. All information must flow into and out of the entity through the ports.
Each port must contain name, data flow direction and type.
entity entity_name is
mode : The ports can be declared in four types which specify the signal
direction.
in : This mode is used for a signal that is an input to an entity (value is read not
written).
out : It is used for a signal that is an output from an entity. The value of such a
signal can not be read inside the entity's architecture. But it can be read by other
entities those use it.
inout : It is used for a signal that is both, an input to an entity and an output
from the entity.
buffer : The signal is an output from the entity and its value can also be read
inside the entity's architecture.
For example, there is a system having its inputs and outputs like rd, wr, ADD, x,
y, z, ad, al. The entity for this can be written as shown below.
wr : in std_logic;
rd : in std_logic;
ADD : in std_logic_vector (0 to 3) ;
end gate_logic ;
Here rd, wr are inputs to the system so they are input ports. The ad is also input
signal but it is 8 bit so it is defined as vector (7 downto 0). It means 7 is
assigned to MSB of your signal and 0 is assigned to LSB of your signal.
Similarly x, y, z are output signals so they are defined as output ports. The al is
coming out and is defined as buffer signal, so that you can also read this signal.
2. Architecture
• Architecture specifies behavior, functionality, interconnections or relationship
between inputs and outputs. It is the actual description of the design. An
architecture consists of two portions : architecture declaration and architecture
body. An architecture body specifies the internal details of an entity.
begin
concurrent statements;
sequential statements;
end architecture_name;
• To design any system, first we have to write the entity. In the architecture, we
write architecture_name for that entity. In declaration part, types, signals,
constants, function definitions, procedure definitions, component definitions
etc. can be declared. The variables can also be declared here. VHDL variables
are similar to signals, except that they usually do not have physical significance
in a circuit. A variable declaration is similar to a signal declaration, except that
the 'variable' keyword is used as shown below.
Example :
3. Configuration Declaration
• Configuration declarations may be used to associate particular design entities
to component instances (unique references to lower-level components) in a
hierarchical design, or to associate a particular architecture to an entity. As their
name implies, configuration declarations are used to provide configuration
management and project organization for a large design.
For HA_STRUCTURE
For XI : XOR2
For A1 : AND2
end for;
end for;
end HA_BINDING;
The library statement makes library names CMOS_LIB and MY_LIB visible
within the configuration declaration.
• As shown by the shaded portions there are two component bindings. The
component instantiation XI is bound to an entity represented by XOR-GATE
entity declaration and the DATAFLOW architecture body, which resides in the
CMOS_LIB design library. Similarly, component instantiation A1 is bound to a
configuration of an entity defined by the configuration declaration, with name
AND_CONFIG, residing in the MYJLIB design library.
4. Package Declaration
• There are some declarations which are common across many design units. A
package is a convenient mechanism to store and share such declarations. It is an
optional design unit. A set of declarations contained in a package declaration
may be shared by many design units. It defines items that can be made visible to
other design units. A package is represented by :
■ Package declaration
PACKAGE package_name IS
type declarations
subtype declarations
constant declarations
signal declarations
variable declarations
subprogram declarations
file declarations
alise declarations
component declarations
attribute declarations
attribute specifications
disconnection specifications
use clauses
END package_name;
(1 downto 0)
f : OUT STD_LOGIC ;
end component;
5. Package Body
• It contains the details of a package, that is the behavior of the subprograms and
the values of the deferred constants which are declared in a package declaration.
The package body may contain other declarations.
subprogram bodies
subprogram declarations
use clauses
end package_name;
• The name of the package must be same as the name of its corresponding
package declaration. If the package declaration does not have any subprogram
or deferred constant declarations, a package body is not necessary.
Styles of Modeling
AU : Dec.-14, 15, 16, 17, May-15
* Behavioral
* Data flow
* Structural
* Switch-level
* Mixed-Type
* Mixed-Language
• Let us see the VHDL description of full adder shown in the Fig. 10.3.1 in
various modeling styles.
1. Behavioral Description
• It is sometimes possible to directly describe the behavior or the functionality
of a circuit. Such a modeling style is called behavioral modeling which is very
similar in syntax and semantics to that of a high-level programming language
(For example : C, Pascal). A behavioral description models the system as to
how the outputs behave with the inputs.
description
entity full_add is
end full_add;
begin
begin
end process;
end adder;
In Verilog, the key mechanism used to model the behavior is predefined words
always or initial.
Listing 10.3.2 : Example of Verilog behavioral
description
input A, B, Cin;
begin
Sum = (A Λ B) Λ Cin;
end
endmodule
2. Dataflow Description
• Data flow describes how the circuit signals flow from the inputs to the outputs.
There are some concurrent statements which allow to describe the circuit in
terms of operations on signals and flow of signals in the circuit. When such
concurrent statements are used in a program, the style is called a 'dataflow
design'. Concurrent signal assignment statements are used in this type of
modeling style.
description
entity full_add is
begin
end adder;
In Verilog, predefined word assign is used to assign a value to the left-hand side
of a signal-assignment statement.
description
input A, B, Cin;
endmodule
• The built in operators of VHDL (for example : AND, OR, NOT) and verilog
(for example & I A) are used in the expression.
• Here, the data flow model for the full_add is described using a two concurrent
signal assignment. In a signal assignment statement, the symbol <= implies an
assignment of a value to a signal in VHDL. The value of the expression on the
right-hand-side of the statement is computed and is assigned to the signal on the
left-hand-side, called a target signal. In Verilog, predefined word assign is used
to assign a value to a signal. A concurrent signal assignment is executed only
when any signal in the expression on the right-hand-side has an event on it, that
is, the value of the signal changes.
3. Structural Description
• In structural design, a VHDL and verilog uses components or gates to model
the system. The important features of VHDL structural type of architecture
body are :
■ Design hierarchy
entity full_add is
end full_add;
component xor3
O1 : out bit);
end component;
component and2
O1 : out bit);
end component;
component or3
port ( I1, I2,I3 : in bit;
O1 : out bit);
end component;
begin
end adder;
• The name of the architecture body is adder. The entity declaration for full_add
specifies the interface ports for this architecture body. The architecture body is
composed of two parts : the declarative part (before the keyword begin) and the
statement parts (after the keyword begin). The components may either be
predefined components in a library or they may later be bound to other
components in a library. The declared components are instantiated in the
statement part of the architecture body using component instantiation statement.
Yl, XI, X2, X3, Y2 are component labels for this component instantiations. Il is
connected to signal A, 12 is connected to signal B, 13 is connected to signal
Cin, and O1 is connected to Sum in portmap xor3 gate. Similarly, port maps for
and 2 and or 3 are defined. Note that in this case, the signals in the port map of a
component instantiation and the port signals in the component declaration are
associated by position. A component instantiation statement is a concurrent
statement.
VHDL Identifiers and Types
There are two types of identifiers in VHDL :
• Basic identifiers
• Extended identifiers
• Digit (0 ... 9)
• Underscore (_)
Note 1. The first character in a basic identifier must be a letter, and the last
character may not be an underscore.
2. The characters are not case sensitive. Therefore, as an example, NUM, num
and Num are considered to be same identifier.
Note 1. Extended identifiers are case sensitive. Thus Num and NUM are distinct
identifiers.
3. The architecture body starts with the predefined word begin, followed by
statements that detail the relationship between the outputs and inputs.
5. Leaving the blank spaces between two words or at the beginning of the line
are allowed.
1. Signal
• A signal is data object which holds a list of values. These values include the
current value of the signal and also a set of possible future values that are to
appear on the signal. The signal represents a wire/logic signal in a circuit. In
VHDL, the signal can be placed in any of the following three places,
a) An entity declaration,
In this, the type_name indicates the legal value of the signal. The different
signal types are : BIT, BIT.VECTOR, BOOLEAN,
INTEGER,ENUMERATION, SIGNED, UNSIGNED, STD_LOGIC,
STD_LOGIC_VECTOR, STD_ULOGIC etc.
• This signal declares the signal object X which is of type BIT. The initial value
of this signal is 'O' as 'O' is the leftmost value of type BIT.
2. Variable
• A variable is used to hold a signal value of a given type. Unlike a signal, a
variable does not necessarily represent a wire in a circuit. Variables can be
assigned a single value of a specific type. The different values can be assigned
to the variable at different times. For this a variable assignment statement is
used. The variable declaration has the following form :
• Here, the variable 'index' is an integer having values between 0 and 20 and is
initialized to the value 0.
• The variables are used for computations within procedures, functions and
processes. The variables are sometimes used for the index variables in loops.
3. Constant
• The syntax for declaring a constant in a VHDL is given below.
For example,
■ Declaration of a file
• While declaring a file, we should ensure that the host environment correctly
interprets the format of the data which is stored in the file. So before declaration
of the file, it is necessary to declare its type. For example, text file. This file
consists of text strings of variable length. The syntax of a file type declaration is
as given below,
The type_name is the type of values contained in the file. For example,
This defines a file of type TEXT that has a sequence of strings as values in it.
2. File declarations
• After declaring a particular type of a file, we can declare a file object. The
syntax of a file declaration is as given below,
• The file can be used as a read-only, write-only or in the append mode. The
mode in the syntax specifies any of these utilization. The host-environment
interprets the string expression as the physical name of a file. For example,
FILE Input_File : TEXT OPEN READ-MODE IS
"/user/home/add.txt";
• Here, a file Input_File is declared to be of file type TEXT. That is, it has a
sequence of strings. The READ_MODE specifies that the file will be opened in
read-only mode. The string expression given after the keyword 'IS' specifies the
path name to a physical file in the host environment.
• After declaring file of a specific type, it is necessary to open the file before
using it and to close it before terminating the program. There are procedures and
functions to open and close a file. These are given below :
file_name : IN STRING;
OPENKIND : IN FILEOPENKIND : =
READMODE);
- - Opens the file FI that points to the physical file specified in the string
file_name - - with the specified mode. Type FILE_OPEN_KIND has value
READ_MODE.
FILE_OPEN_STATUS;
file FI : file_type_name;
file_name : IN STRING
- - This procedure returns the file open status, (other things are -similar to the
first procedure).
• The FILE_CLOSE procedure closes the file. There exists an implicit call to
FILE_CLOSE procedure which is called when execution terminates.
1. Scalar types : The scalar types include numeric data types and enumerated
data types. The numeric types consist of integer, floating point (real) and
physical types. Bit, Boolean and character are all enumerated types.
2. Composite types : Array and record types are composite data types. The
values of these types are collection of their elements.
3. Access types : They are pointers; they provide access to objects of a given
data type.
4. File type : They provide access to object that contain a sequence of values of
a given type.
5. Other types : They include the data types provided by the several external
libraries.
1. Scalar Types
• We have seen that, the scalar types consist of enumeration types, integer types,
physical types, and floating point types. Enumeration, data types and integer
types are called discrete types. On the other hand, integer types, floating point
types and physical types are called numeric types.
Integer type
• As the name indicates, it covers all integer values, the values can be positive
or negative. The default range of Integer is -2147483647 to +2147483647.
However, user can specify a shorter range by using the predefined word range.
The shorter range may require less bits to represent the number when binary
encoded. We can define the subtype of base type whose range must be wholly
contained within the bounds of the range of base type.
Examples :
Note : The encoding of integers in a binary format means that all ranges are
rounded up to the nearest power of two. This means that if shorter had been
declared as :
• Then the object is synthesized into 4 wires. Objects declared type of type
integer without a range constraint will be synthesized into 32 wires.
O1 : out integer);
• Floating point type definition defines both a type and subtype of that types.
The default range of floating point is -1E38 to + IE38. Like integer type, here
also we can specify the shorter range by using the predefined word range.
Examples :
O1 : out real);
Enumerated types
Bit, Boolean, Character and severity_level are the enumerated types. These are
defined in a library such as std or ieee.
Bit data type allows only two values 0 or 1. It is used to describe a signal that
takes only l(High) or 0(Low). The type Boolean has two values, True(l) or
False(0). Both True and False are predefined words.
The type character constitutes the 128 characters of the ASCII character set.
These character values are called character literals and are always written
between two single quotes (' ')• F°r example, 'A', ‘_’ ' 3 ' and so on.
An object with type severity can take one of four values ; note, warning, error or
failure. This type is typically used in assertion statements.
Examples :
O1 : out Boolean);
Physical type
• A physical type definition defines both a type and a subtype of that type. Each
unit declaration (either the base unit declaration or a secondary unit declaration)
defines a unit name. Unit name declared in secondary unit declaration must be
directly or indirectly defined in terms of integral multiples of the base unit of
the type declaration in which they appear.
Examples :
units
fs; - femtosecond
end units;
units
- base unit:
A; - angstrom
- metric lengths;
nm = 10 A; - nanometer
cm = 10 mm; - centimeter
km = 1000 m; - kilometer
- - English lengths :
ft = 12 inch; - foot
yd = 3 ft; - yard
fm = 6 ft; - fathom
lg = 3 mi; - league
end units;
z : = ns/ps;
x : = z mi;
y : = y/10;
• The arithmetic operations are predefined for all physical types. It is an error if
the execution of such an operation cannot deliver the correct result (that is, if
the value corresponding to the mathematical result is not a value of the physical
type).
User-defined types
The user can define a type by using the predefined word type.
Example :
Here, multi_level_logic and arith_op are the user defined types. The variables
declared using such data types can take values mentioned in the data type
definition. For example,
2. Composite Types
• Composite types are used to define collection of values. These include both
arrays of values (collection of values of a single type) and records of values
(collection of values of the same or different types).
Array types
• An array object is a composite object consisting of elements that have the
same subtype. The name for an element of an array uses one or more index
values belonging to specified discrete types. The value of an array object is a
composite value consisting of the values of its elements.
• A one-dimensional array has a distinct element for each possible index value.
A multidimensional array has a distinct element for each possible sequence of
index values that can be formed by selecting one value for each index (in the
given order). The possible values for a given index are all the values that belong
to the corresponding range; this range of values is called the index range.
Example :
range
range
declarations
string and bit_vector are the predefined array types, which are defined in
package std.
The values of the predefined type string are one-dimensional arrays of the
predefined type character, indexed by values of the predefined subtype positive;
The values of the predefined type bit_vector are one-dimensional arrays of the
predefined type BIT, indexed by values of the predefined subtype natural :
Record type
Example :
type DATE is
record
MONTH : MONTH_NAME;
end record;
3. Access Types
• Values belonging to an access type are pointers to a dynamically allocated
object of some other type. These are similar to pointers in pascal or C
languages.
Example :
4. File Type
• File types are used to define objects representing files in the host system
environment. The value of a file object is the sequence of values contained in
the host system file.
• The type mark in a file type definition defines the subtype of the values
contained in the file. The type mark may denote either a constrained or an
unconstrained subtype. The base type of this subtype must not be a file type or
an access type. If the base type is a composite type, it must not contain a
subelement of an access type. If the base type is an array type, it must be a one-
dimensional array type.
Examples :
• Three operations are provided for objects of a file type. Given the following
file type declaration :
type FT is file of TM :
• Procedure read retrieves the next value from a file. Procedure write appends a
value to a file. Function endfile returns False if a subsequent read operation on
an input file can retrieve another value from the file; otherwise it returns true.
Function endfile always returns true for an output file.
5. Other Types
• There are several other types provided by external library, IEEE. This library
contains a std_logic_1164 package which supports more types. Let us discuss
them.
Std_logic type
• std_logic is a data type defined by IEEE standard 1164, and defined in the file
ieee.vhd.std_logic is an enumerated type. This logic has nine values as listed in
Table. 10.6.1.
• The std_logic data type is very important for both simulation and synthesis.
Std_logic includes values that allow us to accurately simulate such circuit
conditions as unknowns and high-impedance stages. For synthesis purposes, the
high-impedance and don't care values provide a convenient and easily
recognizable way to represent three-state enables and don't care logic. For
synthesis, only the values 0, 1, z and have meaning and are supported.
std_logic_vector type
Example :
O : out bit);
Signed
The type signed is a numeric type. It is declared in the external package
numeric_std and represents signed integer data in the form of an array. The left
most bit of objects of signed type represents sign and such objects are
represented in 2's complement form, let us see the object definition.
In the above definition, the variable difference is declared as signed type and
has 5-bits with initial value 10011, or - 13.
Unsigned
The type unsigned represents integer data in the form of an array of stdjogic and
it is declared in the external package numeric_std. Let us see the object
definition variable num: unsigned (4 downto 0) := 10011; In the above
definition, the variable num is declared as unsigned type and has 5-bits with
initial value 10011, or 19.
6. Operation in VHDL
VHDL includes the following kinds of operators :
• Logical
• Relational
• Arithmetic
a. Logical Operators
Logical operators, when combined with signals and/or variables, are used to
create combinational logic. VHDL provides the logical operators as shown in
the Table 10.6.2.
• These operators are defined for the types bit, std_logic and Boolean, and for
one-dimensional arrays of these types (for example, an array of type bit_vector
or std_logic_vector).
• The effects of the logical operators are defined in the following tables. The
symbol T represents TRUE for type BOOLEAN, T for type BIT; the symbol F
represents FALSE for type BOOLEAN, 'O' for type BIT.
b. Relational Operators
if (A > B) then
entity entity_name is
begin
entity statements
end entity_name;
The port in the behavioral modeling can have one of the following modes :
in : This mode is used for a signal that is an input to an entity (value is read not
written).
out: It is used for a signal that is an output from an entity. The value of such a
signal can not be read inside the entity's architecture. But it can be read by other
entities those use it.
inout: It is used for a signal that is both, an input to an entity and an output
from the entity.
buffer : The signal is an output from the entity and its value can also be read
inside the architecture of entity. The buffer is different from inout mode in that
it cannot have more than one source.
Linkage : The value of a linkage port can be read and updated. This can be
done only by another port of mode linkage.
• The entity item declaration includes those declarations that are common to all
the design unit. The Fig. 10.7.1 shows the circuit for half-adder and its entity
declaration is
entity half_adder is
port ( A : in bit;
B : in bit;
end half_adder;
2. Architecture Body
• Architecture specifies behavior, functionality, interconnections or relationship
between inputs and outputs. It is the actual description of the design.
begin
statement
statement
end architecture_name;
begin
process (A, B)
begin
end process;
end adder;
process (X)
begin
end process ;
• One important thing to note that we can label any statement in the VHDL such
as stl, st2 and st3 in the previous description.
4. Sequential Statements
• The various forms of sequential statements are associated with behavioral
description. These statements have to appear inside process in VHDL. These
statements execute in the order in which they appear. Let us study these
sequential statements.
a. IF Statement
VHDL Syntax :
statement 1;
statement 2;
else
statement x;S
statement y;
end if;
Example :
Q := S1;
else
Q: = S2;
end if;
if Clk = '1'
then Q:= D;
end if;
if Clk is T (high), then the value of D is assigned to output Q. If Clk is not high,
Q retains its current value, thus simulating a latch.
VHDL syntax :
else
end if ;
Example :
begin
if en = '00' then
c < = a;
c < = b;
else
c < = '0';
end if;
end process;
• The listing 10.8.1 shows the HDL code for the circuit shown in the Fig. 10.8.1.
The circuit is an AND-OR circuit in which signals A, B, C, D and E are input
signals, signal Y is an output signal and signals II and 12 are intermediate
signals.
Listing 10.8.1 : VHDL code for AND-OR circuit
Subprograms
• A subprogram defines a sequential algorithm that performs particular task.
Two types of subprograms are used in VHDL : Procedures and functions.
Procedures and functions in VHDL, are directly analogous to functions and
procedures in a high-level programming language such as C or Pascal.
• They provide the ability to execute common routines from several different
places in a description. They also provide a means of breaking up large
programs into smaller ones to make it easier to read and debug the source
descriptions.
• Subprograms written in VHDL must have body and may have declaration. The
typical format for a subprogram body is :
Subprogram statements
• When parameters are of a variable or constant class, values are passed to the
subprogram by value. On the other hand, files and signals are passed by
reference.
Statements
• Consider a positive edge-triggered D flip-flop. We know that the D flip-flop is
similar to D-latch except 'clock pulse' is used instead of enable input. So VHDL
code for D flip-flop is same as that of D-latch with two exceptions.
• i) The Clk signal is the only signal that can cause a change in the Q output. So
only Clk signal is to be given in the process sensitivity list.
LIBRARY IEEE;
ENTITY DFF IS
Q : OUT STD_LOGIC);
END DFF;
BEGIN
PROCESS (Clock)
BEGIN
Q < = D;
END IF;
END PROCESS;
END Behavior;