Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
• Mealy FSM:
direct combinational path! Level to
outputs
yk = fk(S, x0...xn) L Pulse P
inputs S+ Comb. Converter
x0...xn Comb. D Q
Logic ...output P produces a
n Registers Whenever input L goes
Logic single pulse, one clock
from low to high...
CLK
n CLK period wide.
00 11
unsynchronized Level to
L=0 01
D Q D Q L P Low input, High input,
user input Pulse
Waiting for rise
Edge Detected!
Waiting for fall
L=1
FSM
P=0 P=1 P=0
CLK L=0
L=0
• State transition diagram is a useful FSM representation and
design aid:
• Arcs leaving a state are mutually exclusive, i.e., for any
“if L=1 at the clock edge,
then jump to state 01.”
L=1 L=1 Binary values of states combination input values there’s at most one applicable arc
• Arcs leaving a state are collectively exhaustive, i.e., for any
00 11
11
L=0 01 combination of input values there’s at least one applicable arc
Low input, High input,
Waiting for rise
Edge Detected!
Waiting for fall
L=1
P=0 P=1 P=0 • So for each state: for any combination of input values there’s
L=0
L=0 exactly one applicable arc
“if L=0 at the clock This is the output that results
edge, then stay in state from this state. (Moore or
Mealy?)
• Often a starting state is specified
00.”
• Each state specifies values for all outputs (Moore)
6.111 Fall 2012 Lecture 5 5 6.111 Fall 2012 Lecture 5 6
L 00 01 11 10
For N states, use N bits to encode the state where the bit 0 0 0 0 X
L S+
corresponding to the current state is 1, all the others 0. 1 0 1 1 X Comb. D Q Comb.
P
for P:
n Registers S1
Tradeoffs: more state registers, but often much less S1S0 for S0+: Logic
CLK
Logic
S0 0 1
combinational logic since state decoding is trivial. L 00 01 11 10 n
0 0 X
0 0 0 0 X S
S1+ = LS0 P = S1S0 1 1 0
1 1 1 1 X S0+ = L
• FSM’s state simply remembers the previous value of L • Compared to a Moore FSM, a Mealy FSM might...
• Circuit benefits from the Mealy FSM’s implicit single-cycle – Be more difficult to conceptualize and design
assertion of outputs during state transitions – Have fewer states
lock RESET
1
1 0
Clock
fsm_clock fsm
generator
RESET 0 “0” 1 “01”
Unlock = 0 Unlock = 0 Unlock = 0
unlock Unlock
reset button LED
Button
reset
Enter 0
1 0
Button b0_in button 0
b0 LED
0 1 1
DISPLAY “01011” “0101” “010”
state Unlock = 1 Unlock = 0 Unlock = 0
Button b1_in
button b1
1 0
6 states 3 bits
6.111 Fall 2012 Lecture 5 15 6.111 Fall 2012 Lecture 5 16
Step 2: Write Verilog Step 2A: Synchronize buttons
module lock(input clk,reset_in,b0_in,b1_in, // button
output out); // push button synchronizer and level-to-pulse converter
// OUT goes high for one cycle of CLK whenever IN makes a
// synchronize push buttons, convert to pulses // low-to-high transition.
out
// implement state transition diagram module button(
r1 r2 r3
reg [2:0] state,next_state; input clk,in, in D Q D Q D Q
always @(*) begin output out
// combinational logic! );
clk
next_state = ???; reg r1,r2,r3;
end always @(posedge clk) synchronizer state
always @(posedge clk) state <= next_state; begin
r1 <= in; // first reg in synchronizer
// generate output r2 <= r1; // second reg in synchronizer, output is in sync!
assign out = ???; r3 <= r2; // remembers previous state of button
end
// debugging?
endmodule // rising edge = old value is 0, new value is 1
assign out = ~r3 & r2;
endmodule
6.111 Fall 2012 Lecture 5 17 6.111 Fall 2012 Lecture 5 18
CLK1 CLK1
6.111 Fall 2012 Lecture 5 21 6.111 Fall 2012 Lecture 5 22