62
Lecture 4 Nand, Nor Gates, Circuit Minimization and Karnaugh Maps Prof. Sin-Min Lee Department of Computer Science

Lecture 4 Nand, Nor Gates, Circuit Minimization and Karnaugh Maps

Embed Size (px)

DESCRIPTION

CS147. Lecture 4 Nand, Nor Gates, Circuit Minimization and Karnaugh Maps. Prof. Sin-Min Lee Department of Computer Science. Boolean Algebra to Logic Gates. Logic circuits are built from components called logic gates. The logic gates correspond to Boolean operations +, *, ’. - PowerPoint PPT Presentation

Citation preview

Page 1: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

Lecture 4 Nand, Nor Gates,Circuit Minimization

and Karnaugh Maps

Prof. Sin-Min Lee

Department of Computer Science

Page 2: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

Boolean Algebra to Logic Gates

• Logic circuits are built from components called logic gates.

• The logic gates correspond to Boolean operations +, *, ’.

• Binary operations have two inputs, unary has one

OR+

AND*

NOT’’

Page 3: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

Logic Circuits ≡ Boolean Expressions• All logic circuits are equivalent to Boolean expressions and any boolean expression can be

rendered as a logic circuit.• AND-OR logic circuits are equivalent to sum-of-products form.• Consider the following circuits:

A

CB

ABC ABC

A*B

y=ABC+AB*C+A*B

Y

A

B

C

Y

Y=AB*+B*C

AB*C

Page 4: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

NAND and NOR Gates

• NAND and NOR gates can greatly simplify circuit diagrams. As we will see, can you use these gates wherever you could use AND, OR, and NOT.

NAND

NOR

A B AB

0 0 1

0 1 1

1 0 1

1 1 0

A B AB

0 0 1

0 1 0

1 0 0

1 1 0

Page 5: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

XOR and XNOR Gates• XOR is used to choose between two mutually exclusive

inputs. Unlike OR, XOR is true only when one input or the other is true, not both.

XOR

XNOR

A B AB

0 0 0

0 1 1

1 0 1

1 1 0

A B A B

0 0 1

0 1 0

1 0 0

1 1 1

Page 6: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

NAND and NOR as Universal Logic Gates

• Any logic circuit can be built using only NAND gates, or only NOR gates. They are the only logic gate needed.

• Here are the NAND equivalents:

Page 7: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

NAND and NOR as Universal Logic Gates (cont)

• Here are the NOR equivalents:

• NAND and NOR can be used to reduce the number of required gates in a circuit.

Page 8: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

Example Problem• A hall light is controlled by two light switches, one

at each end. Find (a) a truth function, (b) a Boolean expression, and (c) a logic network that allows the light to be switched on or off by either switch.

x y f(x,y)

0 0 0

0 1 1

1 0 1

1 1 0

