You are on page 1of 37

Logic Minimization with Karnaugh Maps (KMaps)

Boolean algebra can be used to find minimal SOP (POS) logic equations, but it is hard to automate and not very systematic. For small logic functions (<=5 inputs), we can use Karnaugh Map (KMap). KMaps allow us to minimize functions graphically. A KMap is simply an alternative representation to a truth table.

ECE124 Digital Circuits and Systems

Page 1

Logic Minimization with Karnaugh Maps (KMaps)


A KMap contains all the same information as a truth table, but in a different form: While a truth table is tabular, the KMap is arranged as a grid of squares. The coordinates of a square depend on values of the inputs; The contents of any square is 0 or 1 and is the functions output for the corresponding input. In labeling the rows and columns of a KMap, it is important that only 1 variable changes between adjacent rows and columns (i.e., the rows and columns are labeled with grey code counting). We will use examples to both illustrate KMaps and to see how they help us minimize logic equations.

ECE124 Digital Circuits and Systems

Page 2

KMaps (2-Variable Functions)


Consider a logic function with two inputs.

Canoncial SOP using minterms is: Consider presenting the information in the truth table via a 2-D matrix such that all the same information is presented!

This is a 2-variable Karnaugh map.

ECE124 Digital Circuits and Systems

Page 3

KMaps (2-Variable Functions)


We can encompass groups of minterms via rectangles.

Notice: in the first column (where x1 = 0), the function must output a logical 1. Further, note that the value of x2 does not matter (it can be 0 or 1). Similar situation for the second row (where x2 = 1 and the value of x1 does not matter). Each of these rectangles represents a product term for the logic function f. We need to cover all of the 1s of the function so we can write a SOP using product terms. Minimum SOP using product terms is:

ECE124 Digital Circuits and Systems

Page 4

KMaps (3-Variable Functions)


Consider a logic function with three inputs. If represented as a canonical SOP, this logic function would require 4 minterms in the expression.

Represent the same information as a 2-D matrix. This is a 3-variable Karnaugh map.

Note: we always number such that only one variable changes between adjacent columns or rows (Gray codes). Note: columns (and rows) wrap around from left-to-right (top-to-bottom).
Page 5

ECE124 Digital Circuits and Systems

KMaps (3-Variable Functions)


We can enclose 1s for the logic function.
In the 3-rd column, we see the function is 1 with x1=1 and x2=1 regardless of the value of x3; In the 2-nd row, we see the function is 1 with x2=0 and x3 = 1 regardless of the value of x1. Each of the rectangles corresponds to a product term.

Notice that, in adjacent squares, only 1 variable is changing its value.

The SOP of the function using product terms is

ECE124 Digital Circuits and Systems

Page 6

KMaps (More Examples of 3-Variable Functions)


Example 1:

Example 2:

ECE124 Digital Circuits and Systems

Page 7

Some Comments
To properly implement a function using K-Maps, we must make sure to select enough rectangles (product terms) to cover all of the squares for which the function outputs a 1. Rectangles in the K-Map (product terms) are always powers of 2 in terms of area. Minterms are rectangles of area 1 (1x1). Product terms are rectangles of area 2 (1x2,2x1), area 4 (2x2,1x4,4x1), area 8, area 16, etc Every time we can expand a rectangle to enclose additional 1s, we remove a literal from the product term. Note that it is okay to cover an output 1 multiple times!
ECE124 Digital Circuits and Systems Page 8

KMaps (4-Variable Functions)


Consider a function with 4-inputs (truth table not shown).

Enclosing larger squares are better, as it implies fewer literals and product terms.

ECE124 Digital Circuits and Systems

Page 9

KMaps (More Examples of 4-Variable Functions)


Sometimes there are multiple representations for a function that are equally as good in terms of the number of literals and product terms required.

ECE124 Digital Circuits and Systems

Page 10

Watch Out for Corners!


Important to make sure we see all rectangles, especially around the edges and corners.

ECE124 Digital Circuits and Systems

Page 11

KMaps (5-Variable Functions)


Slightly harder to visualize, but still do-able by hand. View one of the 4variable Kmaps to be on top of the other 4-variable Kmap; i.e., we are using the 3-rd axis.
x1x2 x3x4 00 01 11 10 x5=0 x1x2 x3x4 00 01 11 10 x5=1
x1x2

00 1 0 0 0
m4

01 0 1 1 1

11 0 1 1 0

10 1 0 0 0

00 1 0 0 0
m5

01 0 1 1 1

11 0 1 1 0

10 1 0 1 1
01 11

x3x4 00

00

01

11

10 x5=0

m0

m8

m24

m16

m1

m9

m25

m17

x1x2 x3x4 00 01 00 01 11 10 x5=1

m2

m10

m26

m18

m3

m11

m27

m19

10

m6

m14

m30

m22

m7

m15

m31

m23

m12

m28

m20

m13

m29

m21

11 10

ECE124 Digital Circuits and Systems

Page 12

KMaps (5-Variable Functions)


Slightly harder to visualize, but still do-able by hand.

ECE124 Digital Circuits and Systems

