Exercises with Finite State Machines · – No need to go through T.T.s and K-Maps • Current CAD...

17
Exercises with Finite State Machines CS 64: Computer Organization and Design Logic Lecture #17 Winter 2019 Ziad Matni, Ph.D. Dept. of Computer Science, UCSB

Transcript of Exercises with Finite State Machines · – No need to go through T.T.s and K-Maps • Current CAD...

Page 1: Exercises with Finite State Machines · – No need to go through T.T.s and K-Maps • Current CAD software can do this automatically • Implemented with FPGA integrated circuits

ExerciseswithFiniteStateMachines

CS64:ComputerOrganizationandDesignLogicLecture#17Winter2019

ZiadMatni,Ph.D.

Dept.ofComputerScience,UCSB

Page 2: Exercises with Finite State Machines · – No need to go through T.T.s and K-Maps • Current CAD software can do this automatically • Implemented with FPGA integrated circuits

Administrative

•  Lab#8– DuenextweekonWednesday– PapercopydropoffatHFH2ndfloor

3/7/19 Matni,CS64,Wi19 2

Page 3: Exercises with Finite State Machines · – No need to go through T.T.s and K-Maps • Current CAD software can do this automatically • Implemented with FPGA integrated circuits

Administrative

•  TheLast3WeeksofCS64:

3/7/19 Matni,CS64,Wi19 3

Date L# Topic Lab LabDue

2/26 14 CombinatorialLogic,SequentialLogic1 7(CL+SL) Wed.3/6

2/28 15 SequentialLogic23/5 16 FSM1

8(FSM) Wed.3/133/7 17 FSM23/12 18 DigitalLogicReview

9(Ethics) Fri.3/153/14 19 CSEthics&Impact

FinalExamReview

Page 4: Exercises with Finite State Machines · – No need to go through T.T.s and K-Maps • Current CAD software can do this automatically • Implemented with FPGA integrated circuits

DesigningtheCircuitfortheFSM

1.  WestartwithaT.T

–  Alsocalleda“StateTransitionTable”

2.  MakeK-Mapsandsimplify

–  Usuallygiveyouranswerasa“sum-of-products”form

3.  Designthecircuit–  HavetouseD-FFstorepresentthestatebits

3/7/19 Matni,CS64,Wi19 4

Page 5: Exercises with Finite State Machines · – No need to go through T.T.s and K-Maps • Current CAD software can do this automatically • Implemented with FPGA integrated circuits

1.TheTruthTable(TheStateTransitionTable)

3/7/19 Matni,CS64,Wi19 5

State B2 B1 B0 I B2* B1* B0* FOUND

Initial 0 0 0 0 0 0 0 0

1 0 0 1 0

Found“1” 0 0 1 0 0 0 0 0

1 0 1 0 0

Found“11” 0 1 0 0 0 1 1 0

1 0 1 0 0

Found“110” 0 1 1 0 0 0 0 0

1 1 0 0 0

Found“1101” 1 0 0 0 0 0 0 1

1 0 1 0 1

CURRENTSTATE NEXTSTATEINPUT(S) OUTPUT(S)

Nextstate:K-Maps!

Outputs:Relatetostateinput

bits

Page 6: Exercises with Finite State Machines · – No need to go through T.T.s and K-Maps • Current CAD software can do this automatically • Implemented with FPGA integrated circuits

3/7/19 Matni,CS64,Wi19 6

3.DesigntheCircuit

NotethatCLKistheinputtoALLtheD-FFs’clockinputs.Thisisasynchronousmachine.Notetheuseoflabels(example:B2orB0-bar)insteadofroutingwiresallovertheplace!NotethatIissuedbothBnandBn-barfromalltheD-FFs–itmakesiteasierwiththelabelingandyouwon’thavetouseNOTgates!Notethatthesoleoutput(FOUND)doesnotneedaD-FFbecauseitisNOTASTATEBIT!

Page 7: Exercises with Finite State Machines · – No need to go through T.T.s and K-Maps • Current CAD software can do this automatically • Implemented with FPGA integrated circuits

3/7/19 Matni,CS64,Wi19 7

AND ORDFF

FPGAsandProgrammableLogic

Field-ProgrammableGateArrays

Page 8: Exercises with Finite State Machines · – No need to go through T.T.s and K-Maps • Current CAD software can do this automatically • Implemented with FPGA integrated circuits

The“OneHot”Method•  MostpopularlyusedinbuildingFSMs•  Giveeachstateit’sownD-FFoutput

–  #ofFFsneeded=#ofstates–  YouendupusingMORED-FFs,buttheimplementationiseasierto

automate

•  InputstotheD-FFsarecombinatoriallogicthatcansimplifiedintoa“sum-of-products”typeofBooleanexpression–  NoneedtogothroughT.T.sandK-Maps

•  CurrentCADsoftwarecandothisautomatically•  ImplementedwithFPGAintegratedcircuits

3/7/19 Matni,CS64,Wi19 8

Page 9: Exercises with Finite State Machines · – No need to go through T.T.s and K-Maps • Current CAD software can do this automatically • Implemented with FPGA integrated circuits

