Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
ECE 545
Lecture 12
Design of Controllers
Datapath
vs.
Controller
Datapath
(Execution
Unit)
Controller
(Control
Unit)
Status
Signals
Data Outputs
Pseudocode
Interface
Datapath
Block
diagram
VHDL code
Controller
Block
diagram
VHDL code
State diagram
or ASM chart
VHDL code
Text description
Interface
Pseudocode
Block diagram of the Datapath
Interface with the division into the Datapath
and the Controller
ASM chart of the Controller
RTL VHDL code of the Datapath, the Controller, and the
Top Unit
Testbench of the Datapath, the Controller, and the Top
Unit
Functional simulation and debugging
Synthesis and post-synthesis simulation
Implementation and timing simulation
Experimental testing
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
Text description
Interface
Pseudocode
Block diagram of the Datapath
Interface with the division into the Datapath
and the Controller
ASM chart of the Controller
RTL VHDL code of the Datapath, the Controller, and
the Top Unit
Testbench of the Datapath, the Controller, and the
Top Unit
Functional simulation and debugging
Synthesis and post-synthesis simulation
Implementation and timing simulation
Experimental testing
Manual Optimization/Minimization Is
Practical for Small FSMs Only
ECE 448 FPGA and ASIC Design with VHDL
13
14
Moore FSM
Mealy FSM
Inputs
Next State
clock
reset
Inputs
Next State
function
Next State
Present State
clock
reset
Present State
register
Output
function
Next State
function
Present State
Present State
register
Outputs
Output
function
Outputs
15
16
Moore Machine
transition
condition 1
state 1 /
output 1
State Diagrams
17
transition
condition 2
state 2 /
output 2
18
Mealy Machine
transition condition 1 /
output 1
state 2
state 1
transition condition 2 /
output 2
19
20
1
S0 / 0
reset
Meaning
of states:
S0: No
elements
of the
sequence
observed
0
S1 / 0
0
S1: 1
observed
S2 / 1
S2: 10
observed
21
22
1/0
S0
reset
Meaning
of states:
1/0
clock
input
S1
Moore
0/1
S0: No
elements
of the
sequence
observed
S1: 1
observed
Mealy
23
S0
S1
S2
S0
S0
S0
S1
S0
S0
S0
24
FSMs in VHDL
Finite State Machines Can Be Easily
Described With Processes
Synthesis Tools Understand FSM
Description if Certain Rules Are Followed
Moore FSM
Mealy FSM
process(clock, reset)
Inputs
26
process(clock, reset)
Inputs
Next State
function
Next State
Next State
clock
reset
Present State
Register
Present State
Output
function
Outputs
concurrent
statements
Next State
function
clock
reset
concurrent
statements
Output
function
27
S0 / 0
reset
0
S1 / 0
28
Outputs
Present State
Present State
Register
S2 / 1
29
30
WHEN S1 =>
IF input = 0 THEN
Moore_state <= S2;
ELSE
Moore_state <= S1;
END IF;
WHEN S2 =>
IF input = 0 THEN
Moore_state <= S0;
ELSE
Moore_state <= S1;
END IF;
END CASE;
END IF;
END PROCESS;
1/0
S0
reset
1/0
S1
0/1
31
32
33
34
35
36
State Box
State box represents a state.
Equivalent to a node in a state diagram or
a row in a state table.
Contains register transfer actions or
output signals
Moore-type outputs are listed inside of
the box.
It is customary to write only the name of
the signal that has to be asserted in the
given state, e.g., z instead of z<=1.
Also, it might be useful to write an action
to be taken, e.g., count <= count + 1, and
only later translate it to asserting a control
signal that causes a given action to take
place (e.g., enable signal of a counter).
State name
Output signals
or actions
(Moore type)
0 (False)
Condition
expression
1 (True)
Conditional outputs
or actions (Mealy type)
State name
Output signals
or actions
(Moore type)
37
Decision Box
Decision box
indicates that a
given condition is to
be tested and the
exit path is to be
chosen accordingly.
The condition
expression may
include one or more
inputs to the FSM.
38
0 (False)
Condition
expression
Conditional
output box
Denotes output
signals that are of
the Mealy type.
The condition that
determines
whether such
outputs are
generated is
specified in the
decision box.
1 (True)
Conditional outputs
or actions (Mealy type)
39
40
Reset
w = 1
w = 0
Az = 0
Bz = 0
w = 0
w = 1
w = 0
Cz = 1
w = 1
41
42
Next state
Present
state
w= 0
w= 1
Output
z
A
B
C
A
A
A
B
C
C
0
0
1
43
USE ieee.std_logic_1164.all ;
ENTITY simple IS
PORT ( clock
resetn
w
z
END simple ;
44
: IN STD_LOGIC ;
: IN STD_LOGIC ;
: IN STD_LOGIC ;
: OUT STD_LOGIC ) ;
46
END IF ;
END PROCESS ;
z <= '1' WHEN y = C ELSE '0' ;
Reset
w = 1z = 0
END Behavior ;
w = 0z = 0
w = 1z = 1
w = 0z = 0
47
48
LIBRARY ieee ;
USE ieee.std_logic_1164.all ;
ENTITY Mealy IS
PORT ( clock : IN
resetn : IN
w
: IN
z
: OUT
END Mealy ;
STD_LOGIC ;
STD_LOGIC ;
STD_LOGIC ;
STD_LOGIC ) ;
50
CASE y IS
WHEN A =>
IF w = '0' THEN
y <= A ;
ELSE
y <= B ;
END IF ;
WHEN B =>
IF w = '0' THEN
y <= A ;
ELSE
y <= B ;
END IF ;
END CASE ;
51
52
Reset
reset
Idle
0xx
r2
gnt1 g 1 = 1
g1
r1
Arbiter
x0x
g2
1xx
01x
gnt2 g 2 = 1
g3
r3
1xx
xx0
x1x
001
gnt3 g 3 = 1
clock
xx1
53
54
55
LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY arbiter IS
PORT ( Clock, Resetn
r
g
END arbiter ;
: IN
: IN
: OUT
56
STD_LOGIC ;
STD_LOGIC_VECTOR(1 TO 3) ;
STD_LOGIC_VECTOR(1 TO 3) ) ;
57
58
1. Overview on FSM
END IF ;
END PROCESS ;
g(1) <= '1' WHEN y = gnt1 ELSE '0' ;
g(2) <= '1' WHEN y = gnt2 ELSE '0' ;
g(3) <= '1' WHEN y = gnt3 ELSE '0' ;
END Behavior ;
59
Chapter 10
60
10
E.g.
a memory
controller
2. Representation of FSM
State diagram
Chapter 10
61
Chapter 10
62
Chapter 10
64
Chapter 10
66
Chapter 10
63
E.g. 2.
E.g. 1.
Chapter 10
65
11
E.g. 3.
E.g. 4.
Chapter 10
67
E.g. 6.
Chapter 10
68
Basic rules:
For a given input combination, there is one
unique exit path from the current ASM block
The exit path of an ASM block must always
lead to a state box. The state box can be the
state box of the current ASM block or a state
box of another ASM block.
RTL Hardware Design
by P. Chu
Chapter 10
69
Chapter 10
70
71
Chapter 10
72
Chapter 10
12
Moore machine:
output is a function of state
Mealy machine:
output function of state and output
Chapter 10
73
Chapter 10
74
Chapter 10
75
Chapter 10
76
Three designs:
Comparison
Mealy machine uses fewer states
Mealy machine responds faster
Mealy machine may be transparent to glitches
Chapter 10
77
Chapter 10
78
13
E.g. 6.
Chapter 10
79
Chapter 10
80
Chapter 10
81
Chapter 10
82
Chapter 10
83
Chapter 10
84
14
Chapter 10
85
Chapter 10
86
Chapter 10
87
Chapter 10
88
sorting
example
N"
DataIn
DataOut"
L"
RAdd
WrInit
Sort"
Done
S"
(0=initialization"
1=computations)
Rd
15
Sorting - Example
0
1
2
3
Legend:
Pseudocode
FOR k = 4
FOR any k 2
3
2
4
1
During Sorting
i=0
j=1
i=0
j=2
i=0
j=3
i=1
j=2
i=1
j=3
i=2
j=3
3
2
4
1
2
3
4
1
2
3
4
1
1
3
4
2
1
3
4
2
1
2
4
3
position of memory
indexed by i
Mi
position of memory
indexed by j
After
sorting
1
2
3
4
Mj
Pseudocode
wait for s=1
for i=0 to k-2 do
A = Mi
for j=i+1 to k-1 do
B = Mj
if A > B then
Mi = B
Mj = A
A = Mi
end if
end for
end for
Done
wait for s=0
go to the beginning
16
DataIn
ABMux
RAdd
ADDR
RST
Resetn
EB
Bout
LD
EN
CLK
RST
RST
N
Rd
= k-2
= k-1
zi
zj
A>B
AgtB
Clock Resetn
Resetn
Resetn
Rd
Datapath
EN
CLK
Lj
Ej
Clock
Mij
Clock
Clock
1
0
1
EN
CLK
Resetn
+1
Addr
CLK
DOUT
EA
RST
Csel
WE
Clock
Clock
DIN
We
Wr
LD
EN
CLK
Li
Ei
Din
WrInit
DataOut
AgtB
zi
zj
Wr
Li
Ei
Lj
Ej
EA
EB
Bout
Csel
Controller
DataOut
Done
17