comp541 state machines
DESCRIPTION
COMP541 State Machines. Montek Singh Feb 8, 2012. Today ’ s Topics. State Machines How to design machines that go through a sequence of events “ sequential machines ” Basically close the feedback loop in this picture:. Synchronous Sequential Logic. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: COMP541 State Machines](https://reader036.vdocument.in/reader036/viewer/2022070502/56814a18550346895db73ea7/html5/thumbnails/1.jpg)
1
COMP541COMP541
State MachinesState Machines
Montek SinghMontek Singh
Feb 8, 2012Feb 8, 2012
![Page 2: COMP541 State Machines](https://reader036.vdocument.in/reader036/viewer/2022070502/56814a18550346895db73ea7/html5/thumbnails/2.jpg)
Today’s TopicsToday’s Topics State MachinesState Machines
How to design machines that go through a How to design machines that go through a sequencesequence of eventsof events““sequential machines”sequential machines”
Basically close the feedback loop in this picture:Basically close the feedback loop in this picture:
2
![Page 3: COMP541 State Machines](https://reader036.vdocument.in/reader036/viewer/2022070502/56814a18550346895db73ea7/html5/thumbnails/3.jpg)
Synchronous Sequential LogicSynchronous Sequential Logic
Flip-flops/registers contain the system’s Flip-flops/registers contain the system’s statestate state changes only at clock edgestate changes only at clock edge
so system is so system is synchronized synchronized to the clockto the clock all flip-flops receive the same clock signal (important!)all flip-flops receive the same clock signal (important!) every cyclic path must contain a flip-flopevery cyclic path must contain a flip-flop
![Page 4: COMP541 State Machines](https://reader036.vdocument.in/reader036/viewer/2022070502/56814a18550346895db73ea7/html5/thumbnails/4.jpg)
Two common typesTwo common types Two common synchronous sequential circuits:Two common synchronous sequential circuits:
Finite State Machines (FSMs)Finite State Machines (FSMs)
PipelinesPipelines
4
![Page 5: COMP541 State Machines](https://reader036.vdocument.in/reader036/viewer/2022070502/56814a18550346895db73ea7/html5/thumbnails/5.jpg)
Finite State Machine (FSM)Finite State Machine (FSM) Consists of:Consists of:
State register thatState register thatholds the current stateholds the current stateupdates it to the “next updates it to the “next
state” at clock edgestate” at clock edge
Combinational logic (CL) Combinational logic (CL) thatthatcomputes the next statecomputes the next state
– using current state and using current state and inputsinputs
computes the outputscomputes the outputs– using current state (and using current state (and
maybe inputs)maybe inputs)
NextState
CurrentState
S’ S
CLK
CL
Next StateLogic
NextState
CL
OutputLogic
Outputs
![Page 6: COMP541 State Machines](https://reader036.vdocument.in/reader036/viewer/2022070502/56814a18550346895db73ea7/html5/thumbnails/6.jpg)
More and Mealy FSMsMore and Mealy FSMs Two types of finite state machines differ in the Two types of finite state machines differ in the
output logic:output logic: Moore FSMMoore FSM::
outputs depend only on the current stateoutputs depend only on the current state Mealy FSMMealy FSM::
outputs depend on the current state outputs depend on the current state and the inputsand the inputs can convert from one form to the othercan convert from one form to the other
Mealy is more generalMealy is more general
In Both:In Both: Next state is determined by current state and inputsNext state is determined by current state and inputs
![Page 7: COMP541 State Machines](https://reader036.vdocument.in/reader036/viewer/2022070502/56814a18550346895db73ea7/html5/thumbnails/7.jpg)
Moore and Mealy FSMsMoore and Mealy FSMs
7
CLKM Nk knext
statelogic
outputlogic
Moore FSM
CLKM Nk knext
statelogic
outputlogic
inputs
inputs
outputs
outputsstate
statenextstate
nextstate
Mealy FSM
![Page 8: COMP541 State Machines](https://reader036.vdocument.in/reader036/viewer/2022070502/56814a18550346895db73ea7/html5/thumbnails/8.jpg)
FSM ExampleFSM Example Traffic light controllerTraffic light controller
Traffic sensors: TTraffic sensors: TAA, T, TBB (TRUE when there’s traffic) (TRUE when there’s traffic) Lights: LLights: LAA, L, LBB
TA
LA
TA
LB
TB
TB
LA
LB
Academic Ave.
Bravado
Blvd.
Dorms
Fields
DiningHall
Labs
![Page 9: COMP541 State Machines](https://reader036.vdocument.in/reader036/viewer/2022070502/56814a18550346895db73ea7/html5/thumbnails/9.jpg)
FSM Black BoxFSM Black Box Inputs:Inputs:
CLK, Reset, TCLK, Reset, TAA, T, TBB
Outputs: LOutputs: LAA, L, LBB
TA
TB
LA
LB
CLK
Reset
TrafficLight
Controller
![Page 10: COMP541 State Machines](https://reader036.vdocument.in/reader036/viewer/2022070502/56814a18550346895db73ea7/html5/thumbnails/10.jpg)
Design Simple FSMDesign Simple FSM When When resetreset, L, LAA is green is green
and Land LBB is red is red
As long as traffic on As long as traffic on Academic (TAcademic (TAA high), keep high), keep LLAA green green
When TWhen TAA goes low, goes low, sequence to traffic on sequence to traffic on BravadoBravado
Follow same algorithm for Follow same algorithm for BravadoBravado
Let’s say clock period is 5 Let’s say clock period is 5 sec (time for yellow light)sec (time for yellow light)
10
TA
LA
TA
LB
TB
TB
LA
LB
Academic Ave.
Bravado
Blvd.
Dorms
Fields
DiningHall
Labs
![Page 11: COMP541 State Machines](https://reader036.vdocument.in/reader036/viewer/2022070502/56814a18550346895db73ea7/html5/thumbnails/11.jpg)
StatesStates What sequence do the traffic lights follow?What sequence do the traffic lights follow?
Reset Reset State 0, L State 0, LAA is green and L is green and LBB is red is red Next (on board)?Next (on board)?
11
TA
LA
TA
LB
TB
TB
LA
LB
Academic Ave.
Bravado
Blvd.
Dorms
Fields
DiningHall
Labs
![Page 12: COMP541 State Machines](https://reader036.vdocument.in/reader036/viewer/2022070502/56814a18550346895db73ea7/html5/thumbnails/12.jpg)
State Transition DiagramState Transition Diagram• Moore FSM: outputs labeled in each state• States: Circles• Transitions: Arcs
S0LA: greenLB: red
S1LA: yellowLB: red
S3LA: redLB: yellow
S2LA: redLB: green
TATA
TB
TB
Reset
TA
LA
TA
LB
TB
TB
LA
LB
Academic Ave.
Bravado
Blvd.
Dorms
Fields
DiningHall
Labs
![Page 13: COMP541 State Machines](https://reader036.vdocument.in/reader036/viewer/2022070502/56814a18550346895db73ea7/html5/thumbnails/13.jpg)
State Transition TableState Transition Table
Current State Inputs
Next State
S TA TB S'S0 0 X S1S0 1 X S0S1 X X S2S2 X 0 S3S2 X 1 S2S3 X X S0
![Page 14: COMP541 State Machines](https://reader036.vdocument.in/reader036/viewer/2022070502/56814a18550346895db73ea7/html5/thumbnails/14.jpg)
FSM Encoded State Transition FSM Encoded State Transition TableTable
State Encoding
S0 00
S1 01
S2 10
S3 11
Current State Inputs Next StateS1 S0 TA TB S'1 S'00 0 0 X 0 10 0 1 X 0 00 1 X X 1 01 0 X 0 1 11 0 X 1 1 01 1 X X 0 0
![Page 15: COMP541 State Machines](https://reader036.vdocument.in/reader036/viewer/2022070502/56814a18550346895db73ea7/html5/thumbnails/15.jpg)
FSM Output TableFSM Output Table
Current State OutputsS1 S0 LA1 LA0 LB1 LB0
0 0 0 0 1 00 1 0 1 1 01 0 1 0 0 01 1 1 0 0 1
Output Encoding
green 00
yellow 01
red 10
LA1 = S1
LA0 = S1S0
LB1 = S1
LB0 = S1S0
![Page 16: COMP541 State Machines](https://reader036.vdocument.in/reader036/viewer/2022070502/56814a18550346895db73ea7/html5/thumbnails/16.jpg)
FSM Schematic: State RegisterFSM Schematic: State Register
S1
S0
S'1
S'0
CLK
state register
Reset
r
![Page 17: COMP541 State Machines](https://reader036.vdocument.in/reader036/viewer/2022070502/56814a18550346895db73ea7/html5/thumbnails/17.jpg)
Next State LogicNext State Logic
S1
S0
S'1
S'0
CLK
next state logic state register
Reset
TA
TB
inputs
S1 S0
r
Current State Inputs Next StateS1 S0 TA TB S'1 S'00 0 0 X 0 10 0 1 X 0 00 1 X X 1 01 0 X 0 1 11 0 X 1 1 01 1 X X 0 0
![Page 18: COMP541 State Machines](https://reader036.vdocument.in/reader036/viewer/2022070502/56814a18550346895db73ea7/html5/thumbnails/18.jpg)
Output LogicOutput Logic
S1
S0
S'1
S'0
CLK
next state logic output logicstate register
Reset
LA1
LB1
LB0
LA0
TA
TB
inputs outputs
S1 S0
r
LA1 = S1
LA0 = S1S0
LB1 = S1
LB0 = S1S0
![Page 19: COMP541 State Machines](https://reader036.vdocument.in/reader036/viewer/2022070502/56814a18550346895db73ea7/html5/thumbnails/19.jpg)
FSM Timing Diagram: Study FSM Timing Diagram: Study carefully!carefully!
CLK
Reset
TA
TB
S'1:0
S1:0
LA1:0
LB1:0
Cycle 1 Cycle 2 Cycle 3 Cycle 4 Cycle 5 Cycle 6 Cycle 7 Cycle 8 Cycle 9 Cycle 10
S1 (01) S2 (10) S3 (11) S0 (00)
t (sec)
??
??
S0 (00)
S0 (00) S1 (01) S2 (10) S3 (11) S1 (01)
??
??
0 5 10 15 20 25 30 35 40 45
Green (00)
Red (10)
S0 (00)
Yellow (01) Red (10) Green (00)
Green (00) Red (10)Yellow (01)
S0LA: greenLB: red
S1LA: yellowLB: red
S3LA: redLB: yellow
S2LA: redLB: green
TATA
TB
TB
ResetS1
S0
S'1
S'0
CLK
next state logic output logicstate register
Reset
LA1
LB1
LB0
LA0
TA
TB
inputs outputs
S1 S0
r
Current State Inputs Next StateS1 S0 TA TB S'1 S'00 0 0 X 0 10 0 1 X 0 00 1 X X 1 01 0 X 0 1 11 0 X 1 1 01 1 X X 0 0
![Page 20: COMP541 State Machines](https://reader036.vdocument.in/reader036/viewer/2022070502/56814a18550346895db73ea7/html5/thumbnails/20.jpg)
20
Design ProcedureDesign Procedure Take problem description and refine it into a Take problem description and refine it into a
state table or diagramstate table or diagram Assign codes to the statesAssign codes to the states Derive Boolean equations and implementDerive Boolean equations and implement
Or, write Verilog and compileOr, write Verilog and compile
![Page 21: COMP541 State Machines](https://reader036.vdocument.in/reader036/viewer/2022070502/56814a18550346895db73ea7/html5/thumbnails/21.jpg)
21
Example: Sequence RecognizerExample: Sequence Recognizer Circuit has input, X, and output, ZCircuit has input, X, and output, Z Recognizes sequence 1101 on XRecognizes sequence 1101 on X
Specifically, if X has been 110 and next bit is 1, make Specifically, if X has been 110 and next bit is 1, make Z highZ high
![Page 22: COMP541 State Machines](https://reader036.vdocument.in/reader036/viewer/2022070502/56814a18550346895db73ea7/html5/thumbnails/22.jpg)
22
How to Design StatesHow to Design States States States rememberremember past history past history
Clearly must remember we’ve seen 110 when next 1 Clearly must remember we’ve seen 110 when next 1 comes alongcomes along
Tell me one necessary state for this example…?Tell me one necessary state for this example…?
![Page 23: COMP541 State Machines](https://reader036.vdocument.in/reader036/viewer/2022070502/56814a18550346895db73ea7/html5/thumbnails/23.jpg)
23
Beginning StateBeginning State Start state: letStart state: let’’s call it As call it A
if 1 appears on input, move to next state Bif 1 appears on input, move to next state B output remains at 0output remains at 0
Input / Output
![Page 24: COMP541 State Machines](https://reader036.vdocument.in/reader036/viewer/2022070502/56814a18550346895db73ea7/html5/thumbnails/24.jpg)
24
Second 1Second 1 New state, CNew state, C To reach C, must have seen 11To reach C, must have seen 11
![Page 25: COMP541 State Machines](https://reader036.vdocument.in/reader036/viewer/2022070502/56814a18550346895db73ea7/html5/thumbnails/25.jpg)
25
Next a 0Next a 0 If 110 has been received, go to DIf 110 has been received, go to D Next 1 will generate a 1 on output ZNext 1 will generate a 1 on output Z
![Page 26: COMP541 State Machines](https://reader036.vdocument.in/reader036/viewer/2022070502/56814a18550346895db73ea7/html5/thumbnails/26.jpg)
26
What else?What else? What happens to arrow on right?What happens to arrow on right? Must go to some state.Must go to some state. Where?Where?
![Page 27: COMP541 State Machines](https://reader036.vdocument.in/reader036/viewer/2022070502/56814a18550346895db73ea7/html5/thumbnails/27.jpg)
27
What Sequence?What Sequence? Here we have to interpret the problem Here we have to interpret the problem
statementstatement WeWe’’ve just seen 01ve just seen 01
Is this beginning of new 1101?Is this beginning of new 1101? Or do we need to start over w/ another 1?Or do we need to start over w/ another 1?
Textbook: decides that itTextbook: decides that it’’s beginning (01…)s beginning (01…)
![Page 28: COMP541 State Machines](https://reader036.vdocument.in/reader036/viewer/2022070502/56814a18550346895db73ea7/html5/thumbnails/28.jpg)
28
Cover every possibilityCover every possibility Well, must have every possibility out of every Well, must have every possibility out of every
statestate In this case, just two: X = 0 or 1In this case, just two: X = 0 or 1 You fill in other casesYou fill in other cases
![Page 29: COMP541 State Machines](https://reader036.vdocument.in/reader036/viewer/2022070502/56814a18550346895db73ea7/html5/thumbnails/29.jpg)
29
Fill inFill in
![Page 30: COMP541 State Machines](https://reader036.vdocument.in/reader036/viewer/2022070502/56814a18550346895db73ea7/html5/thumbnails/30.jpg)
30
Full AnswerFull Answer
![Page 31: COMP541 State Machines](https://reader036.vdocument.in/reader036/viewer/2022070502/56814a18550346895db73ea7/html5/thumbnails/31.jpg)
31
State MinimizationState Minimization When we make state diagram, do we need all When we make state diagram, do we need all
those states?those states? Some may be redundantSome may be redundant State minimization procedures can be usedState minimization procedures can be used
Is a tough problem (NP-complete)Is a tough problem (NP-complete)but pretty good algorithms existbut pretty good algorithms existexact and approximateexact and approximate
We wonWe won’’t cover in this courset cover in this course
![Page 32: COMP541 State Machines](https://reader036.vdocument.in/reader036/viewer/2022070502/56814a18550346895db73ea7/html5/thumbnails/32.jpg)
32
ReadingReading Read 3.4-3.6Read 3.4-3.6 Might be good to look at Chapter 4 (Verilog Might be good to look at Chapter 4 (Verilog
only)only)