karnaugh maps and other topic on combinatorial logic · k-map rules summary 1. groups can contain...

40
Karnaugh Maps and Other Topic on Combinatorial Logic CS 64: Computer Organization and Design Logic Lecture #12 Fall 2018 Ziad Matni, Ph.D. Dept. of Computer Science, UCSB

Upload: lykien

Post on 30-Apr-2019

221 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Karnaugh Maps and Other Topic on Combinatorial Logic · K-Map Rules Summary 1. Groups can contain only 1s 2. Only 1s in adjacent groups are allowed 3. Groups may ONLY be horizontal

KarnaughMapsandOtherTopiconCombinatorialLogic

CS64:ComputerOrganizationandDesignLogicLecture#12Fall2018

ZiadMatni,Ph.D.

Dept.ofComputerScience,UCSB

Page 2: Karnaugh Maps and Other Topic on Combinatorial Logic · K-Map Rules Summary 1. Groups can contain only 1s 2. Only 1s in adjacent groups are allowed 3. Groups may ONLY be horizontal

Administrative

•  Lab#7onTuesday•  DuebySundayatmidnight– NotFriday…HappyThanksgiving!

•  NoclassthisWednesday!JJJ

11/18/18 Matni,CS64,Fa18 2

Page 3: Karnaugh Maps and Other Topic on Combinatorial Logic · K-Map Rules Summary 1. Groups can contain only 1s 2. Only 1s in adjacent groups are allowed 3. Groups may ONLY be horizontal

LectureOutline

•  LogicFunctionsandtheirSimplifications:

TruthTableUsevs.KarnaughMaps

11/18/18 Matni,CS64,Fa18 3

Page 4: Karnaugh Maps and Other Topic on Combinatorial Logic · K-Map Rules Summary 1. Groups can contain only 1s 2. Only 1s in adjacent groups are allowed 3. Groups may ONLY be horizontal

ScalingUpSimplification

•  Whenwegettomorethan3variables,itbecomeschallengingtousetruthtables

•  WecaninsteaduseKarnaughMapstomakeitimmediatelyapparentastowhatcanbesimplified

11/18/18 Matni,CS64,Fa18 4

Page 5: Karnaugh Maps and Other Topic on Combinatorial Logic · K-Map Rules Summary 1. Groups can contain only 1s 2. Only 1s in adjacent groups are allowed 3. Groups may ONLY be horizontal

ExampleofaK-MapA B f(A,B)0 0 a0 1 b1 0 c1 1 d

11/18/18 Matni,CS64,Fa18 5

A B f(A,B)0 0 00 1 11 0 11 1 1

0123

Page 6: Karnaugh Maps and Other Topic on Combinatorial Logic · K-Map Rules Summary 1. Groups can contain only 1s 2. Only 1s in adjacent groups are allowed 3. Groups may ONLY be horizontal

K-Mapswith3or4Variables

11/18/18 Matni,CS64,Fa18 6

Notetheadjacentplacementof:00011110

It’sNOT:

00011011

Page 7: Karnaugh Maps and Other Topic on Combinatorial Logic · K-Map Rules Summary 1. Groups can contain only 1s 2. Only 1s in adjacent groups are allowed 3. Groups may ONLY be horizontal

RulesforUsingK-MapsforSimplification

1.  Grouptogetheradjacentcellscontaining“1”2.  Groupsshouldnotincludeanythingcontaining“0”

3.  Groupsmaybehorizontalorvertical,butnotdiagonal

11/18/18 Matni,CS64,Fa18 7

Page 8: Karnaugh Maps and Other Topic on Combinatorial Logic · K-Map Rules Summary 1. Groups can contain only 1s 2. Only 1s in adjacent groups are allowed 3. Groups may ONLY be horizontal

RulesforUsingK-MapsforSimplification

4.   Groupsmustcontain1,2,4,8,oringeneral2ncells.

11/18/18 Matni,CS64,Fa18 8

Page 9: Karnaugh Maps and Other Topic on Combinatorial Logic · K-Map Rules Summary 1. Groups can contain only 1s 2. Only 1s in adjacent groups are allowed 3. Groups may ONLY be horizontal

RulesforUsingK-MapsforSimplification

5.   Eachgroupmustbeaslargeaspossible(Otherwisewe’renotbeingasminimalaswecanbe, eventhoughwe’renotbreakinganyBooleanrules)

