Professional Documents
Culture Documents
A COMPREHENSIVE
TUTORIAL
Intended Coverage
Introduction
– System design approach with HDLs
– History of VHDL
– Why VHDL ?
Simulation Fundamentals
– Simulation Cycle
– Digital Simulator
Modeling of Hardware
Language Basics
– Building Blocks in VHDL
– Design Units and Libraries
Intended Coverage(contd.)
Dataflow Description
Complete Example
Introduction
Level of
HDL Description (Behavioral) abstraction
Register Transfer Level
simulation and
verification
Synthesizer
Structural Description
Technology mapping (with ready-made primitives)
+ Floor Planning
Physical Layout
Introduction(contd.)
Why VHDL ?
– Public Availability
Developed initiated under Government Contract
Now is an IEEE standard
– Design Methodology and Design Technology Support
– Technology and Process Independent
– Wide Range of Descriptive capabilities
Digital System (e.g. box) level to gate level
Capability of mixing descriptions
– Design Exchange
– Large Scale Design and Design re-use
Simulation Fundamentals
Purpose of simulation is to verify the behavior of
a system by applying stimulation at the inputs
and monitoring the response of the system over
a period of time.
There are three types of simulators :
– Purely analog simulator.
– A simulator with both digital and analog simulation capabilities.
– Purely digital simulator.
end Adder;
Architecture
encapsulates the behavior and timing information
contains a number of concurrent statements
there can be multiple architecture bodies for a given entity
-- Procedure Specification
Procedure ModTwo (X : inout Integer) is
begin
case X is
When 0 | 1 => null;
When others X := X mod 2;
end case;
end ModTwo;
Packages
Allows data types, subprograms, object declarations (signal,
constants, shared variables and files), component declarations
etc. to be shared by multiple design units.
package identifier is
declarations
end [package] [identifier];
Example :
package logic is
type Three_level_logic is (‘0’, ‘1’, ‘z’);
function invert (Input : Three_level_logic) return
Three_level_logic;
end logic;
Package Body
Package declarations and bodies are separately
described
Package declarations contain public and visible
declarations
Items declared inside package body is not visible
outside the package body
Package body has the same name as the
corresponding package declaration
package body identifier is
declarations
end [package body] [identifier];
Package Body (contd.)
Example of a package body for package logic
package body logic is
-- subprogram body of function invert
function invert (Input: Three_level_logic) return
Three_level_logic is
begin
case Input is
when ‘0’ => return ‘1’;
when ‘1’ => return ‘0’;
when ‘Z’ => return ‘Z’;
end invert;
end logic;
USE CLAUSE
Use clause preceding an unit makes all the elements of a
package or a particular element of a package visible to
the unit
An architecture body inherits the use clauses of its entity.
So if those use clauses are sufficient for the descriptions
inside the architecture, then no explicit use clause is
necessary for the architecture
Simple examples :
Makes all items of package std_logic_1164 in library ieee visible
» use ieee.std_logic_1164.all;
entity Inverter is
port (X : in Three_level_logic;
Y : out Three_level_logic);
end inverter;
Analysis Rules for Units
Units can be separately analyzed provided following rules are
obeyed
– a secondary unit can be analyzed only after its primary unit
is analyzed
– a library unit that references another primrary unit can be
analyzed only after the referred unit has been analyzed
– an entity, architecture, configuration referenced in a
configuration declaration must be analyzed before the
configuration declaration is analyzed
A library clause makes library visible and an use clause makes the units
inside the library visible to other units
library Basic_Library;
Use Basic_Library.Logic;
Use Logic.all;
Objects and Data Types
Something that can hold a value is an object (e.g signal)
In VHDL, every object has a type, the type determining the
kind of value the object can hold
VHDL is strongly typed language
The type of every object and expression can be determined
statically. i.e the types are determined prior to simulation.
Three basic VHDL data types are
– integer types
– floating point types
– enumerated types
Data types can be user defined
Data Types
Data type
Composite Types :
– type Bit_vector is array (Natural range <>) of Bit;
– type String is array (Positive range <>) of Character;
Referencing Elements of
Composite
Can be referenced in entirety or by element
An indexed name is used to refer to an element
The type of an indexed name is the type array element
A slice name is a reference to a contiguous subset of elements in an one-
dimensional array
Examples
– type Byte is array (7 downto 0) of Bit;
– type S_memory is array (0 to 2**16 -1) of Byte;
– signal S_byte : Byte;
– signal S_mem : S_memory;
º S_byte (3 downto 1) --- slice of three elements
º S_mem (2**15 -1 to 2**16 -1) --- slice of 2**15 elements
º S_mem (0) (0 downto 0) --- slice of one element
Subtypes
A subtype is a type with a constraint
A value belongs to a subtype of a given type if it belongs to the
type and satisfies the constraint
The given type is called the base type of the subtype
Subtypes of a type are fully compatible with each other
Two ways to constraint a type by a subtype
– a range constraint that defines a subset of values of a scalar type
subtype LowerCase is Character range ‘a’ to ‘z’;
– to specify an index constraint of a array dimension of
unconstrained type
subtype Register is Bit_Vector (7 downto 0);
Attributes
Attribute is a named characteristic
It may belong to the following classes of items in VHDL
– type, subtypes
– procedure, functions
– signals, variable and constants
– entities, architectures, configurations and packages
– components
– statement labels
– literal, unit, group, file
A particular attribute for a particular item may have a value, and if it
does have a value, the same may referenced as
– name ’attribute_identifier
Attributes may be pre-defined or user-defined
Attributes (contd.)
Pre-defined attributes for scalar subtypes
– ‘left, ‘right, ‘high, ‘low
– Example
type Bit_position is range 15 downto 0;
Bit_position’left = 15
Bit_position’low = 0
Bit_position’right = 0
Bit_position’high = 15
Attributes (contd.)
Pre-defined attributes for any physical subtype or any
discrete subtype
– ‘pos, ‘val, ‘succ, ‘pred, ‘leftof, ‘rightof
– Example
Bit_position’pos(15) = 15
Bit_position’val(15) = 15
– For any physical or discrete type T
T’succ(x) = T’val(T’pos(x) + 1)
T’pred(x) = T’val(T’pos(x) - 1)
– For a physical or discrete type T, with ascending range
T’rightof(x) = T’succ(x)
T’leftof(x) = T’pred(x)
Pre-defined attributes for constrained array subtypes and
array objects
– ‘left, ‘right, ‘high, ‘low, ‘length, ‘range, ‘reverse_range
Attributes (contd.)
User Defined Attribute :
– Attribute declaration
syntax: attribute identifier : type_mark;
type int_type is range 1 to 100;
attribute INDEX : int_type;
– Attribute Specification :
associates a user-defined attribute with one or more
named entities and defines a value of that attribute of
that attribute for that named entity
signal Cin, Cout : int_type;
attribute INDEX of Cout : signal is 5;
attribute CAPACITANCE of all : signal is 10 pF;
Attributes (contd.)
Example :
entity att_example is
end;
architecture att_example of att_example is
subtype int_subtype is integer range 1 to 100;
signal s1, s2, s3 : int_subtype;
--- attribute declaration
attribute SIG_NUM : int_subtype;
--- attribute specification
attribute SIG_NUM of s1 : signal is 1; --- for s1 only
attribute SIG_NUM of others : signal is 3; --- for s2, s3
begin
--- accessing the attribute value
s1 <= s3’SIG_NUM; --- assigns value 3 to signal s1
end
Four types of objects
Objects
– signals, variables, constants and files
Signals and variables can be assigned values in succession.
Constants are assigned only once.
Signals are like wires.
Variables have no hardware equivalent.
A file declaration declares a file of specified type.
Every object must be of a type and has to be defined in its
declaration.
– constant ROM_size : integer := 16#FFFF#;
– variable fetch : Boolean := TRUE;
– variable address : integer range 0 to ROM_size := 10;
– signal enable : Bit := ‘0’;
– type integer_file is file of integer;
– file F1 : integer_file is “test.txt”;
Objects (contd.)
Following are Implicitly defined Objects
º Generics - constants
º Ports (entity, components, blocks) - signals
º Subprograms
º Function Parameters -
- Mode should be “in”.
- Object class must be constant, signal or file.
º Procedure Parameters -
- Mode should be “in”, “out” or “inout”.
- Object class may be constant, signal, variable or file.
º Indexes of Loop and Generate statements
- Within the sequence of statements these are
considered as constants and hence can’t be
modified.
Interface Lists
Specifies interfaces or potential points of communication
between units.
Four VHDL constructs that specify this
– entity declaration, local component declaration, block
statement and subprogram specification
Each interface element declares one or more interface
objects.
The object in a single interface element have three
properties in common
– Object Class : signal, constant, variable or file
– Mode : in, out, inout, buffer(for ports only) or
linkage(for ports only)
– Data type
Association Lists
Actual communication path between separate
units.
Four VHDL constructs that specify this
– Component instantiation statement
– binding indication
– block statement
– subprogram call
Association may be named or positional.
Structural Description
Basic Features
– Component Instantiation Statement
• It is concurrent statement. It can be done by -
Instantiation of a declared Component
A component is instantiated. The component needs to be bound
to some actual entity(architecture) with a configuration.
Direct instantiation statement (VHDL 93 feature)
No component needs to declared. No separate binding is
required. An entity(architecture) can be directly instantiated.
Block Statement
Generate Statement
Configuration Specification
Configuration Declaration
Basic Features
Structural description of a piece of hardware is a description
of what its sub-components are and how the sub-components
are connected
Structural description is more concrete than behavioral
description. i.e. correspondence between a given portion of
description and a portion of hardware is easier to see in
structural descriptions
Component Instantiation statement is basic unit of structural
Description.
Component instantiation can be done by -
» Instantiating a declared component and providing binding
information to bind it with actual entity(architecture)
» Directly instantiating an entity(architecture). No separate
component declaration and binding information is needed. (:
VHDL 93 feature)
Component Instantiation
Component Instantiation statement specifies an instance of a component
(child component) occurring inside another component (parent component)
At the point of instantiation, only the external view of the child component
(the names, types and directions of ports) is visible
The statement identifies the child component and specifies the
connectivity of the local signals or ports of parent component with the ports
of child component
General Form of the statement
label: instantiated_unit generic map association-list
port map association-list;
instantiated_unit ::= [component] component_name
| entity entity_name [(architecture_identifier)]
| configuration configuration_name
Component Instantiation
Generic/Port map associations are omitted if the
corresponding component declaration lacks generics/ports
The component_name must reference a component declared
by a component declaration. The component declaration need
not occur in the architecture body containing the instantiation
but it must be visible at the point of instantiation. (e.g through
a visible package)
A port of Component Declaration is called a local
In a component instantiation statement, the port association
list associates an actual with a local
The associated actual must be
» an object of class signal
» open
» static expression if port mode is “in”
Example
architecture Parent_body of Parent is
component And2 -- Component Declaration
port ( I1, I2 : Bit; O1 : out Bit);
end component;
signal S1, S2, S3 : Bit;
begin
Child : And2 port map ( I1=>S1, I2=>S2, O1=>S3); --
Instance
end Parent_body;
Entity Vs Component
ENTITY
Entity is a library unit which can be compiled separately
and it never occurs inside another library unit
Entity declaration declares something that really “exists” in
the design library
COMPONENT
General Form is :
process_label:
process
declarations
begin
statements
end process;
Process Statement (Contd.)
A process is either active or suspended
A process becomes active when any of the signal
read by the process changes its value
All active processes are executed concurrently
A process may be suspended upon execution of a
wait statement in the process. The process remains
suspended until its reactivation condition is met
Wait Statement
Three kind of reactivation condition can be specified in a wait
statement
– timeout wait for time-expression;
– condition wait until condition;
– signal sensitivity wait on signal-list;
Conditions can be mixed. e.g
wait on A, B until Enable = 1;
If a process is always sensitive to one set of signals, it is possible
to designate sensitivity signals using a sensitivity list.
It is illegal to use wait statement in a process with a sensitivity list
Every process is executed once upon initialization
Example
The following process implements a simple OR gate--
--- this process is sensitive to signals In1 and In2
Or_process : process (In1, In2)
begin
Output <= In1 or In2;
end process;
And_process : process
begin
if In1 = ‘0’ or In2 = ‘0’ then
Out <= ‘0’ after Delay;
elsif In1 = ‘X’ or In2 = ‘X’ then
Out <= ‘X’ after Delay;
else
Out <= ‘1’ after Delay;
end if;
wait on In1, In2;
end process;
Case Statement
General Form is
case expression is
when value =>
statements
when value | value =>
statements
when discrete_range =>
statements
when others =>
statements
end case
Example
Select_process : process
begin
case X is
when 1 => Out <= ‘0’;
when 2 | 3 => Out <= ‘1’;
when others =>
out <= ‘X’;
end case;
end process
Iterative Control
In this control the execution iterates over the
statements until some condition is met
VHDL provides iterative control inform three
kinds of loop statements
– Simple loop
– for loop
– while loop
Simple Loop
•Simple loop encloses a
set of statements in a
structure which is set to
loop forever
•General Form is
loop_label : loop
statements
end loop loop_label;
Example
P1 : process
variable A : Integer :=0;
variable B : Integer;
begin
Loop1 :loop
A := A + 1;
B := 20;
Loop2 :loop
B := B - A;
end loop Loop2;
end loop Loop1;
wait;
end process;
For Loop, While Loop
General Form of for loop:
loop_label:
for loop_variable in range loop
statements
end loop loop_label;
General Form of while loop:
loop_label:
while condition loop
statements
end loop loop_label;
P1 : process Example
variable B : Integer := 1;
begin
Loop1:
for A in 1 to 10 loop
B := 20;
Loop2:
while B >= (A * A) loop
B := B - A;
end loop Loop2;
end loop Loop1;
wait;
end process;
Exit Statement
Exit statement is a sequential statement closely associated with loops
and causes the loop to be exited
Exit statement has two general forms :
– exit loop_label;
– exit loop_label when condition;
P1 : process
variable A, B : Integer :=0;
begin
Loop1 :loop
A := A + 1;
B := 20;
exit Loop1 when A = 20;
end loop Loop1;
end process;
Next Statement
Next statement is used to advance control to the next iteration of the loop
General Form is : next loop_label when condition;
Example :
for j in 1 to 10 loop
if var1 = var2 then
next; When next statement is executed,
elsif var1 < var2
var1 := var1 + 1; execution jumps to the end of the loop,
else i.e last statement k := k + 1, is not
null;
end if; executed. Loop identifier j increments
k := k + 1; and then loop execution resumes with
end loop;
new value of j.
Assertion Statement
The assertion statement has the syntax
assert condition report message severity level;
– When the condition is FALSE the message is sent to system
output with an indication of the severity of the message
– The severity levels are Note, Warning, Error and Failure
– If no message is given the default message is “Assertion
Violation”. The default level is Error
Example
assert (A = B)
report “A is not equal to B”
severity Error;
Concurrent Signal Assignment
A concurrent signal assignment statement represents an
equivalent process that assigns values to signals
Simple example of concurrent signal assignment is
target_sig <= source_sig after delay_period;
It is one of the primary mechanisms for modeling the
data-flow behavior of an entity
There are two forms of concurrent signal assignment :
1) conditional signal assignment
2) selected signal assignment
Example
begin
U0 : Half_adder generic map (5 ns, 5 ns)
port map (A, B, Temp_sum, Temp_carry1);
a2: process
variable sttr : line;
variable rando : integer;
file dataout : text is out "data.out";
begin
rando := 1;
Test Bench (contd.)
for i in 0 to 40 loop
temp <= int2vec(rando);
rando := (rando * 3)/2 +1;
wait for 1 ms;
write(sttr, string('(" A = ")); write(sttr, A);
write(sttr, string('(" B = ")); write(sttr, B);
write(sttr, string('(" Carry_in = ")); write(sttr, Carry_in);
write(sttr, string('(" Sum = ")); write(sttr, Sum);
write(sttr, string('(" Carry_out = ")); write(sttr, Carry_out);
writeline (dataout, sttr);
wait for 0 ns;
end loop;
wait;
end process;
end bench;