Professional Documents
Culture Documents
inputs
Combinational
Logic
+
present
state
outputs
+
next
state
n
Q
Registers
CLK
Lecture 5
A level-to-pulse converter produces a singlecycle pulse each time its input goes high.
Moore FSM:
inputs
x0...xn
Comb.
Logic
Lecture 5
Comb.
Logic
Registers
CLK
Sample uses:
outputs
yk = fk(S)
present state S
Mealy FSM:
direct combinational path!
inputs
x0...xn
Comb.
Logic
S+
n
Comb.
Logic
Registers
CLK
outputs
yk = fk(S, x0...xn)
L
Whenever input L goes
from low to high...
Level to
P
Pulse
Converter
CLK
...output P produces a
single pulse, one clock
period wide.
S
6.111 Fall 2009
Lecture 5
Lecture 5
D Q
L=1
Edge Detector
D Q
Level to
Pulse
FSM
00
L=0
CLK
L=0
L=1
L=1
00
01
Low input,
Waiting for rise
P=0
Edge Detected!
L=0
P=1
L=1
L=0
Lecture 5
L=1
L=1
For N states, use ceil(log2N) bits to encode the state with each
state represented by a unique combination of the bits.
Tradeoffs: most efficient use of state registers, but requires
more complicated combinational logic to detect when in a
particular state.
L=0
00
P=0
Edge Detected!
L=0
L=1
11
01
Low input,
Waiting for rise
P=1
High input,
Waiting for fall
P=0
L=0
Current
State
In
S1 S0
0 0
0 0
0 1
0 1
1 1
1 1
L
0
1
0
1
0
1
Next
State
S1
0
0
0
1
0
1
S0
0
1
0
1
0
1
Out
+
P
0
0
1
1
0
0
S1S0 for S1 :
00 01 11 10
+
For N states, use N bits to encode the state where the bit
corresponding to the current state is 1, all the others 0.
Tradeoffs: more state registers, but often much less
combinational logic since state decoding is trivial.
L=0
L=1
P=0
P=0
Lecture 5
P=1
11
11
L=0
High input,
Waiting for fall
Edge Detected!
High input,
Waiting for fall
11
01
Low input,
Waiting for rise
P=0
L=1
Lecture 5
0 0 0 0 X
1 0 1 1 X
for S0+:
S 1S 0
00 01 11 10
L
0 0 0 0 X
1 1 1 1 X
7
Comb.
Logic
S1+ = LS0
S 0+ = L
S+
n
Comb.
Logic
Registers
CLK
Lecture 5
P = S 1S 0
P
S0
S1
for P:
0 1
0 0 X
1 1 0
inputs
Comb.
Logic
x0...xn
outputs
yk = fk(S)
Comb.
Logic
Registers
n
CLK
Comb.
Logic
Since outputs are determined by state and inputs, Mealy FSMs may
need fewer states than Moore FSM implementations
P = S 1S 0
CLK
S0
CLK
S 1+
Q
Q
Comb.
Logic
Registers
present state S
S1+ = LS0
S 0+ = L
S+
n
L=0 | P=0
L
P
L=1 | P=1
Input is low
Clock
Stat
e
Input is high
L=0 | P=0
S1
L=1 | P=0
Lecture 5
Lecture 5
Input is low
Pres.
State
Input is high
L=0 | P=0
L=0 | P=0
L=1 | P=0
Moore/Mealy Trade-Offs
In
Next
State
Out
S+
S+
CLK
Q
Q
Lecture 5
10
Clock
Clock
State
[0]
State
Lecture 5
12
FSM Example
GOAL:
Build an electronic combination lock with a reset
button, two number buttons (0 and 1), and an unlock
output. The combination should be 01011.
RESET
0
1
STEPS:
1. Design lock FSM (block diagram, state transitions)
2. Write Verilog module(s) for FSM
Lecture 5
13
Button
Enter
Button
0
Button
1
fsm_clock
b0_in button
b1_in
unlock
reset
RESET
Unlock = 0
Unlock
LED
1
0
Unlock = 0
01
Unlock = 0
0
1
b0
state
button
14
RESET
fsm
reset button
Lecture 5
lock
Clock
generator
UNLOCK
LED
DISPLAY
01011
Unlock = 1
0101
Unlock = 0
010
Unlock = 0
b1
0
6 states ! 3 bits
Lecture 5
15
Lecture 5
16
module button(
input clk,in,
output out
);
reg r1,r2,r3;
always @(posedge
begin
r1 <= in;
//
r2 <= r1;
//
r3 <= r2;
//
end
button
push button synchronizer and level-to-pulse converter
OUT goes high for one cycle of CLK whenever IN makes a
low-to-high transition.
in
D Q
r1
D Q
r2
D Q
r3
clk
clk)
synchronizer
state
17
out
0
Unlock = 0
18
0
0
Lecture 5
01
Unlock = 0
0
0
0
1
Unlock = 1
reg [2:0] state, next_state;
always @(*) begin
// implement state transition diagram
if (reset) next_state = S_RESET;
else case (state)
S_RESET: next_state = b0 ? S_0
: (b1 ? S_RESET
S_0:
next_state = b0 ? S_0
: (b1 ? S_01
S_01:
next_state = b0 ? S_010 : (b1 ? S_RESET
S_010:
next_state = b0 ? S_0
: (b1 ? S_0101
S_0101: next_state = b0 ? S_010 : (b1 ? S_01011
S_01011: next_state = b0 ? S_0
: (b1 ? S_RESET
default: next_state = S_RESET; // handle unused
endcase
end
0101
Unlock = 0
010
Unlock = 0
: state);
: state);
: state);
: state);
: state);
: state);
states
// hmmm.
Current state?
Lecture 5
19
Lecture 5
20
Lecture 5
D Q
21
CLK1
Lecture 5
CLK2
CLK1
22