Sequential Logic Design - GitHub Pages

30
Sequential Logic Design CS 64: Computer Organization and Design Logic Lecture #14 Ziad Matni Dept. of Computer Science, UCSB

Transcript of Sequential Logic Design - GitHub Pages

Page 1: Sequential Logic Design - GitHub Pages

SequentialLogicDesign

CS64:ComputerOrganizationandDesignLogicLecture#14

ZiadMatni

Dept.ofComputerScience,UCSB

Page 2: Sequential Logic Design - GitHub Pages

Administrative•  Only2.5weeksleft!!!!!!!!OMG!!!!!

•  Th.5/24 SequentialLogic–  Lab#7 CombinatorialLogic

•  Tu.5/29 MoreSequentialLogic!•  Th.5/31 FiniteStateMachines

–  Lab#8 SequentialLogicandCPUDesign

•  Tu.6/4 MoreFiniteStateMachines!•  Th.6/8 CSEthicsandSocietalImpactofCS

–  Lab#9 FiniteStateMachines–  Lab#10 Ethics/SocietalImpact(short;online)

5/24/18 Matni,CS64,Sp18 2

Page 3: Sequential Logic Design - GitHub Pages

LectureOutline

•  SequentialLogic

•  S-RLatch

•  D-Latch

•  D-FlipFlop

•  Reviewingwhat’sneededforLab8 (nextweek’slab)

5/24/18 Matni,CS64,Sp18 3

Page 4: Sequential Logic Design - GitHub Pages

SequentialLogic

•  CombinatorialLogic–  Combiningmultiplelogicblocks–  Theoutputisafunctiononlyofthepresentinputs–  Thereisnomemoryofpast“states”

•  SequentialLogic–  Combiningmultiplelogicblocks–  Theoutputisafunctionofbothpresentandpastinputs–  Thereexistsamemoryofpast“states”

5/24/18 Matni,CS64,Sp18 4

Page 5: Sequential Logic Design - GitHub Pages

TheS-RLatch

•  Onlyinvolves2NORs

•  Theoutputsarefed-backtotheinputs

•  Theresultisthattheoutputstate(eithera1ora0)ismaintainedeveniftheinputchanges!

5/24/18 Matni,CS64,Sp18 5

Page 6: Sequential Logic Design - GitHub Pages

HowaS-RLatchWorks•  NotethatifoneNORinputis0,theoutput

becomestheinverseoftheotherinput

•  So,ifoutputQalreadyexistsandifS=0,R=0,thenQwillremainatwhateveritwasbefore!(holdoutputstate)

•  IfS=0,R=1,thenQbecomes0(resetoutput)

•  IfS=1,R=0,thenQbecomes1(setoutput)

•  MakingS=1,R=1isnotallowed(undeterminedoutput)5/24/18 6

S R Q0 Comment0 0 Q* Holdoutput0 1 0 Resetoutput1 0 1 Setoutput1 1 X Undetermined

Page 7: Sequential Logic Design - GitHub Pages

Consequences?

•  AslongasS=0andR=0,thecircuitoutputholdsmemoryofitspriorvalue(state)

•  Tochangetheoutput,justmakeS=1(butalsoR=0)tomaketheoutput1(set)ORS=0(butalsoR=1)tomaketheoutput0(reset)

•  JustavoidS=1,R=1…

5/24/18 Matni,CS64,Sp18 7

S R Q0 Comment0 0 Q* Holdoutput0 1 0 Resetoutput1 0 1 Setoutput1 1 X Undetermined

Page 8: Sequential Logic Design - GitHub Pages

AboutthatS=1,R=1Case…

•  WhatifweavoideditonpurposebymakingR=NOT(S)?– Where’stheproblem?

•  This,byitself,precludesacasewhenR=S=0–  You’dneedthatifyouwantto

preservethepreviousoutputstate!

•  Solution:theclockedlatchandtheflip-flop

5/24/18 Matni,CS64,Sp18 8

S/R’

S R Q0 Comment

0 0 Q* Holdoutput

