Salta al contenuto
Note per Studenti Karnaugh Maps and Two-Level Minimization Report

Karnaugh Maps and Two-Level Minimization

In questa pagina 8

Simplifying with algebra needs insight and no algorithm guarantees the simplest form. The Karnaugh map is a graphical method that reliably gives a minimal sum of products (or, dually, a minimal product of sums). It works well up to 4 variables; synthesis tools use similar principles for larger functions.

How a map is built

The map has one cell per truth-table row, i.e. per minterm (Canonical Forms - Minterms, Maxterms, SOP and POSA minterm is a product containing every variable exactly once and is 1 on a single truth-table row; a maxterm is the dual sum and is 0 on a single row; with n variables there are 2^n of each and the complement of minterm i is maxterm i. Canonical SOP = sum of minterms of rows with F=1; canonical POS = product of maxterms of rows with F=0. They come mechanically from the truth table but are redundant, so they are the starting point for minimization. SOP and POS are two-level circuits.Canonical Forms - Minterms, Maxterms, SOP and POS →). Variables are spread over rows and columns, with combinations in Gray code (00,01,11,1000,01,11,10, not 00,01,10,1100,01,10,11), so neighbouring cells differ in one variable (Hamming distance 11).

The map is wrapped around: left edge adjacent to right edge, top to bottom (cylinder with 3 variables, torus with 4). E.g. the four corners of a 4-variable map are all adjacent. Cell numbering (minterm index):

A\BCA\backslash BC 00 01 11 10
0 0 1 3 2
1 4 5 7 6
AB\CDAB\backslash CD 00 01 11 10
00 0 1 3 2
01 4 5 7 6
11 12 13 15 14
10 8 9 11 10

Put 1 in the cells of the function minterms.

Why grouping simplifies

Two adjacent cells differ in one variable; if both are 1 that variable disappears, by adjacency XY+XY‾=XXY+X\overline Y=X: m2=A‾BC‾m_2=\overline AB\overline C and m3=A‾BCm_3=\overline ABC give A‾B\overline AB.

A rectangular group of 2k2^k cells (1, 2, 4, 8, 16) of 1s eliminates kk variables; its product contains only the variables that do not change inside the group, direct if 1, negated if 0.

Cells 0,1,4,50,1,4,5 (4 variables): constants A=0A=0, C=0C=0, group A‾ C‾\overline A\,\overline C.

Implicants and cover

  • Implicant: product for which the function is 1 whenever the product is 1 (a group of 1s).
  • Prime implicant (PI): implicant not contained in a larger one (maximal group).
  • Essential prime implicant (EPI): PI that is the only one covering at least one minterm; it is in every cover.
  • Cover: set of implicants covering all 1s. Goal: minimum cover = all EPIs plus the fewest other PIs covering the remaining minterms.

Procedure. (1) Fill the map. (2) Find the PIs: largest rectangles of 2k2^k adjacent 1s, using wrapped edges. (3) Find the EPIs: 1s covered by one PI only. (4) Cover remaining 1s with few other PIs (equivalent choices mean the minimal form is not unique). (5) Write the sum of the group products and verify on some rows.

Worked examples

Two variables. F=∑m(1,2,3)F=\sum m(1,2,3): groups {1,3}\{1,3\} (BB) and {2,3}\{2,3\} (AA), both essential: F=A+BF=A+B.

Three variables with a choice. F=∑m(0,1,2,5,6)F=\sum m(0,1,2,5,6):

A\BCA\backslash BC 00 01 11 10
0 1 1 0 1
1 0 1 0 1

PIs: {1,5}→B‾C\{1,5\}\to\overline BC; {2,6}→BC‾\{2,6\}\to B\overline C; {0,2}→A‾ C‾\{0,2\}\to\overline A\,\overline C (adjacent across the edge); {0,1}→A‾ B‾\{0,1\}\to\overline A\,\overline B. Essential: B‾C\overline BC (only cover of 55) and BC‾B\overline C (only cover of 66). Cell 00 can be covered by either of the other two: F=B‾C+BC‾+A‾ C‾orF=B‾C+BC‾+A‾ B‾,F=\overline BC+B\overline C+\overline A\,\overline C\qquad\text{or}\qquad F=\overline BC+B\overline C+\overline A\,\overline B, both with 3 products and 6 literals. Check: cell 00 gives F=1F=1, cell 33 (A=0,B=C=1A=0,B=C=1) gives 00.

Four variables, three essentials. F=∑m(1,3,4,5,6,7,9,11,12,13,15)F=\sum m(1,3,4,5,6,7,9,11,12,13,15):

AB\CDAB\backslash CD 00 01 11 10
00 0 1 1 0
01 1 1 1 1
11 1 1 1 0
10 0 1 1 0

