Karnaugh Maps

advertisement
Karnaugh Maps
To begin, it is easiest to simply view the Karnaugh map (or K-map for short)
as an alternative representation of the truth table.
Returning to the example we considered earlier, ‘Can I go out tonight?’ The
three variables which determined whether or not we could were: Money (M) –
do I have any? Is it raining? (R), and do I have a coat? (C).
We produced a truth table:
M
R
C
T
0
0
0
0
0
0
1
0
0
1
0
0
0
1
1
0
1
0
0
1
1
0
1
1
1
1
0
0
1
1
1
1
And from the truth table we wrote the canonical sum of products:
T = M/R/C + M/RC + MRC
and then, using the rules of Boolean algebra, we minimised this expression
T= M(/R/C + /RC + RC)
= M(/R/C + C)
= M(/R + C)
= M/R + MC (this is the ‘Minimal Sum of Products’)
This is fine if we are good at Boolean algebra, but it is not always obvious how
to derive the minimal sum of products.
The Karnaugh map bypasses the Boolean algebra and, with a little practice,
enables us to generate minimal expressions quickly and easily.
Our problem has three variables (M,R,C) so let’s begin by drawing a 3
variable Karnaugh map.
MR
C
00
01
11
10
0
1
Each square on the K-map corresponds to a row of the truth table – the truth
table has eight rows and the K-map has eight squares. Notice how the
numbers describing M and R are arranged along the top of the map. This
order is important – you may have encountered this (Gray code) sequence
elsewhere.
Now look at the truth table, there are three rows where T = 1. These
coorrespond to M,R, and C having the values 100, 101, and 111.
We can plot these onto the K-map:
MR
00
C
01
11
0
1
10
1
1
1
Make sure that you understand what we’ve done here. By convention we
don’t bother to fill in the other squares. If they are not 1s they must be 0s so
why waste effort writing the 0s?
So far the truth table and the K-map are simply two different tables which say
exactly the same thing, but the layout of the K-map enables us to do
something clever:
We form groups of 1 squares on the map according to the rules:
Adjacent squares can be grouped, where adjacent means up, down,
left, right.
The groups formed must be of size 2n (1, 2, 4, 8 etc.)
Following these rules we can produce two overlapping (the square MRC =
101 is common to both) groups as shown:
MR
00
C
01
11
0
1
10
1
1
1
The next trick is to figure out a description for these two groups. Beginning
with the right hand column, notice that the group fills the entire column so we
need a description of the entire column. Now look at the numbers along the
top of the K-map. Hopefully you will spot that ‘10’ describes the column in
question, i.e. M=1 and R=0, in other words the column is called M/R and so is
the group.
The next group isn’t as easy. It isn’t a whole column (or a whole row). Look at
the shaded area for this group on the K-map and look carefully at the two
columns it straddles. You should spot that M = 1 in both columns. The two
columns together can be described by M = 1, or simply M.
The row is easy; C = 1 in the row we are looking at, so the row is C.
The group lies on the intersection of two columns (M) and the C=1 row. If you
are familiar with set theory; Venn diagrams etc. it helps a little. A union on the
K-map is a logical OR and an intersection is a logical AND
We said an intersection on the K-map is equivalent to a logical AND, so our
group is the intersection of M with C,i.e. MC.
So there we have it, two groups: M/R, MC
We bring the groups together (this is a union) so we OR them and the result
is:
T = M/R + MC
If you’ve followed this so far, check your wallet, get your coat and go out. You
deserve it!
We’ve only considered groups on the K-map very briefly – it gets more
complicated!
In general we look for:
•
•
The biggest possible groups
As few groups as possible
The reason we want as few groups as possible is because each group
corresponds to a term in the final expression; the less we have then the
simpler our circuit is to build. It might not be immediately obvious why we want
big groups but by forming groups of 2n squares we eliminate n variables.
In our example we began with three variables (M,R, and C) and we identified
two groups of two. A group of two means that we will eliminate one variable
because 21=2. This can also provide a useful check to determine whether or
not our description of the group is correct. In the example, if our groups were
described by anything other than two variables we’d know immediately that
we’d made a mistake.
When we talked about adjacency we didn’t quite complete the picture, we
made the point that adjacency only applies in the vertical and horizontal
directions (i.e. not diagonal) but a less than obvious characteristic of the Kmap is that the left and right edges of the map are adjacent, and so are the
top and bottom edges. It might help you to think of the K-map not as a flat
rectangle but as the surface of a torus (a doughnut) which has been cut open
and flattened.
Consider a three variable map like the one from our example:
AB
00
C
01
11
10
0
1
The shaded areas are adjacent, so if we had a K-map:
AB
00
C
0
01
11
1
10
1
1
We can form a group from the two adjacent squares:
AB
00
C
0
1
1
01
11
10
1
Let’s find a description for this group; think about where the group lies – it is
the intersection (AND) of the outer two columns and the top row. Looking
carefully at the columns we see that B=0 in both of them, so the two columns
taken together may be described by /B. The top row has C=0, in other words it
is /C so a description of the group is /BC. Notice again how we have lost a
variable.
A slightly simpler example:
AB
00
C
01
11
10
0
1
1
1
1
1
In this example we have a group of four which occupies the outer columns.
We have just determined that these columns are described by /B so our group
is simply /B. Notice we have a group of four (22) and have lost two variables.
You are probably suspicious about this so lets look at the example in a
different way. This time we’ll pick two groups of two:
AB
00
C
01
11
10
0
1
1
1
1
1
The left hand group is /A/B and the right hand group is A/B. So a ‘solution’
from the K-map could be:
T = /A/B + A/B
but we notice that this can be simplified:
T = /B(A + /A)
A + /A = 1, so T = /B
In general, if you don’t identify the largest possible groups you don’t produce a
‘wrong’ answer but it isn’t minimal.
With practice, working with K-maps becomes second nature but there are a
few tricks worth knowing to make life easier.
Imagine we had the following truth table:
A
B
C
T
0
0
0
1
0
0
1
1
0
1
0
1
0
1
1
1
1
0
0
1
1
0
1
1
1
1
0
1
1
1
1
0
We can transfer this to the K-map by looking at each term where T = 1 (the
minterms) and plotting each 1 onto the K map individually.
AB
00
01
11
10
0
1
1
1
1
1
1
1
C
1
It would have been far easier to look at the truth table and spot that only one
row exists where T = 0. If we identify where this is on the K-map then we
know that all of the other squares must contain a 1!
You should be able to identify three groups of four on the K-map:
AB
00
01
11
10
0
1
1
1
1
1
1
1
C
1
Using the same approach as previously, we end up with:
T = /A + /B + /C
Spotting large groups which overlap isn’t always easy but in this example the
single empty (0) square stands out like a sore thumb, so let’s look at that
instead.
AB
00
01
11
10
0
1
1
1
1
1
1
1
0
1
C
By focussing on the 0 square (or squares in some cases) we can generate an
expression for /T. In this example we can’t group any 0 squares, the solitary 0
is described by ABC.
so /T = ABC
T = /(ABC)
We might stop here, but you will remember from De Morgan’s theorem that
we can write this another way:
T = /A + /B + /C
The two approaches have produced the same result.
Four and more variables
So far we’ve only considered K-maps with three variables. Four variable maps
are no more difficult to work with, you might even find them easier because of
their inherent symmetry. It is possible to work with five and six variable maps
but this isn’t a trivial task and is an exercise which should be left until you
really need to do it.
The following diagram illustrates a four variable K-map.
AB
CD
00
01
11
10
00
01
11
10
To illustrate the use of the four variable map let’s take a look at a completely
contrived example:
AB
CD
00
01
11
10
00
1
1
01
1
1
11
1
1
10
1
1
We perform the grouping just as before and identify two groups of four:
AB
CD
00
01
11
10
00
1
1
01
1
1
11
1
1
10
1
1
In the back of your mind you should be thinking, ‘Group of four..., 22 = 4...,
lose two variables..., start with four, so end up with two.’
First we’ll look at the group shaded light grey at the top right of the map. It sits
at the intersection of the top two rows and the rightmost two columns.
CD
AB
00
01
11
10
00
1
1
01
1
1
11
10
Starting with the columns, look carefully at the numbers along the top of the
map. A =1 in both of these columns so we can call the two columns together
‘A’. Looking at the rows we observe that C=0 in both rows, so the two rows
together are ‘/C’. Our group sits on the intersection (AND) so it is described as
A/C.
The other group is much the same – it sits on the intersection of the leftmost
two columns and the bottom two rows.
AB
CD
00
01
11
1
1
10
1
1
11
10
00
01
Looking at the columns we note that A=0 in both of them so together we can
call them ‘/A’. Similarly C=1 in both of the rows, so they are ‘C’, and the group
is /AC.
The two groups together are:
A/C + /AC
At risk of confusing the issue this could have been easier. Let’s look again at
the second group:
Starting with the columns, we don’t need to give them a second thought.
We’ve already decided that the other two columns (in the first group) are A so
these must be /A. Similarly for the rows, we figured out that the top two are /C
so the bottom two must be C.
Don’t cares
Although each square in the K-map must be filled with a 1 or a 0, in some
cases it doesn’t matter which. We mark this on the K-map with a ‘X’ and then
when we form groups we can choose whether X=1 or X=0 to make the best
groupings. At first this can be a little difficult to understand, but a simple
example (the one found in nearly all textbooks!) should make it clear.
Earlier we looked at the Binary Coded Decimal (BCD) number system. In this
scheme we use four bits to represent a decimal digit. From 0 which has the bit
pattern 0000 up to 9 which is represented by 1001. BCD is redundant in that
the bit patterns 1010, 1011, 1100, 1101, 1110, and 1111 do not occur.
Suppose that we are to build a circuit which accepts a four bit BCD number as
its input and displays the decimal number on a display. This is a fairly daft
thing to do because we could simply buy a chip to do it! The diagram
illustrates what we are trying to do.
In this diagram we have a chip, a ‘seven segment’ display, and a hexadecimal
keypad. Only the numbers 0 to 9 have any meaning to the chip as these are
the only numbers which can be displayed. The hexadecimal numbers A to F
will generate nonsensical outputs as the following example illustrates.
The chip labelled 46 (which is short for 7446) is called a BCD to 7 segment
decoder. Let’s look at how we might design a circuit which does the same
thing.
We need to consider each segment of the display separately, so in fact, we
need to design seven separate circuits. By convention, the segments of the
display are labelled a to g as shown below.
a
f
b
g
e
c
d
Let’s consider segment a. With a little thought we can determine that segment
a will illuminate to display the numbers: 0,2,3,5,7,8,9. In the diagram, the BCD
number is represented by the four bits A,B,C, and D of which A is the least
significant etc. Now we can draw a truth table for segment a.
Decimal
D C B A
a
0
0
0
0
0
1
1
0
0
0
1
0
2
0
0
1
0
1
3
0
0
1
1
1
4
0
1
0
0
0
5
0
1
0
1
1
6
0
1
1
0
0
7
0
1
1
1
1
8
1
0
0
0
1
9
1
0
0
1
1
-
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
Because values greater than 9 should never appear at the input, we don’t
care what the corresponding output would be – hence the Xs in the truth
table. Now we can draw a K-map:
DC
BA
00
00
01
11
10
X
1
1
X
1
1
X
X
X
X
1
01
11
1
10
1
Now we can decide what to do with the Xs. We have a completely free choice,
and in this case we can form a group of eight squares if we pretend that they
are 1s. Our K-map grouping should look like:
BA
DC
00
01
11
10
X
1
1
X
1
1
X
X
X
X
00
01
11
1
10
1
We have one group of eight and three groups of four which gives:
a = D + CA + BA + /C/A
If the Xs were not there (which amounts to calling them 0s) we would have
four groups of two, in which case the simplest expression we could derive
would be:
a = D/C/B + /DCA + /DBA + /D/C/A
Clearly it is in our interest to use the Xs wisely. In this case we set all of them
to 1 but some can be 1 and some can be 0. Our aim in forming groups is to
create the largest possible groups and the smallest possible number of
groups. We can do whatever we want with the Xs to achieve this.
Download