11/18/18 Matni,CS64,Fa18 9

Page 10: Karnaugh Maps and Other Topic on Combinatorial Logic · K-Map Rules Summary 1. Groups can contain only 1s 2. Only 1s in adjacent groups are allowed 3. Groups may ONLY be horizontal

RulesforUsingK-MapsforSimplification

6.   Eachcellcontaininga“1”mustbeatleastinonegroup

11/18/18 Matni,CS64,Fa18 10

Page 11: Karnaugh Maps and Other Topic on Combinatorial Logic · K-Map Rules Summary 1. Groups can contain only 1s 2. Only 1s in adjacent groups are allowed 3. Groups may ONLY be horizontal

RulesforUsingK-MapsforSimplification

7.   Groupsmayoverlapesp.tomaximizegroupsize

11/18/18 Matni,CS64,Fa18 11

Page 12: Karnaugh Maps and Other Topic on Combinatorial Logic · K-Map Rules Summary 1. Groups can contain only 1s 2. Only 1s in adjacent groups are allowed 3. Groups may ONLY be horizontal

RulesforUsingK-MapsforSimplification

8.   Groupsmaywraparoundthetable.Theleftmostcellinarowmaybegroupedwiththerightmostcellandthetopcellinacolumnmaybegroupedwiththebottomcell.

11/18/18 Matni,CS64,Fa18 12

Page 13: Karnaugh Maps and Other Topic on Combinatorial Logic · K-Map Rules Summary 1. Groups can contain only 1s 2. Only 1s in adjacent groups are allowed 3. Groups may ONLY be horizontal

Example12vars

F(X,Y)=XY+Y=Y(X+1)=Y

11/18/18 Matni,CS64,Fa18 13

0 1

0

1

YX

1

1

F(X,Y)=Y

Y=1column

Verifyingresults!

Page 14: Karnaugh Maps and Other Topic on Combinatorial Logic · K-Map Rules Summary 1. Groups can contain only 1s 2. Only 1s in adjacent groups are allowed 3. Groups may ONLY be horizontal

Example23vars