Page 13

Some Comments
So far we have used KMaps to find minimized SOP representations for functions. Our general strategy is as follows: Find product terms with as few literals as possible (by finding larger rectangles in the K-Map covering 1s). Select as few rectangles (product terms) as possible, so that all of the 1s in the KMap are covered. It is okay is a 1 is covered by more than one product term. It is possible that there are multiple solutions that are equally as good.

ECE124 Digital Circuits and Systems

Page 14

KMaps for Finding Minimized POS


More or less the same thing as Sum-Of-Products minimization, except We try to surround the 0s in the K-Map, and We AND together the resulting sum terms. An example with four inputs:

A different way to think of enclosing the 0s is that you are finding an SOP for !f, and then taking the complement for get a POS expression for f.

ECE124 Digital Circuits and Systems

Page 15

Dont Cares
Sometimes, we might have inputs and it doesnt matter what the output is; i.e., we dont care what the output is. These situations are called dont cares. Rather than using a 1 or a 0, we can use an X to mark a dont care. Why are dont cares important and useful???

Well, if we are looking for a minimum representation using as few literals and gates as possible, we can force the dont care locations to either 0 or 1, however it helps us.

ECE124 Digital Circuits and Systems

Page 16

Example of Dont Cares


Consider the following four input function where there are three input patterns for which the output can be either 0 or 1, and we dont care which.

For the smallest SOP implementation, it appears good to let one of the dont cares be a 1, while the other 2 are 0.

Question: Is there another equally as good implementation that uses the dont cares differently?
Page 17

ECE124 Digital Circuits and Systems

Logical vs. Algebraic Equivalence

When we have dont cares, we can get equally good expressions that are logically correct (i.e., we get output of 1 when it must be 1, and 0 when it must be 0). However, depending on how we use the dont cares, multiple expressions will not equal each other algebraically.

Note that both f1 and f2 are valid implementations of f, but are not algebraically equal to each other since the dont cares are used differently when finding both f1 and f2.
Page 18

ECE124 Digital Circuits and Systems

Multiple Output/Function Minimization


Sometimes, we might have multiple functions that require minimization.

We can minimize each function individually, but sometimes the overall circuit implementation will be better if we consider both functions simultaneously.
Basically, we will try to find common product terms useful for both functions and then share them.

ECE124 Digital Circuits and Systems

Page 19

Example of Multiple Output/Function Minimization


Consider the following 2, four input functions and the minimal implementation of each function separately.

The functions have no product terms in common. The cost of f_1 is 1 OR + 3 AND + 10 gate inputs = 14. The cost of f_2 is 1 OR + 3 AND + 11 gate inputs = 15. Therefore, to implement the entire circuit the cost is 29.
Page 20

ECE124 Digital Circuits and Systems

Example of Multiple Output/Function Minimization


Consider trying to include some product terms that appear in both K-Maps.

The individual expressions for f1 and f2 are not the best, but If we consider that 2 product terms are shared, the entire circuit requires 2 OR + 4 AND + 17 gate inputs. The total cost of the entire circuit is 23.
Page 21

ECE124 Digital Circuits and Systems

Multiple Outputs Illustrated

ECE124 Digital Circuits and Systems

Page 22

Some More Terminology


Useful to be aware of some terminology

When we have a function and we are told the output is 0 or 1 for every possible input, the function is called completely specified.
When we have a function and are told the output is 0 or 1 for only some of the inputs, we can assume the other inputs have dont cares as outputs. It the situation that we have dont care outputs, the function is incompletely specified. Consider the minterms for any function. We can separate the minterms in to three sets: The on-set is those minterms which require the output to be 1. The off-set is those minterms which require the output to be 0. The dc-set is those minterms which have an output of X (dont care).

ECE124 Digital Circuits and Systems

Page 23

Implicants, Prime Implicants and Covers


A product term is called an Implicant if the logic function outputs a 1 for all minterms in the product term. E.g., all rectangles in a K-Map that contain only 1s are implicants. An Implicant is called a Prime Implicant if the removal of any literal from the implicant results in a new product term that is not an implicant. E.g., Removing any literal from a product term in a K-Map corresponds to increasing the size (doubling the area) of the rectangle. If we cannot increase the size of the rectangle without including a 0, then the implicant is prime. A cover is a collection of implicants that account for all cases in which the function is 1. We can always form a cover using only prime implicants.

ECE124 Digital Circuits and Systems

Page 24

Example of Implicants
In the K-Map, product terms x1 and x2 x3 are prime implicants. Product term x1 x2 is an implicant, but it is not a prime implicant.

ECE124 Digital Circuits and Systems

Page 25

Essential Prime Implicants


A prime implicant is called an Essential Prime Implicant if it includes a minterm that in not found in any other prime implicant. In realizing any function using only prime implicants, all essential prime implicants must be included! If not, we would miss terms for which the function outputs a 1.

ECE124 Digital Circuits and Systems

Page 26

Why all this Terminology?


