Buoi 2-Introduction To HDL
Buoi 2-Introduction To HDL
Introduction to Hardware
Description Languages
Contents
❑ Design methodology
❑ VHDL fundamental
– Design entity
– Libraries
– Std_Logic demystify
– Modeling Wires & Buses
– Testbenhes
1
RS232 port to
computer
Supply
voltages
CRYPTO_RUNNING_O
SPI_SS_CRYPTO_N
FLL_FREQ_OUT_0
VDD_NOCPERF1
Test FSM & configs
VDD_CRYPTO
VDD_CFG_1
Crypto. kernel
VDDE2
GNDE2
GND3
CLK_I
GND4
VDD4
VDD3
SPI
VDD1 GND7
GND1 VDD7
VDD_CFG4 SPI_MOSI_I
SPI_SCLK_I
VDD_FLL
SPI_SS_ASN_N_I
FLL GNDE1
VDD2
VDD0
RESETN_I
SPI_MISO_O
GND
GND2 GND8
VDD6
SNACk
VDDE1
GND0
VDD_NOCPERF2
VDD_NOCPERF3 VDD_CFG2
VDD9 GND5
GND9 VDD5
GNDBGCON
VDD_ASN
GNDE1
VDD8
VDD_NOCPERF3
VDD
GND
VDD
VDD_CFG3
GND6
Jumper to
measure
FLL output
the current
Ref. clock
Reset, SPI
slave selects
9/10/2022 Xuan-Tu Tran 3
Design Methodology
2
Models
3
Entity/Module Ports
above_30_0
>30°C temp_bad_0
or_0a
inv_0 or_0b
above_25_0
>25°C
wake_up_0
below_25_0
low_level_0
low level select_mux
0 buzzer
1
buzzer
above_30_1
>30°C temp_bad_1
or_1a
inv_1 or_1b wake_up_1 +V
above_25_1
>25°C
select_vat_1
below_25_1
low_level_1
low level
4
Structure design implementation
entity vat_buzzer is
port ( buzzer : out std_logic;
above_25_0, above_30_0, low_level_0 : in std_logic;
above_25_1, above_30_1, low_level_1 : in std_logic;
select_vat_1 : in std_logic );
end entity vat_buzzer;
architecture behavior of vat_buzzer is
begin
buzzer <= low_level_1 or (above_30_1 or not above_25_1)
when select_vat_1 = '1' else
low_level_0 or (above_30_0 or not above_25_0);
end architecture behavior;
5
Design Methodology
Requirements
and
Constraints
Physical
Design Synthesize Manufacture
Implementation
Y Y Y
OK? OK? OK?
N N N
6
Hierarchical Design
❑Circuits are too complex for us to design all the detail at once
❑Top-down/bottom-up design
Hierarchical Design
Architecture
Design
Unit
Design
Design
Unit
Verification
Functional
Verification
N
OK?
Y
Y
OK?
Integration
N
Verification
N
OK?
Y
9/10/2022 Xuan-Tu Tran 14
7
Synthesis
Physical Implementation
❑ Implementation fabrics
– Application-specific ICs (ASICs)
– Field-programmable gate arrays (FPGAs)
8
Codesign Methodology
Requirements
and
Constraints
Partitioning
Hardware Software
Requirements Requirements
and Constraints and Constraints
Hardware Software
Design and Design and
Verification Verification
N N
OK? OK?
Manufacture
and Test
9/10/2022
Xuan-Tu Tran 17
Summary
❑ Real-world constraints
– logic levels, loads, timing, area, etc
❑ Design methodology
9
Brief History of VHDL
VHDL
– VHDL is an acronym for VHSIC (Very High Speed Integrated Circuit) Hardware Description Language
10
Genesis of VHDL
11
Four versions of VHDL
❑ VHDL-87
❑ VHDL-93
❑ VHDL-01
❑ VHDL-08
Verilog/SystemVerilog
12
Verilog/SystemVerilog
13
Language Zoos
14
Semantic programming: C
Verilog
15
VHDL
SystemVerilog: Enhancements
SystemVerilog
4 state logic 3.1
Basic has (for, if, while,..)
programming
Packed structs
advanced verification and
Hardware concurrency Gate level modelling
and unions
Coverage &
design entity modularization C interface
modeling features and timing Assertion
API
Switch level modeling and timing ASIC timing
16
Examples
❑ VHDL Example:
process (clk, rstn)
begin
if (rstn = '0') then
q <= '0';
elseif (clk'event and clk = '1') then
q <= a + b;
end if;
end process;
❑ Verilog Example:
always@(posedge clk or negedge rstn)
begin
if (! rstn)
q <= 1'b0;
else
q <= a + b;
end
❑ Technology/vendor independent
❑ Portable
❑ Reusable
17
Other hardware description languages
18
VHDL for Specification
Algorithmic level
Level of description
Register Transfer Level
most suitable for synthesis
Logic (gate) level
19
Register Transfer Logic (RTL) Design Description
Combinational
Logic
Combinational
Logic
…
Registers
VHDL Fundamentals
20
Naming and Labeling (1)
21
Free Format
Example:
if (a=b) then
or
if (a=b) then
or
if (a =
b) then
are all equivalent
Comments
22
Comments
Design Entity
23
Design Entity
design entity
architecture 1
One entity can have
architecture 2 many different architectures.
architecture 3
Entity Declaration
• Entity Declaration describes the interface of the component, i.e. input and
output ports.
ENTITY nand_gate IS
PORT(
a : IN STD_LOGIC;
b : IN STD_LOGIC;
No Semicolon
z : OUT STD_LOGIC
);
END nand_gate;
24
Entity declaration – simplified syntax
ENTITY entity_name IS
PORT (
port_name : signal_mode signal_type;
port_name : signal_mode signal_type;
………….
port_name : signal_mode signal_type);
END entity_name;
Architecture
25
Architecture – simplified syntax
nand_gate.vhd
LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY nand_gate IS
PORT(
a : IN STD_LOGIC;
b : IN STD_LOGIC;
z : OUT STD_LOGIC);
END nand_gate;
26
Mode In
Driver resides
outside the entity
Mode out
Entity
Port signal
Driver resides
inside the entity c <= z
27
Mode out with signal
Entity
Port signal
x z
c Signal X can be
read inside the entity
Mode inout
Signal can be
read inside the entity
28
Mode buffer
Entity
Port signal
c
Port signal Z can be
read inside the entity
Driver resides
c <= z
inside the entity
Port Modes
The Port Mode of the interface describes the direction in which data travels with respect to the component
❑ In: Data comes in 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.
❑ Buffer: Used for a signal that is an output from an entity. The value of the signal can be used inside the
entity, which means that in an assignment statement the signal can appear on the left and right sides of
the <= operator
29
Libraries
Library declarations
Library declaration
ENTITY nand_gate IS
PORT(
a : IN STD_LOGIC;
b : IN STD_LOGIC;
z : OUT STD_LOGIC);
END nand_gate;
30
Library declarations - syntax
LIBRARY library_name;
USE library_name.package_name.package_parts;
LIBRARY
PACKAGE 1 PACKAGE 2
TYPES TYPES
CONSTANTS CONSTANTS
FUNCTIONS FUNCTIONS
PROCEDURES PROCEDURES
COMPONENTS COMPONENTS
31
Libraries
• ieee
STD_LOGIC Demystified
32
STD_LOGIC
LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY nand_gate IS
PORT(
a : IN STD_LOGIC;
b : IN STD_LOGIC;
z : OUT STD_LOGIC);
END nand_gate;
Value Meaning
‘X’ Forcing (Strong driven) Unknown
33
More on STD_LOGIC Meanings (1)
‘1’
‘X’
Contention on the bus
X
‘0’
34
More on STD_LOGIC Meanings (3)
VDD
VDD
‘H’
‘1’
‘0’
‘L’
35
Resolving logic levels
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
36
Signals
SIGNAL a : STD_LOGIC;
a
1 wire
b
8 bus
SIGNAL a: STD_LOGIC;
SIGNAL b: STD_LOGIC_VECTOR(3 DOWNTO 0);
SIGNAL c: STD_LOGIC_VECTOR(3 DOWNTO 0);
SIGNAL d: STD_LOGIC_VECTOR(7 DOWNTO 0);
SIGNAL e: STD_LOGIC_VECTOR(15 DOWNTO 0);
SIGNAL f: STD_LOGIC_VECTOR(8 DOWNTO 0);
……….
a <= ‘1’;
b <= ”0000”; -- Binary base assumed by default
c <= B”0000”; -- Binary base explicitly specified
d <= ”0110_0111”; -- You can use ‘_’ to increase readability
e <= X”AF67”; -- Hexadecimal base
f <= O”723”; -- Octal base
9/10/2022 Xuan-Tu Tran 74
37
Vectors and Concatenation
a <= ”0000”;
b <= ”1111”;
c <= a & b; -- c = ”00001111”
e <= ‘0’ & ‘0’ & ‘0’ & ‘0’ & ‘1’ & ‘1’ &
‘1’ & ‘1’;
-- e <= ”00001111”
38
VHDL Design Styles
VHDL Design
Styles
xor3 Example
39
Entity xor3
ENTITY xor3 IS
PORT(
A : IN STD_LOGIC;
B : IN STD_LOGIC;
C : IN STD_LOGIC;
Result : OUT STD_LOGIC
);
end xor3;
U1_out
40
Dataflow Description
XOR3
9/10/2022 Xuan-Tu Tran
82
41
Component and Instantiation (1)
COMPONENT xor2 IS
PORT(
I1 : IN STD_LOGIC;
I2 : IN STD_LOGIC;
Y : OUT STD_LOGIC
);
END COMPONENT;
COMPONENT xor2 IS
PORT(
I1 : IN STD_LOGIC;
I2 : IN STD_LOGIC;
Y : OUT STD_LOGIC
);
END COMPONENT;
42
Structural Description
43
Behavioral Description
Testbenches
44
Testbench Block Diagram
Testbench
Processes
Design Under
Generating Test (DUT)
Stimuli
Observed Outputs
Testbench Defined
❑ Testbench applies stimuli (drives the inputs) to the Design Under Test (DUT) and (optionally) verifies
expected outputs.
❑ Since Testbench is written in VHDL, it is not restricted to a single simulation tool (portability).
❑ The same Testbench can be easily adapted to test different implementations (i.e. different
architectures) of the same design.
45
Testbench Anatomy
ENTITY tb IS
--TB entity has no ports
END tb;
ARCHITECTURE arch_tb OF tb IS
LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY xor3_tb IS
END xor3_tb;
-- Stimulus signals - signals mapped to the input and inout ports of tested entity
SIGNAL test_vector: STD_LOGIC_VECTOR(2 DOWNTO 0);
SIGNAL test_result : STD_LOGIC;
46
Testbench for XOR3 (2)
What is a PROCESS?
47
Execution of statements in a PROCESS
Testing: PROCESS
BEGIN
test_vector<=“00”;
• The execution of statements continues WAIT FOR 10 ns;
sequentially till the last statement in the test_vector<=“01”;
Order of execution
process. WAIT FOR 10 ns;
test_vector<=“10”;
• After execution of the last statement,
WAIT FOR 10 ns;
the control is again passed to the
test_vector<=“11”;
beginning of the process.
WAIT FOR 10 ns;
END PROCESS;
statement is executed.
WAIT FOR 10 ns;
• This form of WAIT can be used in a test_vector<=“10”;
process included in a testbench when WAIT FOR 10 ns;
test_vector<=“11”;
all possible combinations of inputs
WAIT;
have been tested or a non-periodical
END PROCESS;
signal has to be generated.
48
WAIT FOR vs. WAIT
0 1 2 3 0 1 2 3 …
Loop Statement
• Loop Statement
49
Loop Statement – Example (1)
Testing: PROCESS
BEGIN
test_vector<="000";
FOR i IN 0 TO 7 LOOP
WAIT FOR 10 ns;
test_vector<=test_vector+”001";
END LOOP;
END PROCESS;
Testing: PROCESS
BEGIN
test_ab<="00";
test_sel<="00";
FOR i IN 0 TO 3 LOOP
FOR j IN 0 TO 3 LOOP
WAIT FOR 10 ns;
test_ab<=test_ab+"01";
END LOOP;
test_sel<=test_sel+"01";
END LOOP;
END PROCESS;
50