fsm examples - wikimedia · 2015. 11. 6. · fsm examples 8 young won lim 11/6/15 moore fsm (1) d q...
TRANSCRIPT
![Page 1: FSM Examples - Wikimedia · 2015. 11. 6. · FSM Examples 8 Young Won Lim 11/6/15 Moore FSM (1) D Q D Q S' 1 S' 0 S 1 S 0 T A T B L A1 L A0 L B1 L B0 S 1 S 0 clk Current State Next](https://reader033.vdocuments.net/reader033/viewer/2022053123/60ac821a0c9c6a739407c7f1/html5/thumbnails/1.jpg)
Young Won Lim11/6/15
FSM Examples
![Page 2: FSM Examples - Wikimedia · 2015. 11. 6. · FSM Examples 8 Young Won Lim 11/6/15 Moore FSM (1) D Q D Q S' 1 S' 0 S 1 S 0 T A T B L A1 L A0 L B1 L B0 S 1 S 0 clk Current State Next](https://reader033.vdocuments.net/reader033/viewer/2022053123/60ac821a0c9c6a739407c7f1/html5/thumbnails/2.jpg)
Young Won Lim11/6/15
Copyright (c) 2011 – 2015 Young W. Lim.
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".
Please send corrections (or suggestions) to [email protected].
This document was produced by using OpenOffice and Octave.
![Page 3: FSM Examples - Wikimedia · 2015. 11. 6. · FSM Examples 8 Young Won Lim 11/6/15 Moore FSM (1) D Q D Q S' 1 S' 0 S 1 S 0 T A T B L A1 L A0 L B1 L B0 S 1 S 0 clk Current State Next](https://reader033.vdocuments.net/reader033/viewer/2022053123/60ac821a0c9c6a739407c7f1/html5/thumbnails/3.jpg)
FSMExamples
3 Young Won Lim11/6/15
Latches and FF's
![Page 4: FSM Examples - Wikimedia · 2015. 11. 6. · FSM Examples 8 Young Won Lim 11/6/15 Moore FSM (1) D Q D Q S' 1 S' 0 S 1 S 0 T A T B L A1 L A0 L B1 L B0 S 1 S 0 clk Current State Next](https://reader033.vdocuments.net/reader033/viewer/2022053123/60ac821a0c9c6a739407c7f1/html5/thumbnails/4.jpg)
FSMExamples
4 Young Won Lim11/6/15
FSM Inputs and Outputs
LA
LA
LB
LB
TB
TB
TA
TA
Traffic Lights - Outputs
LA
LB
Sensor - Inputs
TB
TA
![Page 5: FSM Examples - Wikimedia · 2015. 11. 6. · FSM Examples 8 Young Won Lim 11/6/15 Moore FSM (1) D Q D Q S' 1 S' 0 S 1 S 0 T A T B L A1 L A0 L B1 L B0 S 1 S 0 clk Current State Next](https://reader033.vdocuments.net/reader033/viewer/2022053123/60ac821a0c9c6a739407c7f1/html5/thumbnails/5.jpg)
FSMExamples
5 Young Won Lim11/6/15
States
LA
LA
LB
LB
LA
LA
LB
LB
LA
LA
LB
LB
LA
LA
LB
LB
TB
TA
=0
=0
TA =1
TB =1
![Page 6: FSM Examples - Wikimedia · 2015. 11. 6. · FSM Examples 8 Young Won Lim 11/6/15 Moore FSM (1) D Q D Q S' 1 S' 0 S 1 S 0 T A T B L A1 L A0 L B1 L B0 S 1 S 0 clk Current State Next](https://reader033.vdocuments.net/reader033/viewer/2022053123/60ac821a0c9c6a739407c7f1/html5/thumbnails/6.jpg)
FSMExamples
6 Young Won Lim11/6/15
Moore FSM State Transition Table
1
1
0
0
0
1
0 X 0
1 X X
0 1 X
0 0 X
1 X X
0 X 1
S0
TA
TB
S'1
1
0
0
0
1
1
S1
1
0
0
1
0
0
S'0
1
1
0
0
0
1
0 X 0
1 X X
0 1 X
0 0 X
1 X X
0 X 1
S0
TA
TB
S'1
1
0
0
0
1
1
S1
S1 S0
S1 S0T B
S1 S0T B
S '1 = S1 S0 + S1S0
= S1 + S0
0 X 0
1 X X
0 1 X
0 0 X
1 X X
0 X 1
S0
TA
TB
1
0
0
0
1
1
S1
1
0
0
1
0
0
S'0
S1 S0T A
S1 S0T B
S '0 = S1S0T A + S1 S0T B
![Page 7: FSM Examples - Wikimedia · 2015. 11. 6. · FSM Examples 8 Young Won Lim 11/6/15 Moore FSM (1) D Q D Q S' 1 S' 0 S 1 S 0 T A T B L A1 L A0 L B1 L B0 S 1 S 0 clk Current State Next](https://reader033.vdocuments.net/reader033/viewer/2022053123/60ac821a0c9c6a739407c7f1/html5/thumbnails/7.jpg)
FSMExamples
7 Young Won Lim11/6/15
States
000110
0
0
1
1
1 1 0
0 1 0
1 0 1
0 0 0
S2L
A1L
A0L
B1
1
1
0
0
S1
1
0
0
0
LB0
1 1
0 1
1 0
0 0
S2L
A1
1
1
0
0
S1
LA1=S1
1 0
0 0
1 1
0 0
S2
LA0
1
1
0
0
S1
LA0=S1S0
0
0
1
1
1
0
1
0
S2
LB1
1
1
0
0
S1
1
0
1
0
S2
1
1
0
0
S1
1
0
0
0
LB0
LB1=S1 LA0=S1S0
![Page 8: FSM Examples - Wikimedia · 2015. 11. 6. · FSM Examples 8 Young Won Lim 11/6/15 Moore FSM (1) D Q D Q S' 1 S' 0 S 1 S 0 T A T B L A1 L A0 L B1 L B0 S 1 S 0 clk Current State Next](https://reader033.vdocuments.net/reader033/viewer/2022053123/60ac821a0c9c6a739407c7f1/html5/thumbnails/8.jpg)
FSMExamples
8 Young Won Lim11/6/15
Moore FSM (1)
D Q
D Q
S'1
S'0
S1
S0
TA
TB
LA1
LA0
LB1
LB0
S1
S0
clk
Current State
Next State
inputs
outputs
states00: S001: S110: S211: S3
outputs (LA/LB)00: Green01: Yellow10: Red11: X
NextSt
CurrSt
Compute NextSt from CurrSt, Ta, Tb
This NextSt becomes a new CurrSt
Compute NextSt
CurrSt <= NextSt
![Page 9: FSM Examples - Wikimedia · 2015. 11. 6. · FSM Examples 8 Young Won Lim 11/6/15 Moore FSM (1) D Q D Q S' 1 S' 0 S 1 S 0 T A T B L A1 L A0 L B1 L B0 S 1 S 0 clk Current State Next](https://reader033.vdocuments.net/reader033/viewer/2022053123/60ac821a0c9c6a739407c7f1/html5/thumbnails/9.jpg)
FSMExamples
9 Young Won Lim11/6/15
Moore FSM
D Q
D Q
S'1
S'0
S1
S0
TA
TB
S'1 = S1 + S0
S '0 = S1S0T A + S1 S0T B
LA1
LA0
LB1
LB0
LA1=S1
LA0=S1S0
LB1=S1
LB0=S1S0
Next States
Outputs
S'0 = S1S0T A
+ S1 S0T B
S'1 = S1 + S0
Inputs TA
TB
Current State S1
S0
S1
S0
Current State S1
S0
LA1=S1
LA0=S1S0
LB1=S1
LB0=S1S0
clk
Current State
Next State
inputs
outputs
states00: S001: S110: S211: S3
outputs (LA/LB)00: Green01: Yellow10: Red11: X
![Page 10: FSM Examples - Wikimedia · 2015. 11. 6. · FSM Examples 8 Young Won Lim 11/6/15 Moore FSM (1) D Q D Q S' 1 S' 0 S 1 S 0 T A T B L A1 L A0 L B1 L B0 S 1 S 0 clk Current State Next](https://reader033.vdocuments.net/reader033/viewer/2022053123/60ac821a0c9c6a739407c7f1/html5/thumbnails/10.jpg)
FSMExamples
10 Young Won Lim11/6/15
Verilog Gate Level Design - testbench
`timescale 1ns/100ps
module traffic_controller_testbench;
parameter cycle = 40;
reg clock;
always begin #(cycle/2) clock=~clock; end
traffic_controller DUT (.clock(clock), .reset(reset), .TA(TA), .TB(TB), .LA(LA), .LB(LB) );
reg reset; reg TA, TB; wire [1:0] LA, LB;
initial begin clock = 1; reset = 1; TA = 1; TB = 0;
#1; #(cycle) reset = 0;
#(cycle) TB = 1; #(cycle) TA = 0; #(cycle*3) TA = 1; TB = 0; #(cycle*3) TA = 0; end
initial begin $dumpfile("traffic.vcd"); $dumpvars(0, DUT); #(cycle * 10); $finish; end
endmodule
![Page 11: FSM Examples - Wikimedia · 2015. 11. 6. · FSM Examples 8 Young Won Lim 11/6/15 Moore FSM (1) D Q D Q S' 1 S' 0 S 1 S 0 T A T B L A1 L A0 L B1 L B0 S 1 S 0 clk Current State Next](https://reader033.vdocuments.net/reader033/viewer/2022053123/60ac821a0c9c6a739407c7f1/html5/thumbnails/11.jpg)
FSMExamples
11 Young Won Lim11/6/15
module traffic_controller(clock, reset, TA, TB, LA, LB); input clock, reset; input TA, TB; output [1:0] LA, LB;
reg [1:0] S; wire [1:0] NextS;
always @(posedge clock) begin: SEQ if (reset) #8 S = 2'b00; else
#8 S = NextS; end
not #8 (S1b, S[1]); not #8 (S0b, S[0]); not #8 (TAb, TA); not #8 (TBb, TB);
xor #8 (NextS[1], S[1], S[0]); or #8 (NextS[0], NS1, NS2); and #8 (NS1, S1b, S0b, TAb); and #8 (NS2, S[1], S0b, TBb);
buf #8 (LA[1], S[1]); and #8 (LA[0], S1b, S[0]); not #8 (LB[1], S[1]); and #8 (LB[0], S[1], S[0]);
endmodule
Verilog Gate Level Design – traffic_gate.v
![Page 12: FSM Examples - Wikimedia · 2015. 11. 6. · FSM Examples 8 Young Won Lim 11/6/15 Moore FSM (1) D Q D Q S' 1 S' 0 S 1 S 0 T A T B L A1 L A0 L B1 L B0 S 1 S 0 clk Current State Next](https://reader033.vdocuments.net/reader033/viewer/2022053123/60ac821a0c9c6a739407c7f1/html5/thumbnails/12.jpg)
FSMExamples
12 Young Won Lim11/6/15
VCD Output with zero delay
![Page 13: FSM Examples - Wikimedia · 2015. 11. 6. · FSM Examples 8 Young Won Lim 11/6/15 Moore FSM (1) D Q D Q S' 1 S' 0 S 1 S 0 T A T B L A1 L A0 L B1 L B0 S 1 S 0 clk Current State Next](https://reader033.vdocuments.net/reader033/viewer/2022053123/60ac821a0c9c6a739407c7f1/html5/thumbnails/13.jpg)
FSMExamples
13 Young Won Lim11/6/15
VCD Output with gate delays
![Page 14: FSM Examples - Wikimedia · 2015. 11. 6. · FSM Examples 8 Young Won Lim 11/6/15 Moore FSM (1) D Q D Q S' 1 S' 0 S 1 S 0 T A T B L A1 L A0 L B1 L B0 S 1 S 0 clk Current State Next](https://reader033.vdocuments.net/reader033/viewer/2022053123/60ac821a0c9c6a739407c7f1/html5/thumbnails/14.jpg)
FSMExamples
14 Young Won Lim11/6/15
VCD Output with gate delays
Output Delay
![Page 15: FSM Examples - Wikimedia · 2015. 11. 6. · FSM Examples 8 Young Won Lim 11/6/15 Moore FSM (1) D Q D Q S' 1 S' 0 S 1 S 0 T A T B L A1 L A0 L B1 L B0 S 1 S 0 clk Current State Next](https://reader033.vdocuments.net/reader033/viewer/2022053123/60ac821a0c9c6a739407c7f1/html5/thumbnails/15.jpg)
FSMExamples
15 Young Won Lim11/6/15
Divide By N Counter FSM
S0 S1
S2
Y=1 Y=0
Y=0
reset Input: none
S1Output: Y=1 every 3 cycles
S2
S1
S0
Curr St
S0
S2
S1
Next St
S2
S1
S0
Curr St
0
0
1
Output
State Transition Table Output Table
![Page 16: FSM Examples - Wikimedia · 2015. 11. 6. · FSM Examples 8 Young Won Lim 11/6/15 Moore FSM (1) D Q D Q S' 1 S' 0 S 1 S 0 T A T B L A1 L A0 L B1 L B0 S 1 S 0 clk Current State Next](https://reader033.vdocuments.net/reader033/viewer/2022053123/60ac821a0c9c6a739407c7f1/html5/thumbnails/16.jpg)
FSMExamples
16 Young Won Lim11/6/15
Encoding States
S2
S1
S0
Curr St
S0
S2
S1
Next St
S2
S1
S0
Curr St
0
0
1
Output
State Transition Table Output Table
0
1
0
1 0
0 1
0 0
0
0
1
1 0
0 1
0 0
0
0
1
S0
S'1
S1
S'0
S0 YS
1
S '1=S1S0
S '0=S1 S0
Y=S1S0
S2
S1
S0
Curr St
S0
S2
S1
Next St
S2
S1
S0
Curr St
0
0
1
Output
State Transition Table Output Table
0
1
0
1 0 0
0 1 0
0 0 1
0
0
1
1
0
0
1 0 0
0 1 0
0 0 1
0
0
1
S0
S'2
S2
S'0
S0 YS
2
S '2=S2 S1 S0 Y=S2 S1S0
S1
S1
S'1
S '1=S2 S1 S0
S '0=S2 S1 S0
⇒ S1
⇒ S0
⇒ S2
⇒ S0
![Page 17: FSM Examples - Wikimedia · 2015. 11. 6. · FSM Examples 8 Young Won Lim 11/6/15 Moore FSM (1) D Q D Q S' 1 S' 0 S 1 S 0 T A T B L A1 L A0 L B1 L B0 S 1 S 0 clk Current State Next](https://reader033.vdocuments.net/reader033/viewer/2022053123/60ac821a0c9c6a739407c7f1/html5/thumbnails/17.jpg)
FSMExamples
17 Young Won Lim11/6/15
Resolution Time
![Page 18: FSM Examples - Wikimedia · 2015. 11. 6. · FSM Examples 8 Young Won Lim 11/6/15 Moore FSM (1) D Q D Q S' 1 S' 0 S 1 S 0 T A T B L A1 L A0 L B1 L B0 S 1 S 0 clk Current State Next](https://reader033.vdocuments.net/reader033/viewer/2022053123/60ac821a0c9c6a739407c7f1/html5/thumbnails/18.jpg)
FSMExamples
18 Young Won Lim11/6/15
FF Timing (Ideal)
D Q
D Q
D Q
D Q
D3
D2
D1
D0
Q3
Q2
Q1
Q0
D3:0
Q3:0
Inputs to FFs
Outputs of FFs
Q3
Q2
Q1
Q0
D3
D2
D1
D0
CLK
Register
Inpu
ts to
FF
s
Out
puts
of F
Fs
![Page 19: FSM Examples - Wikimedia · 2015. 11. 6. · FSM Examples 8 Young Won Lim 11/6/15 Moore FSM (1) D Q D Q S' 1 S' 0 S 1 S 0 T A T B L A1 L A0 L B1 L B0 S 1 S 0 clk Current State Next](https://reader033.vdocuments.net/reader033/viewer/2022053123/60ac821a0c9c6a739407c7f1/html5/thumbnails/19.jpg)
FSMExamples
19 Young Won Lim11/6/15
Sequence of States
Q(t+1) Q(t+2) Q(t+3) Q(t+4) Q(t+5)Q(t)
D3:0
Q3:0
(t+1)th edge
(t+2)th edge
(t+3)th edge
(t+4)th edge
(t+5)th edge
(t)th edge
Inputs to FFs
Outputs of FFs
? ? ? ? ? ?
Q(t+1) Q(t+2) Q(t+3) Q(t+4) Q(t+5)Q(t)
D3:0
Q3:0
Find inputs to FFs
which will make outputs in this sequence
(t+1)th edge
(t+2)th edge
(t+3)th edge
(t+4)th edge
(t+5)th edge
(t)th edge
![Page 20: FSM Examples - Wikimedia · 2015. 11. 6. · FSM Examples 8 Young Won Lim 11/6/15 Moore FSM (1) D Q D Q S' 1 S' 0 S 1 S 0 T A T B L A1 L A0 L B1 L B0 S 1 S 0 clk Current State Next](https://reader033.vdocuments.net/reader033/viewer/2022053123/60ac821a0c9c6a739407c7f1/html5/thumbnails/20.jpg)
FSMExamples
20 Young Won Lim11/6/15
When NextSt becomes CurrSt
NextSt
CurrSt
Compute NextSt from CurrSt, Ta, Tb
This NextSt becomes a new CurrSt
Compute NextSt
CurrSt <= NextSt
![Page 21: FSM Examples - Wikimedia · 2015. 11. 6. · FSM Examples 8 Young Won Lim 11/6/15 Moore FSM (1) D Q D Q S' 1 S' 0 S 1 S 0 T A T B L A1 L A0 L B1 L B0 S 1 S 0 clk Current State Next](https://reader033.vdocuments.net/reader033/viewer/2022053123/60ac821a0c9c6a739407c7f1/html5/thumbnails/21.jpg)
FSMExamples
21 Young Won Lim11/6/15
Finding FF Inputs
? ? ? ? ? ?
Q(t+1) Q(t+2) Q(t+3) Q(t+4) Q(t+5)Q(t)
D Q
D Q
D Q
D Q
D3:0
Q3:0
D3
D2
D1
D0
Q3
Q2
Q1
Q0
Inputs
Inputs to FFs
Outputs of FFs
During the tth clock edge period,
Compute the next state Q(t+1) using the current state Q(t) and other external inputs
Place it to FF inputs
After the next clock edge, (t+1)th, the computed next state Q(t+1) becomes the current state
![Page 22: FSM Examples - Wikimedia · 2015. 11. 6. · FSM Examples 8 Young Won Lim 11/6/15 Moore FSM (1) D Q D Q S' 1 S' 0 S 1 S 0 T A T B L A1 L A0 L B1 L B0 S 1 S 0 clk Current State Next](https://reader033.vdocuments.net/reader033/viewer/2022053123/60ac821a0c9c6a739407c7f1/html5/thumbnails/22.jpg)
FSMExamples
22 Young Won Lim11/6/15
Method of Finding FF Inputs
Q(t+1) Q(t+2) Q(t+3) Q(t+4) Q(t+5) Q(t+6)
Q(t+1) Q(t+2) Q(t+3) Q(t+4) Q(t+5)Q(t)
D Q
D Q
D Q
D Q
D3:0
Q3:0
D3
D2
D1
D0
Q3
Q2
Q1
Q0
Inputs
Q3
Q2
Q1
Q0
I D3
Q3
Q2
Q1
Q0
I D3
Q3
Q2
Q1
Q0
I D3
Q3
Q2
Q1
Q0
I D3
Find the boolean functions D3, D2, D1, D0in terms of Q3, Q2, Q1, Q0, and external inputsfor all possible cases.
![Page 23: FSM Examples - Wikimedia · 2015. 11. 6. · FSM Examples 8 Young Won Lim 11/6/15 Moore FSM (1) D Q D Q S' 1 S' 0 S 1 S 0 T A T B L A1 L A0 L B1 L B0 S 1 S 0 clk Current State Next](https://reader033.vdocuments.net/reader033/viewer/2022053123/60ac821a0c9c6a739407c7f1/html5/thumbnails/23.jpg)
FSMExamples
23 Young Won Lim11/6/15
State Transition
Q(t+1)
Q(t+1)Q(t)
D3:0
Q3:0
Q(t
)
Q(t
+1)
Inputs
Q(t+1)
Q(t+1)Q(t)
Inputs
Compute the next stateusing the current state and external inputsin the current clock cycle
After the next clock edge, the computed next state (FF Inputs) becomes the current state (FF Outputs)
![Page 24: FSM Examples - Wikimedia · 2015. 11. 6. · FSM Examples 8 Young Won Lim 11/6/15 Moore FSM (1) D Q D Q S' 1 S' 0 S 1 S 0 T A T B L A1 L A0 L B1 L B0 S 1 S 0 clk Current State Next](https://reader033.vdocuments.net/reader033/viewer/2022053123/60ac821a0c9c6a739407c7f1/html5/thumbnails/24.jpg)
FSMExamples
24 Young Won Lim11/6/15
Moore FSM
1
clock
INPUT StateRegister
Next StateCombinational
Logic
Output Combinational
Logic
OUTPUT
D Q D Q D Q
D Q D Q D Q
![Page 25: FSM Examples - Wikimedia · 2015. 11. 6. · FSM Examples 8 Young Won Lim 11/6/15 Moore FSM (1) D Q D Q S' 1 S' 0 S 1 S 0 T A T B L A1 L A0 L B1 L B0 S 1 S 0 clk Current State Next](https://reader033.vdocuments.net/reader033/viewer/2022053123/60ac821a0c9c6a739407c7f1/html5/thumbnails/25.jpg)
FSMExamples
25 Young Won Lim11/6/15
Mealy Machine
1
clock
INPUT StateRegister
Next StateCombinational
Logic
Output Combinational
Logic
OUTPUT
D Q D Q D Q
D Q D Q D Q
![Page 26: FSM Examples - Wikimedia · 2015. 11. 6. · FSM Examples 8 Young Won Lim 11/6/15 Moore FSM (1) D Q D Q S' 1 S' 0 S 1 S 0 T A T B L A1 L A0 L B1 L B0 S 1 S 0 clk Current State Next](https://reader033.vdocuments.net/reader033/viewer/2022053123/60ac821a0c9c6a739407c7f1/html5/thumbnails/26.jpg)
Young Won Lim11/6/15
References
[1] http://en.wikipedia.org/[2] M. M. Mano, C. R. Kime, “Logic and Computer Design Fundamentals”, 4th ed.[3] J. Stephenson, Understanding Metastability in FPGAs. Altera Corporation white paper. July 2009.