F(X,Y,Z)=XZ+Z(X'+XY)=XZ+ZX’+ZXY=Z(X+X’+XY)=Z(1+XY)=Z

11/18/18 Matni,CS64,Fa18 14

00 01 11 10

0

1

XYZ

1111

F(X,Y,Z)=Z

Y=1 X=1

Verifyingresults!

Page 15: Karnaugh Maps and Other Topic on Combinatorial Logic · K-Map Rules Summary 1. Groups can contain only 1s 2. Only 1s in adjacent groups are allowed 3. Groups may ONLY be horizontal

Example33vars

!A!B!C+!A!BC+!ABC+!AB!C+A!B!C+AB!C

11/18/18 Matni,CS64,Fa18 15

00 01 11 10

0

1

ABC

1111

F(X,Y,Z)=!C+!A

1 1

Page 16: Karnaugh Maps and Other Topic on Combinatorial Logic · K-Map Rules Summary 1. Groups can contain only 1s 2. Only 1s in adjacent groups are allowed 3. Groups may ONLY be horizontal

Example44vars

F(A,X,Y,Z)=AX+Z(X+A’+Y)=AX+ZX+ZA’+ZY

11/18/18 Matni,CS64,Fa18 16

00 01 11 10

00

01

11

10

XYAZ

1 1F(A,X,Y,Z)=ZA’+AX+ZY

11

1 1Z=1

A=1

Y=1 X=1

11

1

Page 17: Karnaugh Maps and Other Topic on Combinatorial Logic · K-Map Rules Summary 1. Groups can contain only 1s 2. Only 1s in adjacent groups are allowed 3. Groups may ONLY be horizontal

Example44vars

F(A,B,C,D)=ABCD’+ABC’D+CD+A’B’+C’D

11/18/18 Matni,CS64,Fa18 17

00 01 11 10

00

01

11

10

ABCD

F(A,B,C,D)=A’B’+D+ABC

D=1

C=1

B=1 A=1

1

1

1 1 1 1

1

1

1

1 1

Page 18: Karnaugh Maps and Other Topic on Combinatorial Logic · K-Map Rules Summary 1. Groups can contain only 1s 2. Only 1s in adjacent groups are allowed 3. Groups may ONLY be horizontal

K-MapRulesSummary1.  Groupscancontainonly1s2.  Only1sinadjacentgroupsareallowed3.  GroupsmayONLYbehorizontalorvertical(nodiagonals)4.  Thenumberof1sinagroupmustbeapoweroftwo(1,2,4,8...)5.  GroupsmustbeaslargeANDasfewinno.sas“legally”possible6.  All1smustbelongtoagroup,evenifit’sagroupofoneelement7.  Overlappinggroupsarepermitted8.  Wrappingaroundthemapispermitted

11/18/18 Matni,CS64,Fa18 18

Page 19: Karnaugh Maps and Other Topic on Combinatorial Logic · K-Map Rules Summary 1. Groups can contain only 1s 2. Only 1s in adjacent groups are allowed 3. Groups may ONLY be horizontal

Exploiting“Don’tCares”

•  Anoutputvariablethat’sdesignated“don’tcare”(symbol=X)meansthatitcouldbea0ora1(i.e.we“don’tcare”which)– Thatis,itisunspecified,

usuallybecauseofinvalidinputs

11/18/18 Matni,CS64,Fa18 19

Page 20: Karnaugh Maps and Other Topic on Combinatorial Logic · K-Map Rules Summary 1. Groups can contain only 1s 2. Only 1s in adjacent groups are allowed 3. Groups may ONLY be horizontal

ExampleofaDon’tCareSituation

•  Considercodingalldecimaldigits(say,foradigitalclockapp):– 0thru9---requireshowmanybits?

•  4bits– But!4bitsconveymorenumbersthanthat!

•  Don’tforgetAthruF!

•  Notallbinaryvaluesmaptodecimal

11/18/18 Matni,CS64,Fa18 20

Page 21: Karnaugh Maps and Other Topic on Combinatorial Logic · K-Map Rules Summary 1. Groups can contain only 1s 2. Only 1s in adjacent groups are allowed 3. Groups may ONLY be horizontal

ExampleContinued…

11/18/18 Matni,CS64,Fa18 21

Page 22: Karnaugh Maps and Other Topic on Combinatorial Logic · K-Map Rules Summary 1. Groups can contain only 1s 2. Only 1s in adjacent groups are allowed 3. Groups may ONLY be horizontal

Don’tCare:SoWhat?

•  RecallthatinaK-map,wecanonlygroup1s

•  Becausethevalueofadon’tcareisirrelevant,wecantreatitasa1ifitisconvenienttodoso(ora0ifthatwouldbemoreconvenient)

11/18/18 Matni,CS64,Fa18 22

Page 23: Karnaugh Maps and Other Topic on Combinatorial Logic · K-Map Rules Summary 1. Groups can contain only 1s 2. Only 1s in adjacent groups are allowed 3. Groups may ONLY be horizontal

Example

•  Acircuitthatcalculatesifthe4-bitbinarycodedsingledigitdecimalinput%2==0

•  So,although4-bitswillgivemenumbersfrom0to15,Idon’tcareabouttheonesthatyield10to15.

11/18/18 Matni,CS64,Fa18 23

I3 I2 I1 I0 R

0 0 0 0 1

0 0 0 1 0

0 0 1 0 1

0 0 1 1 0

0 1 0 0 1

0 1 0 1 0

0 1 1 0 1

0 1 1 1 0

1 0 0 0 1

1 0 0 1 0

1 0 1 0 X

1 0 1 1 X

1 1 0 0 X

1 1 0 1 X

1 1 1 0 X

1 1 1 1 X

Page 24: Karnaugh Maps and Other Topic on Combinatorial Logic · K-Map Rules Summary 1. Groups can contain only 1s 2. Only 1s in adjacent groups are allowed 3. Groups may ONLY be horizontal

ExampleasaK-Map

11/18/18 Matni,CS64,Fa18 24

0 1 0 1

Page 25: Karnaugh Maps and Other Topic on Combinatorial Logic · K-Map Rules Summary 1. Groups can contain only 1s 2. Only 1s in adjacent groups are allowed 3. Groups may ONLY be horizontal

IfWeDon’tExploit“Don’tCares”

11/19/18 Matni,CS64,Fa18 25

0 1 0 1

R=I1I0I3+I1I0I3+I0I1I2I3

Page 26: Karnaugh Maps and Other Topic on Combinatorial Logic · K-Map Rules Summary 1. Groups can contain only 1s 2. Only 1s in adjacent groups are allowed 3. Groups may ONLY be horizontal

IfWeDOExploit“Don’tCares”

11/19/18 Matni,CS64,Fa18 26

0 1 0 1

R=I0

Page 27: Karnaugh Maps and Other Topic on Combinatorial Logic · K-Map Rules Summary 1. Groups can contain only 1s 2. Only 1s in adjacent groups are allowed 3. Groups may ONLY be horizontal

CombinatorialLogicDesigns

•  Whenyoucombinemultiplelogicblockstogethertoformamorecomplexlogicfunction/circuit

11/18/18 Matni,CS64,Fa18 27

Whatistheoutput?A.B+C

Whatisitstruthtable?A B C F0 0 0 10 0 1 00 1 0 10 1 1 01 0 0 11 0 1 01 1 0 11 1 1 1

WhatisitsK-Map?00 01 11 10

01

ABC

1 1 111

Page 28: Karnaugh Maps and Other Topic on Combinatorial Logic · K-Map Rules Summary 1. Groups can contain only 1s 2. Only 1s in adjacent groups are allowed 3. Groups may ONLY be horizontal

Exercise1

•  Giventhefollowingtruthtable,drawtheresultinglogiccircuit

– STEP1:DrawtheK-Mapandsimplifythefunction

– STEP2:Constructthecircuitfromthenowsimplifiedfunction

11/18/18 Matni,CS64,Fa18 28

A B C D F0 0 0 0 00 0 0 1 00 0 1 0 00 0 1 1 00 1 0 0 10 1 0 1 00 1 1 0 00 1 1 1 01 0 0 0 01 0 0 1 01 0 1 0 11 0 1 1 11 1 0 0 11 1 0 1 01 1 1 0 11 1 1 1 1

Page 29: Karnaugh Maps and Other Topic on Combinatorial Logic · K-Map Rules Summary 1. Groups can contain only 1s 2. Only 1s in adjacent groups are allowed 3. Groups may ONLY be horizontal

Exercise1–Step1Getthesimplifiedfunction

11/18/18 Matni,CS64,Fa18 29

A B C D F0 0 0 0 00 0 0 1 00 0 1 0 00 0 1 1 00 1 0 0 10 1 0 1 00 1 1 0 00 1 1 1 01 0 0 0 01 0 0 1 01 0 1 0 11 0 1 1 11 1 0 0 11 1 0 1 01 1 1 0 11 1 1 1 1

00 01 11 10

00

01

11

10

ABCD

1 1

11

B=1 A=1

D=1

C=1

F(A,B,C)=B.C’.D’+A.C1 1

Page 30: Karnaugh Maps and Other Topic on Combinatorial Logic · K-Map Rules Summary 1. Groups can contain only 1s 2. Only 1s in adjacent groups are allowed 3. Groups may ONLY be horizontal

Exercise1–Step2Drawthelogiccircuitdiagram

11/18/18 Matni,CS64,Fa18 30

F(A,B,C)=B.C’.D’+A.C

AC

CBD

F

Page 31: Karnaugh Maps and Other Topic on Combinatorial Logic · K-Map Rules Summary 1. Groups can contain only 1s 2. Only 1s in adjacent groups are allowed 3. Groups may ONLY be horizontal

Exercise2

•  Giventhefollowingtruthtable,drawtheresultinglogiccircuit

11/18/18 Matni,CS64,Fa18 31

A B C F0 0 0 10 0 1 10 1 0 10 1 1 01 0 0 11 0 1 11 1 0 01 1 1 0

00 01 11 10

0

1

ABC

111

F(A,B,C)=B’+A’.C’

1 1

B

AC

F

Page 32: Karnaugh Maps and Other Topic on Combinatorial Logic · K-Map Rules Summary 1. Groups can contain only 1s 2. Only 1s in adjacent groups are allowed 3. Groups may ONLY be horizontal

Exercise3

•  Giventhefollowingschematicofacircuit,(a)writethefunctionand(b)filloutthetruthtable:

X=A.B+(A.C)’(notethatalsomeans:X=A.B+A’+C’)

11/18/18 Matni,CS64,Fa18 32

ABAC

X

A.B

(A.C)’

A B C X0 0 0 10 0 1 10 1 0 10 1 1 11 0 0 11 0 1 01 1 0 11 1 1 1

X

Page 33: Karnaugh Maps and Other Topic on Combinatorial Logic · K-Map Rules Summary 1. Groups can contain only 1s 2. Only 1s in adjacent groups are allowed 3. Groups may ONLY be horizontal

Exercise3

•  Giventhefollowingschematicofacircuit,(a)writethefunctionand(b)filloutthetruthtable:

X=A.B+(A.C)’(notethatalsomeans:X=A.B+A’+C’)

11/18/18 Matni,CS64,Fa18 33

ABAC

X

A.B

(A.C)’

A B C X0 0 0 10 0 1 10 1 0 10 1 1 11 0 0 11 0 1 01 1 0 11 1 1 1

Page 34: Karnaugh Maps and Other Topic on Combinatorial Logic · K-Map Rules Summary 1. Groups can contain only 1s 2. Only 1s in adjacent groups are allowed 3. Groups may ONLY be horizontal

Multiplexer•  Alogicalselector:–  SelecteitherinputAorinputBtobetheoutput

//ifs=0,outputisa//ifs=1,outputisbintmux(inta,intb,ints){if(!s)returna;elsereturnb;

}11/18/18 Matni,CS64,Fa18 34