EncodingourStatesPerthelastexample(“1101Detector”):Wehad5separatestates,sowe’regoingtoneed5bits(i.e.5DFFs)todescribethestates:NAME “Regular”Code“OneHot”Code OUTPUTSInitialState S0 000 00001 “1” S1 001 00010“11” S2 010 00100“110” S3 011 01000“1101” S4 100 10000 FOUND

•  Advantageofthis“OneHot”approach?–  Whenweimplementthemachinewithcircuits,wecanuseaD-FFfor

everystate(so,inthisexample,we’duse5ofthem)

3/7/19 Matni,CS64,Wi19 9

Page 10: Exercises with Finite State Machines · – No need to go through T.T.s and K-Maps • Current CAD software can do this automatically • Implemented with FPGA integrated circuits

Usingthe“OneHot”CodetoDeterminetheCircuitDesign

•  Everystatehas1D-FF•  Wecanseethat

(followthearrows!!):S0*=S0.I+S1.I+S3.I+S4.IS1*=S0.IS2*=S1.I+S2.I+S4.IS3*=S2.IS4*=S3.IAlso,whenS4isTrue,FOUNDisTrue,i.e.FOUND=S4WehavenowdescribedALLtheoutputsofthemachineascombinationsofcertaininputsWITHOUTneedingtodoT.T.&K-Maps!

3/7/19 Matni,CS64,Wi19 10

“1” “11”

“110”“1101”

InitialState

Input=0 Input=1

Input=1

Input=0Input=0

FOUND=1

Input=1

S0

S4 S3

S2S1

Page 11: Exercises with Finite State Machines · – No need to go through T.T.s and K-Maps • Current CAD software can do this automatically • Implemented with FPGA integrated circuits

3/7/19 Matni,CS64,Wi19 11

ImplementingtheCircuitFor“Detect1101”FSMUsingthe“OneHot”Method

Page 12: Exercises with Finite State Machines · – No need to go through T.T.s and K-Maps • Current CAD software can do this automatically • Implemented with FPGA integrated circuits

FSMExercise1•  GivenaFSMdescribedwiththefollowingstatediagram

where:–  TheinitialstateisS1–  Thereisonly1input,X–  Thereisonly1output,Y,

anditisinitializedto0

•  WhatstatedoyouendupinifXtakesonthesequentialvalues0110?

•  WhichoftheseinputswillresultinY=1attheendoftheirsequences?A.   0110B.   1111101C.   0101010

3/7/19 Matni,CS64,Wi19 12

X= X=

X=X=

1

Y=1

Page 13: Exercises with Finite State Machines · – No need to go through T.T.s and K-Maps • Current CAD software can do this automatically • Implemented with FPGA integrated circuits

FSMExercise1b•  Howmanybitsdoweneedto

representallthestatesinthisFSM?–  Usingregular,non-alternativemethods

•  WritetheT.T.forthisFSM

•  Writethenext-statefunctionsforthisFSM

•  DesignthedigitallogiccircuittoimplementthisFSM,showingallinputsandalloutputs

3/7/19 Matni,CS64,Wi19 13

X= X=

X=X=

1

Y=1

Page 14: Exercises with Finite State Machines · – No need to go through T.T.s and K-Maps • Current CAD software can do this automatically • Implemented with FPGA integrated circuits

FSMExercise2•  DesignaFSMthattakesin2single-bitbinaryinputs,AandBandalwaysis

resetto(beginsin)aninitialstate.

•  ThemachinewillmovefromtheinitialstateonlyifA&&Bistrue.Onceitdoesthat,however,itwillgothroughNstatessequentially,onceforeverytimeA||Bistrue.

•  Onthelaststate,itsimplygoestotheinitialstateagainandrepeats.

A.  DrawthestatediagramforN=3.B.   Usingthe“one-hotmethod”,howmanybitsdoweneedtorepresentall

thestatesinthisFSM?C.  Writethenext-statefunctionsforthisFSMusingtheapproachinB.D.  Designthedig.logiccircuittoimplementtheFSMusingyourresultssofar

3/7/19 Matni,CS64,Wi19 14

Page 15: Exercises with Finite State Machines · – No need to go through T.T.s and K-Maps • Current CAD software can do this automatically • Implemented with FPGA integrated circuits

FSMExercise3•  ConsidertheFSMcircuit,

shownhereusingthe“one-hotmethod”

A.  Identifythenon-clockinputsandoutputs

B.  Writethenextstateequations

C.  WritetheT.T.forthisFSM

D.  DrawthestatediagramforthisFSM

3/7/19 Matni,CS64,Wi19 15

D QClk

y1

Clk

D QClk

y2

Clk

x

OR

Page 16: Exercises with Finite State Machines · – No need to go through T.T.s and K-Maps • Current CAD software can do this automatically • Implemented with FPGA integrated circuits

YOURTO-DOs

•  Lab8

3/7/19 Matni,CS64,Wi19 16

Page 17: Exercises with Finite State Machines · – No need to go through T.T.s and K-Maps • Current CAD software can do this automatically • Implemented with FPGA integrated circuits

3/7/19 Matni,CS64,Wi19 17