ECE 324 VHDL Tutorial Notes
ECE 324 VHDL Tutorial Notes
ECE 324
VHDL Tutorial Notes
June 2002
Section I:
VHDL Tutorial
June 2002
VHDL Tutorial
Tutorial Outline
• Introduction to VHDL
• VHDL Designs
• Signals
• Assignment Statements
• Process Statements
• Examples
VHDL
VHDL Documentation
• Books
– Michael John Sebastian Smith, Application Specific Integrated Cir-
cuits, Addison-Wesley, Reading Mass., 1998.
– Stephen Brown and Zvonko Vranesic, Fundamentals of Digital Logic
with VHDL Design, McGraw-Hill, New York, NY, 2000.
– Douglas Perry, VHDL, 3rd Edition, McGraw Hill, New York, NY,
1998.
– Peter J. Ashenden, The Designer’s Guide to VHDL, Morgan Kauf-
mann Publishers, Inc., San Francisco, CA, 1996.
– Sudhakar Yalamanachili, VHDL Starter’s Guide, Prentice-Hall, Up-
per Saddle River, NJ, 1998.
– David Pellerin and Douglas Taylor, VHDL Made Easy, Prentice-Hall,
Upper Saddle River, NJ, 1997.
– K.C. Chang, Digital Design and Modelling with VHDL and Synthesis
IEEE Computer Society, Los Alamitos, CA, 1997.
entityintro 1.
X
Y D
Z
E1: Module 1 (Entity for Module 1) E2: Module 2 (Entity for Module 2)
separate the separate the
A A
implementation from implementation from
C its interface C
its interface B
B in the system
in the system
entityintro 2.
Small Example
andnand.vhd
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY andNand IS
PORT(
a, b : IN STD_LOGIC;
q, qBar : OUT STD_LOGIC
);
END andNand;
BEGIN
a_and_b <= a AND b;
q <= a_and_b;
qBar <= NOT a_and_b;
END gateVersion;
NOTE
andnand.
Language Elements
Comments :
Datatypes :
VHDL supports a set of built-in datatypes as well as user-defined datatypes.
Only a few will be introduced in this tutorial!
• Built-in datatypes will not be used this term. They work well for
simulation but not so well for synthesis.
– BIT: Boolean value of 0 or 1.
– BIT VECTOR: An array of bits.
– INTEGER: An integer value (within a range).
• The datatypes specified in STD LOGIC 1164 will be used exclusively this
term.
Entity Declaration
• Set of port declarations defining the inputs and outputs to the digital
hardware design.
– Port name
∗ Consists of letters, digits, and/or underscores
∗ Must begin with a letter
∗ Case insensitive
– Port direction
IN Input port
OUT Output port
INOUT Bidirectional port
BUFFER Buffered output port
LINKAGE Deprecated in IEEE 1076-2000
VHDL Designs I - 10
VHDL Tutorial
Signals
In VHDL, signals are used to convey information between (and within) entities.
Signals represent connection points in a VHDL design.
Sample Signal Specifications:
SIGNAL x1 : BIT;
SIGNAL c : BIT_VECTOR(1 TO 4);
SIGNAL byte : BIT_VECTOR(10 DOWNTO 0);
VHDL Designs I - 11
VHDL Tutorial
Signal Operators
Logical Operators :
• AND
• OR
• XOR
• XNOR
• NOT
• NAND
• NOR
Relational Operators :
• Equal =
• Not Equal /=
• Less Than <
• Greater Than >
VHDL Designs I - 12
VHDL Tutorial
Assignment Statements
SIGNAL x, y, z : STD_LOGIC;
SIGNAL a, b, c : STD_LOGIC_VECTOR(7 DOWNTO 0);
SIGNAL sel : STD_LOGIC_VECTOR(2 DOWNTO 0);
VHDL Designs I - 13
VHDL Tutorial
Assignment Statements
SIGNAL x, y, z : STD_LOGIC;
SIGNAL a, b, c : STD_LOGIC_VECTOR( 7 downto 0);
SIGNAL sel : STD_LOGIC_VECTOR( 2 downto 0);
VHDL Designs I - 14
VHDL Tutorial
Process Statements
This construct is not required for the labs this term. However, a process is a
fundamental concept of VHDL.
The process statement allows a VHDL designer to describe the behaviour of
a portion of an architecture. It is easy to fall into the trap of believing that
statements within a process are sequential. This is not (necessarily) the case!
The following is a quote from the Brown and Vranesic text...
VHDL Designs I - 15
VHDL Tutorial
Variables :
Variables can be declared within a process. Variables can be used like sig-
nals. However, variables and signals have a subtle difference with respect
to the assignment of a value.
VARIABLE variable_name : variable_type;
IF Statements :
IF condition1 THEN
statements1;
ELSIF condition2 THEN
statements2;
ELSE
statements3;
END IF;
VHDL Designs I - 16
VHDL Tutorial
Case Statements :
CASE variable_name IS
WHEN value1 =>
statement1;
WHEN value2 =>
statement2;
WHEN OTHERS =>
statement4;
END CASE;
Loop Statements :
Assert Statements :
Wait Statements :
Wait statements halt the execution of a process until a desired event or
delay has happened. Wait statements can be used to build sequential
designs.
VHDL Designs I - 17
VHDL Tutorial
SIGNAL a, b, c : STD_LOGIC;
SIGNAL Sel, x, y, z : STD_LOGIC;
SIGNAL DV : STD_LOGIC_VECTOR(17 DOWNTO 0);
-- Assume that a, b, c and Sel are set on elsewhere
PROCESS (a, b, c)
-- a, b, and c are in the sensitivity list.
-- In this case (combinational) they are
-- inputs.
BEGIN
-- Signal assignment statements can go anywhere
-- inside a process.
x <= a;
-- If statements
IF a = ’0’ THEN
x <= c AND b;
y <= c OR b;
ELSIF b = ’0’ THEN
z <= c OR a;
ELSE
w <= ’0’;
END IF; -- Note x, y, and z are
-- not always assigned
-- in this example
VHDL Designs I - 18
VHDL Tutorial
-- Case statement
CASE Sel IS
WHEN ’0’ =>
z <= a AND b;
WHEN OTHERS
z <= a OR b;
-- For Loops
FOR i IN 1 to 4 LOOP
DV(i) <= a XOR b;
END LOOP;
-- While Loops
END PROCESS;
VHDL Designs I - 19
VHDL Tutorial
ff1: PROCESS
(
clock,
reset
)
BEGIN
IF (reset = ’1’) THEN
q <= ’0’;
ELSIF (clock = ’1’) AND (clock’EVENT) THEN
q <= d;
END IF;
END PROCESS ff1;
VHDL Designs I - 20
VHDL Tutorial
Example
Logical Problem
(ECE 223, ME 262)
Entity
DataIn(vector)
Segments(6)
Segments
Segments(1)
Segments(4) Segments(5)
DPin
Segments(0)
Segments(2)
Segments(3)
DP
Segments(7)
sevenseg
VHDL Designs I - 21
VHDL Tutorial
Assumption:
LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY seven_seg IS
PORT
(
dataIn : IN STD_LOGIC_VECTOR(3 DOWNTO 0);
decimalIn: IN STD_LOGIC;
segments : OUT STD_LOGIC_VECTOR(7 DOWNTO 0)
);
END seven_seg;
VHDL Designs I - 22
VHDL Tutorial
-- 2 4
-- 3
-- 7 is decimal point, always off
VHDL Designs I - 22
VHDL Tutorial
END theLongWay;
VHDL Designs I - 22
VHDL Tutorial
VHDL Designs I - 22
VHDL Tutorial
• LIBRARY
• USE
• ENTITY
• ARCHITECTURE
VHDL Designs I - 23
VHDL Tutorial
LIBRARY ieee;
USE ieee.std_logic_1164.all;
VHDL Designs I - 24
VHDL Tutorial
Designing a Multiplexer
select_data
data_a
data_q
data_a
• Required Inputs
– 1 control bit
– 4 pairs of 2 input lines
• Outputs
– Four output lines
VHDL Designs I - 25
VHDL Tutorial
LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY quad_2_input IS
PORT
(
select_data : IN STD_LOGIC;
data_a, data_b : IN STD_LOGIC_VECTOR(3 DOWNTO 0);
data_q : OUT STD_LOGIC_VECTOR(3 DOWNTO 0)
);
END quad_2_input;
VHDL Designs I - 26
VHDL Tutorial
Device Functionality
VHDL Designs I - 27
VHDL Tutorial
Architecture Body
VHDL Designs I - 28
VHDL Tutorial
Gate Model
-- Quadruple 2 Input MUX
LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY quad_2_input IS
PORT
(
select_data : IN STD_LOGIC;
data_a, data_b : IN STD_LOGIC_VECTOR(3 DOWNTO 0);
data_q : OUT STD_LOGIC_VECTOR(3 DOWNTO 0)
);
END quad_2_input;
BEGIN
END gates_only;
VHDL Designs I - 29
VHDL Tutorial
Conditional Assignment
-- Quadruple 2 Input MUX
LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY quad_2_input IS
PORT
(
select_data : IN STD_LOGIC;
data_a, data_b : IN STD_LOGIC_VECTOR(3 DOWNTO 0);
data_q : OUT STD_LOGIC_VECTOR(3 DOWNTO 0)
);
END quad_2_input;
BEGIN
END conditional_assign;
VHDL Designs I - 30
VHDL Tutorial
LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY quad_2_input IS
PORT
(
select_data : IN STD_LOGIC;
data_a, data_b : IN STD_LOGIC_VECTOR(3 DOWNTO 0);
data_q : OUT STD_LOGIC_VECTOR(3 DOWNTO 0)
);
END quad_2_input;
BEGIN
END using_select;
VHDL Designs I - 31
VHDL Tutorial
LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY quad_2_input IS
PORT
(
select_data : IN STD_LOGIC;
data_a, data_b : IN STD_LOGIC_VECTOR(3 DOWNTO 0);
data_q : OUT STD_LOGIC_VECTOR(3 DOWNTO 0)
);
END quad_2_input;
BEGIN
END process_if;
VHDL Designs I - 32
VHDL Tutorial
LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY quad_2_input IS
PORT
(
select_data : IN STD_LOGIC;
data_a, data_b : IN STD_LOGIC_VECTOR(3 DOWNTO 0);
data_q : OUT STD_LOGIC_VECTOR(3 DOWNTO 0)
);
END quad_2_input;
BEGIN
END process_case;
VHDL Designs I - 33
VHDL Tutorial
LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY quad_2_input IS
PORT
(
select_data : IN STD_LOGIC;
data_a, data_b : IN STD_LOGIC_VECTOR(3 DOWNTO 0);
data_q : OUT STD_LOGIC_VECTOR(3 DOWNTO 0)
);
END quad_2_input;
BEGIN
END process_loop;
VHDL Designs I - 34
VHDL Tutorial
Execution of VHDL
VHDL Designs I - 35
VHDL Tutorial
Using Components
VHDL Designs I - 36