Page 35: Karnaugh Maps and Other Topic on Combinatorial Logic · K-Map Rules Summary 1. Groups can contain only 1s 2. Only 1s in adjacent groups are allowed 3. Groups may ONLY be horizontal

Multiplexer(Muxforshort)

•  Typicallyhas3groupsofinputsand1output–  IN:2data,1select–  OUT:1data

•  1oftheinputdatalinesgetsselectedtobecometheoutput,basedonthe3rd(select)input–  If“Sel”=0,thenI0getstobetheoutput–  If“Sel”=1,thenI1getstobetheoutput

•  TheoppositeofaMuxiscalledaDemulitplexer(orDemux)

11/18/18 Matni,CS64,Fa18 35

Page 36: Karnaugh Maps and Other Topic on Combinatorial Logic · K-Map Rules Summary 1. Groups can contain only 1s 2. Only 1s in adjacent groups are allowed 3. Groups may ONLY be horizontal

MuxConfigurations

11/18/18 Matni,CS64,Fa18 36

MuxescanhaveI/Othataremultiplebits

Ortheycanhavemorethantwodatainputs

2:1

A0A1B0B1SEL

O0O1

Thisiscalleda2-bit,2-to-1mux

6:1

ABCDEFSEL

O

Thisiscalleda1-bit,6-to-1mux