Columns CD=01,11CD=01,11 (8 cells): DD; cells 4,5,12,134,5,12,13: BC‾B\overline C; row AB=01AB=01: A‾B\overline AB. All essential (33 only by DD; 1212 only by BC‾B\overline C; 66 only by A‾B\overline AB): F=D+BC‾+A‾BF=D+B\overline C+\overline AB, against 11 four-literal minterms.

Four variables, essentials plus completion. F=∑m(0,1,2,5,6,7,8,9,10,14)F=\sum m(0,1,2,5,6,7,8,9,10,14):

AB\CDAB\backslash CD 00 01 11 10
00 1 1 0 1
01 0 1 1 1
11 0 0 0 1
10 1 1 0 1

Column CD=10CD=10 (cells 2,6,14,102,6,14,10): CD‾C\overline D; wrapped square 0,1,8,90,1,8,9: B‾ C‾\overline B\,\overline C; both essential. Cells 5,75,7 remain: group {5,7}\{5,7\} gives A‾BD\overline ABD. F=CD‾+B‾ C‾+A‾BDF=C\overline D+\overline B\,\overline C+\overline ABD.

If two covers have the same products and literals both are minimal; for gate input cost compare the totals.

Product of sums (POS)

The SOP groups the 1s. The POS is obtained by grouping the 0s, i.e. working on F‾\overline F: (1) group the zeros like the ones, getting a minimal SOP of F‾\overline F; (2) complement with De Morgan: for each group write a sum of the variables that do not change, direct if 0 in the group, negated if 1; (3) FF is the product of these sums.

A zero group giving A‾B\overline AB for F‾\overline F becomes the sum A+B‾A+\overline B.

Example: F=∏M(2,5,6,7,8,9,10,11,14)F=\prod M(2,5,6,7,8,9,10,11,14):

AB\CDAB\backslash CD 00 01 11 10
00 1 1 1 0
01 1 0 0 0
11 1 1 1 0
10 0 0 0 0

Zero groups (all essential): {2,6,14,10}\{2,6,14,10\} (CD‾C\overline D for F‾\overline F, sum C‾+D\overline C+D); {5,7}\{5,7\} (A‾BD\overline ABD, sum A+B‾+D‾A+\overline B+\overline D); {8,9,10,11}\{8,9,10,11\} (AB‾A\overline B, sum A‾+B\overline A+B). F=(C‾+D)(A+B‾+D‾)(A‾+B)F=(\overline C+D)(A+\overline B+\overline D)(\overline A+B) The minimal SOP has 4 products of 3 literals (12 literals); the POS has 3 sums and 7 literals: here the POS is much more compact because the zeros are fewer and better grouped. Work on the phase (1 or 0) with fewer cells and larger groups. Check: cell 44 gives F=1F=1, cell 66 gives C‾+D=0\overline C+D=0, so F=0F=0.

Don't care conditions

The function may be not completely specified: for some inputs the output is indifferent, because the combination cannot occur (e.g. codes 10101010-11111111 at a BCD input, Binary Codes - BCD, ASCII, Unicode, Parity and GrayAn n-bit code distinguishes 2^n elements. BCD encodes each decimal digit on 4 bits (1010 to 1111 unused; it differs from the plain binary of the number). ASCII uses 7 bits for 128 characters; Unicode UTF-8 uses 1 to 4 bytes and is ASCII compatible. A parity bit detects errors on an odd number of bits. Hamming distance is the number of differing bits. Gray code makes consecutive numbers differ by one bit and is built by reflection or with g_i = b_i xor b_(i+1).Binary Codes - BCD, ASCII, Unicode, Parity and Gray →) or the result does not matter. An X is written in the table and map.

An X may be used as 1 or as 0, whichever enlarges the groups. An X inside a group counts as 1 (and is not covered explicitly); one left out counts as 0; never make a group of only Xs; covering Xs is not mandatory; an X does not make a group essential (EPIs are defined on the 1s only).

Example: BCD digit, F=1F=1 for 1,2,3,5,71,2,3,5,7; rows 1010-1515 are don't care.

AB\CDAB\backslash CD 00 01 11 10
00 0 1 1 1
01 0 1 1 0
11 X X X X
10 0 0 X X

Cells 1,3,5,71,3,5,7: A‾D\overline AD (no X used); cells 3,2,11,103,2,11,10: B‾C\overline BC (uses the Xs of 1010 and 1111). F=B‾C+A‾DF=\overline BC+\overline AD (2 products, 4 literals); treating Xs as 0 would need A‾D+A‾ B‾C\overline AD+\overline A\,\overline BC (5 literals). In POS: zeros in cells 0,4,6,8,90,4,6,8,9; groups {0,4,8,12}\{0,4,8,12\} (sum C+DC+D), {4,6,12,14}\{4,6,12,14\} (sum B‾+D\overline B+D), rows AB=11AB=11 and 1010 (sum A‾\overline A): F=A‾(C+D)(B‾+D)F=\overline A(C+D)(\overline B+D), equivalent to the SOP on valid combinations (on the Xs the two may differ, which is fine).