0 1 0 Resetoutput

1 0 1 Setoutput

1 1 X Undetermined

Page 9: Sequential Logic Design - GitHub Pages

Addingan“Enable”Input:TheGatedS-RLatch

•  Createawayto“gate”theinputs–  R/Sinputsgothroughonlyifan“enableinput”(E)is1

–  IfEis0,thentheS-RlatchgetsSR=00anditholdthestateofpreviousoutputs

•  So,thetruthtablewouldlooklike:

5/24/18 Matni,CS64,Sp18 9

S R Q0 Comment0 0 Q* Holdoutput0 1 0 Resetoutput1 0 1 Setoutput1 1 X Undetermined

S R E Q0 CommentX X 0 Q* Holdoutput0 1 1 0 Resetoutput1 0 1 1 Setoutput

Page 10: Sequential Logic Design - GitHub Pages

CombiningRandSinputsintoOne:TheGatedDLatch

•  ForceSandRinputstoalwaysbeoppositeofeachother–  Makethemthesameas

aninputD,whereD=Rand!D=S.

•  Createawayto“gate”theDinput–  Dinputgoesthrough

onlyifanenableinput(E)is1–  IfEis0,thenholdthestateofthe

previousoutputs

5/24/18 Matni,CS64,Sp18 10

DE

SR

QQ

D E Q0 CommentX 0 Q* Holdoutput0 1 0 Resetoutput1 1 1 Setoutput

Page 11: Sequential Logic Design - GitHub Pages

EnablingtheLatchSynchronously:TheClockedDLatch

•  IfyouapplyaclockoninputE,yougetaclockedDlatch.

•  Aclockisaninputthatgoes1then0,then1againinasettimeperiod

•  WhenCLKis0,bothSandRinputstothelatchare0too,sotheQholdsitsvalue(Q=Q0)

5/24/18 Matni,CS64,Sp18 11

DCLK

SR

•  WhenCLKis1,thenifD=1,thenQ=1,butifD=0,thenQ=0

Page 12: Sequential Logic Design - GitHub Pages

ClockedDLatchasDigitalSampler

•  Thisclockedlatchcanbeusedasa“programmable”memorydevicethat“samples”aninputonaregularbasis

5/24/18 Matni,CS64,Sp18 12

DCLK

QQ

Page 13: Sequential Logic Design - GitHub Pages

TheClockedDLatchByAnyOtherName…

•  Observinginputandoutput“waveforms”

5/24/18 Matni,CS64,Sp18 13

DCLK

SR

DClockedLatch

DCLK

QQ

Page 14: Sequential Logic Design - GitHub Pages

TheJoysofSampling…

•  Samplingdatainaperiodicwayisadvantageous–  Icanstartdesigningmorecomplexcircuitsthatcanhelpmedosynchronouslogicalfunctions•  Synchronous:in-time

•  VeryusefulinpipeliningdesignsusedinCPUs–  Pipelining:atechniquethatallowsCPUstoexecuteinstructionsmoreefficiently–inparallel

5/24/18 Matni,CS64,Sp18 14

Instructionfetch,decode,execute,memoryaccess,registerwrite

Page 15: Sequential Logic Design - GitHub Pages

TheMostEfficientWaytoSampleInputs

•  Insteadofsamplingtheinputtothelatchusingaleveloftheclock…–  Thatis,whentheclockis“1”(or“0”)

•  …sampletheinputattheedgeoftheclock–  Thatis,whentheclockistransitioningfrom0à1,calledarisingorpositiveedge(oritcouldbedonefrom1à0, thefallingedgea.k.anegativeedge)

– Why??

5/24/18 Matni,CS64,Sp18 15

Page 16: Sequential Logic Design - GitHub Pages

TheD-FF

•  Whentheinputclockedgeisrising,theinput(D)iscapturedandplacedontheoutput(Q)–  Risingedgea.k.apositiveedgeFF–  SomeFFarenegativeedgeFF(captureonthefallingedge)

5/24/18 Matni,CS64,Sp18 16