Page 37: Karnaugh Maps and Other Topic on Combinatorial Logic · K-Map Rules Summary 1. Groups can contain only 1s 2. Only 1s in adjacent groups are allowed 3. Groups may ONLY be horizontal

TheUseofMultiplexers

•  Makesitpossibleforseveralsignals(variables)toshareoneresource– Verycommonlyusedindatacommunicationlines

11/18/18 Matni,CS64,Fa18 37Mux De

mux

… …DataLines

DataLines

Select

Shareddataline(“trunk”)

Select

Page 38: Karnaugh Maps and Other Topic on Combinatorial Logic · K-Map Rules Summary 1. Groups can contain only 1s 2. Only 1s in adjacent groups are allowed 3. Groups may ONLY be horizontal

MuxTruthTableandLogicCircuit1-bitMux

I0 I1 S O0 0 00 0 10 1 00 1 11 0 01 0 11 1 01 1 1

11/18/18 Matni,CS64,Fa18 38

00 01 11 10

0

1

I0I1S

1

11

1

O=S.I1+S’.I0

I0I1

S

O

=linesarephysicallyconnected

00011011

Page 39: Karnaugh Maps and Other Topic on Combinatorial Logic · K-Map Rules Summary 1. Groups can contain only 1s 2. Only 1s in adjacent groups are allowed 3. Groups may ONLY be horizontal

YOURTO-DOs

•  Lab#7onTuesday–DuebySundayatmidnight

•  NoclassonWednesday!JJJ

11/18/18 Matni,CS64,Fa18 39

Page 40: Karnaugh Maps and Other Topic on Combinatorial Logic · K-Map Rules Summary 1. Groups can contain only 1s 2. Only 1s in adjacent groups are allowed 3. Groups may ONLY be horizontal

11/18/18 Matni,CS64,Fa18 40