Professional Documents
Culture Documents
4
Basic Design Methodology
Requirements
Synthesize
Gate-level
Model Simulate Test Bench
Timing
Model Simulate 5
6
7
HDL
( Hardware Description Language )
8
Need of HDLs
Arguments :
Why ONE More language ?
Can’t our CHAMPs do everything ?
FORTRAN , PASCAL , COBOL
C , C++ , VB , JAVA
9
Strengths & Limitations of C
Strengths…
• C is an extremely powerful Language.
• In fact even JAVA Compiler has been written Using C Language.
Limitations…
• C is a sequential language & the statements are executed in the order
in which they are written.
• But Electronic Hardware is CONCURRENT in Nature, which means
it functions on the occurrence of EVENTS.
• eg. In Asynchronous Counter when LSB F/F outputs a 1 0 then
middle F/F changes state and so on…till MSB F/F.
• C LANGUAGE cannot represent the CONCURRENT Nature of
Electronic Hardware EFFICIENTLY.
• Thus there is a need of a Special language which can efficiently
represent the behavior of Electronics Hardware.
VHDL
VHDL = V + H.D.L.
V.H.S.I.C. means
Very High Speed Integrated Circuit
Thus…..
V.H.D.L. = Very High Speed Integrated Circuit Hardware Description Language
History of V.H.D.L.
• DOD-USA needed Very High SPEED ICs ( VHSICs )
• Contract Given to different vendors
• Incompatibility Issues while Integrating Designs
• Need of common standard to describe Digital Designs
• IBM , Texas Instruments , Intermetrics collaborate
• Standardized in 1987 as IEEE STD 1076 / VHDL-87
• Standardized in 1993 as IEEE STD 1164 / VHDL-93
• So , we will be studying VHDL-93 & Not VHDL-87
• VHDL : VERBOSE , Strongly Typed , Form-Free , Case-Insensitive
• VHDL is a combination of ….
Sequential Language , Concurrent Language , Net-List Language ,
Waveform Generation Language & Timing Specifications
VHDL…
• Is used to “ MODEL the PDS ( Proposed Digital System )“
• Modeling means 2 Things :
a) To define signals through which PDS interacts with Real World
b) To define the Logical relationship between I/P & O/P Signals
• Primary usage is to describe DIGITAL HARDWARE.
• Digital Circuits are ultimately made up of LOGIC GATES.
• Keywords : AND,OR,NOT,XOR,XNOR ,describe LOGIC GATES.
• Hence VHDL can efficiently represent a DIGITAL SYSTEM.
main( )
{
int x=10,y=20,z;
z=x+y;
What’s That ?
printf ( “ %d “, z ); Give me only
1010001111
getch( ) ;
}
..
1.
Th
11
at
00
’s
d
10
el
10
ic
iou
s!
Turbo C- Compiler
!
C - Program C-Compiler
main( )
( Software )
{
Processor
int x=10,y=20,z; Syntax Check ( Hardware )
z=x+y; Generates .obj File The ALU Then
printf ( “ %d “, z ); ie. Program into
machine language Adds the 2 nos. 10 & 20 and
getch( ) ;
Generates the result 30.
} (11000011….)
On your PC
HARDWARE
SYNTHESIS
TOOL
VHDL Program
( XILINX Software ) CPLD / FPGA
Syntax Check ( Programmable H/W )
For Converts VHDL Programming The above device then operates
Half-Adder , MUX , Code Program Instructions as the desired Digital Circuit
Counter , into a GATE-
LEVEL NETLIST ( Half-Adder , MUX , Counter ,
µController
(11000011….) Or even a MicroController )
A VHDL Program may consist of….
• LIBRARY STATEMENTS (LS)
COMPULSORY
• ENTITY Declaration (ED)
• ARCHITECTURE Body (AB)
• Configuration Declaration (CD)
• Package OPTIONAL
LIBRARY IEEE ;
USE IEEE.STD_LOGIC_1164.ALL ;
USE IEEE.STD_LOGIC_UNSIGNED.ALL ;
USE IEEE.NUMERIC_STD.ALL ;
Syntax For Entity Declaration
ENTITY entity_name IS
PORT
(
signalname_1 : [ MODE ] [ DATATYPE ] ;
signalname_2 : [ MODE ] [ DATATYPE ] ; NO Semi-colon
signalname_3 : [ MODE ] [ DATATYPE ] ; after Last Signal
.
.
signalname_n : [ MODE ] [ DATATYPE ]
);
END entity_name ;
IN / OUT / INOUT
1) BIT ( 2-Valued Logic )
2) STD_LOGIC ( 9-Valued LOGIC ) --Preferred
Example of ED For an AND Gate
A
Y
and_gate
B
ENTITY and_gate IS
PORT
(
A : IN STD_LOGIC ;
B : IN STD_LOGIC ;
Y : OUT STD_LOGIC
);
END and_gate ;
Syntax For ARCHITECTURE BODY
Declaratio
n Section
Local variables / Global Variables / Constants / …..
Don’t write anything if not needed
BEGIN
Here you ….
LOGIC
Section
b) Various Modeling Styles
c) Various Constructs
END arch_name ;
Example of AB For AND Gate
ARCHITECTURE andgate_arch OF and_gate IS
BEGIN
END arch_name ;
The Complete VHDL Program For AND Gate
LIBRARY IEEE ;
USE IEEE.STD_LOGIC_1164.ALL ;
USE IEEE.STD_LOGIC_UNSIGNED.ALL ;
USE IEEE.NUMERIC_STD.ALL ;
ENTITY and_gate IS
PORT
(
A : IN STD_LOGIC ;
B : IN STD_LOGIC ;
Y : OUT STD_LOGIC
);
END and_gate ;
BEGIN
Y < = A and B ;
END arch_name ;
DATA TYPES
DATA OBJECTS
26
Data Types
• All declarations of VHDL ports, signals, and
variables must specify their corresponding type
or subtype Types
Access Composite
Array Record
Scalar
Integer Physical
Real Enumerated
27
VHDL Data Types
Scalar Types
• Integer
• Minimum range for any implementation as defined by standard: -
2,147,483,647 to 2,147,483,647
• Example assignments to a variable of type integer :
ARCHITECTURE
ARCHITECTURE test_int
test_int OFOF test
test IS
IS
BEGIN
BEGIN
PROCESS
PROCESS (X)
(X)
VARIABLE
VARIABLE a:a: INTEGER;
INTEGER;
BEGIN
BEGIN
aa :=
:= 1;
1; --
-- OK
OK
aa :=
:= -1;
-1; --
-- OK
OK
aa :=
:= 1.0;
1.0; --
-- illegal
illegal
END
END PROCESS;
PROCESS;
END
END test_int;
test_int;
28
VHDL Data Types
Scalar Types (Cont.)
• Real
• Minimum range for any implementation as defined by
standard: -1.0E38 to 1.0E38
• Example assignments to a variable of type real :
ARCHITECTURE
ARCHITECTURE test_real
test_real OF OF test
test IS
IS
BEGIN
BEGIN
PROCESS
PROCESS (X)
(X)
VARIABLE
VARIABLE a:a: REAL;
REAL;
BEGIN
BEGIN
aa :=
:= 1.3;
1.3; --
-- OK
OK
aa :=
:= -7.5;
-7.5; ---- OK
OK
aa :=
:= 1;
1; --
-- illegal
illegal
aa :=
:= 1.7E13;
1.7E13; ---- OKOK 29
a := 5.3 ns; -- illegal
VHDL Data Types
Scalar Types (Cont.)
• Enumerated
• User specifies list of possible values
• Example declaration and usage of enumerated data type :
TYPE
TYPE binary
binary ISIS (( ON,
ON, OFF
OFF );
);
...
... some
some statements
statements ... ...
ARCHITECTURE
ARCHITECTURE test_enum
test_enum OF OF test
test IS
IS
BEGIN
BEGIN
PROCESS
PROCESS (X)
(X)
VARIABLE
VARIABLE a:a: binary;
binary;
BEGIN
BEGIN
aa :=
:= ON;
ON; ---- OK
OK
...
... more
more statements
statements ... ...
aa :=
:= OFF;
OFF; ---- OK
OK
...
... more
more statements
statements ... ...
END
END PROCESS;
PROCESS;
END
END test_enum;
test_enum;
30
VHDL Data Types
Scalar Types (Cont.)
• Physical
• Require associated units
• Range must be specified
• Example of physical type declaration :
TYPE
TYPE resistance
resistance IS
IS RANGE
RANGE 00 TO
TO 10000000
10000000
UNITS
UNITS
ohm;
ohm; ---- ohm
ohm
Kohm
Kohm == 1000
1000 ohm;
ohm; --
-- i.e.
i.e. 11 KW
KW
Mohm
Mohm == 1000
1000 kohm;
kohm; --
-- i.e.
i.e. 11 MW
MW
END
END UNITS;
UNITS;
TYPE
TYPE data_bus
data_bus IS
IS ARRAY(0
ARRAY(0 TO
TO 31)
31) OF
OF BIT;
BIT;
• (vector) : 0 ...element indices... 31
0 ...array values... 1
VARIABLE
VARIABLE XX :: data_bus;
data_bus;
VARIABLE
VARIABLE YY :: BIT;
BIT;
YY :=
:= X(12);
X(12); --
-- YY gets
gets value
value of
of element
element at
at index
index 12
1232
VHDL Data Types
Composite Types (Cont.)
• Example one-dimensional array using
DOWNTO :
TYPE
TYPE reg_type
reg_type IS
IS ARRAY(15
ARRAY(15 DOWNTO
DOWNTO 0)
0) OF
OF BIT;
BIT;
15 ...element indices... 0
0 ...array values... 1
VARIABLE
VARIABLE XX :: reg_type;
reg_type;
VARIABLE
VARIABLE YY :: BIT;
BIT;
YY :=
:= X(4);
X(4); --
-- YY gets
gets value
value of
of element
element at
at index
index 44
• Records
• Used to group elements of possibly different types into a single
VHDL object
• Elements are indexed via field names
• Examples of record declaration and usage :
TYPE
TYPE binary
binary IS
IS (( ON,
ON, OFF
OFF );
);
TYPE
TYPE switch_info
switch_info IS IS
RECORD
RECORD
status
status :: BINARY;
BINARY;
IDnumber
IDnumber :: INTEGER;
INTEGER;
END
END RECORD;
RECORD;
VARIABLE
VARIABLE switch
switch :: switch_info;
switch_info;
switch.status
switch.status :=
:= ON;
ON; ---- status
status of
of the
the switch
switch
switch.IDnumber
switch.IDnumber :=:= 30;
30; --
-- e.g.
e.g. number
number ofof the
the switch
switch 34
VHDL Data Types
Access Type
• Access
• Analogous to pointers in other languages
• Allows for dynamic allocation of storage
• Useful for implementing queues, fifos, etc.
35
VHDL Data Types
Subtypes
• Subtype
• Allows for user defined constraints on a data type
• e.g. a subtype based on an unconstrained VHDL type
• May include entire range of base type
• Assignments that are out of the subtype range are illegal
• Range violation detected at run time rather than compile time
because only base type is checked at compile time
• Subtype declaration syntax :
SUBTYPE
SUBTYPE name
name IS
IS base_type
base_type RANGE
RANGE <user
<user range>;
range>;
• Subtype
SUBTYPE example : IS INTEGER
SUBTYPE first_ten
first_ten IS INTEGER RANGE
RANGE 00 TO
TO 9;
9;
36
VHDL Data Types
Summary
• All declarations of VHDL ports, signals, and
variables must include their associated type
or subtype
• Three forms of VHDL data types are :
• Access -- pointers for dynamic storage allocation
• Scalar -- includes Integer, Real, Enumerated, and
Physical
• Composite -- includes Array, and Record
• A set of built-in data types are defined in
VHDL standard
• User can also define own data types and subtypes
37
VHDL Objects
• There are four types of objects in VHDL
• Constants
• Variables
• Signals
• Files
• The scope of an object is as follows :
• Objects declared in a package are available to all
VHDL descriptions that use that package
• Objects declared in an entity are available to all
architectures associated with that entity
• Objects declared in an architecture are available to all
statements in that architecture
• Objects declared in a process are available only within
that process 38
VHDL Objects
Constants
• Name assigned to a specific value of a type
• Allow for easy update and readability
• Declaration of constant may omit value so
that the value assignment may be deferred
• Facilitates reconfiguration
• Declaration
CONSTANT syntax : :: type_name
CONSTANT constant_name
constant_name type_name [:=
[:= value];
value];
CONSTANT
CONSTANT PI
PI :: REAL
REAL :=
:= 3.14;
3.14;
CONSTANT SPEED : INTEGER;
CONSTANT SPEED : INTEGER;
39
VHDL Objects
Variables
• Provide convenient mechanism for local
storage
• E.g. loop counters, intermediate values
• Scope is process in which they are declared
• VHDL ‘93 provides for global variables, to be
discussed in the Advanced Concepts in VHDL
module
• VARIABLE
All variable
VARIABLE assignments
variable_name
variable_name take[:=
:: type_name
type_name place
[:= value];
value];
immediately
• No delta
VARIABLE
VARIABLE or user
opcode
opcode specified delay
:: BIT_VECTOR(3
BIT_VECTOR(3 DOWNTOis0)
DOWNTO incurred
0) :=
:= "0000";
"0000";
• Declaration syntax:
VARIABLE
VARIABLE freq
freq :: INTEGER;
INTEGER; 40
VHDL Objects
Signals
• Used for communication between VHDL
components
• Real, physical signals in system often mapped
to VHDL signals
• ALL VHDL signal assignments require either
delta cycle or user-specified delay before new
value is assumed
SIGNAL
SIGNAL signal_name
signal_name :: type_name
type_name [:=
[:= value];
value];
• Declaration syntax :
SIGNAL
SIGNAL brdy
brdy :: BIT;
BIT;
brdy
brdy <=
<= '0'
'0' AFTER
AFTER 5ns,
5ns, '1'
'1' AFTER
AFTER 10ns;
10ns;
• Declaration and assignment examples : 41
Signals and Variables
• This example highlights the difference
between signals and variables
ARCHITECTURE
ARCHITECTURE test1
test1 OFOF mux
mux IS
IS ARCHITECTURE
ARCHITECTURE test2
test2 OFOF mux
mux IS
IS
SIGNAL
SIGNAL xx :: BIT
BIT :=
:= '1';
'1'; SIGNAL
SIGNAL yy :: BIT
BIT :=
:= '0';
'0';
SIGNAL
SIGNAL yy :: BIT
BIT :=
:= '0';
'0'; BEGIN
BEGIN
BEGIN
BEGIN PROCESS
PROCESS (in_sig,
(in_sig, y)y)
PROCESS
PROCESS (in_sig,
(in_sig, x,x, y)y) VARIABLE
VARIABLE xx :: BIT
BIT :=:= '1';
'1';
BEGIN
BEGIN BEGIN
BEGIN
xx <=
<= in_sig
in_sig XOR
XOR y;y; xx :=
:= in_sig
in_sig XOR
XOR y;
y;
yy <=
<= in_sig
in_sig XOR
XOR x;x; yy <=
<= in_sig
in_sig XOR
XOR x;
x;
END
END PROCESS;
PROCESS; END PROCESS;
END PROCESS;
END
END test1;
test1; END
END test2;
test2;
0 0 1 1 1 0
1 1 1 1 1 0
1+d 1 1 1 0 0
1+2d 1 1 1 0 1 43
VHDL Objects
Signals vs Variables (Cont.)
ARCHITECTURE
ARCHITECTURE var_ex
var_ex OF OF test
test IS
IS
BEGIN
BEGIN
PROCESS
PROCESS (a,
(a, b,b, c)
c)
VARIABLE
VARIABLE out_3
out_3 :: BIT;
BIT;
BEGIN
BEGIN
out_3
out_3 :=
:= aa NAND
NAND b;b;
out_4
out_4 <=
<= out_3
out_3 XOR
XOR c;c;
END
END PROCESS;
PROCESS;
END
END var_ex;
var_ex;
0 0 1 1 1 0
1 1 1 1 0 0
1+d 1 1 1 0 1
44
Types of Statements
Concurrent Statements
PROCESS Clause ( Most Frequently used )
WHEN-ELSE Construct ( Frequently used )
WITH-SELECT Construct ( Sparingly used )
Sequential Statements
IF-THEN-ELSE-END IF Construct ( 2 conditions )
IF-THEN-ELSIF-END IF Construct ( > 2 conditions)
( Most Frequently used )
CASE Construct ( Frequently used )
Sequential Statements are always embedded
within Concurrent statements
Concurrent Statements are Stand-Alone 45
VHDL Constructs
46
PROCESS Clause
&
CASE Construct
47
Syntax For PROCESS Clause
ARCHITECTURE arch_name OF entity_name IS
BEGIN
PROCESS ( Sensitivity List )
BEGIN
END PROCESS ;
END arch_name ;
SENSITIVITY List ( SL ) :
entity mux41_bms_CASE is
Port
(
I : in STD_LOGIC_VECTOR (0 to 3);
S : in STD_LOGIC_VECTOR (1 downto 0);
Y : out STD_LOGIC
);
end mux41_bms_CASE;
entity mux41_dms is
Port
(
I : in STD_LOGIC_VECTOR (0 to 3);
S : in STD_LOGIC_VECTOR (1 downto 0);
Y : out STD_LOGIC
);
end mux41_dms;
entity mux21 is
Port
(
I0 , I1 : in STD_LOGIC ;
S : in STD_LOGIC ;
Y : out STD_LOGIC
);
end mux21;
architecture mux21 _arch of mux21 is
begin
PROCESS ( I0 , I1 , S )
BEGIN
IF S=‘0’ THEN ----- Do not FORGET to write “ THEN “
Y <= I0 ;
ELSE
Y <= I1 ;
END IF ; ----- ENDIF is not allowed
END PROCESS;
I0
I1
mux41_bms_CASE Y
I2
I3
s1 s0
4:1 MUX ( Behavioral Modeling Style )
LIBRARY IEEE ;
USE IEEE.STD_LOGIC_1164.ALL ;
USE IEEE.STD_LOGIC_UNSIGNED.ALL ;
USE IEEE.NUMERIC_STD.ALL ;
entity mux41_bms_CASE is
Port
(
I : in STD_LOGIC_VECTOR (0 to 3);
S : in STD_LOGIC_VECTOR (1 downto 0);
Y : out STD_LOGIC
);
end mux41_bms_CASE;
I0
I1
mux41_bms_CASE Y
I2
I3
s1 s0
4:1 MUX ( DMS ) : WHEN-ELSE
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity mux41_dms is
Port
(
I : in STD_LOGIC_VECTOR (0 to 3);
S : in STD_LOGIC_VECTOR (1 downto 0);
Y : out STD_LOGIC
);
end mux41_dms;
64
STRUCTURAL Modeling Style
cout
b
FULL ADDER
sum
cin
STRUCTURAL Modeling Style…
carry1
a x1 c1
add1
x2 s1
b cout
sum1
carry2
x1 c1
add2
cin x2 s1 sum
VHDL Program For FULL-ADDER
LIBRARY IEEE ;
USE IEEE.STD_LOGIC_1164.ALL ;
USE IEEE.STD_LOGIC_UNSIGNED.ALL ;
USE IEEE.NUMERIC_STD.ALL ;
ENTITY FA IS
Port
(
a : in std_logic;
b : in std_logic; ED for Main Entity
c : in std_logic;
“ THE FULL-ADDER “
sum : out std_logic;
cout : out std_logic
);
END FA ;
ARCHITECTURE FA_arch IS
COMPONENT add IS
PORT Creating COMPONENT
( “add” ( Half-Adder )
x1,x2 : in std_logic;
s1,c1 : out std_logic
);
END COMPONENT;
END FA_arch ;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITY add IS
PORT ED for the COMPONENT
( “add” ( Half-Adder )
x1,x2 : in std_logic;
s1,c1 : out std_logic
);
END add;
END add_struct;
PACKAGES
LIBRARIES
70
Packages and Libraries
• User defined constructs declared inside
architectures and entities are not visible to
other VHDL components
• Scope of subprograms, user defined data types,
constants, and signals is limited to the VHDL
components in which they are declared
• Basic declarations
• Types, subtypes
• Constants
72
• Subprograms
Packages
Declaration
• An example of a package declaration :
PACKAGE
PACKAGE my_stuff
my_stuff ISIS
TYPE
TYPE binary
binary IS
IS (( ON,
ON, OFF
OFF );
);
CONSTANT
CONSTANT PI
PI :: REAL
REAL :=
:= 3.14;
3.14;
CONSTANT
CONSTANT My_ID
My_ID :: INTEGER;
INTEGER;
PROCEDURE
PROCEDURE add_bits3(SIGNAL
add_bits3(SIGNAL a, a, b,
b, en
en :: IN
IN BIT;
BIT;
SIGNAL
SIGNAL temp_result,
temp_result, temp_carry
temp_carry :: OUTOUT BIT);
BIT);
END
END my_stuff;
my_stuff;
PROCEDURE
PROCEDURE add_bits3(SIGNAL
add_bits3(SIGNAL a, a, b,
b, en
en :: IN
IN BIT;
BIT;
SIGNAL
SIGNAL temp_result,
temp_result, temp_carry
temp_carry :: OUT OUT BIT)
BIT) IS
IS
BEGIN
BEGIN --
-- this
this function
function cancan return
return aa carry
carry
temp_result
temp_result <=
<= (a
(a XOR
XOR b)b) AND
AND en;
en;
temp_carry
temp_carry <=
<= aa AND
AND bb AND
AND en;
en;
END
END add_bits3;
add_bits3;
END
END my_stuff;
my_stuff;
74
Packages
Use Clause
• Packages must be made visible before their
contents can be used
• The USE clause makes packages visible to
entities, architectures, and other packages
-- use only the binary and add_bits3 declarations
USE my_stuff.binary, my_stuff.add_bits3;
SHIFTED 0 0 1 0
87
rst
w MOORE_MC z
clk
entity MOORE_MC is
Port ( rst : in std_logic;
clk : in std_logic;
W : in std_logic;
Z : out std_logic);
end MOORE_MC;
TYPE state_name IS ( A , B , C );
SIGNAL statemc : state_name;
begin
VHDL Model of State m/c…..
PROCESS( rst , clk , W )
BEGIN
IF rst='1' THEN
statemc<=A ;
CASE statemc IS
WHEN A =>
IF W='1' THEN
statemc<= B;
ELSE
statemc<= A;
END IF;
WHEN B =>
IF W='1' THEN
statemc<= C;
ELSE
statemc<= A;
END IF;
WHEN C =>
IF W='1' THEN
statemc<= C;
ELSE
statemc<= A;
END IF;
END CASE;
VHDL Model of State m/c…..
END IF;
END PROCESS;
ELSE '0';
end MOORE_MC_arch;
SIMULATION
93
Testing the functionality of PDS
If I write in AND Gate Model : Y <= A OR B ;
Will it generate a SYNTHESIS Error ? NO
Download this Model into FPGA , you get OR Gate
If I would have Simulated my MODEL …
I would have caught LOGIC Error in my Design
Done by writing a TestBench (TB) for PDS
TB is 2nd VHDL MODEL in FPGA Design Flow
TB uses a Blank Entity & Structural MS
TB uses Multiple PROCESS’es w/o SL
As many I/Ps , those many PROCESS’es
Simulator ( ISim in XILINX ISE ) runs TB
W/Fs show the Functional Correctness of MODEL
You will Appreciate it better , during Practical Session
94
KNOWN
CORRECT
PDS RESULTS
TB Program ( Main Program )
STIMULUS DUT
DRIVER ( Device Under Test ) O/P Comparison
Test O/P
Vectors W/Fs
Modify
NO Real World I/Ps Model
Hence BLANK ED
YES
ERROR
96
SYNTHESIS
97
PLD
AREA ( Area )
Technology -Family
User TIMING ( Speed ) --Member
Library
Constraints POWER ( Power ) ---Capacity
Balanced ---No. of Pins
99
Hierarchical
&
Flat Designs
100
Hierarchy in Design is achieved by : Structural MS
a) Component Creation Top-Down Design Approach
b) Component Instantiation
G
C E
A
F
D
B
E
XOR GATE
4-Bit
FULL-
Binary ADDER
AND GATE
Adder
OR GATE
BCD ADDER NOT GATE
XOR GATE
Partitioning
for Synthesis
( PFS )
103
METHOD -1 : Partitioning between Datapath and Control
METHOD -2 : Clock and Reset Structures
Y <= A + B; ADDER -1
else MUX
Y <= C + D; ADDER -2
end if ;
end process;
119