VHDL
VHDL
University of Torino
A.Y. 2019/2020, Spring 2020
Introduction to digital systems
design using VHDL
References
− https://www.fpga4fun.com
− https://www.nandland.com/vhdl/tutorials/index.html
− http://www.asic-world.com/vhdl/index.html
Digital systems
analog signals :
− continuous in both time and amplitude
− usually a voltage v(t) or a current i(t) as a function of time
− reach of information (e.g. frequency spectrum, FFT)
digital signals :
− usually continuous in time but discrete in amplitude
− only two possible values e.g. high/low voltage levels, true/false, on/off,
closed/open etc.
− less information, but more robust against noise
− can be either asynchronous signals or synchronous signals
Classification of digital circuits
− sequential circuits
− asynchronous
− synchronous
Hardware Description Languages (HDL)
Verilog and VHDL are the two most widespread HDLs in the world for this job :
− approx. 50% market each one
− Verilog more popular in US and Japan, VHDL in Europe
− Verilog more used (and integrated with professional CAD tools) to design
Application-Specific Integrated Circuits (ASIC) design
− traditionally VHDL more used for FPGA programming instead
− both equally and well supported by Xilinx Vivado flows
− Verilog is easier to learn, but also potentially more error-prone due to its
relaxed data typing
− if you will do my job at the end you will learn both, or at least you will be able
to read both codes
− if you start alone (but I’m here ...) from scratch... learn VHDL first, then move
to Verilog once really annoyed with VHDL ”verbose” coding
VHDL fundamentals
History
entity BlockName is
port (
...
... ) ;
Input ports :
clk : in std_logic ,
rst : in std_logic , ...
Output ports :
-- initial declarations
...
begin
In order to simulate the functionality of the digital block we also need a testbench that
generates stimuli fed to input ports of our Device Under Test (DUT):
entity tb_BlockName is
end entity ;
The module under test is always instantiated inside the testbench module, which
contains non-synthesizable code.
Boolean algebra
Logic constants
"0010" "1010"
Unresolved logic values
...
...
Source code :
<install dir>/data/vhdl/src/ieee/distributable/std_logic_1164.vhd
Extended logic values /2
1 logic one
0 logic zero
Z high-impedance
U uninitialized (sim. only)
X unknown (driven)
- don’t care
H weak high
L weak low
W weak signal
Buses and endianess
”little endian”
"000" -- 0
"001" -- 1
"010" -- 2
"011" -- 3
"100" -- 4
"101" -- 5
"110" -- 6
"111" -- 7
N
X −1
x = b0 × 20 + b1 × 21 + b2 × 22 + ... + bN −1 2N −1 = bi 2i
i=0
Gray code
"000" -- 0
"001" -- 1
"011" -- 2
"010" -- 3
"110" -- 4
"111" -- 5
"101" -- 6
"100" -- 7
Thermometer code
"0000000" -- 0
"0000001" -- 1
"0000011" -- 2
"0000111" -- 3
"0001111" -- 4
"0011111" -- 5
"0111111" -- 6
"1111111" -- 7
One-hot code
"0000000" -- 0
"0000001" -- 1
"0000010" -- 2
"0000100" -- 3
"0001000" -- 4
"0010000" -- 5
"0100000" -- 6
"1000000" -- 7
Z=X
VHDL syntax :
Z <= not X ;
AND gate
Z =A·B
VHDL syntax :
Z <= A and B ;
OR gate
Z =A+B
VHDL syntax :
Z <= A or B ;
NAND gate
Z =A·B
VHDL syntax :
Z <= A nand B ;
NOR gate
Z =A+B
VHDL syntax :
Z <= A nor B ;
De Morgan’s theorem /1
A·B =A+B
De Morgan’s theorem /2
A+B =A·B
XOR gate
Z = A ⊕ B = (A · B) + (A · B)
VHDL syntax :
Z <= A xor B ;
XNOR gate
Z = A ⊕ B = (A · B) + ( A · B )
VHDL syntax :
Z <= A xnor B ;
Propagation delays
VHDL syntax :
Z <= X (0) and X (1) and X (2) and ... and X (N -1) ;
Z <= X (0) nand X (1) nand X (2) nand ... nand X (N -1) ;
WRONG !
Z <= not ( X (0) and X (1) and X (2) and ... and X (N -1)) ;
When/Else conditional signal assignment