HDL Lecture5
HDL Lecture5
HDL Lecture5
Languages
Rectangles
Floor Plans
Clusters
Physical Partitions
Physical/Geometry
Synopsys University Courseware
Copyright © 2014 Synopsys, Inc. All rights reserved.
Hardware Description Languages
Lecture - 5
Developed By: Vazgen Melikyan
7
Additional Benefits of VHDL
END half_adder;
x
Half carry
y
Adder result
enable
Synopsys University Courseware
Copyright © 2014 Synopsys, Inc. All rights reserved.
Hardware Description Languages
Lecture - 5
Developed By: Vazgen Melikyan
10
Specifications
Behavioral
Data Flow
Structural
x
y carry
enable
result
--
-- continuing
continuing half_adder_c
half_adder_c description
description
SIGNAL
SIGNAL xor_res
xor_res :: BIT;
BIT; --
-- internal
internal signal
signal
--
-- Note
Note that
that other
other signals
signals are
are already
already declared
declared inin entity
entity
BEGIN
BEGIN
A0
A0 :: and2
and2 PORT
PORT MAP
MAP (enable,
(enable, xor_res,
xor_res, result);
result);
A1 : and3 PORT MAP (x, y, enable,
A1 : and3 PORT MAP (x, y, enable, carry);carry);
X0
X0 :: xor2
xor2 PORT
PORT MAP
MAP (x,
(x, y,
y, xor_res);
xor_res);
END
END half_adder_c;
half_adder_c;
Entity
Defines a component’s interface
Architecture
Defines a component’s function
Alternative architectures
Structural
Behavioral
Timing and delay
Output
Output <=
<= My_id
My_id ++ 10;
10;
Example signal assignment statement :
Synopsys University Courseware
Copyright © 2014 Synopsys, Inc. All rights reserved.
Hardware Description Languages
Lecture - 5
Developed By: Vazgen Melikyan
19
Entity Declarations
x
Half carry
y result
Adder
enable
ENTITY
ENTITY half_adder
half_adder IS
IS
GENERIC(prop_delay
GENERIC(prop_delay :: TIME
TIME :=
:= 10
10 ns);
ns);
PORT(
PORT( x,
x, y, enable
enable:::OUT
y,result IN
IN BIT;
BIT;
carry,
carry, result : OUT BIT);
BIT);
END
END half_adder;
half_adder;
The port mode of the interface describes the direction in which data
travels with respect to the component
Port modes
In
Data comes in this port and can only be read
Out
Data travels out this port
Buffer
Data may travel in either direction, but only one signal driver may be on at any one time
Inout
Data may travel in either direction with any number of active drivers allowed; requires a
Bus Resolution Function
Linkage
Direction of data flow is unknown
Update
UpdateSignals
Signals Execute
ExecuteProcesses
Processes
End
EndSimulation
Simulation
Synopsys University Courseware
Copyright © 2014 Synopsys, Inc. All rights reserved.
Hardware Description Languages
Lecture - 5
Developed By: Vazgen Melikyan
27
Delay Types
Input Output
delay
Input Output
Input
Output
0 5 10 15 20 25 30 35
Synopsys University Courseware
Copyright © 2014 Synopsys, Inc. All rights reserved.
Hardware Description Languages
Lecture - 5
Developed By: Vazgen Melikyan
29
Inertial Delay
Input
Input Output
Output
0 5 10 15 20 25 30 35
Synopsys University Courseware
Copyright © 2014 Synopsys, Inc. All rights reserved.
Hardware Description Languages
Lecture - 5
Developed By: Vazgen Melikyan
30
Inertial Delay (2)
Input
Output
0 5 10 15 20 25 30 35
The REJECT feature is new to VHDL 1076-1993
Synopsys University Courseware
Copyright © 2014 Synopsys, Inc. All rights reserved.
Hardware Description Languages
Lecture - 5
Developed By: Vazgen Melikyan
31
Delta Delay
B
1
NAND AND
ANDgate
gateevaluated
evaluatedfirst:
NANDgate
gateevaluated
evaluatedfirst:
first: first:
IN: IN: 1->0
IN:1->0
1->0 IN: 1->0
A: A:
A: 0->1
A: 0->1
0->1 0->1
B: C:C: 0->1
B: 1->0
1->0 0->1
C: B:
B: 1->0
C: 0->0
0->0 1->0
C:
C: 1->0
1->0
eval AND
4 C: 1->0
1 ns
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; -- OK
-1; -- OK
aa :=
:= 1.0;
1.0; ---- illegal
illegal
END PROCESS;
END PROCESS;
END test_int;
END test_int;
Synopsys University Courseware
Copyright © 2014 Synopsys, Inc. All rights reserved.
Hardware Description Languages
Lecture - 5
Developed By: Vazgen Melikyan
36
VHDL Data Types: Scalar Types (2)
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; ---- OKOK
aa :=
:= -7.5; -- OK
-7.5; -- OK
aa := 1; -- illegal
:= 1; -- illegal
aa :=
:= 1.7E13;
1.7E13; -- -- OK
OK
aa := 5.3 ns; -- illegal
:= 5.3 ns; -- illegal
END PROCESS;
END PROCESS;
END test_real;
END test_real;
Enumerated
User specifies list of possible values
Example declaration and usage of enumerated data type:
TYPE
TYPE binary
binary IS IS (( ON,
ON, OFF
OFF );
);
... some statements
... some 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 statements ...
more statements ...
aa := OFF; --
:= OFF; -- OK OK
...
... more
more statements
statements ......
END PROCESS;
END PROCESS;
END test_enum;
END test_enum;
Physical
Requires 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 ohm;
= 1000 ohm; --
-- i.e.
i.e. 11 K
K
Mohm
Mohm == 1000
1000 kohm;
kohm; --
-- i.e.
i.e. 11 M
M
END UNITS;
END UNITS;
Time is the only physical type predefined in VHDL standard
Array
Used to group elements of the same type into a single VHDL object
Range may be unconstrained in declaration
Range would then be constrained when array is used
Example declaration for 1D array (vector):
TYPE
TYPE data_bus
data_bus IS
IS ARRAY(0
ARRAY(0 TO
TO 31)
31) OF
OF BIT;
BIT;
0 ...element indices... 31
0 ...array values... 1
VARIABLE
VARIABLE XX :: data_bus;
data_bus;
VARIABLE Y : BIT;
VARIABLE Y : BIT;
YY :=
:= X(12);
X(12); --
-- YY gets
gets value
value of
of element
element at
at index
index 12
12
15 0
...element indices...
0 1
...array values...
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
DOWNTO keyword must be used if leftmost index is greater than rightmost index
e.g. ‘Big-Endian’ bit ordering
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 switch_info
TYPE 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
Access
Analogous to pointers in other languages
Allows dynamic allocation of storage
Useful for implementing queues, fifos, etc.
Subtype
Allows 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 example:
SUBTYPE
SUBTYPE first_ten
first_ten IS
IS INTEGER
INTEGER RANGE
RANGE 00 TO
TO 9;
9;
Object types
Constants
Variables
Signals
Files
ARCHITECTURE
ARCHITECTURE test1
test1 OFOF mux
mux IS
IS ARCHITECTURE
ARCHITECTURE test2
test2 OF
OF mux
mux IS
IS
SIGNAL x : BIT :=
SIGNAL x : BIT := '1'; '1'; SIGNAL y : BIT :=
SIGNAL y : 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 x : BIT :=
x : 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 XOR
<= in_sig XOR x; x; yy <= in_sig XOR
<= in_sig XOR x;x;
END
END PROCESS;
PROCESS; END
END PROCESS;
PROCESS;
END test1;
END test1; END test2;
END test2;
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;
Time a b c out_3 out_4
0 0 1 1 1 0
1 1 1 1 0 0
1+d 1 1 1 0 1
Files provide a way for a VHDL design to communicate with the host
environment
File declarations make a file available for use to a design
Files can be opened for reading and writing
In VHDL87, files are opened and closed when their associated objects
come into and out of scope
In VHDL93 explicit FILE_OPEN() and FILE_CLOSE() procedures were
added
The package STANDARD defines basic file I/O routines for VHDL
types
The package TEXTIO defines more powerful routines handling I/O
of text files
PROCEDURE
PROCEDURE add_bits3(SIGNAL
add_bits3(SIGNAL a, a, b,b, en
en :: IN
IN BIT;
BIT;
SIGNAL
SIGNAL temp_result, temp_carry : OUT BIT)
temp_result, temp_carry : OUT BIT) IS
IS
BEGIN
BEGIN -- this function can return a
-- this function can return a carry carry
temp_result
temp_result <=
<= (a
(a XOR
XOR b)
b) AND
AND en;
en;
temp_carry <= a AND b AND
temp_carry <= a AND b AND en; en;
END add_bits3;
END add_bits3;
END my_stuff;
END my_stuff;
Synopsys University Courseware
Copyright © 2014 Synopsys, Inc. All rights reserved.
Hardware Description Languages
Lecture - 5
Developed By: Vazgen Melikyan
61
Packages: Use Clause
The following example shows how attributes can be used to make an 8-bit
register
Specifications
Triggers on rising clock edge
Latches only on enable high
Has a data setup time of x_setup
Has propagation delay of prop_delay
ENTITY 8_bit_reg IS
GENERIC (x_setup, prop_delay : TIME);
PORT(enable, clk : IN qsim_state;
a : IN qsim_state_vector(7 DOWNTO 0);
b : OUT qsim_state_vector(7 DOWNTO 0));
END 8_bit_reg;
qsim_state type is being used - includes logic values 0, 1, X, and Z
Synopsys University Courseware
Copyright © 2014 Synopsys, Inc. All rights reserved.
Hardware Description Languages
Lecture - 5
Developed By: Vazgen Melikyan
65
Attributes: Register Example (2)
ARCHITECTURE
ARCHITECTURE behavior
behavior OFOF 8_bit_reg
8_bit_reg IS IS
BEGIN
BEGIN
PROCESS
PROCESS (clk)
(clk)
BEGIN
BEGIN
IF
IF (enable
(enable == '1')
'1') AND
AND a'STABLE(x_setup)
a'STABLE(x_setup) AND AND
(clk
(clk == '1')
'1') AND
AND (clk'LAST_VALUE
(clk'LAST_VALUE == '0')
'0') THEN
THEN
bb <=
<= aa AFTER
AFTER delay;
delay;
END
END IF;
IF;
END
END PROCESS;
PROCESS;
END
END behavior;
behavior;
An ELSE clause could be added to define the behavior when the requirements are
not met
0 1 2 3
SHIFTIN 1 0 0 1
SHIFTED 0 0 1 0
The exponentiation operator **
x := 5**5 -- 5^5, OK
x := 5**5 -- 5^5, OK
y := 0.5**3 -- 0.5^3, OK
y := 0.5**3 -- 0.5^3, OK
x := 4**0.5 -- 4^0.5, Illegal
x := 4**0.5 -- 4^0.5, Illegal
y := 0.5**(-2) -- 0.5^(-2), OK
y := 0.5**(-2) -- 0.5^(-2), OK
Synopsys University Courseware
Copyright © 2014 Synopsys, Inc. All rights reserved.
Hardware Description Languages
Lecture - 5
Developed By: Vazgen Melikyan
69
Examples
PACKAGE
PACKAGE resources
resources IS
IS
TYPE
TYPE level
level IS
IS ('X',
('X', '0',
'0', '1',
'1', 'Z');
'Z'); --
-- enumerated
enumerated type
type
TYPE
TYPE level_vector
level_vector IS
IS ARRAY
ARRAY (NATURAL
(NATURAL RANGE
RANGE <>)
<>) OF
OF level;
level;
--
-- type
type for
for vectors
vectors (buses)
(buses)
SUBTYPE
SUBTYPE delay
delay IS
IS TIME;
TIME; --
-- subtype
subtype for
for gate
gate delays
delays
--
-- Function
Function and
and procedure
procedure declarations
declarations go
go here
here
END
END resources;
resources;
USE
USE work.resources.all;
work.resources.all; ARCHITECTURE
ARCHITECTURE behav
behav OF
OF and2
and2 IS
IS
ENTITY BEGIN
ENTITY and2
and2 IS
IS BEGIN
GENERIC(trise one
one :: PROCESS
PROCESS (a,b)
(a,b)
GENERIC(trise :: delay
delay :=
:= 10
10 ns;
ns;
tfall : delay := 8
tfall : delay := 8 ns);ns);
BEGIN
BEGIN
IF
IF (a
(a == '1'
'1' AND
AND bb == '1')
'1') THEN
THEN
PORT(a,
PORT(a, bb :: IN
IN level;
level; cc <= '1' AFTER trise;
<= '1' AFTER trise;
cc :: OUT
OUT level); ELSIF
level); ELSIF (a(a == '0'
'0' OR
OR bb == '0')
'0') THEN
THEN
END and2;
END and2; cc <= '0' AFTER tfall;
<= '0' AFTER tfall;
ELSE
ELSE
c<=
c<= 'X'
'X' AFTER
AFTER (trise+tfall)/2;
(trise+tfall)/2;
END IF;
END IF;
END
END PROCESS
PROCESS one;
one;
END
END behav;
behav;
Package
Concurrent Process
Concurrent
Statements
Statements
Sequential Statements