Professional Documents
Culture Documents
Xuan-Tu Tran
Email: tutx@vnu.edu.vn
Contents
1
Register Transfer Level (RTL) Design Description
Today’s Topic
Combinational
Logic
Combinational …
Logic
Registers
Describing
Combinational Logic
Using
Dataflow Design Style
2
VHDL Design Styles
VHDL Design
Styles
Data-flow VHDL
Major instructions
Concurrent statements
• concurrent signal assignment ()
• conditional concurrent signal assignment
(when-else)
• selected concurrent signal assignment
(with-select-when)
• generate scheme for equations
(for-generate)
3
Data-flow VHDL
Major instructions
Concurrent statements
• concurrent signal assignment ()
• conditional concurrent signal assignment
(when-else)
• selected concurrent signal assignment
(with-select-when)
• generate scheme for equations
(for-generate)
xi yi
ci 00 01 11 10
0 1 1
ci xi yi si xi yi
c
i
ci
+ 1
xi yi 1 00 011 11 10
1
Data-flow VHDL:0 Example
0 0
c
0 0
c i x y 00 01 11 10 0 1 1
0 0 1 i 0i 1 i si
i si = xi yi ci
c
+ 1
0 1 0 0 1 1 1 1
0 1 1 0 10 0 0 0 0 1 0 1
ci xi yi si 0x i y i0 1 xi yi
i 1 0 0 0 1 0 1
si = xi yi ci
c
+ 1
0 1 000 0 1 10 ci
1 0 1 c i 0 11 1 1
1001 1 11 0
1 00 01 11 10
0 0 0 0 0 1 1 0 1 0 xi yi
10 0 0 1 0 1 1 0 ci
1
0 0 ci 1x i 0 1 1 1 1 1 10 1 1 1 00 01 11 10
yi c
i + 1
si si = x i 0 y i ci
0 1 0 0 1 1 1 0 1 0 1 1 1 11
1 1 1 0
1 1 1 1 1
0 10 10 0 1 0 0 0
xi yi
(a) Truth table 1 1 1 1
1 00 00 1
0 0
1 1
i i s = x y ci
i
ci + 1 = xi yi + xici + yici
0 10 0 1 c i (a) Truth
00 table01 11 10
1 00 11 1
1 1
0 0 ci + 1 = xi yi + xici + yici
xi yi
1 11 00 0 1 0 0 1 0 00 1 (b) Karnaugh maps
ci 01 11 10
1 11 10 1 1 1 1 0 (b) Karnaugh maps
1 1 0 1 0 xi
Truth table 0 1 xi 11 1 1
1 1 1 1 1
yi si
(a) Truth table 1 yi 1 1 1 si
ci
ci + 1 = xi yi + xici + yici
(a) Truth table c
c i + 1 = x ii y i + x i c i + y i c i
ci ci
September 11, 2022 Xuan-Tu Tran 8
(c) Circuit
(c) Circuit
ci + 1
ci + 1
(c) Circuit
4
Data-flow VHDL: Example (1)
LIBRARY ieee ;
USE ieee.std_logic_1164.all ;
ENTITY fulladd IS
PORT ( x : IN STD_LOGIC ;
y : IN STD_LOGIC ;
cin : IN STD_LOGIC ;
s : OUT STD_LOGIC ;
cout : OUT STD_LOGIC );
END fulladd ;
5
Logic Operators
• Logic operators
and or nand nor xor not xnor
Highest
not
and or nand nor xor xnor
Lowest
No Implied Precedence
Wanted: y = ab + cd
Incorrect
y <= a and b or c and d ;
equivalent to
y <= ((a and b) or c) and d ;
equivalent to
y = (ab + c)d
Correct
y <= (a and b) or (c and d) ;
6
Concatenation
a <= ”0000”;
b <= ”1111”;
c <= a & b; -- c = ”00001111”
e <= ‘0’ & ‘0’ & ‘0’ & ‘0’ & ‘1’ & ‘1’ &
‘1’ & ‘1’; -- e <= ”00001111”
f <= (‘0’,‘0’,‘0’,‘0’,‘1’,‘1’,‘1’,‘1’) ;
-- f <= ”00001111”
September 11, 2022 Xuan-Tu Tran 13
Rotations in VHDL
a<<<1
7
Arithmetic Operators in VHDL (1)
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_unsigned.all;
or
USE ieee.std_logic_signed.all;
8
Mixing Signed and Unsigned arithmetic
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.numeric_std.all;
signal A : UNSIGNED(3 downto 0);
signal B : UNSIGNED(3 downto 0);
signal C : UNSIGNED(3 downto 0);
signal D : SIGNED(3 downto 0);
……
C <= A + B;
D <= SIGNED(A) + SIGNED(B);
Data-flow VHDL
Major instructions
Concurrent statements
• concurrent signal assignment ()
• conditional concurrent signal assignment
(when-else)
• selected concurrent signal assignment
(with-select-when)
• generate scheme for equations
(for-generate)
9
Conditional concurrent signal assignment
When - Else
target_signal <= value1 when condition1 else
value2 when condition2 else
. . .
valueN-1 when conditionN-1 else
valueN;
0
Value N
.… … 0
1
Value N-1 0
1 Target Signal
1
Value 2
Value 1
Condition N-1
Condition 2
Condition 1
September 11, 2022 Xuan-Tu Tran 19
Operators
• Relational operators
= /= < <= > >=
Highest not
= /= < <= > >=
Lowest and or nand nor xor xnor
10
Priority of logic and relational operators
compare a = bc
Incorrect
… when a = b and c else …
equivalent to
… when (a = b) and c else …
Correct
… when a = (b and c) else …
LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY tri_state IS
PORT ( ena: IN STD_LOGIC;
input: IN STD_LOGIC_VECTOR(7 downto 0);
output: OUT STD_LOGIC_VECTOR (7 DOWNTO 0)
);
END tri_state;
11
Tri-state Buffer – example (2)
Data-flow VHDL
Major instructions
Concurrent statements
• concurrent signal assignment ()
• conditional concurrent signal assignment
(when-else)
• selected concurrent signal assignment
(with-select-when)
• generate scheme for equations
(for-generate)
12
Selected concurrent signal assignment
With –Select-When
with choice_expression select
target_signal <= expression1 when choices_1,
expression2 when choices_2,
. . .
expressionN when choices_N;
expression1 choices_1
expression2 choices_2
target_signal
expressionN choices_N
choice expression
September 11, 2022 Xuan-Tu Tran 25
WHEN value
13
Allowed formats of choice_k - example
14
MLU: Block Diagram
MUX_0
A1
A
IN 0
MUX_1
NEG_A IN 1
Y1
MUX_2
IN 2
IN 3 O U T PU T Y
S E L1
S E L0
B1 NEG_Y
B MUX_4_1
MUX_3
NEG_B
L1 L0
LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY mlu IS
PORT(
NEG_A : IN STD_LOGIC;
NEG_B : IN STD_LOGIC;
NEG_Y : IN STD_LOGIC;
A: IN STD_LOGIC;
B: IN STD_LOGIC;
L1 : IN STD_LOGIC;
L0 : IN STD_LOGIC;
Y: OUT STD_LOGIC
);
END mlu;
15
MLU: Architecture Declarative Section
SIGNAL A1 : STD_LOGIC;
SIGNAL B1 : STD_LOGIC;
SIGNAL Y1 : STD_LOGIC;
SIGNAL MUX_0 : STD_LOGIC;
SIGNAL MUX_1 : STD_LOGIC;
SIGNAL MUX_2 : STD_LOGIC;
SIGNAL MUX_3 : STD_LOGIC;
SIGNAL L: STD_LOGIC_VECTOR(1 DOWNTO 0);
BEGIN
A1<= NOT A WHEN (NEG_A='1') ELSE
A;
B1<= NOT B WHEN (NEG_B='1') ELSE
B;
Y <= NOT Y1 WHEN (NEG_Y='1') ELSE
Y1;
END mlu_dataflow;
16
Exercise
17