Professional Documents
Culture Documents
Lecture09 PDF
Lecture09 PDF
Lecture09 PDF
Lecture 9: 1
Announcements
• Prelab 3(B) due tomorrow
Lecture 9: 2
Example: Procedural Assignments
reg Y, Z; reg Y, Z;
always @ (posedge clk) always @ (posedge clk)
begin begin
Y = ~Z; = Y <= ~Z;
Z = A & B; Z <= A & B;
end end
Blocking assignments Nonblocking assignments
A A
B B
Z Y Z Y
Lecture 9: 3
FSM Design Procedure
(1) Understand the problem statement and
determine inputs and outputs
This
(4) Implement combinational logic for outputs lecture
and next state
• Input In
• Output Out
• Reset causes FSM to start in initial state
• Clock input not shown (always present)
Lecture 9: 5
State Diagrams
Reset
In = 1 In = 1 In = 1
In = 0 In = 0 In = 1
In = 0
In = 1 In = 1
Reset Out = 0 Out = 0
Lecture 9: 7
Moore Transition/Output Table 1
Reset
In = 1 In = 1 In = 1
In = 0 In = 0 In = 1
In = 0
In = 0 In = 0 In = 1
In = 0
S 1* S 0* Out
S1 S0 In = 0 In = 1
00 00 01 0
01 00 10 0
10 00 11 0
11 00 11 1
• Version 2: uses state binary encodings
Lecture 9: 9
Minimized Equations for S* and Out
S 1* S 0* Out
S1 S0 In = 0 In = 1
00 00 01 0
01 00 10 0
10 00 11 0
11 00 11 1
Lecture 9: 10
Mealy Transition/Output Table 1
In = 1 In = 1
Reset Out = 0 Out = 0
<reg declarations>
endmodule
Lecture 9: 14
Moore FSM in Verilog
Reset
In = 1 In = 1 In = 1
In = 0 In = 0 In = 1
In = 0
reg Out;
reg [1:0] Scurr, Snext;
In = 0 In = 0 In = 1
In = 0
always @ (In, Scurr)
begin
case (Scurr)
Init: if (In == 1) Snext = Got1; else Snext = Init;
Got1: if (In == 1) Snext = Got11; else Snext = Init; next state
Got11: if (In == 1) Snext = Got111; else Snext = Init; comb logic
Got111: if (In == 1) Snext = Got111; else Snext = Init;
default: Snext = Init;
endcase
end
Lecture 9: 16
Moore FSM in Verilog
Reset
In = 1 In = 1 In = 1
In = 0 In = 0 In = 1
In = 0
always @ (Scurr)
if (Scurr == Got111) Out = 1; else Out = 0; output comb logic
endmodule
Lecture 9: 17
Mealy FSM in Verilog
In = 1 In = 1
Reset Out = 0 Out = 0
reg Out;
reg [1:0] Scurr, Snext;
Lecture 9: 18
Mealy FSM in Verilog
In = 1 In = 1
Reset Out = 0 Out = 0
Lecture 9: 19
Mealy FSM in Verilog
In = 1 In = 1
Reset Out = 0 Out = 0
endmodule
Lecture 9: 20
Example FSM: Pushbutton Lock
• Two pushbutton inputs, X1 and X2
• One output, UL (“Unlock”)
Lecture 9: 21
Pushbutton Lock: Moore State Diagram
• Output: UL=1 with sequence X1, X2, X2
• Input: 00 (neither), 10 (X1), 01 (X2), 11 (reset)
01
X1 X1-X2 00
00 UL = 0 UL = 0
[01] [10]
11
10 11 10 01
10
00
01 Init X1-X2-X2 00
11 UL = 0 UL = 1 01
[00] 11 [11] 10
Lecture 9: 22
Moore Transition/Output Table 1
Current Next State (S*) UL
State (S)
Input Input Input Input
00 01 10 11
(neither) (X2) (X1) (reset)
Init Init Init X1 Init 0
Lecture 9: 23
Moore Transition/Output Table 2
S1* S0* UL
S1 S0
Input Input Input Input
00 01 10 11
00 00 00 01 00 0
01 01 10 00 00 0
10 10 11 00 00 0
11 11 11 11 00 1
X1 01/
00/ UL=0 X1-X2 00/
UL=0 UL=0
[01] [10]
11
10/
10/ 11 UL=0 01/
UL=0 10/ UL=0
UL=0
00 00
01 Init X1-X2-X2 01
11/ 11/ 10/
UL=0 [00] UL=0 [11] UL=1
Lecture 9: 25
Mealy Transition/Output Table
S1* S0* , UL
S1 S0
Input Input Input Input
00 01 10 11
00 0 0, 0 0 0, 0 0 1, 0 0 0, 0
01 0 1, 0 1 0, 0 0 0, 0 0 0, 0
10 1 0, 0 1 1, 0 0 0, 0 0 0, 0
11 1 1, 1 1 1, 1 1 1, 1 0 0, 0
State0 State1
D Q
Q=0 Q=1
[0] [1]
CLK
D=0 D=1 D=1
Moore state diagram
• Input: D
• Output: Q
• Clock is implicit in
the state diagram
Lecture 9: 27
Analyzing the FSM
S 0*
S 1*
S1* =
Out =
S0*
S1*
Lecture 9: 29
Exercise: State Diagram
In = 0
In = 1
1. Complete the [00] [01] In = 0
transition/output
Out = 0 Out = 0
table and state
diagram
In = 1
2. Identify the [11] [10]
functionality of the
Out = 1 Out = 0
FSM (Hint: Pattern
detector?) S1* S0*
Out
S1 S0 In = 0 In = 1
S0* = In’ 00 01 00 0
S1* = In’•S1•S0’+In•S0 01 01 10 0
Out = S1•S0 10 0
11 1
Lecture 9: 30
Next Time
• H&H 2.9, 4.6, 4.9
More FSMs
Timing, Clocking
Lecture 9: 31