Understanding implicants, primes and essentials help us form a more methodical procedure for minimization of logic functions. Covers using prime implicants typically have low cost. So to minimize, we should Generate prime implicants. Identify essential prime implicants. Include the essential prime implicants in the cover. If the function is covered, stop. Include as few non-essential prime implicants to finish covering the function. And then stop

ECE124 Digital Circuits and Systems

Page 27

Methodical Example
The following K-Map has 6 prime implicants.
4 of them are essential, 2 are not essential.

ECE124 Digital Circuits and Systems

Page 28

Supplmentary Notes on KMaps


Some people have trouble understanding why the area of the rectangles in the K-map must always double in size when combining boxes, but it important to understand whats happening when you use a K-Map. Understanding K-Maps is important! So, Ill do a simple example here, illustrating what is happening in the K-Map, the truth table and in Boolean Algebra.

ECE124 Digital Circuits and Systems

Page 29

The Example
Say we have the following function with 4-inputs. We can draw the truth table, the K-Map, and write the Canonical SOP using minterms.
x1x2 x3x4 00 01 11 10 00 0 1 1 0
m2

01 0 1 1 1

11 0 1 1 0

10 0 0 0 0

m0

m4

m12

m8

m1

m5

m13

m9

m3

m7

m15

m11

m6

m14

m10

Note that the minterms are 1x1 boxes (area 1) in the K-Map.

ECE124 Digital Circuits and Systems

Page 30

The Example (First Step)


Rearrange and duplicate rows of the truth table so that pairs of rows adjacent to each other produce an output of 1. Make sure only 1 variable changes in these pairs of rows. We can put m1 and m3 next to each other; We can put m5 and m7 next to each other; We can put m13 and m15 next to each other; We can put m6 and m7 next to each other.

ECE124 Digital Circuits and Systems

Page 31

What Happens Algebraically (First Step)?


Since only 1 variable in changing, we can duplicate minterms (which are product terms) and factor out a common part. The result is a set of product terms with some variables removed.

ECE124 Digital Circuits and Systems

Page 32

What Happens In the K-Map (First Step)?


In the K-Map, we see that the 1x1 boxes grow to be boxes of area 2 (i.e., 1x2 or 2x1).
x1x2 x3x4 00 01 11 10 x1x2 x3x4 00 01 11 10

00 0 1 1 0
m2

01 0 1 1 1

11 0 1 1 0

10 0 0 0 0

00 0 1 1 0
m2

01 0 1 1 1

11 0 1 1 0

10 0 0 0 0

m0

m4

m12

m8

m0

m4

m12

m8

m1

m5

m13

m9

m1

m5

m13

m9

m3

m7

m15

m11

m3

m7

m15

m11

m6

m14

m10

m6

m14

m10

The boxes have DOUBLED in size by merging with an adjacent box of compatible dimension. The result are product terms that handles two rows (minterms) in the truth table.

ECE124 Digital Circuits and Systems

Page 33

The Example (Second Step)


Again, rearrange and duplicate rows of the condensed truth table so that pairs of rows adjacent to each other produce an output of 1.

Make sure only 1 variable changes in these pairs of rows.

If a variable was removed and replaced with - previously, then the - must match too!!!
We can put (m1,m3) and (m5,m7) next to each other. (Only x2 changes and doesnt matter; x3 = - in both cases). We can put (m5,m7) and (m13.m15) next to each other. (Only x1 changes and doesnt matter; x3 = - in both cases).

ECE124 Digital Circuits and Systems

Page 34

What Happens Algebraically (Second Step)?


Since only 1 variable in changing, we can duplicate product terms and factor out a common part of the product terms. The result is a set of product terms with some variables removed.

ECE124 Digital Circuits and Systems

Page 35

What Happens In the K-Map (Second Step)?


In the K-Map, we see that (some) of the squares of area two have been expanded to be squares of area 4.

x1x2 x3x4 00 01 11 10

00 0 1 1 0
m2

01 0 1 1 1

11 0 1 1 0

10 0 0 0 0

x1x2 x3x4 00 01 11 10

00 0 1 1 0
m2

01 0 1 1 1

11 0 1 1 0

10 0 0 0 0

m0

m4

m12

m8

m0

m4

m12

m8

m1

m5

m13

m9

m1

m5

m13

m9

m3

m7

m15

m11

m3

m7

m15

m11

m6

m14

m10

m6

m14

m10

The boxes have DOUBLED in size by merging with an adjacent box of compatible dimension. The result are product terms that handles four rows (minterms) in the truth table.

ECE124 Digital Circuits and Systems

Page 36

The Summary
So why do rectangles in the K-Map need to have areas of 1, 2, 4, 8, etc

Given a product term, we need to find another product term involving the same set of variables.
For these two product terms, it must also be true that one and only one variable appears in complemented form in one of the product terms and in un-complemented form in the other product term.

The two product terms get merged by factoring out the common part which gives something like the following:

Therefore, we are always merging pairs (two) of product terms.

Since we begin with minterms (area 1), and merge, and merge, etc. We should see that areas will always double going 1, 2, 4, 8, 16, etc

ECE124 Digital Circuits and Systems

Page 37

You might also like