L7 VHDL 1
L7 VHDL 1
Introduction to VHDL
Reading
• P. Chu, FPGA Prototyping by VHDL
Examples
– Chapter 1, Gate-level combinational circuits
• Xilinx XST User Guide
– Xilinx specific language support
05.2023 2
Lecture Overview
• VHDL Fundamentals
• Describing Designs
• Libraries
• STD_Logic
• Modeling Styles
• Dataflow Modeling
• Structural Modeling
• Behavioral Modeling
• Verification and Test Bench
05.2023 3
VHDL
• VHDL is a language for describing digital logic
systems used by industry worldwide
• VHDL is an acronym for VHSIC (Very High
Speed Integrated Circuit) Hardware Description
Language
• Now, there are extensions to describe analog
designs.
05.2023 4
Versions of VHDL
• IEEE-1076 1987
• IEEE-1076 1993 ← most commonly supported by CAD
tools
• IEEE-1076 2000 (minor changes)
• IEEE-1076 2002 (minor changes)
• IEEE-1076 2008
05.2023 5
VHDL FUNDAMENTALS
05.2023 6
Naming and Labeling (1)
• VHDL is case insensitive.
– Example of a name or label
• databus
• Databus
• DataBus
• DATABUS
– are all equivalent
• Avoid inconsistent styles
05.2023 7
Naming and Labeling (2)
General rules of thumb (according to VHDL-87)
1. All names should start with an alphabet character (a-z or A-Z)
2. Use only alphabet characters (a-z or A-Z) digits (0-9) and
underscore (_)
3. Do not use any punctuation or reserved characters within a
name (!, ?, ., &, +, -, etc.)
4. Do not use two or more consecutive underscore characters (_
_) within a name (e.g., Sel_ _A is invalid)
5. No forward slashes “/” in names.
6. All names and labels in a given entity and architecture must
be unique.
05.2023 8
Extended Identifiers
• Allowed only in VHDL-93 and higher:
1. Enclosed in backslashes
2. May contain spaces and consecutive underscores
3. May contain punctuation and reserved characters within a name
(!, ?, ., &, +, -, etc.)
4. VHDL keywords allowed
5. Case sensitive
• Examples:
\rdy\ \My design\ \!a\
\RDY\ \my design\ \-a\
• Should not be used to avoid confusioin!
05.2023 9
Literals
• Numeric: 32, -16, 3.1415927
• Bits : ‘1’, ‘0’
• Strings: “Hello”
• Bit strings: B”1111_1111”, O”353”, X”AA55”
• Concatenation: “1111” & “0000” => “1111_0000”
05.2023 10
Objects
• Signal – model real physical wires for communications
– Or physical storage of information
• Variable – a programming construct to model temporary
storage
• Constant – its value never changes after initialization
05.2023 11
Comments (1)
• Comments in VHDL are indicated with a “double dash”,
i.e., “--”
– Comment indicator can be placed anywhere in the line
– Any text that follows in the same line is treated as a comment
– Carriage return terminates a comment
– No method for commenting a block extending over a couple of
lines
• Examples:
-- main subcircuit
Data_in <= Data_bus; -- reading data from the input FIFO
05.2023 12
Comments (2)
• Explain function of module to other designers
• Explanatory, not Just restatement of code
• Placed close to the code described
– Put near executable code, not just in a header
05.2023 13
Free Format
• VHDL is a “free format” language
– No formatting conventions, such as spacing or indentation
imposed by VHDL compilers. Space, tabs, and carriage return
treated the same way.
• Example:
if (a=b) then
or
if (a=b) then
or
if (a =
b) then
are all equivalent
05.2023 14
DESCRIBING DESIGNS
05.2023 15
Example: NAND Gate
Design name
and
Interface
entity nand_gate is
port( a : in STD_LOGIC;
b : in STD_LOGIC;
z : out STD_LOGIC);
end nand_gate;
05.2023 16
Example: NAND Gate –
Function
05.2023 18
Design Entity
05.2023 19
Entity Declaration
• Entity Declaration describes an interface of the
component, i.e. input and output ports.
Semicolon
after closing parenthesis
05.2023 20
Entity Declaration –
Simplified Syntax
ENTITY entity_name IS
PORT (
port_name : port_mode signal_type;
port_name : port_mode signal_type;
………….
port_name : port_mode signal_type
);
END ENTITY entity_name;
05.2023 21
Port Mode – IN
05.2023 22
Port Mode – OUT
05.2023 23
Port Mode – OUT (with Extra Signal)
05.2023 24
Port Mode – INOUT
05.2023 25
Port Modes – Summary
• The Port Mode of the interface describes the direction in
which data travels with respect to the component
– In: Data comes into this port and can only be read
within the entity. It can appear only on the right side
of a signal or variable assignment.
– Out: The value of an output port can only be updated within the
entity. It cannot be read. It can only appear on the left side of
a signal assignment.
– Inout: The value of a bi-directional port can be read and
updated within the entity model. It can appear on both sides of
a signal assignment.
05.2023 26
Architecture (Architecture body)
• Describes an implementation of a design entity
• Architecture example:
• Logic operators:
– NOT, AND, OR, NAND, NOR, XOR, XNOR
05.2023 27
Architecture – Simplified Syntax
05.2023 28
Entity Declaration & Architecture
05.2023 29
Tips & Hints (1)
• Place each entity in a different file.
• The name of each file should be exactly the same
as the name of an entity it contains.
05.2023 30
Tips & Hints (2)
• Place the declaration of each port, signal,
constant, and variable in a separate line for better
readability
05.2023 31
LIBRARIES
05.2023 32
Library Declarations
05.2023 33
Library Declarations – Syntax
05.2023 34
Structure of a Library
05.2023 35
Libraries
05.2023 36
Operators in Standard VHDL
05.2023 37
Standard VHDL – Data Types
• integer
– Minimal range: -(2^31 – 1) to 2^31 – 1
• boolean: {true, false}
• bit: {‘1’, ‘0’}
• bit_vector: string of bits.
– “0001_1111”
05.2023 38
STD_LOGIC DEMYSTIFIED
05.2023 39
Operators in Standard VHDL
05.2023 40
STD_LOGIC
05.2023 41
BIT versus STD_LOGIC
• VHDL standard BIT type
– Can only model a value of ‘0’ or ‘1’
05.2023 42
STD_LOGIC type demystified
05.2023 43
STD_LOGIC Meanings (1)
05.2023 44
STD_LOGIC Meanings (2)
05.2023 45
Resolving Logic Levels
05.2023 46
STD_LOGIC Rules
• In this course, use only std_logic or std_logic_vector
for all entity input or output ports
• Do NOT use integer, unsigned, signed, bit for ports
– You can use them inside of architectures if desired
– You can use them in generics
• Instead use std_logic_vector and a conversion function
inside of your architecture
05.2023 47
Signals Modeling Wires and Buses
SIGNAL a : STD_LOGIC;
05.2023 48
Standard Logic Vectors
05.2023 49
Vectors and Concatenation
05.2023 50
Merging Wires and Buses
05.2023 51
Splitting Buses
05.2023 52
MODELING STYLES
05.2023 53
Design Entity
05.2023 54
Types of VHDL Descriptions
05.2023 55
xor3 Example
05.2023 56
Entity xor3 Gate
LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY xor3 IS
PORT( A : IN STD_LOGIC;
B: IN STD_LOGIC;
C: IN STD_LOGIC;
Result : OUT STD_LOGIC);
end ENTITY xor3;
05.2023 57
DATAFLOW MODELING
05.2023 58
Dataflow Architecture - xor3 Gate
05.2023 59
Dataflow Description
• Describes how data moves through the various processing steps
of the system.
– Uses series of concurrent statements to realize logic.
• Most useful style when series of Boolean equations can represent
a logic used to implement simple combinational logic
– Dataflow code also called concurrent code
• Concurrent statements are evaluated at the same time; thus, the
order of these statements does NOT matter
– This is not true for sequential/behavioral statements
05.2023 60
Event-Driven Semantics (1)
• When a concurrent statement is evaluated?
05.2023 61
Event-Driven Semantics (2)
05.2023 62
Event-Driven Semantics (3)
05.2023 63
Event-Driven Semantics (4)
05.2023 64
Event-Driven Semantics (5)
05.2023 65
Event-Driven Semantics
Another Example (1)
05.2023 66
Event-Driven Semantics
Another Example (2)
05.2023 67
Event-Driven Semantics
Another Example (3)
05.2023 68
STRUCTURAL MODELING
05.2023 69
Structural Architecture – xor3 Gate
05.2023 70
Structural Architecture in VHDL 93
05.2023 72
Structural Architecture in VHDL 87
ARCHITECTURE structural OF xor3 IS
SIGNAL U1_OUT: STD_LOGIC;
COMPONENT xor2
PORT(
I1 : IN STD_LOGIC;
I2 : IN STD_LOGIC;
Y : OUT STD_LOGIC);
END COMPONENT;
BEGIN
U1: xor2 PORT MAP (I1 => A, I2 => B, Y=> U1_OUT);
U2: xor2 PORT MAP (I1 => U1_OUT,
I2 => C,
Y => Result);
END05.2023
structural; 73
Structural Description
• Allows divide-n-conquer for large designs.
• This style is the closest to schematic capture and utilizes
simple building blocks to compose logic functions.
• Components are interconnected in a hierarchical
manner.
• Structural descriptions may connect simple gates or
complex, abstract components.
• Structural style is useful when expressing a design that
is naturally composed of sub-blocks.
05.2023 74
BEHAVIORAL MODELING
05.2023 75
Behavioral Architecture – xor3 Gate
ARCHITECTURE behavioral OF xor3 IS
BEGIN
xor3_behave: PROCESS (A, B, C)
BEGIN
IF ((A XOR B XOR C) = '1') THEN
Result <= '1';
ELSE
Result <= '0';
END IF;
END PROCESS xor3_behave;
END ARCHITECTURE behavioral;
05.2023 76
Behavioral Description
• It describes what happens on the inputs and outputs of
the black box (no matter how a design is actually
implemented).
– Focus on functions mapping inputs to outputs
– Similar to dataflow style,
– More like sequential SW programming.
• This style uses process statements in VHDL.
– A process itself is a concurrent statement.
– A process consist of sequential statements.
• More later.
05.2023 77
VERIFICATION AND TEST
BENCH
05.2023 78
Design Testing and Testbenches
• After a design is done, it needs to be tested.
• During testing, design inputs are driven by various test
vectors, and
• Outputs are monitored and checked.
05.2023 79
Testbench in VHDL
library ieee;
use ieee.std_logic_1164.all;
ENTITY testbench IS
END testbench;
05.2023 80
05.2023 81
05.2023 82