ECE545 Lecture3 VHDL Basics 6
ECE545 Lecture3 VHDL Basics 6
Recommended reading
VHDL - http://en.wikipedia.org/wiki/VHDL
Verilog - http://en.wikipedia.org/wiki/Verilog
Accellera - http://en.wikipedia.org/wiki/Accellera
3 4
5 6
1
ECE 448 – FPGA and ASIC Design with VHDL 7 ECE 448 – FPGA and ASIC Design with VHDL 8
VHDL
11 12
2
Four versions of VHDL
Verilog
• Simpler and syntactically different
• C-like
Government Commercially
Developed Developed
Ada based C based
Case-insensitive Case-sensitive
17 18
3
How to learn Verilog by yourself ? Features of VHDL and Verilog
• Technology/vendor independent
• Portable
• Reusable
19 20
23 24
4
Free Format Readability standards & coding style
• VHDL is a “free format” language Adopt readability standards based on one of the
No formatting conventions, such as spacing or the two main textbooks:
indentation imposed by VHDL compilers. Space Chu or Brown/Vranesic
and carriage return treated the same way.
Example: Use coding style recommended in
if (a=b) then
or
OpenCores Coding Guidelines
if (a=b) then linked from the course web page
or
if (a = Strictly enforced by the lab instructors and myself.
b) then
Penalty points may be enforced for not following
are all equivalent
these recommendations!!!
25 26
Comments Comments
• Comments in VHDL are indicated with • Explain Function of Module to Other
a “double dash”, i.e., “--” Designers
Comment indicator can be placed anywhere in the
line • Explanatory, Not Just Restatement of Code
Any text that follows in the same line is treated as • Locate Close to Code Described
a comment
Carriage return terminates a comment • Put near executable code, not just in a header
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
27 28
a a b z
Design Entity b
z
0 0 1
0 1 1
1 0 1
1 1 0
5
Example VHDL Code Design Entity
• 3 sections to a piece of VHDL code
• File extension for a VHDL file is .vhd design entity
• Name of the file should be the same as the entity name
(nand_gate.vhd) [OpenCores Coding Guidelines]
entity declaration Design Entity - most basic
LIBRARY ieee;
USE ieee.std_logic_1164.all; LIBRARY DECLARATION
building block of a design.
ENTITY nand_gate IS
PORT(
architecture 1
a : IN STD_LOGIC; One entity can have many
ENTITY DECLARATION
b : IN STD_LOGIC; different architectures.
z : OUT STD_LOGIC);
END nand_gate;
architecture 2
31 32
ENTITY nand_gate IS
port_name : port_mode signal_type;
PORT( ………….
a : IN STD_LOGIC;
No Semicolon
b : IN STD_LOGIC;
after last port
port_name : port_mode signal_type);
z : OUT STD_LOGIC
); END entity_name;
END nand_gate;
33 34
Entity
Port signal Entity
Port signal
a
z
35 36
6
Port Mode OUT (with extra signal) Port Mode BUFFER
Entity
Port signal
Entity
Port signal
z
x z
c
Port signal Z can be
Signal x can be read inside the entity
c
read inside the entity
Driver resides
c <= z
inside the entity
Driver resides z <= x Not recommended by OpenCores Coding Guidelines.
inside the entity
c <= x Port of mode buffer can not be connected to other types of ports
so buffer mode will propagate throughout the entire hierarchical design.
Problems reported with synthesis of designs using these ports.
37 38
• 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.
a
• 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.
Signal can be
read inside the entity • 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.
Driver may reside • Buffer: Used for a signal that is an output from an entity. The value of the
both inside and outside signal can be used inside the entity, which means that in an assignment
of the entity statement the signal can appear on the left and right sides of the <=
operator. Not recommended to be used in the synthesizable code.
39 40
41 42
7
Tips & Hints
Entity Declaration & Architecture
nand_gate.vhd
LIBRARY ieee;
USE ieee.std_logic_1164.all; Place each entity in a different file.
ENTITY nand_gate IS
PORT( The name of each file should be exactly the same
a : IN STD_LOGIC;
b : IN STD_LOGIC; as the name of an entity it contains.
z : OUT STD_LOGIC);
END nand_gate;
43 44
LIBRARY ieee;
USE ieee.std_logic_1164.all;
Library declaration
ENTITY nand_gate IS
PORT(
a : IN STD_LOGIC; LIBRARY library_name;
b : IN STD_LOGIC;
z : OUT STD_LOGIC);
Use all definitions from the package USE library_name.package_name.package_parts;
END nand_gate; std_logic_1164
47 48
8
Fundamental parts of a library Libraries
• work
Holds current designs after compilation
49 50
STD_LOGIC
LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY nand_gate IS
PORT(
STD_LOGIC Demystified
a : IN STD_LOGIC;
b : IN STD_LOGIC;
z : OUT STD_LOGIC);
END nand_gate;
• BIT type can only have a value of ‘0’ or ‘1’ Value Meaning
‘U’ Uninitialized
• STD_LOGIC can have nine values
‘X’ Forcing (Strong driven) Unknown
• ’U’,’X’,‘0’,’1’,’Z’,’W’,’L’,’H’,’-’
‘0’ Forcing (Strong driven) 0
• Useful mainly for simulation ‘1’ Forcing (Strong driven) 1
• ‘0’,’1’, and ‘Z’ are synthesizable (your codes ‘Z’ High Impedance
should contain only these three values) ‘W’ Weak (Weakly driven) Unknown
53 54
9
More on STD_LOGIC Meanings (1) More on STD_LOGIC Meanings (2)
‘1’
‘X’
Contention on the bus
X
‘0’
55 56
57 58
59 60
10
Signals
SIGNAL a : STD_LOGIC;
a
1
wire
Modeling Wires and Buses
SIGNAL b : STD_LOGIC_VECTOR(7 DOWNTO 0);
b
8 bus
63 64
A>>1
A<<<1
65 66
11
VHDL Design Styles
VHDL Design
Styles
• Testbenches
behavioral
dataflow structural
VHDL Design Styles (sequential)
Concurrent Components and Sequential statements
statements interconnects • Registers
• State machines
• Decoders
ENTITY xor3_gate IS
PORT(
A : IN STD_LOGIC;
B : IN STD_LOGIC;
C : IN STD_LOGIC;
Result : OUT STD_LOGIC
);
end xor3_gate;
69 70
71 72
12
Structural Architecture in VHDL 87 xor2
ARCHITECTURE structural OF xor3_gate IS xor2.vhd
SIGNAL U1_OUT: STD_LOGIC;
A
COMPONENT xor2 LIBRARY ieee;
B xor3_gate Result USE ieee.std_logic_1164.all;
PORT(
I1 : IN STD_LOGIC; C
I2 : IN STD_LOGIC; ENTITY xor2 IS
Y : OUT STD_LOGIC PORT(
); I1
U1_OUT I1 : IN STD_LOGIC;
END COMPONENT; Y I1 I2 : IN STD_LOGIC;
I2 Y
I2 Y : OUT STD_LOGIC);
BEGIN END xor2;
U1: xor2 PORT MAP (I1 => A,
I2 => B, ARCHITECTURE dataflow OF xor2 IS
Y => U1_OUT); BEGIN
PORT NAME Y <= I1 xor I2;
U2: xor2 PORT MAP (I1 => U1_OUT, END dataflow;
I2 => C,
LOCAL WIRE NAME
Y => Result);
END structural;
73 74
75 76
77 78
13
?
79
14