Page 17: Sequential Logic Design - GitHub Pages

Latchesvs.FFs•  Latchescapturedataonanentire1or0oftheclock•  FFscapturedataontheedgeoftheclock

–  Thisexampleshowsthepositive(0à1)edgeused

LatchoutFFout

5/24/18 Matni,CS64,Sp18 17

FFsgiveoutless“glitchy”outputs

Page 18: Sequential Logic Design - GitHub Pages

AnImprovementontheLatch:TheDFlip-Flop

Don’tworryaboutthecircuitimplementationdetails,butunderstandtheuse!TheDFlip-Floponlychangestheoutput(Q)intotheinput(D)atthepositiveedge(the0à1transition)oftheclock

5/24/18 Matni,CS64,Sp18 18

DFlip-Flop(D-FF)

D>CLK

QQ

DGatedLatch

DCLK

QQ

Asopposedto:

Notethe(slight)differenceinthe2symbols…

Page 19: Sequential Logic Design - GitHub Pages

PopularUsesforD-FFs

•  Counter

•  Serial-to-Parallelconverter

•  Digitaldelayline

5/24/18 Matni,CS64,Sp18 19

Again,don’tworryaboutthecircuitimplementationdetails,butunderstandtheuses!

Page 20: Sequential Logic Design - GitHub Pages

Lab8

5/24/18 Matni,CS64,Sp18 20

Page 21: Sequential Logic Design - GitHub Pages

NoteWhenEverythingisDue…•  NextMonday(5/28)isaUniversityHoliday•  So…nolabonMonday