XOR and parity functions

The 3-variable XOR (odd parity, 1 if the number of 1s is odd) is X⊕Y⊕Z=∑m(1,2,4,7)X\oplus Y\oplus Z=\sum m(1,2,4,7), with a checkerboard map:

X\YZX\backslash YZ 00 01 11 10
0 0 1 0 1
1 1 0 1 0

No 1 is adjacent to another (minterms at Hamming distance 2), so there are no groups larger than one cell: the minimal SOP equals the canonical one (4 products of 3 literals) and does not simplify. Use XOR gates: S=(X⊕Y)⊕ZS=(X\oplus Y)\oplus Z with two gates. The same holds for 4 variables (checkerboard of 8 odd minterms) and for the even-parity function (replace XOR with XNOR). This function is the sum bit of a full adder (Binary Adders and SubtractorsHalf adder: S = X xor Y, C = XY. Full adder with carry in Z: S = X xor Y xor Z, C = XY + XZ + YZ = G + PZ with P = X xor Y, G = XY; two half adders and an OR. The n-bit ripple carry adder chains n full adders, so delay grows linearly with n. Adder-subtractor: XOR of each B bit with a control S, which is also the carry in, computes A+B or A+not B+1 = A-B. The 2-bit multiplier uses 4 ANDs and 2 half adders.Binary Adders and Subtractors →).

Common mistakes

  • Ordering cells in binary instead of Gray.
  • Ignoring the wrapped edges.
  • Groups whose size is not a power of 2 or not rectangular; non-maximal groups (useless literals).
  • Wrong literal sign: direct if 1 in the whole group, negated if 0 (reversed for POS zero groups).
  • Groups of Xs not linked to any 1; treating Xs as mandatory.
  • Trying to group a checkerboard map.

Versione ripasso

  • Map: one cell per minterm, rows/columns in Gray code (00,01,11,1000,01,11,10); edges wrap around; up to 4 variables. 4-variable indices: 0,1,3,20,1,3,2 / 4,5,7,64,5,7,6 / 12,13,15,1412,13,15,14 / 8,9,11,108,9,11,10.
  • Group of 2k2^k ones: eliminates kk variables (XY+XY‾=XXY+X\overline Y=X); keep constant variables, direct if 1, negated if 0. Cells 0,1,4,5→A‾ C‾0,1,4,5\to\overline A\,\overline C.
  • Implicant, prime (maximal), essential (unique cover of some minterm); minimum cover = all EPIs + fewest other PIs.
  • Procedure: fill, find PIs, find EPIs, cover the rest, write the SOP, verify.
  • Examples: ∑m(1,2,3)→A+B\sum m(1,2,3)\to A+B; ∑m(0,1,2,5,6)→B‾C+BC‾+A‾ C‾\sum m(0,1,2,5,6)\to\overline BC+B\overline C+\overline A\,\overline C (or A‾ B‾\overline A\,\overline B for the last term); ∑m(1,3,4,5,6,7,9,11,12,13,15)→D+BC‾+A‾B\sum m(1,3,4,5,6,7,9,11,12,13,15)\to D+B\overline C+\overline AB; ∑m(0,1,2,5,6,7,8,9,10,14)→CD‾+B‾ C‾+A‾BD\sum m(0,1,2,5,6,7,8,9,10,14)\to C\overline D+\overline B\,\overline C+\overline ABD.
  • POS: group the 0s; each group gives a sum, variables direct if 0, negated if 1; FF = product. ∏M(2,5,6,7,8,9,10,11,14)→(C‾+D)(A+B‾+D‾)(A‾+B)\prod M(2,5,6,7,8,9,10,11,14)\to(\overline C+D)(A+\overline B+\overline D)(\overline A+B) (7 literals vs 12 for the SOP). Use the phase with fewer cells.
  • Don't care (X): use as 1 or 0 to enlarge groups; no groups of only X; not mandatory; never makes a group essential. BCD "1,2,3,5,71,2,3,5,7": F=B‾C+A‾DF=\overline BC+\overline AD; POS A‾(C+D)(B‾+D)\overline A(C+D)(\overline B+D) (equal on valid inputs).
  • XOR/parity: X⊕Y⊕Z=∑m(1,2,4,7)X\oplus Y\oplus Z=\sum m(1,2,4,7), checkerboard, no groups: do not simplify, use XOR gates; parity via XNOR; it is the full-adder sum bit.
  • Mistakes: binary-ordered cells; ignored wrapped edges; group sizes not powers of 2; non-maximal groups; wrong signs (POS reversed); groups of only X; grouping a checkerboard.

Teoria collegata