LAST VERSION OF VHDL Language AeroAUTO 20232024
LAST VERSION OF VHDL Language AeroAUTO 20232024
Concurrent structures
02
Sequential structures
03
Testbenches
04
Introduction
• Classical digital design flow
Introduction
• Classical digital design flow
Introduction
Modern digital design flow
Introduction
Modern digital design flow
Introduction
Integrated Circuits
▪ An integrated circuit (IC) is a collection of a set of electronic components (transistors, resistors,capacitors, diodes, etc.)
integrated in one small flat piece (called chip) of semiconductor material such as silicon.
Integrated Circuits
Microcontroller
74HC… Microprocessor PLD,CPLD, FPGA… ASIC
Introduction
FPGA : Field Programmable Grid Array
• Hardware integration of additional components
• RAM: called LUT (Look-Up Table)
• Mutiplexers
• PLL
• DSP
Introduction
Specifications
FPGA
• Cyclone II EP2C35F672C6 FPGA and
EPCS16 serial configuration device
I/O Devices
• Built-in USB Blaster for FPGA configuration
• 10/100 Ethernet, RS-232, Infrared port
• Video Out (VGA 10-bit DAC)
• Video In (NTSC/PAL/Multi-format)
• USB 2.0 (type A and type B)
• PS/2 mouse or keyboard port
• Line-in, Line-out, microphone-in
(24-bit audio CODEC)
• Expansion headers (76 signal pins)
Memory
• 8-MB SDRAM, 512-KB SRAM, 4-MB Flash
• SD memory card slot
Switches, LEDs, Displays, and Clocks
• 18 toggle switches
• 4 debounced pushbutton switches
• 18 red LEDs, 9 green LEDs
• Eight 7-segment displays
• 16 x 2 LCD display
• 27-MHz and 50-MHz oscillators, external SMA clock input
VHDL basics
The Anatomy of a VHDL File
Package
(IEEE standard package is inherent. additional
packages are optional)
Entity
(description of inputs/outputs of the system)
Architecture
(description of the behavior of the system)
VHDL basics
Entity declaration
Describes the name, the parameters and the interface
(input/output signals) of the component
Ports types
Entity name
Ports names
Semicolon
ENTITY and2_op IS
PORT(
Without semicolon
a, b: IN STD_LOGIC;
z : OUT STD_LOGIC
);
END and2_op;
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY and2_op IS
PORT(
a, b: IN STD_LOGIC;
z : OUT STD_LOGIC);
END and2_op;
• IN: input port – data coming to this port can be read inside the component, the name of the port can be
situated only on the right side of the assignment expression
VHDL basics
Port mode OUT
Entity
Int_sig B
Int_sig B
B <= Int_sig;
The signal is generated
C <= B;
inside the entity
Problem: the output signal in the mode BUFFER cannot be connected to a port in the mode
OUT in the higher hierarchical level
VHDL basics
Port mode BUFFER (cont)
Superior entity
Entity
Signal of the port Signal of the port
in mode BUFFER in mode OUT
B D
C
D <= B;
'X'
VDD
VDD
'1' 'H'
'W' 'Z'
(not connected)
'0' 'L'
VHDL basics
Meaning of the STD_LOGIC levels
‘-’
• Any level
• Can be assigned to the output if the corresponding signal does not
depend on input signals (synthesis results can be significantly
improved, logic area can be reduced)
VHDL basics
Signals and constants
Signal – simple wire interconnection
Two signal types
• std_logic
• std_logic_vector
Internal signals declaration examples:
SIGNAL dff, reset : std_logic;
SIGNAL internal_bus : std_logic_vector(3 DOWNTO 0);
SIGNAL zero, carry_out : std_logic;
– example:
Intended function:
Example : A * B + C < D or E > F
Results -- Evaluation order:
-- 1. A * B (Multiplication)
-- 2. C (Addition with Result of 1)
-- 3. (Result of 2) < D (Relational)
-- 4. E (Relational with F)
-- 5. (Result of 3) or (Result of 4)
VHDL basics
VHDL design models
U1
a U2
b result
c
ENTITY xor3 IS
PORT(
a : IN STD_LOGIC;
b : IN STD_LOGIC;
c : IN STD_LOGIC;
result : OUT STD_LOGIC
);
END xor3;
VHDL basics
Dataflow architecture
U1
a u1_out U2
b result
c
u1: xor2 PORT MAP (i1 => a, u1: xor2 PORT MAP (a, b, u1_out);
Component instantiation
i2 => b,
(in the architecture body)
y => u1_out);
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
Simulation verification
(comparison with expected
values specified in a file)
VHDL basics
Testbench – example
LIBRARY ieee;
USE ieee.std_logic_1164.ALL; Testbench does not
ENTITY tb_xor3 IS have ports!
END tb_xor3;
ARCHITECTURE structure OF tb_xor3 IS
COMPONENT xor3
PORT(
a: IN std_logic;
b: IN std_logic;
c: IN std_logic; DUT declaration
d: OUT std_logic
);
END COMPONENT;
SIGNAL x1, x2, x3 : std_logic; Declaration of
SIGNAL y : std_logic; internal signals
BEGIN
u_xor3: xor3
port map (
a => x1, DUT instantiation
b => x2,
c => x3,
d => y
); see next page … 1
VHDL basics
Testbench – example (cont.)
stimuli: PROCESS Stimuli generation
BEGIN
x1 <= '0';
x2 <= '0';
x3 <= '0';
WAIT FOR 10 ns;
x1 <= '1';
x2 <= '0';
x3 <= '0';
WAIT FOR 10 ns;
x1 <= '0';
x2 <= '1';
x3 <= '0';
WAIT FOR 10 ns;
x1 <= '1';
x2 <= '1';
x3 <= '0';
WAIT FOR 10 ns;
x1 <= '0';
x2 <= '0';
x3 <= '1';
WAIT FOR 10 ns;
value2
value1
conditionN-1
condition2
condition1
q = (sel1 AND a)
OR ((NOT sel1) AND sel2 AND b)
OR ((NOT sel1) AND (NOT sel2) AND c)
Concurrent structures
Concurrent instructions (cont.)
Selective assignment
WITH selector SELECT
target_signal <= value1 WHEN selector_value,
value2 WHEN selector_ value,
...
valueN WHEN OTHERS;
value1
target_signal
value2
value3 MUX
value4
selector
Concurrent structures
Concurrent instructions (cont.)
LIBRARY ieee;
USE ieee.std_logic_1164.ALL; If we change a,b,c and d by a: IN
ENTITY multiplexer IS std_logic vector(3 DOWNTO 0);
PORT (a, b, c, d : IN std_logic;
sel : IN std_logic_vector(1 DOWNTO 0);
y : OUT std_logic);
END multiplexer;
ARCHITECTURE rtl OF multiplexer IS a(0) WHEN "00",
BEGIN a(1) WHEN "01",
-- selective assignment a(2) WHEN "10",
WITH sel SELECT a(3) WHEN OTHERS;
y <= a WHEN "00",
b WHEN "01", Selection without priority!
c WHEN "10",
d WHEN OTHERS;
END rtl; Address of vector
par_in(1) par_out
par_in(2)
par_in(3)
par_in(4)
par_in(5)
par_in(6)
par_in(7)
Concurrent structures
Concurrent instructions (cont.)
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY parity IS
PORT (par_in : IN std_logic_vector(7 DOWNTO 0);
y : OUT std_logic);
END parity;
ARCHITECTURE rtl OF parity IS
SIGNAL par_int : std_logic_vector(7 DOWNTO 0);
BEGIN We can use the signal par_int(7)
par_int(0) <= par_in(0); before a value is assigned to it
y <= par_int(7);
Calc_parity: (concurrent structure)
FOR i IN 1 TO 7 GENERATE
par_int(i) <= par_in(i) XOR par_int(i-1);
END GENERATE Calc_parity;
END rtl;
variable := expression (with variables); • Any variable that is created in one process cannot be
used in another process
• Conditional structure
• Variables need to be defined after the
IFcondition THEN keyword process but before the keyword begin
{sequential instruction(s)} • Variables that are assigned immediately take the value
[ELSIF condition THEN of the assignment
{sequential instruction(s)}]
Optional
[ELSE parts
{sequential instruction(s)}]
...
END IF;
sequential structures
Basic sequential structures (cont.)
• Selective structure ‘‘WHEN value’’ can take up three forms:
CASE selector IS WHEN value -- single value
WHEN value1 to value2 -- range, for enumerated data types -- only
WHEN selector_value1 =>
WHEN value1 | value2 |... -- value1 or value2 or ...
{sequential instruction(s)}
WHEN selector_value2 =>
{sequential instruction(s)} ✓ keyword NULL (the counterpart of UNAFFECTED), can
be used when no action is to take place. Example:
WHEN selector_value3 =>
WHEN OTHERS => NULL;
{sequential instruction(s)}
...
❑ Example:
[WHEN OTHERS =>
{sequential instruction(s)}]
CASE control IS
WHEN "00" => x<=a; y<=b;
END CASE; WHEN "01" | “10" => x<=b; y<=c;
Optional, but WHEN OTHERS => NULL;
recommended part END CASE;
sequential structures
Basic sequential structures (cont.)
sequential structures
Basic sequential structures (cont.)
• Loop FOR ❑ Example of Loop FOR:
[label :] FOR loop_variable IN interval LOOP lbl : FOR i IN 0 TO 5 LOOP
{sequential instruction(s)} var := var + 5 ;
END LOOP [label] ; END LOOP lbl ;
Optional
BEGIN
{sequential instruction(s)}
END PROCESS [label ];
Optional
sequential structures
Two PROCESS interpretations
• Compiler infers a combinatorial structure
– Sensitive to all signals used in the
combinatorial logic a
Example
c
b
PROCESS(a, b, sel)
clr
sensitivity list does not contain input D,
only clock and asynchronous control signals
sequential structures
Implementation of several PROCESSes
An architecture can contain several PROCESSes
They are executed in parallel, because they are situated in the
concurrent part of the architecture
Inside the PROCESS, the instructions are executed
sequentially, the PROCESS is a sequential structure
Reduction of the number of processes increases readability
Architecture
Process 1
Concurrent . Order is not
Signals . important
structures .
Process 2
sequential structures
Two structures that give the same result after the synthesis, but not in the functional simulation
LIBRARY ieee; LIBRARY ieee;
USE ieee.std_logic_1164.ALL; USE ieee.std_logic_1164.all;
ENTITY simp IS ENTITY simp_prc IS
PORT(a, b : IN std_logic; PORT(a,b : IN std_logic;
x : OUT std_logic); x : OUT std_logic);
END simp; END simp_prc;
ARCHITECTURE exam OF simp IS ARCHITECTURE exam OF simp_prc IS
SIGNAL c : std_logic; SIGNAL c : STD_LOGIC;
BEGIN BEGIN
c <= a AND b; A PROCESS(a, b)
B
x <= c; BEGIN
END exam; simulation before and c <= a and b;
after the synthesis of A x <= c;
END PROCESS;
a END exam; functional
b
c simulation of B
x
a
b
post-synthesis simulation of B c
x
sequential structures
Basic sequential structures (cont.)
Conclusions :
Ena 0 1 -Q -nQ
D 1 0 0 1
1 1 1 0
Q
D Q
Truth table
clk _
Q
clk D Q+ nQ+
0 x -Q -nQ
Sensitivity on the rising edge
1 x -Q -nQ
clk x -Q -nQ
0 0 1
D
1 1 0
Q
Basic sequential blocks
Synchronous D flip-flop (cont.) ---- Solution 2: OK -------------------
2 LIBRARY ieee;
---- Solution 1: doesn’t Work-------- 3 USE ieee.std_logic_1164.all;
2 LIBRARY ieee; 4 ---------------------------------------
3 USE ieee.std_logic_1164.all; 5 ENTITY dff IS
4 --------------------------------------- 6 PORT ( d, clk: IN STD_LOGIC;
5 ENTITY dff IS 7 q: BUFFER STD_LOGIC;
6 PORT ( d, clk: IN STD_LOGIC; 8 qbar: OUT STD_LOGIC);
7 q: BUFFER STD_LOGIC; LINE 19
9 END dff;
8 qbar: OUT STD_LOGIC); I’m describing a 10 ---------------------------------------
9 END dff; 11 ARCHITECTURE ok OF dff IS
10 ---------------------------------------
logic operation =>
write it outside of 12 BEGIN
11 ARCHITECTURE not_ok OF dff IS 13 PROCESS (clk)
12 BEGIN PROCESS!!!
14 BEGIN
13 PROCESS (clk) 15 IF (clk'EVENT AND clk='1') THEN
14 BEGIN 16 q <= d;
15 IF (clk'EVENT AND clk='1') THEN 17 END IF;
16 q <= d; LINE 17
18 END PROCESS;
17 qbar <= NOT q; q will be updated at the end of 19 qbar <= NOT q;
18 END IF; 20 END ok;
the process execution
19 END PROCESS; 21 ---------------------------------------
20 END not_ok; 70
Basic sequential blocks
Synchronous D flip-flop (cont.) ---- Solution 3: OK NOT RECOMENDED---------
2 LIBRARY ieee;
3 USE ieee.std_logic_1164.all;
4 ---------------------------------------
5 ENTITY dff IS
6 PORT ( d, clk: IN STD_LOGIC;
7 q: OUT STD_LOGIC;
8 qbar: OUT STD_LOGIC);
9 END dff;
10 ---------------------------------------
11 ARCHITECTURE ok OF dff IS
12 BEGIN
13 PROCESS (clk)
14 BEGIN
15 IF (clk'EVENT AND clk='1') THEN
16 q <= d;
17 qbar <= NOT d;
18 END IF;
19 END PROCESS;
20 END ok;
21 ---------------------------------------
Basic sequential blocks
Testbench of Synchronous D flip-flop (cont.) process
begin
library ieee; T_clk <= '0';
use ieee.std_logic_1164.all; wait for clk_period/2;
entity Dflipflop_test is T_clk <= '1';
end Dflipflop_test; wait for clk_period/2;
------------------------------------------ end process;
architecture testbench of Dflipflop_test is process
begin
component dff --case1
port (d, clk: IN STD_LOGIC; T_d <= '0';
q: BUFFER STD_LOGIC; wait for clk_period*2;
qbar: OUT STD_LOGIC); --case2
end component; T_d <= '1';
wait for clk_period*1.5;
signal T_d: std_logic; --case3
signal T_clk: std_logic; T_d <= '0';
signal T_q: std_logic; wait for clk_period*0.5;
signal T_qbar : std_logic; --case4
T_d <= '1';
constant clk_period : time := 50 ns; wait for clk_period*2;
begin end process;
uut: dff port map (T_d,T_clk,T_q,T_qbar); end testbench;
Basic sequential blocks
JK synchronous flip-flop – behaviour similar to that of the RS
flip-flop (J input works as S and K input as R), except for the
case when J and K were equal to one, in this case the output
is inverted
J Q
Truth table
clk _ clk J K Q+ nQ+ Next state
Q -Q
K 0 x x -nQ Previous state
0 1 0 1 Reset
1 1 -nQ -Q Inversion
Basic sequential blocks
Synchronous JK flip-flop - behavioral description
LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY jk_ff IS
PORT ( j, k, clk : IN std_logic;
q : OUT std_logic
);
END jk_ff;
ARCHITECTURE behavior OF jk_ff IS
SIGNAL sel : std_logic_vector(1 DOWNTO 0);
SIGNAL q_int : std_logic;
BEGIN
sel <= j & k;
PROCESS (clk)
BEGIN
IF rising_edge(clk) THEN set
CASE sel IS
WHEN "10" => q_int <= '1'; reset
WHEN "01" => q_int <= '0';
WHEN "11" => q_int <= NOT q_int; inversion
WHEN OTHERS => q_int <= q_int;
END CASE; storing
END IF;
END PROCESS;
q <= q_int;
END behavior;
Basic sequential blocks
Up/down counter using a signal
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE ieee.std_logic_unsigned.ALL; updn q
USE ieee.numeric_std.ALL;
ENTITY count_a IS clk
PORT (clk, rst, updn : IN std_logic;
q : OUT std_logic_vector(15 DOWNTO 0)); rst
END count_a; CMPT
ARCHITECTURE logic OF count_a IS
SIGNAL int_q : std_logic_vector(15 DOWNTO 0);
BEGIN
PROCESS(rst, clk) Internal signal declaration
BEGIN (an output signal cannot be
IF rst = '0' THEN
int_q <= (OTHERS => '0'); referenced in the right-side
ELSIF rising_edge(clk) THEN expression)
IF updn = '1' THEN
int_q <= int_q + 1;
ELSE
int_q <= int_q - 1; The signal value is stored until the
END IF; next rising edge of the clock signal
END IF;
END PROCESS;
q <= int_q;
END logic; Output signal assignment
Basic sequential blocks
Up/down counter using a variable
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE ieee.std_logic_unsigned.ALL; updn q
USE ieee.numeric_std.ALL;
ENTITY count_a IS clk
PORT (clk, rst, updn : IN std_logic;
q : OUT std_logic_vector(7 DOWNTO 0));
END count_a; rst
CMPT
ARCHITECTURE logic OF count_a IS
BEGIN
PROCESS(rst, clk)
VARIABLE tmp_q : std_logic_vector(7 DOWNTO 0);
BEGIN
IF rst = '0' THEN
q <= (OTHERS => '0'); Arithmetic expressions
ELSIF rising_edge(clk) THEN assigned to a variable
IF updn = '1' THEN
tmp_q := tmp_q + 1;
ELSE
tmp_q := tmp_q - 1;
END IF;
q <= tmp_q; Output signal assignment
END IF;
END PROCESS;
END logic;
Basic sequential blocks
Concurrent and sequential structures - summary
Concurrent Sequential
structures structures
Unconditional assignment Unconditional assignment
… <= … … <= …
Conditional assignment Conditional structure
… <= … WHEN … ELSE … IF … THEN … ELSE … END IF
Selective assignment Selective structure
WITH … SELECT CASE … IS
… <= … WHEN … WHEN … => …
END CASE
Structures GENERATE Structures LOOP
FOR … GENERATE … FOR … LOOP …
END GENERATE END LOOP
Finite State machine structure
Two types of finite state machines (FSM) : Mealy and moore