•  BUT!YoustillhaveanewLab(#8)thatweek!!!–  Issuedtoyouovertheweekend

•  Getstartedonitearly–it’slong-ish•  GoseeTAsduringtheirofficehours(We.&Fr.)forhelp

•  Lab#8willbedueonMONDAY6/4–  NottheusualFriday!

•  Lab#9willbeISSUEDONMONDAY6/4&BEDUEONFRIDAY6/8•  Lab#10willbeISSUEDONTHURSDAY6/7&BEDUEONFRIDAY6/8

–  Here’sWhy…

5/24/18 Matni,CS64,Sp18 21

Page 22: Sequential Logic Design - GitHub Pages

What’sLab8About?•  Designa“simple”ALU(Task1)•  Designa“simple”registerblockusingD-FFs(Task2)•  Begivenaspecificationfora“simple”CPUthatuses:–  1“Simple”RegisterBlock–  1“Simple”ALU–  1AbstractComputerMemoryInterface–  AsmanyANDs,ORs,NOTs,XORs,Muxesthatyouneed

•  DesignthisCPU!(Task3)

•  Youwilldrawallofthese(BENEAT!)–  Takepicturesor(betteryet)scanthem,thenturnin

5/24/18 Matni,CS64,Sp18 22

Page 23: Sequential Logic Design - GitHub Pages

AbstractSchematicoftheMIPSCPU

5/24/18 Matni,CS64,Sp18 23

Page 24: Sequential Logic Design - GitHub Pages

RegisterObjectforLab8(Task2)

5/24/18 Matni,CS64,Sp18 24

I/OName I/ODescription

R0Thefirstregistertoread,asasinglebit.If0,thenreg0shouldberead.If1,thenreg1shouldberead.

R1Thesecondregistertoread,asasinglebit.If0,thenreg0shouldberead.If1,thenreg1shouldberead.

WR

“WriteRegister”.Specifieswhichregistertowriteto.If0,thenreg0shouldbewrittento.If1,thenreg1shouldbewrittento.

WThedatathatshouldbewrittentotheregisterspecifiedbyWR.Thisisasinglebit.

WE

“WriteEnable”.If1,thenwewillwritetoaregister.If0,thenwewillnotwritetoaregister.NotethatifWE=0,thentheinputstoWRandWareeffectivelyignored.

O1

Valueofthefirstregisterread.Asdescribedpreviously,thisdependsonwhichregisterwasselectedtoberead,viaR0.

O2

Valueofthesecondregisterread.Asdescribedpreviously,thisdependsonwhichregisterwasselectedtoberead,viaR1.

ThiswillbemadefromD-FFsorD-LatchesandCombinatorialLogic

Page 25: Sequential Logic Design - GitHub Pages

MemoryInterfaceObjectforLab8

5/24/18 Matni,CS64,Sp18 25

I/OName I/ODescription

A0 Bit0oftheaddress(LSB)

A1 Bit1oftheaddress(MSB)

OE

“OutputEnable”.If1,thenthevalueattheaddressspecifiedbyA0andA1willberead,andsenttotheoutputlineO.If0,thenthememorywillnotbeaccessed,andthevaluesenttotheoutputlineisunspecified(couldbeeither0or1,inanunpredictablefashion).

W Thevaluetowritetomemory.

WE

“WriteEnable”.If1,thenthevaluesentintoWwillbewrittentomemoryattheaddressspecifiedbyA0andA1.If0,thennomemorywriteoccurs(thevaluesenttoWwillbeignored).

O Thevaluereadfrommemory(orunspecifiedifOE=0).

Page 26: Sequential Logic Design - GitHub Pages

Task3:BuildaMock-CPU!

5/24/18 Matni,CS64,Sp18 26

Actually, just a small instruction decoder and executor…

OP1 OP0 B0 B1 B2 Human-readableEncoding Description

0 0 0 0 0 xorreg0,reg0,reg0 ComputetheXORofthecontentsofreg0withthecontentsofreg0,storingtheresultinreg0.

0 1 1 0 1 norreg1,reg0,reg1 ComputetheNORofthecontentsofreg0withthecontentsofreg1,storingtheresultinreg1.

1 0 1 0 1 loadreg1,01 Copythebitstoredataddress01(decimal1)intoregisterreg1.

1 1 0 1 0 storereg0,10 Storethecontentsofreg0ataddress10(decimal2)1 1 1 1 1 storereg1,11 Storethecontentsofreg1ataddress11(decimal3)

ThesesaysomethingaboutwhichoperationisbeingdoneThesesaysomethingaboutwhichregistersareused

Page 27: Sequential Logic Design - GitHub Pages

HintsforTask3•  Designthefinalcircuitinpieces:

–  Onepieceforeachofthe3typesofinstruction:load,store,XOR/NOR

•  Forexample,thestoretask:–  Ifanoutputisn’tused,tieittoapermanent“0”(i.e.ground)–  Ifaninputisn’tused,thenyoucanuse“X”(don’tcare)onit

5/24/18 Matni,CS64,Sp18 27

WhatregistersamIusing?Whichinstructionbitsgowhere?

WhatcontrolsshouldIuse?Whatvaluesshouldtheybe?

HowdoIbestconnecttheregisterstothememoryinterface?Again,askyourselfifsomeoftheinputshereshouldbeop-codebits.

Istheoutputevenusedinthis“store”task?

Page 28: Sequential Logic Design - GitHub Pages

TyingInAllThePieces(Task3)

•  Nowseehowtheycanallfittogether–  Youwillhave1registerblock+1memoryinterface–  Youwon’tneedtouseanyadditionallatcheshere–  Youwillneedtousemuxesandregularlogic(andthesimpleALUyoudesignedearlier–seelabinstructionsformoredetails)

•  REQUIREMENT:UseONLY1registerblock,1ALU,and1memoryinterface

5/24/18 Matni,CS64,Sp18 28

Page 29: Sequential Logic Design - GitHub Pages

YourToDos

•  Lab#7isdueendofdayFriday

•  Lab#8willbeissuedthisweekend– DueMonday6/4

•  Lab#9willbeissuedweekendafternext– DueFriday6/8(lastdayofclasses)

•  Lab#10willbeissuedinthelastweek– DueFriday6/8(lastdayofclasses)

5/24/18 Matni,CS64,Sp18 29

Page 30: Sequential Logic Design - GitHub Pages

5/24/18 Matni,CS64,Sp18 30