ECE545_lecture_5_dataflow_6
ECE545_lecture_5_dataflow_6
Lecture 5
• P. Chu, RTL Hardware Design using VHDL
VHDL Descriptions
Dataflow VHDL VHDL code
• Testbenches Description synthesizable
behavioral
dataflow structural
(sequential)
Concurrent Components and Sequential statements Dataflow VHDL VHDL code
statements interconnects • Registers
• State machines
Description synthesizable
• Instruction decoders
Combinational
Logic
Combinational … • conditional concurrent signal assignment
Logic
(when-else)
5 6
1
Simple concurrent signal assignment Conditional concurrent signal assignment
7 8
9 10
Signals
SIGNAL a : STD_LOGIC;
a
1 wire
Wires and Buses
SIGNAL b : STD_LOGIC_VECTOR(7 DOWNTO 0);
b
8 bus
2
Merging wires and buses Merging wires and buses
a a
4 4
10 10
b 5 b 5
d = a || b || c d = a || b || c
c c
13 14
c=d c = d0
SIGNAL a: STD_LOGIC_VECTOR(3 DOWNTO 0); SIGNAL a: STD_LOGIC_VECTOR(3 DOWNTO 0);
SIGNAL b: STD_LOGIC_VECTOR(4 DOWNTO 0); SIGNAL b: STD_LOGIC_VECTOR(4 DOWNTO 0);
SIGNAL c: STD_LOGIC; SIGNAL c: STD_LOGIC;
SIGNAL d: STD_LOGIC_VECTOR(9 DOWNTO 0); SIGNAL d: STD_LOGIC_VECTOR(9 DOWNTO 0);
15 16
x LIBRARY ieee ;
y USE ieee.std_logic_1164.all ;
s
cin
ENTITY fulladd IS
PORT ( x : IN STD_LOGIC ;
y : IN STD_LOGIC ;
cout cin : IN STD_LOGIC ;
s : OUT STD_LOGIC ;
cout : OUT STD_LOGIC ) ;
END fulladd ;
17 18
3
Data-flow VHDL: Example (2) Logic Operators
ARCHITECTURE dataflow OF fulladd IS • Logic operators
BEGIN
s <= x XOR y XOR cin ; and or nand nor xor not xnor
cout <= (x AND y) OR (cin AND x) OR (cin AND y) ;
END dataflow ;
equivalent to • Logic operators precedence in VHDL-93
and later
Highest
ARCHITECTURE dataflow OF fulladd IS not
BEGIN and or nand nor xor xnor
cout <= (x AND y) OR (cin AND x) OR (cin AND y) ; Lowest
s <= x XOR y XOR cin ;
END dataflow ;
19 20
No Implied Precedence
arith_result <= a + b + c – 1;
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) ;
RTL Hardware Design Chapter 4 22
21
4
Conditional concurrent signal assignment Most often implied structure
When - Else
target_signal <= value1 when condition1 else
When - Else value2 when condition2 else
. . .
target_signal <= value1 when condition1 else
valueN-1 when conditionN-1 else
value2 when condition2 else
valueN;
. . .
valueN-1 when conditionN-1 else
F
valueN; Value N
.… … F
T
Value N-1 T F
Target Signal
T
Value 2
Value 1
Condition N-1
Condition 2
Condition 1
25 26
5
• E.g., Signed and Unsigned Types
33 34
35 36
6
Most Often Implied Structure Allowed formats of choices_k
With –Select-When
with choice_expression select
target_signal <= expression1 when choices_1,
WHEN value
expression2 when choices_2,
. . .
expressionN when choices_N; WHEN value_1 | value_2 | .... | value N
expression1 choices_1
expression2 choices_2
WHEN OTHERS
target_signal
expressionN choices_N
choice expression
37 38
7
E.g., 2-to-22 binary decoder
• Can 11 be used to replace others?
Conceptual implementation
– select_expression is with a data type of 5
• Achieved by a values: c0, c1, c2, c3, c4
multiplexing circuit
• Abstract (k+1)-to-1
multiplexer
– sel is with a data type
of (k+1) values:
c0, c1, c2, . . . , ck
8
• E.g.,
9
– May over-specify for a functional table
based circuit.
• Conditional signal assignment:
– E.g., mux
– good match for a circuit that needs to give
preferential treatment for certain conditions or
to prioritize the operations
– E.g., priority encoder
– Can handle complicated conditions. e.g.,
57 58
10
• Fix #1:
Use ‘-’ in VHDL 2
2 1
• As input value (against our intuition): 2 0
• Wrong:
• Fix #2:
• Wrong:
• ‘-’ as an output value in VHDL
• May work with some software
• Fix:
• Major application:
Use and synthesis of ‘Z’ – Bi-directional I/O pins
• Tri-state buffer: – Tri-state bus
– Output with “high-impedance” • VHDL description:
– Not a value in Boolean algebra y <= 'Z' when oe='1' else
– Need special output circuitry (tri-state buffer) a_in;
• ‘Z’ cannot be used as input or manipulated
f <= 'Z' and a;
y <= data_a when in_bus='Z' else
data_b;
11
• Separate tri-state buffer from regular code:
– Less clear:
Bi-directional i/o pins
with sel select
y <= 'Z' when "00",
'1' when "01"|"11",
'0' when others;
– better:
with sel select
tmp <= '1' when "01"|"11",
'0' when others;
y <= 'Z' when sel="00" else
tmp;
RTL Hardware Design Chapter 6 67 RTL Hardware Design Chapter 6 68
Tri-state bus
12
• Problem with tri-state bus
– Difficult to optimize, verify and test
– Somewhat difficult to design: “parking”,
“fighting”
• Alternative to tri-state bus: mux
13