VHDL Presentation
VHDL Presentation
ON
VHDL PROGRAMMING
1.INTRODUCTION
• VHDL is a hardware description language
• Describe behavior of an electronic ckt or system,from
which the physical circuit can be implemented
• VHDL stands for Very High Speed Integrated Cricuit
(VHSIC) Hardware Description Language(VHDL)
• Funded by DOD
• First version in 1980 ie VHDL 87
• Upgraded to VHDL 93
• First hardware description language to be
standardized by IEEE through 1076
• Upgraded to IEEE 1164
Introduction Cont…
----xxx----
Next APPLICATION
APPLICATIONS
• Programmable Logic Devices(CPLDs,FPGAs)
• ASIC(Application Specific Integrated Ckt)
Once a VHDL code has been writtean,it can be used either to
implement the ckt on
1. Programmable logic Devices from Altera,Xilinx Atmel
etc
2. Can be submitted to a foundry for fabrication of an ASIC
chip
Currently many complex commercial chips (microcontrollers,
for example) are designed using such an approach
FINAL NOTE
• VHDL statements are inherently concurrent
(parallel)
• For this reason VHDL is usually referred to
as a code rather than a program
• In VHDL only statements placed inside a
PROCESS,FUNCTION or PROCEDURE
are executed sequentially
DESIGN FLOW
VHDL entry
(RTL Level)
Compilation
Netlist
(Gate Level)
Synthesis Optimization
Optimized netlist
(Gate Level) Simulation
Place and Route
Physical Device
Simulation
DESIGN FLOW Cont . . .
A A B Cin S Cout
S 0 0 0 0 0
B Full 0 0 1 1 0
Adder Cout 0 1 0 1 0
cin 0 1 1 0 1
1 0 0 1 0
1 0 1 0 1
1 1 0 0 1
1 1 1 1 1
NOTE:-
1. S must be high when ever the number of inputs that are
high is odd
2. While Cout must be high when two or more inputs are high
VHDL CODE
library ieee; As can be seen it consist of an
use ieee.std_logic_1164.all; ENTITY,which is a
entity full_adder is description of the
port (a,b,cin:in bit; pins(PORTS) of the ckt and
s,cout:out bit); an ARCHITECTURE,which
end full_adder; describes how the circuit
------------------------------------- should function.Sum bit is
architecture dataflow of full_adder is computed as a b cin,
begin while cout is obtained from
s <= a xor b xor cin; cout = a.b + a.cin + b.cin
cout<= (a and b) or (a and cin) or (b and
cin);
A
end dataflow;
S
B Full
Adder Cout
CIRCUIT cin
OUTPUT VARIABLE OUTPUT VALUE
OUTPUT WAVEFORM
INPUT VALUE
INPUT VARIABLE
SIMULATION RESULT
2.CODE STRUCTURE
CODE STRUCTURE
FUNCTIONS
PROCEDURES
COMPONENTS
CONSTANTS
TYPES
LIBRARY BY DEFAULT ADDED
EXPLICITY WRITTEN
Work.all:- where we save our design (the .vhd file,plus all files created
by the compiler,simulator etc)
SYNTAX
ENTITY entity_name is
PORT (
port name : signal_mode signal_type;
port name : signal_mode signal_type;
. . . );
END entity_name;
SIGNAL_MODE
IN OUT
OUT CKT INOUT
IN
INOUT BUFFER
BUFFER
•BUFFER on the under hand is employed when the output signal must
be used internally
SIGNAL_TYPE
BIT
STD_LOGIC
INTEGER
•DATA TYPES WILL BE DISCUSSED IN DETAIL IN COMING
CHAPTERS
EXAMPLE : - Let us consider the NAND gate of below. Its
ENTITY can be specified as :
ENTITY nand_gate IS
a
PORT (a,b:IN BIT; x
b
x: OUT BIT);
END nand_gate;
SYNTAX
ARCHITECTURE architecture_name OF
entity_name IS
[declaration] Part 1 optional signals and
constant are declared
BEGIN
(code) Part 2 VHDL programe code
END architecture_name;
STRUCTURE MODELING
BEHAVIOR MODELING
MIXED MODELING
1.STRUCTURE MODELING
SET OF INTERCONNECTED COMPONENTS
4.MIXED MODELING
COMBINATION OF THE ABOVE THREE
d q EXAMPLE-1
DFF Fig shows DFF triggered at the rising edge
clk of the clk and with an asynchronous reset
Input rst.When rst=1,the output must be turned
Low,regardless of clk.Otherwise,the output
Must copy the input i.e q <= d at the moment
rst when clk changes from 0 to 1
1-----------------------------------------------------------------------
2 LIBRARY ieee;
3 USE ieee.std_logic_1164.all;
4------------------------------------------------------------------------
5 ENTITY dff IS
6 PORT (d,clk,rst:IN STD_LOGIC;
7 q:OUT STD_LOGIC);
8 END dff;
9------------------------------------------------------------------------
10 ARCHITECTURE behavior OF dff is
11 BEGIN
12 PROCESS (rst,clk)
13 BEGIN
14 IF (rst=‘1’) THEN
15 Q <= ‘0’;
16 ELSIF (clk’EVENT AND clk=‘1’) THEN
17 Q <= d;
18 END IF;
19 END PROCESS;
20 END behavior;
21 -----------------------------------------------------
EXPLANATION
LINE 2-3: Library declaration (Library name and Library use
clause).Recall that the other two indispensable libraries (std and work)
are made visible by default.
LINE 5-8: Entity dff
LINE 10-20: Architecture behavior
LINE 6: Input ports(input mode can only be IN).In this example,all input
signal is of type STD_LOGIC.
LINE 7: Output port(output mode can be OUT,INOUT,or BUFFER).Here
the output is also of type STD_LOGIC
LINE 11-19: Code part of the Architecture (from word BEGIN on)
LINE 12-19: A PROCESS (inside it the code is executed sequentially)
EXPLANATION
LINE 12: The PROCESS is executed every time a signal
declared in its sensitivity list changes.In this example
every time rst or clk changes the PROCESS is run..
LINE 14-15: Every time rst goes to ‘1’ the output is
reset,regardless of the clk (asyn reset)
LINE 16-17: If rst is not active,plus clk has changed (an
EVENT occurred on clk),plus such event was a
rising edge (clk=‘1’),then the input signal (d) is
stored in the FF (q <= d)
LINE 15 and 17: The “<=“ is used to assign a value to a
SIGNAL,”:=“would be used for a VARIABLE.All ports in
an entity are signals by default
LINE 1,4,9,21: Commented
Note:-VHDL is not case sensitive
3.DATA TYPES
PRE-DEFINED DATA TYPES
USER-DEFINED DATA TYPES
SUBTYPES
ARRAYS
PORT ARRAYS
RECORDS
SIGNED AND UNSIGNED DATA TYPES
DATA CONVERSION
INTRODUCTION
• ESSENTIAL TO KNOW DATA TYPES
FOR EFFICIENT VHDL CODING
• WHAT DATA TYPES ARE ALLOWED
• HOW TO SPECIFY AND USE THEM
• ALL FUNDAMENTL DATA TYPES ARE
DESCRIBED HERE
• DATA COMPATIBILITY AND DATA
CONVERSION
PRE-DEFINED DATA TYPES
• CONTAINS A SERIES OF PRE-DEFINED DATA TYPES
• SPECIFIED BY ieee 1076 AND ieee 1064
• SUCH DATA TYPES DEFINITIONS CAN BE FOUND IN
FOLLOWING PACKAGES AND LIBRARIES AS SHOWN
BELOW
1. LIBRARY
(std)
PACKAGE
(standard)
DEFINITIONS
(BIT,BOOLEAN,INTEGER AND REAL)
2. LIBRARY
(ieee)
PACKAGE
(std_logic_1164)
DEFINITIONS
(STD_LOGIC AND STD_ULOGIC)
3. LIBRARY
(ieee)
PACKAGE
(std_logic_arith)
DEFINITIONS
SIGNED AND UNSIGNED
conv_integer(p),conv_unsigned(p.b),conv_signed(p,b)
and conv_std_logic_vector(p,b)
4. LIBRARY
(ieee)
PACKAGE
(std_logic_signed and std_logic_unsigned)
EXAMPLE 1.
SIGNAL x : BIT;
--x is declared as a one-digit signal of type BIT
EXAMPLE 2.
SIGNAL y : BIT_VECTOR (3 DOWNTO 0);
--y is a 4-bit vector,with the lefmost bit being the MSB
EXAMPLE 3.
SIGNAL w : BIT_VECTOR(0 TO 7);
--w is 8-bit vector, with the rightmost bit being the MSB
EXAMPLE 2.
y <= “0111”;
--y is a 4-bit signal,whose value is “0111” MSB=‘0’.Notice that
double quote (“ ”) are used for vectors
EXAMPLE 3.
w <= “01110001”;
--w is 8-bit signal, whose value is “01110001” (MSB=‘1’)
EXAMPLE 2.
SIGNAL y : STD_LOGIC_VECTOR (3 DOWNTO 0) := “0001”;
--y is a 4-bit vector,with the lefmost bit being the MSB.The initial
value (optional) of y is “0001”.Notice that the “:=“ operator is
used to establish the initial value
•STD_LOGIC LEVELS ARE INTENDED FOR SIMULATION
•‘0’,’1’,’Z’ ARE SYNTHESIZABLE WITH NO RESTRICTIONS
•WITH RESPECT TO WEAK VALUE S THEY ARE RESOLVED IN
FAVOUR OF THE FORCING VALUES IN MULTIPLY DRIVEN
NODE(AS SHOWN INTABLE)
•IF ANY TWO STD_LOGIC ARE CONNECTED TO THE SAME
NODE,THEN CONFLICTING LOGIC LEVELS ARE
AUTOMATICALLY RESOLVED ACCORDING TO THE TABLE
RESOLVED LOGIC SYSTEM (STD_LOGIC)
X 0 1 Z W L H -
X X X X X X X X X
0 X 0 X 0 0 0 0 X
1 X X 1 1 1 1 1 X
Z X 0 1 Z W L H X
W X 0 1 W W W W X
L X 0 1 L W L W X
H X 0 1 H W W H X
- X X X X X X X X
STD_ULOGIC_VECTOR
9-VALUED LOGIC SYSTEM INTRODUCED IN THE IEEE
1164 STANDARD
S.NO. VALUE MEANING
1 U UNRESOLVED
2. ‘X’ Forcing unknown
3. ‘0’ Forcing low
4. ‘1’ Forcing high
5. ‘Z’ High impedance
6. ‘W’ Weak unknown
7. ‘L’ Weak low
8. ‘H’ Weak High
9 ‘-’ Don’t Care
BOOLEAN : True,False
INTEGER : 32-bit integers (from –2,147,483,647 to 2,147,483,647)
NATURRAL : Non-negative integers (from 0 to 2,147,483,647)
REAL : Real numbers ranging from –1.0E38 to 1.0E38.Not
synthesizable
EAMPLES :
x0 <= ‘0’; --bit,std_logic,std_ulogic value ‘0’
x1 <= “00011111”; --bit_vector,std_logic_vector,std_ulogic_vector,signed,or
--unsigned
x2<= “0001_1111”;--underscore allowed to ease visualization
x3 <= “101111” –binary representation of decimal 47
x4 <= B”101111” --binary representation of decimal 47
x5 <= O”57” --octal representation of decimal 47
x6 <= X”2F” --hexadecimal representation of decimal 47
n <= 1200; –integer
m <= 1_200; --integer,underscore allowed
IF ready THEN . . . --Boolean,executed if ready=true
y <= 1.2E-5; --real, not synthesizable
q <= d after 10 ns; --physical,not synthesizable
LEGAL AND ILLEGAL OPERATIONS BETWEEN DATA OF DIFFERENT
TYPES
SIGNAL a: BIT;
SIGNAL b: BIT_VECTOR (7 DOWNT 0 );
SIGNAL c:STD_LOGIC;
SIGNAL d:STD_LOGIC_VECTOR (7 DOWNTO 0);
SIGNAL e:INTEGER RANGE 0 to 255;
a <= b(5); --legal same scalar type:BIT
--------------------------------------------------------------------------------------
b(0) <= a; --legal same scalar type:BIT
01000 1D (vector)
RECORDS
Records are similar to arrays,with only difference that they contain
objects of different types.
EXAMPLE:
TYPE birthday IS RECORD
Day:INTEGER RANGE 1 TO 31;
Month:month_name;
SIGNED AND UNSIGNED DATA TYPES
These types are defined in std_logic_arith package
EXAMPLES:
SIGNAL x: SIGNED (7 DOWNTO 0);
SIGNAL y: UNSIGNED (0 TO 3);
--UNSIGNED value is a number never lower to zero
--Intended mainly for arithmatic operations
--Logical operations are not allowed
EXAMPLE:Legal and illegal operations
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;--extra package necessary
...
SIGNAL a: IN SIGNED (7 DOWNTO 0)
SIGNAL b: IN SIGNED (7 DOWNTO 0)
SIGNAL x: OUT SIGNED (7 DOWNTO 0)
...
V <= a+b; --illegal arithmetic operations not OK
w <= a and b;--legal (logical operations OK)
IEEE library provides two packages std_logic_signed
and std_logic_unsigned which allow operations with
STD_LOGIC_VECTOR data.
Example:
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_unsigned.all;--extra package included
SIGNAL a: IN STD_LOGIC_vecTO (7 DOWNTO 0)
SIGNAL b: IN STD_LOGIC_vecTO (7 DOWNTO 0)
SIGNAL x: IN STD_LOGIC_vecTO (7 DOWNTO 0)
...
V <= a+b;--legal arithmetic operation OK),unsigned
W <= a and b;--legal logical operation OK
DATA CONVERSION
Direct operations(arith,logi) between data of different types are not
Allowed.
SO conersion is required.
Done in two ways either user defined programme or invoking
FUNCTION from predefined functions.
If operand base is same but belong to different type classs than
std_logic_1164 library provides direct conversion.
•ASSIGNMENT OPERATORS
•LOGICAL OPERATORS
•ARITHMETIC OPERATORS
•RELATIONAL OPERATORS
•SHIFT OPERATORS
•CONCATENATION OPERATORS
Described in coming slides
<= USED TO ASSIGN A VALUE TO A SIGNAL
:= USED TO ASSIGN A VALUE TO A VARIABLE,CONSTANT OR
GENERIC.These all are used for establishing initial value
=>USED TO ASSIGN VALUES TO INDIVIDUAL VECTOR
ELEMENTS OR WITH OTHERS
EXAMPLE
SIGNAL x: STD_LOGIC;
VARIABLE y : STD_LOGIC_VECTOR(3 DOWNTO 0);
SIGNAL w: STD_LOGIC_VECTOR(0 TO 7);
Then the following assignment are legal:
x < = ‘1’;
y : = “0000”;
w <= “10000000”;
w <= (0 => ‘1’,others =>’0’);--LSB is 1 others are 0
LOGICAL OPERATORS
Used for logical operations.Data must be of
TYPE BIT,STD_LOGIC, STD_ULOGIC and their respective
extensions that are BIT_VECTOR,STD_LOGIC_VECTOR,
STD_ULOGIC_VECTOR.The logical operations are
• NOT
• AND
• OR
• NAND
• NOR
• XOR
• XNOR –INTRODUCED IN VHDL93
EXAMPLE
y <= NOT a AND b;
y <= NOT (a AND b);
ARITHMATIC OPERATORS
Used for arithmetic operations.Data must be of TYPE
INTEGER,SIGNED, UNSIGNED or REAL. If std_logic_unsigned and
std_logic_signed packages are included then STD_LOGIC_VECTOR
Can be employed directly in addition and subtraction (to be described)
+ Addition
- Subtraction
* Multiplication
/ Division
** Exponentiation
MOD modulus
REM Remainder Not Synthesiable
ABS Absolute value
ARITHMATIC OPERATORS
Used for arithmetic operations.Data must be of TYPE
INTEGER,SIGNED, UNSIGNED or REAL. If std_logic_unsigned and
std_logic_signed packages are included then STD_LOGIC_VECTOR
Can be employed directly in addition and subtraction (to be described)
+ Addition
- Subtraction
* Multiplication
/ Division
** Exponentiation
MOD modulus
REM Remainder Not Synthesiable
ABS Absolute value
COMPARISON OPERATORS
Used for making comparisons.Data must be of any TYPE listed above
The relational(comparison) operators are:
= equal to
/= not equal to
< Less than
> Greater than
<= less than or equal to
>= greater than or equal to
SHIFT OPERATORS
Used for shifting data.Data must be of any TYPE listed above
SYNTAX
<left operand> <shift operation> <right operand>
Left operand must be BIT_VECTOR
Right operand must be INTEGER
SHIFT MEANING DEFINITIONS
OPERATORS
Sll Shift left logic Position on the right are filled with
0
Srl Shift right logic Position on the left are filled with 0
Sla Shift left Rightmost bit is replicated on the
arithmetic right
Sra Shift right Leftmost bit is replicated on the left
arithmetic
Rol Rotate left logic Rotate left logic
ror Rotate right logic Rotate left logic
EXAMPLE
Say that x <=“01001”.Then
Y <= x sll 2; --y<=“00100”
Y <= x sla 2; --y<=“00111”
Y <= x srl 3; --y<=“00001”
Y <= x sra 3; --y<=“00001”
Y <= x rol 2; --y<=“00101”
CONCATENATION
Are used to group values.The concatenation
operators are & and ,
Examples:
Z <= x & “1000000”;--if x=1 then z=11000000
Z=(‘1’,’1’,’0’,’0’,’0’,’0’,’0’,’0’); --z=11000000
ATTRIBUTES
• Allows VHDL more flexibility
• Allows GENERIC piece of code construct
ATTRIBUTES