finite state machines - web02web02.gonzaga.edu/faculty/talarico/cp430/lec/fsm.pdf · ·...
Post on 20-May-2018
229 Views
Preview:
TRANSCRIPT
FiniteStateMachines
talarico@gonzaga.edu 1
FSM
talarico@gonzaga.edu 2
nextstatestate
GenericStateMachineModel
GuidelinesforcodingFSMsinVHDL:
*Useseparateprocessesforsequentiallogicandcombinationallogic
*Useenumerateddatatypetolistallpossiblestates
(optional)(state registers)
StateMachine:keyidea
• StatemachinesareaneffectivemathematicalMoC thatallowtocharacterizeinanun-ambiguousandformalwaythebehaviorofasystem
• Goal:givenasetofexternalstimuliwewanttodesignasystemthatexhibitadesiredbehavior,i.e.thesystemmustbeabletoprocessthestimuli providedatitsinputstoproducecertainactions atitsoutputs
talarico@gonzaga.edu 3
SYSTEMinputs outputs
StateMachine:keyidea
talarico@gonzaga.edu 4
STATE,ACTIONS
checkstimuli
IfnecessarychangeSTATEandACTIONS
SystemBehavior:
stimuli inputs
actions outputs
actionsdependsonstimuli&state
Insummary:1. atanygiventimeyouare
inacertainstate,andperformcertainactions
2. monitorexternalstimuliand“decide”whatnextstateandactionsshouldbe
MoorestyleFSM
talarico@gonzaga.edu 5
NextstateC.L.
OutputC.L.
StateRegistersS.L.
clock reset(optional)
nextstate state outputsinputs
Theremaybeglitchesontheoutputs
MealystyleFSM
talarico@gonzaga.edu 6
NextstateC.L.
OutputC.L.StateRegisters
S.L.
clock reset(optional)
nextstatestate outputs
inputs
Theremaybeglitchesontheoutputsandtheoutputsmaylastlessthanonecycle
RegisteredOutputsFSMs
talarico@gonzaga.edu 7
PipelinedMealy
Noglitchesandtheoutputslastone cycle
NextstateC.L.
OutputC.L.StateRegisters
S.L.
clock reset(optional)
nextstatestateinputs
OutputRegistersS.L.
storedoutputs
RegisteredOutputsFSMs
talarico@gonzaga.edu 8
NextstateC.L.
OutputC.L.
StateRegistersS.L.
clock reset(optional)
nextstate statestoredoutputsinputs
OutputRegistersS.L.
Noglitchesandtheoutputslastoneclockcycle
Ifwewant,wecandefinitelypipeline“Moore”…
Registered(a.k.a stored)outputsFSMs
talarico@gonzaga.edu 9
NextstateC.L.
OutputCodedStateRegisters
clock reset(optional)
nextstatestate/outputs
inputs
Noglitches+outputsarefaster
Solution1:outputcodedMoore
Solution2:output“forecasting”
Usuallysolution2requireslessthinking
NOTE:withMooreFSMsispossibletogetregisteredoutputswithouthavingtoaddapipelinestageà outputsgetspeedupbyoneclockcycle!!!
DesignExample:EdgeDetector
talarico@gonzaga.edu 10
EdgeDetector• Designastatemachinetoimplementanedgedetector
Intuitivesolution:
talarico@gonzaga.edu 11
SYSTEMDIN
CLKPULSE
MoorestyleASM
talarico@gonzaga.edu 12
SYSTEMDIN
CLKPULSE
K.MapsforMoore’sFSM
talarico@gonzaga.edu 13
MealystyleASM
talarico@gonzaga.edu 14
SYSTEMDIN
CLKPULSE
K.MapsforMealy’s FSM
talarico@gonzaga.edu 15
MealyImplementation
talarico@gonzaga.edu 16
pulse~0
Mooreimplementation
talarico@gonzaga.edu 17
Mux0~0
Moorewithregisteredoutput
talarico@gonzaga.edu 18
Mux0~0
InthissimpleexampletheMoore’soutputregisteredFSMandthe“pipelined”MealyFSMhappentocoincides!
DesignExample:EdgeDetectorVHDLcoding
talarico@gonzaga.edu 19
Mealy’s FSM
talarico@gonzaga.edu 20
Moore’sFSM
talarico@gonzaga.edu 21
Moore’sstoredoutputFSM
talarico@gonzaga.edu 22
EdgeDetector:FunctionalSimulation
talarico@gonzaga.edu 23
FunctionalSimulation
talarico@gonzaga.edu 24
Mealy:
Moore:
Moorewithstoredoutput:
EdgeDetector:Testbench VHDLcode
talarico@gonzaga.edu 25
Testbench
26
top related