(What kind of gate has this truth table?

Let Let xx and and yy be the switches: be the switches:

Page 9: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

Example (cont)

• One possible equation is the complete sum-of-products form:

f(X,Y) = XY* + X*Y• Use The Most Complex Machine xLogicCircuit

Module to implement the

equation.

x y f(x,y)

0 0 0

0 1 1

1 0 1

1 1 0

Page 10: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

How to use NAND gates to build an OR gate?

Truth TableA B C D Q

0 0 1 1 0

0 1 1 0 1

1 0 0 1 1

1 1 0 0 1Hint 1 : Use 3 NAND gates

Hint 2 : Use 2 NAND gates to build 2 NOT gates

Hint 3 : Put the 3rd NAND gate after the 2 “NOT” gates

A

B

C

DQ

Page 11: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

How to use NAND gates to build a NOR gate?

Truth TableA B C D E Q

0 0 1 1 0 1

0 1 1 0 1 0

1 0 0 1 1 0

1 1 0 0 1 0

A

B

C

DQ

E

Hint 4 : Put the “NOT” gate after “OR” gate

Hint 3 : Use a NOR gate to build a NOT gate

Hint 2 : Use 3 NAND gates to build an OR gate

Hint 1 : Use 4 NAND gates

Page 12: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps
Page 13: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

How to use NOR gate to build a NOT gate?Truth Table

A B C Q

0 0 0 1

1 1 1 0Hint!

Link inputs B & C together (to a same source).

A Q

B

C

When A = 0, B = C = A = 0When A = 1, B = C = A = 1

Page 14: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

How to use NOR gates to build an OR gate?Truth Table

Hint 1 : Use 2 NOR gates

AQ

B

C

Hint 2 : From a NOR gate, build a NOT gate Hint 3 : Put this “NOT” gate after a NOR gate

D

E

A B C D E Q

0 0 1 1 1 0

0 1 0 0 0 1

1 0 0 0 0 1

1 1 0 0 0 1

NOR NOT

Page 15: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

How to use NOR gates to build an AND gate?Truth Table

Hint 1 : Use 3 NOR gatesHint 2 : From 2 NOR gates, build 2 NOT gates Hint 3 : Each “NOT” gate is an input to the 3rd NOR gate

A B C D Q

0 0 1 1 0

0 1 1 0 0

1 0 0 1 0

1 1 0 0 1

A

B

C

D

Q

Page 16: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

How to use NOR gates to build a NAND gate?Truth Table

Hint 2 : Use 3 NOR gates to build a NAND gate (previous lesson)

Hint 3 : Use the 4th NOR gate to build a NOT gate

Hint 4 : Insert “NOT” gate after “NAND” gate

Hint 5 : NOT-NAND = AND

Hint 1 : Use 4 NOR gates

A

B

C

DQ

E A B C D E Q

0 0 1 1 0 1

0 1 1 0 0 1

1 0 0 1 0 1

1 1 0 0 1 0

Page 17: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

How to use NAND gates to build a NOT gate?Truth Table

Hint! Link inputs B & C together (to a same source).

When A = 0, B = C = A = 0When A = 1, B = C = A = 1

A Q

C

B A B C Q

0 0 0 1

1 1 1 0

Page 18: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

How to use NAND gates to build an AND gate?Truth Table

AQ

B

A B C Q

0 0 1 0

0 1 1 0

1 0 1 0

1 1 0 1

C

Hint 1 : Use 2 NAND gatesHint 2 : From a NAND gate, build a NOT gate

Hint 3 : Put this “NOT” gate after a NAND gate

NAND NOT

Hint 4 : NOT-NAND = AND

Page 19: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

How to use NAND gates to build an OR gate?Truth Table

A B C D Q

0 0 1 1 0

0 1 1 0 1

1 0 0 1 1

1 1 0 0 1Hint 1 : Use 3 NAND gates

Hint 2 : Use 2 NAND gates to build 2 NOT gates

Hint 3 : Put the 3rd NAND gate after the 2 “NOT” gates

A

B

C

DQ

Page 20: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

How to use NAND gates to build a NOR gate?Truth Table

A B C D E Q

0 0 1 1 0 1

0 1 1 0 1 0

1 0 0 1 1 0

1 1 0 0 1 0Hint 1 : Use 4 NAND gates

Hint 2 : Use 3 NAND gates to build an OR gate

Hint 3 : Use a NOR gate to build a NOT gate

A

B

C

DQ

E

Hint 4 : Put the “NOT” gate after “OR” gate

Page 21: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps
Page 22: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps
Page 23: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps
Page 24: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

Since functions can be represented by a sum of product form of minterms, any function can be shown in the map by placing each a 1 in each square which represents a minterm in the function.

EXAMPLE: Draw the map for f = X + Y

1. Determine which minterms are needed by using truth table.

X Y f = X + Y minterm0 0 0 m0

0 1 1 m1

1 0 1 m2

1 1 1 m3

Page 25: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

2. Draw the map and place a 1 in each square for required minterms.

1 1

1

1Y

X

0

X 1

Y

f = X + Y = m1 + m2 + m3 = X´ Y + X Y´ + X Y

Page 26: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

Use the 2-Variable Karnaugh Mapfor Minimization

Example: Given f (X,Y) = (0, 2)

Find: Simplified sum of products

XY

X

Y

m0

m2 m3

m1

Page 27: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

2-Variable Karnaugh Map

1. Place the 1’s corresponding to the minterms on the map.

XY

X

Y

1

1 0

0

f (X,Y) = (0, 2)

Page 28: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

2-Variable Karnaugh Map

2. Now group the 1’s into columns or rows; in this casewe can group them in the first column.

XY

X

Y

1

1 0

0

f (X,Y) = (0, 2)

3. This column is Y´ so the simplified function f (X,Y) = Y´

Page 29: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

2-Variable Karnaugh Map

Example 2: Given f (X,Y) = (0, 2, 3)

Find: Simplified sum of products

XY

X

Y

m0

m2 m3

m1

Page 30: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

2-Variable Karnaugh Map

Example 3: Given f (X,Y) = (0, 1)

Find: Simplified sum of products

XY

X

Y

m0

m2 m3

m1

Page 31: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

Three Variable Map

m0 m1 m3 m2

m4 m5 m7 m6

X´ Y´ Z´ X´ Y´ Z X´ Y Z X´ YZ´

X Y´ Z´ XY´Z X Y Z X Y Z´1X

0

0 0 0 1 1 1 10

Y

YZX

Z

Page 32: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

There are 2N = 23 = 8 squares.

The minterms are arranged so that only one variable changes from 0 to 1 or from 1 to 0 as you move from square to square in the vertical or horizontal direction.

For any two adjacent squares, only one literal changes from complemented to non-complemented (normal).From this property the left and right ends of the map are “adjacent.”

Three Variable Map

Page 33: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

Using the distributive and complement properties, any two adjacent minterms can be combined and simplified to a single term with one less literal.

X´Y´Z´ X´ Y´ Z X´ Y Z X´ Y Z´

X Y´Z´ X Y´ Z X Y Z X YZ´1X

0

0 0 0 1 1 1 10

Y

YZX

Z

Page 34: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

Example: combine adjacent squares for X´ Y´ Z and XY´Z

X´Y´ Z + XY´Z = Y´ Z ( X´ + X) = Y´ Z · 1 = Y´ Z

Example: Combine adjacent squares for X Y´Z´ and X YZ´

XY´Z´ + X YZ´ = X Z´ ( Y´ + Y) = X Z´ · 1 = X Z´

Combining terms on the Karnaugh Map simplifies Boolean functions.

X´Y´Z´ X´ Y´ Z X´ Y Z X´ Y Z´

X Y´Z´ X Y´ Z X Y Z X YZ´1X

0

0 0 0 1 1 1 10

YYZ

X

Z

Page 35: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

Example: Simplify f = X´Y´ Z´ + X Y Z + X´Y´ Z + X´ Y Z

1X

0

0 0 0 1 1 1 10

Y

YZX

f = X´Y´ + Y Z

Z

1

1

1 1

Page 36: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

Even if the function is not in its simplest form, we can stilluse the map to simplify it further.

Example: Simplify f = X´ Y´ + Y´ Z + X´ Z + X Y Z

1X

0

0 0 0 1 1 1 10

Y

YZX

Z f = Z + X´ Y´ (by further grouping of minterms)

1 1

1

1

1

Page 37: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

3-Variable Karnaugh Map

Example: Given f (X,Y,Z) = (0, 2, 3, 4, 7)

Find: Simplified sum of products

XYZ

X

Y

m0

m4m5 m7

m6

m2m3m1

Z

Page 38: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

3-Variable Karnaugh Map

Example: Given f (X,Y,Z) = (0, 2, 3, 4, 7)

Simplified sum of products: f = YZ + YZ + XY

XYZ

X

Y

1

1 0 1 0

110

Z

Page 39: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

Truth Table

f (X,Y,Z) = (0, 2, 3, 4, 7)

Simplified sum of products: f = Y´Z´ + YZ + X´Y

0 0 0 10 0 1 0 0 1 0 10 1 1 11 0 0 11 0 1 01 1 0 01 1 1 1

The truth table for f:

X Y Z f

Page 40: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

f

Y

Z

Y

Z

X

f (X,Y,Z) = (0, 2, 3, 4, 7) = Y´Z´ + YZ + X´Y

Y

Page 41: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

3-Variable Karnaugh Map

Example 2: Given f (X,Y,Z) = (2, 3, 4, 5)

Find: Simplified sum of products

XYZ

X

Y

m0

m4m5 m7

m6

m2m3m1

Z

Page 42: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

3-Variable Karnaugh Map

Example 2: Given f (X,Y,Z) = (1, 2, 5, 6, 7)

Find: Simplified sum of products

XYZ

X

Y

m0

m4m5 m7

m6

m2m3m1

Z

Page 43: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

3-Variable Karnaugh Map

Example 3: Given f (X,Y,Z) = X´Z + X´Y + XY´Z + YZ

Find: “Sum of minterms” expression

XYZ

X

Y

m0

m4m5 m7

m6

m2m3m1

Z

Page 44: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

X Y f0 0 0 0 1 11 0 11 1 0

Exclusive OR XOR

f = X´Y + XY´ = X Y

Page 45: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

Exclusive OR

f (X,Y) = (1, 2) = X Y

XY

X

Y

0

1 0

1

Page 46: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

XOR Truth Table

f (X,Y,Z) = X Y Z = (1, 2, 4, 7)

0 0 0 00 0 1 1 0 1 0 10 1 1 01 0 0 11 0 1 01 1 0 01 1 1 1

The truth table for f:

X Y Z f

Page 47: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

Exclusive OR

Y

X

Zf (X,Y,Z) = X Y Z

Page 48: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

Four Variable Map

m0 m1 m3 m2

m4 m5 m7 m6

m12 m13 m15 m14 m8 m9 m11 m10

W x´y´z

01

W

00

0 0 0 1 1 1 10YZ

WX

Z

11

10

Y

w x y´z

X

Page 49: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

N = 4 variables 2N = 24 = 16 square (minterms)

Row and column are numbered using a reflected-code sequence. The minterm number can be obtained by concatenation of the row and column number .

Example: Row 4 = 10, Column 2 = 01 giving 1001 = 9 decimal for W X´ Y´ Z.

Four Variable Map

Page 50: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

wx´y´z 1 1wx´y´z´

1 1

01

00

0 0 0 1 1 1 10 YZ

11

10

wx´y´z´ w´x´y z´

W

X

Z

Notice that top and bottom edges and right and left edges are “adjacent.”

Y

Page 51: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

1 square = a term with 4 literals2 square = a term with 3 literal 4 square = a term with 2 literals 8 square = a term with 1 literal 16 square = a function equal to 1

Z

WX

Y

01

00

0 0 0 1 1 1 10YZ

11

10

X

W

Page 52: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

Z

WX

Y

01

00

0 0 0 1 1 1 10YZ

11

10

X

Simplify: f (W, X, Y, Z) = W X´ Z + W X Z + W´ Y Z

f = W Z + Y Z f = Z ( W + Y)

W

Page 53: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

Simplify: f (W, X, Y, Z) = ( 0, 1, 4, 5, 6, 8, 9, 12, 13, 14)

f = Y´ + WZ´ + XZ´

Z

W

Y

01

00

0 0 0 1 1 1 10YZ

11

10

X

8 square 4 square 4 square

WX

Page 54: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

Simplify: f = W´ X´ Y´ + X´Y Z´ + W´ X Y Z´ + W X´ Y´

f = X´ Z´ + X´ Y´ + W´ Y Z´

Z

WX

Y

01

00

0 0 0 1 1 1 10YZ

11

10

X

Page 55: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

Simplification of kmap

• Generate all PIs

• Find EPIs

• If EPIs can cover all minterms, then it is answer. Otherwise choose some non-essential PIs (which has less cost) such that all minterms are cover.

Page 56: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

Step 1

• Generate PIs– Blue circle are PIs

– They are the largest circle you can drawn on kmap

1 1

1 1

1 1

1

1 1

00 01

00

01

11

10

x1x2

x3x4

0

1

3

2

4

5

7

6

12

13

15

14

8

9

11

10

11 10

Page 57: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

Step 2

• Find EPIs– Red circle are EPIs

• Minterm 5, 14, 11 can only be cover by these 3 red circle 1 1

1 1

1 1

1

1 1

00 01

00

01

11

10

x1x2

x3x4

0

1

3

2

4

5

7

6

12

13

15

14

8

9

11

10

11 10

Page 58: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

Step 3

• EPIs cannot cover minterm 7– Choose between

green/blue circle to cover minterm 7

– Green is chosen as it is larger

• Less cost

1 1

1 1

1 1

1

1 1

00 01

00

01

11

10

x1x2

x3x4

0

1

3

2

4

5

7

6

12

13

15

14

8

9

11

10

11 10

Page 59: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

Final

• Final result is obtained– x3x4’ + x2’x3 + x1’x3 + x2x3’x4

1 1

1 1

1 1

1

1 1

00 01

00

01

11

10

x1x2

x3x4

0

1

3

2

4

5

7

6

12

13

15

14

8

9

11

10

11 10

Page 60: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

On the K Map a 1 was placed in the squares which representedminterms for a function. The squares not used represent thecomplement of the function. Mark these squares with 0, combine them and read the complement as a sum of productsfunction, f´. Using De Morgan’s Law on f´ will give f, the originalFunction. It will be in a product of sums form.

Example: Determine the Product of sums formfor f ( W, X, Y, Z) = (0, 1, 2, 5, 8, 9, 10)

f´ = W X + YZ + X Z´ from the mapf = (W´ + X´) ( Y´ + Z´) ( X´ + Z) by De Morgan’s

Complement and Product of Sums

Page 61: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

Also, can determine the product of sums form directly fromThe map by recognizing that the 0’s on the map representmaxterms. Remember that a 1 on the edge of the map Represents a complemented literal for maxterms.

Thus, for f ( W, X, Y, Z) = (0, 1, 2, 5, 8, 9, 10)…….

(combine 0’s on k-map)…

f = ( Y´ + Z´) (W´ + X´) ( X´ + Z)

Complement and Product of Sums

Page 62: Lecture 4 Nand, Nor Gates, Circuit Minimization  and  Karnaugh Maps

01

00

0 0 0 1 1 1 10YZ

Z

11

10

Y

0 1 0 0

0 0 0 0

1 1 0 1

W

WX

f = ( Y´ + Z´ ) ( W´ + X´ ) ( X´ + Z)

1 1 0 1