VHDL
VHDL
History
1980: US Department of Defense had launched Very High
Speed Integrated Circuit program (VHSIC) project
1986: It was transferred to the IEEE for standardization
1987: Institute of Electrical and Electronics Engineers approves
IEEE Standard 1076 (VHDL’87)
1993: VHDL language was revised and updated
Package
Architecture
Architecture Architecture
(structural)
Sequential
statement
Modeling styles-Example
Dataflow modeling: Behavioral modeling:
library ieee; architecture behav of ha_df is
Use ieee.std_logic_1164.all; Begin
entity ha_df is Process (a,b)
port(a, b : in std_logic; c, s : out Begin
std_logic); If (a= ‘0’ and b= ’0’) then
end ha_df ; c<= ‘0’;
architecture df of ha_df is s<= ‘0’;
begin elsIf (a= ‘0’ and b= ’1’) then
c <= a and b; c<= ‘0’;
s <= a xor b ; s<= ‘1’;
end df; elsIf (a= ‘1’ and b= ’0’) then
c<= ‘0’;
s<= ‘1’;
else
c<= ‘1’;
s<= ‘0’;
end if;
End process;
End behave;
Modeling styles-Example
Structural Modeling AND_2:
architecture arch of ha_df is library ieee;
component xor_2 use ieee.std_logic_1164.all;
port(m,n : in std_logic; o : out std_logic); entity and_2 is
end component; port(x,y : in std_logic; z : out std_logic);
component and_2 end entity;
port(x,y : in std_logic; z : out std_logic); architecture arch_and2 of and_2 is
end component; begin
begin z <= x and y;
X1: xor_2 port map (a, b, s); end arch_and2;
A1: and_2 port map (a, b, c);
end arch;
XOR_2 :
library ieee;
use ieee.std_logic_1164.all;
entity xor_2 is
port(m,n : in std_logic; o : out std_logic);
end entity;
architecture arch_xor2 of xor_2 is
begin
o <= m xor n;
end arch_xor2;
7
Terminology
Dataflow modeling
Describes the functionality of a component/system as a set of
concurrent signal assignment statements
Concurrent signal assignment statements are used to express
dataflow modeling
Behavioral modeling
Describes the functionality of a component/system as a set of
sequential statements
Process statements are used to express sequential behavior
modeling.
Structural modeling
A component is described by the interconnection of lower level
components/primitives
Component instantiations are used to express structural
modeling.
Synthesis:
Translating the HDL code into a circuit, which is then optimized
Entity Declaration
Provides complete interface for circuit
It defines I/O for connection and verification
Comments in a description must be preceded by two consecutive
hyphens (--). BLACK_BOX
syntax:
entity identifier is rst
q[7:0]
port ( port_interface_list ); d[7:0]
co
end identifier ; clk
-- eight bit comparator
Mode Entity name
entity compare is
port (A, B : in bit_vector ( 7 downto 0 );
EQ : out bit );
end compare;
A[7:0] EQ
List of inputs B[7:0]
compare
and outputs Port types
P P
O O
R ENTITY R
T T
S S
Port Modes
Describes direction of data transfer
Port in : Data flows only into circuit (never be on the left to the
signal assignment)
Port out : Data flows only out of circuit (never be on the right to
the signal assignment)
Port buffer : For internal feedback or driver. NOT bidirectional. It
is basically an external output but can be used as an internal
input.
Port inout : Bidirectional signal. Can be used as external input or
external output.
In(A) (X)Out
(Y)Buffer
In(B)
(Z)Inout
In(C)
Architecture Body
Describes how circuit is implemented
Describes the internal operation/view of the model
Every entity must have at least one architecture body
syntax:
architecture identifier of entity_name is
[Architecture –item-declarations] A[7:0]
compare1 EQ
begin
[statements]; B[7:0]
Declaration Entity
end identifier ; name
--eight bit comparator name
architecture compare1 of compare is
begin
Functional EQ ‘1’ when ( A = B ) else ‘0’;
description end compare1; Assignment
operator
The ports or generics declared in the entity declarations are available for use
within the architecture body due to association of the entity with the architecture
body.
Data Objects
They hold values of a specific type.
They must be declared before they are used.
They belong to one of four classes:
Constants : hold values that cannot be changed within the design
description.
Signals: can represent wires, can interconnect components.
Variables: used only in processes and subprograms (functions and
procedures) and therefore be declared in the declarative region of a
process or sub program.
An object declaration is used to declare an object, its type, and its
class, and optionally assign it a value.
e.g. signal cout: bit_vector (3 downto 0);
variable result: std_logic := ‘0’;
constant width : integer := 8;
Implementation of function
f(A,B,C) = AB’C+ABC’+ABC
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.all;
ENTITY function IS
PORT (A, B, C: IN STD_LOGIC;F: OUT STD_LOGIC);
END function;
ARCHITECTURE Dataflow OF function IS
SIGNAL term_1, term_2, term_3: STD_LOGIC;
BEGIN
term_1 <= A AND (NOT B) AND C;
term_2 <= A AND B AND (NOT C);
term_3 <= A AND B AND C;
F <= term_1 OR term_2 OR term_3;
END Dataflow;
VHDL Data Types
Every data object in VHDL can hold a value that belongs to a set
of values. This set of values is specified by using a type declaration. A type
is a name that has associated with it a set of values and a set of
operations.
VHDL is a strongly typed language (you cannot assign a signal of one type
to the signal of another type)
16
Predefined enumeration types
CHARACTER: 191 characters of the ISO 8-bit coded character set
Examples: 'A', '_', '" (the single quote character itself), '3' (the
character literal 3). These values are called character literals and
are always written between two single quotes (' ').
17
Integer type
It defines a type whose set of values fall within a specified integer
range.
It must at least cover the range -(2^ 31 - 1) to +(2^31 - 1).
Examples:
type INDEX is range 0 to 15;
type MY_WORD is range 4 to 6;
Integer literals
56349, 6E2, 0, 98_71_28
18
Real/Floating point type
It has a set of values in a given range of real numbers.
It must at least cover the range -1.OE38 to +1.OE38 and it must
allow for at least six decimal digits of precision.
Examples:
type REAL_DATA is range 0.0 to 31.9;
19
Physical type
It contains values that represent measurement of some physical
quantity, like time, length, voltage, and current.
Values of this type are expressed as integer multiples of a base
unit.
Predefined physical type is TIME; predefined physical subtype is
delay_length.
Physical literals are written as an integer literal followed by the unit
name.
Example:
type CURRENT is range 0 to 1E-9
units
nA; -- (base unit) nano-ampere
uA = 1000 nA; -- micro-ampere
mA = 1000 μA; --milli-ampere
Amp = 1000 mA; -- ampere
end units;
20
Composite type: Array type
It represents collection of values all belonging to a single type
An element of a composite type could have a value belonging to
either a scalar type, a composite type, or an access type.
Examples:
type ADDRESS_WORD is array (0 to 63) of BIT;
type DATA_WORD is array (7 downto 0) of MVL; --Type MVL is
('U','0','1','Z’);
type ROM is array (0 to 125) of DATA_WORD;
Examples of object declarations using these types are
signal ADDRESS_BUS: ADDRESS_WORD;
variable DECODER: ROM
DECODER(5,2) refers to the value of the element at the 2nd
column and 5th row of the two-dimensional object.
21
Record type
It represents a collection of values that may belong to same or different
types.
Example:
type PIN_TYPE is range 0 to 10;
type MODULE is
record
SIZE: INTEGER range 20 to 200;
CRITICAL_DLY: TIME;
NO_INPUTS: PIN_TYPE:
NO_OUTPUTS: PIN_TYPE;
end record;
Object declaration:
variable NAND_COMP: MODULE;
NAND_COMP := (50, 20 ns, 3,2);
NAND_COMP.NO_INPUTS := 2:
22
VHDL Operators
Logical: For BIT and BOOLEAN or 1-D array of BIT and Boolean
AND, NAND
OR, NOR
XOR, XNOR
NOT
The result of a logical operation has the same type as its
operands.
Relational: Result is always of type BOOLEAN
= (equal to)
/= (not equal to)
< (less than)
<= (less than or equal to)
> (greater than)
>= (greater than or equal to)
The = and /= operators are predefined on any type. <, <=, > and
>= operators are predefined on any scalar type or the bit_vector
type. 23
Semantics: Sequential & Concurrent Statements
There are two types of statements
Sequential