3.9 Design examples
Why this matters
Up to now each map came with its truth table already filled in. A real design starts earlier, with a description in words of what the circuit must do. This section takes three small descriptions all the way: words, then a table, then one K-map per output, then equations, then a module that a program checks against the table. Once you have done it three times, the method is a habit.
Learning goals
Section titled “Learning goals”- Turn a description in words into a truth table, and mark as don't cares the input patterns that cannot occur.
- Draw one K-map for each output of a circuit and read a minimal sum of products from each.
- Write a decoder with a
casestatement and say what itsdefaultarm does in simulation. - Check that a module computes the table it was designed from.
Intuition first
Section titled “Intuition first”Intuition
In software you might specify a function by a list of test cases and then write code that passes them. For a small combinational circuit the list of cases can be complete, because the inputs are a few bits: the truth table is the whole specification. Design is then a series of translations of that table into forms that cost less. The place where the software analogy breaks is the outputs. A function returns one value, but a circuit has all its outputs at once, and each output has its own map.
The steps are the same each time.
- Name the inputs and the outputs, and say in words what each input pattern means.
- Fill in the truth table. Mark an output X where it can never be looked at.
- Draw one K-map per output and group the 1s, using the Xs that help.
- Read the terms off the groups.
- Write the module and check it against the table.
Example one: a 2-bit adder
Section titled “Example one: a 2-bit adder”The first number has bits A (the high bit) and B (the low bit), and the second has bits C (high) and D (low). The largest sum is 3 + 3 = 6, which needs three bits, so the answer is three bits X, Y and Z, with X the most significant. Figure 3.9.1 lists all sixteen input patterns.
| A | B | C | D | X | Y | Z |
|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 1 | 0 | 0 | 1 |
| 0 | 0 | 1 | 0 | 0 | 1 | 0 |
| 0 | 0 | 1 | 1 | 0 | 1 | 1 |
| 0 | 1 | 0 | 0 | 0 | 0 | 1 |
| 0 | 1 | 0 | 1 | 0 | 1 | 0 |
| 0 | 1 | 1 | 0 | 0 | 1 | 1 |
| 0 | 1 | 1 | 1 | 1 | 0 | 0 |
| 1 | 0 | 0 | 0 | 0 | 1 | 0 |
| 1 | 0 | 0 | 1 | 0 | 1 | 1 |
| 1 | 0 | 1 | 0 | 1 | 0 | 0 |
| 1 | 0 | 1 | 1 | 1 | 0 | 1 |
| 1 | 1 | 0 | 0 | 0 | 1 | 1 |
| 1 | 1 | 0 | 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 0 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 | 1 | 1 | 0 |
Description: A truth table with inputs A, B, C and D and outputs X, Y and Z, sixteen rows in binary order.
There are three outputs, so there are three maps. The first is X, which is 1 when the sum is 4 or more.
X =
- 2-by-2 square: rows 11 and 10, columns 11 and 10
- horizontal pair: row 11, columns 01 and 11 (2 cells)
- vertical pair: rows 01 and 11, column 11 (2 cells)
| AB=00 | AB=01 | AB=11 | AB=10 | |
|---|---|---|---|---|
| CD=00 | 0 | 0 | 0 | 0 |
| CD=01 | 0 | 0 | 1 | 0 |
| CD=11 | 0 | 1 | 1 | 1 |
| CD=10 | 0 | 0 | 1 | 1 |
Groups drawn:
- A and C: 2-by-2 square in rows CD=11 and 10, columns AB=11 and 10; 4 cells.
- B and C and D: horizontal pair in row CD=11, columns AB=01 and 11; 2 cells.
- A and B and D: vertical pair in rows CD=01 and 11, column AB=11; 2 cells.
Description: A four-variable Karnaugh map of X with three groups.
The 2-by-2 square in rows CD=11 and 10, columns AB=11 and 10 says that when both high bits are 1, both numbers are at least 2, so the sum is at least 4 whatever the low bits are. The term is 1 when the second number is 3 and the first number is odd, which also adds up to at least 4. The term is the mirror image: the first number is 3 and the second is odd.
The second output is Z, the low bit of the sum.
Z =
- 2-by-2 square, wraps top and bottom: rows 10 and 00, columns 01 and 11
- 2-by-2 square, wraps left and right: rows 01 and 11, columns 10 and 00
| AB=00 | AB=01 | AB=11 | AB=10 | |
|---|---|---|---|---|
| CD=00 | 0 | 1 | 1 | 0 |
| CD=01 | 1 | 0 | 0 | 1 |
| CD=11 | 1 | 0 | 0 | 1 |
| CD=10 | 0 | 1 | 1 | 0 |
Groups drawn:
- B and not D: 2-by-2 square wrapping around the top and bottom edges in rows CD=10 and 00, columns AB=01 and 11; 4 cells.
- not B and D: 2-by-2 square wrapping around the left and right edges in rows CD=01 and 11, columns AB=10 and 00; 4 cells.
Description: A four-variable Karnaugh map of Z with two groups of four cells.
The two groups wrap around the map's edges: the 2-by-2 square wrapping around the top and bottom edges in rows CD=10 and 00, columns AB=01 and 11 and the 2-by-2 square wrapping around the left and right edges in rows CD=01 and 11, columns AB=10 and 00. Together they read , which is the same as : . The low bit of the sum depends only on the low bits of the two numbers, as it does in a one-bit adder.
The third output, Y, is the awkward one.
Y =
- horizontal pair: row 10, columns 00 and 01 (2 cells)
- horizontal pair: row 00, columns 11 and 10 (2 cells)
- vertical pair: rows 11 and 10, column 00 (2 cells)
- vertical pair: rows 00 and 01, column 10 (2 cells)
- single cell: row 01, column 01
- single cell: row 11, column 11
| AB=00 | AB=01 | AB=11 | AB=10 | |
|---|---|---|---|---|
| CD=00 | 0 | 0 | 1 | 1 |
| CD=01 | 0 | 1 | 0 | 1 |
| CD=11 | 1 | 0 | 1 | 0 |
| CD=10 | 1 | 1 | 0 | 0 |
Groups drawn:
- not A and C and not D: horizontal pair in row CD=10, columns AB=00 and 01; 2 cells.
- A and not C and not D: horizontal pair in row CD=00, columns AB=11 and 10; 2 cells.
- not A and not B and C: vertical pair in rows CD=11 and 10, column AB=00; 2 cells.
- A and not B and not C: vertical pair in rows CD=00 and 01, column AB=10; 2 cells.
- not A and B and not C and D: single cell in row CD=01, column AB=01; 1 cell.
- A and B and C and D: single cell in row CD=11, column AB=11; 1 cell.
Description: A four-variable Karnaugh map of Y with six groups: four pairs and two single cells.
Its 1s are scattered, so a minimal sum of products has six terms and twenty literals. A map does not always give a small answer. Here the problem is not the method but the shape of the function: the middle bit of a sum is an XOR of the two high bits and the carry out of the low bits, and an XOR written as a sum of products needs many terms.
The check above confirms that the six-term sum equals this form with XOR gates, where is the carry out of the low bits.
Example two: a seven-segment decoder
Section titled “Example two: a seven-segment decoder”A seven-segment display is seven separate lights arranged to draw a digit. Section 3.1 simulated a decoder for it; this section works out the decoder's truth table and maps, and then reads Section 3.1's module as the answer. The segments are named as the lecture names them: L0 is the top segment, L1 the upper right, L2 the lower right, L3 the bottom, L4 the lower left, L5 the upper left and L6 the middle. The decoder's input is a 4-bit number B3 B2 B1 B0 holding a digit, and its seven outputs L0 to L6 say which segments light. Ten of the sixteen input codes are digits; the other six are not.
7'b0111111active high: a 1 lights a segment
7'b0000110active high: a 1 lights a segment
7'b1011011active high: a 1 lights a segment
7'b1001111active high: a 1 lights a segment
7'b1100110active high: a 1 lights a segment
7'b1101101active high: a 1 lights a segment
7'b1111101active high: a 1 lights a segment
7'b0000111active high: a 1 lights a segment
7'b1111111active high: a 1 lights a segment
7'b1101111active high: a 1 lights a segment
Description: The digits 0 to 9 drawn as seven-segment displays.
The truth table has seven outputs and sixteen rows. The rows for 10 to 15 are X: no digit has those codes, so nothing looks at the decoder's output there.
| 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 0 |
| 0 | 0 | 0 | 1 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 | 1 | 1 | 0 | 1 | 1 | 0 | 1 |
| 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 1 |
| 0 | 1 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 1 | 1 | 0 | 1 | 1 | 0 | 1 | 1 |
| 0 | 1 | 1 | 0 | 1 | 0 | 1 | 1 | 1 | 1 | 1 |
| 0 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 |
| 1 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| 1 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 0 | 1 | 1 |
| 1 | 0 | 1 | 0 | X | X | X | X | X | X | X |
| 1 | 0 | 1 | 1 | X | X | X | X | X | X | X |
| 1 | 1 | 0 | 0 | X | X | X | X | X | X | X |
| 1 | 1 | 0 | 1 | X | X | X | X | X | X | X |
| 1 | 1 | 1 | 0 | X | X | X | X | X | X | X |
| 1 | 1 | 1 | 1 | X | X | X | X | X | X | X |
Description: A truth table with inputs B3, B2, B1 and B0 and outputs L0 to L6. The rows for 0 to 9 hold 1s and 0s, and the rows for 10 to 15 hold X in every output.
Each column is a separate function and gets its own map. Take L5, the upper left segment, which is lit for 0, 4, 5, 6, 8 and 9.
L5 =
- group of eight: columns 11 and 10 (8 cells); 6 of the cells are don't care
- row of four: row 00 (4 cells); 1 of the cells is a don't care
- 2-by-2 square, wraps top and bottom: rows 10 and 00, columns 01 and 11; 2 of the cells are don't care
- 2-by-2 square: rows 00 and 01, columns 01 and 11; 2 of the cells are don't care
| B3B2=00 | B3B2=01 | B3B2=11 | B3B2=10 | |
|---|---|---|---|---|
| B1B0=00 | 1 | 1 | X | 1 |
| B1B0=01 | 0 | 1 | X | 1 |
| B1B0=11 | 0 | 0 | X | X |
| B1B0=10 | 0 | 1 | X | X |
Groups drawn:
- B 3: group of eight in columns B3,B2=11 and 10; 8 cells, 6 of them don't care.
- not B 1 and not B 0: row of four in row B1,B0=00; 4 cells, 1 of them don't care.
- B 2 and not B 0: 2-by-2 square wrapping around the top and bottom edges in rows B1,B0=10 and 00, columns B3,B2=01 and 11; 4 cells, 2 of them don't care.
- B 2 and not B 1: 2-by-2 square in rows B1,B0=00 and 01, columns B3,B2=01 and 11; 4 cells, 2 of them don't care.
Description: A four-variable Karnaugh map of L5 with 1s, 0s and X cells and four groups, the largest covering the two columns where B3 is 1.
The group of eight in columns B3,B2=11 and 10 holds the digits 8 and 9 and all six don't care cells, which is how six Xs help: they let a group of two become a group of eight, and its term is just . The other groups are (the codes ending in 00), and . Together lights the upper left segment, with four terms and seven literals. Each segment has its own map and chooses its own Xs, so the other segments need other groups.
What the module does with the codes above 9
Section titled “What the module does with the codes above 9”How CSE 369 writes this
The decoder in this book is active high: a 1 lights a segment, the way the lecture's decoder does. The handout for Lab 4 says the DE1 board's displays are active low: a 0 on a segment's wire turns that segment on. (fact ch03/de1-seg7-active-low) The two conventions differ in which value means lit, and a decoder has to match the display it drives. This section shows only the active-high decoder. The decoder has digits 0 to 9 only, and bit i of its output drives segment Li.
In SystemVerilog
Section titled “In SystemVerilog”A table with many outputs and many rows is the case where a case statement is the natural code: one line per row. This is the decoder of Section 3.1, which can now be read as the answer to the table above. Its input is called bcd and carries B3 B2 B1 B0.
// Seven-segment decoder for the digits 0 to 9. leds[i] drives segment Li and 1 means lit.// The codes 10 to 15 are not digits, so their output is left unknown.module seg7_digit ( input logic [3:0] bcd, output logic [6:0] leds); always_comb begin case (bcd) // leftmost bit is segment 6 4'd0: leds = 7'b0111111; 4'd1: leds = 7'b0000110; 4'd2: leds = 7'b1011011; 4'd3: leds = 7'b1001111; 4'd4: leds = 7'b1100110; 4'd5: leds = 7'b1101101; 4'd6: leds = 7'b1111101; 4'd7: leds = 7'b0000111; 4'd8: leds = 7'b1111111; 4'd9: leds = 7'b1101111; default: leds = 7'bX; endcase endendmoduleThe comment over the arms says the leftmost bit is segment 6, which is the order a code is written in. For 0 the lit segments are L0 to L5, and the code is 7'b0111111. The last arm, default, covers every input that no earlier arm names, which here is the six codes from 10 to 15 (A to F in hexadecimal). It gives the output the value 7'bX: unknown.
In simulation the output for those inputs is X, as Figure 3.1.4 in Section 3.1 shows: the leds lane is hatched, the drawing for an unknown value, for the codes A to F. That matches the table, which does not say what the output is there. When a synthesis tool builds the circuit, the X is permission to choose, the same as an X in a K-map. (not machine-checked: A property of synthesis tools in general, not checked by this book's tools: they treat an X assigned in a case arm as permission to choose whatever output is cheapest.) So the decoder does not promise any output for those inputs, and nothing in a design should depend on one.
Section 3.1 checks this module digit by digit: its check bench lists the lit segments of each of the ten digits by segment name and compares them with leds.
Example three: rock-paper-scissors
Section titled “Example three: rock-paper-scissors”Two players each choose rock, paper or scissors. Rock beats scissors, scissors beats paper, and paper beats rock. The poses are coded in two bits: rock is 00, paper is 01 and scissors is 10. Player 1's pose is the pair of bits A and B, and player 0's pose is the pair C and D. The circuit has two outputs. Win is 1 when player 1 wins, and Tie is 1 when the two poses are equal.
The don't cares come from two facts about how the outputs are used. First, 11 is not a pose, so when either player's pair is 11, neither output matters. Second, when the poses are equal there is no winner, but that alone does not make Win a don't care: a judge that reports no winner would normally show Win as 0. Win is free on a tie only because we state an interface rule, which is that whoever reads the outputs checks Tie first and ignores Win whenever Tie is 1. When Tie is 0, Win equal to 1 means player 1 wins and Win equal to 0 means player 0 wins. With that rule, the three tie rows are don't cares for Win.
| A | B | C | D | ||
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | X | 1 |
| 0 | 0 | 0 | 1 | 0 | 0 |
| 0 | 0 | 1 | 0 | 1 | 0 |
| 0 | 0 | 1 | 1 | X | X |
| 0 | 1 | 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 1 | X | 1 |
| 0 | 1 | 1 | 0 | 0 | 0 |
| 0 | 1 | 1 | 1 | X | X |
| 1 | 0 | 0 | 0 | 0 | 0 |
| 1 | 0 | 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 | X | 1 |
| 1 | 0 | 1 | 1 | X | X |
| 1 | 1 | 0 | 0 | X | X |
| 1 | 1 | 0 | 1 | X | X |
| 1 | 1 | 1 | 0 | X | X |
| 1 | 1 | 1 | 1 | X | X |
Description: A truth table with inputs A, B, C and D and outputs Win and Tie. Rows where the two poses are equal have X for Win, and rows where either pair is 11 have X for both outputs.
Win has three 1s, one for each way that player 1 can win: rock against scissors, paper against rock, scissors against paper. Everything else is a 0 or an X.
Win =
- 2-by-2 square: rows 00 and 01, columns 01 and 11; 3 of the cells are don't care
- 2-by-2 square: rows 01 and 11, columns 11 and 10; 3 of the cells are don't care
- 2-by-2 square, wraps left and right: rows 11 and 10, columns 10 and 00; 3 of the cells are don't care
| AB=00 | AB=01 | AB=11 | AB=10 | |
|---|---|---|---|---|
| CD=00 | X | 1 | X | 0 |
| CD=01 | 0 | X | X | 1 |
| CD=11 | X | X | X | X |
| CD=10 | 1 | 0 | X | X |
Groups drawn:
- B and not C: 2-by-2 square in rows CD=00 and 01, columns AB=01 and 11; 4 cells, 3 of them don't care.
- A and D: 2-by-2 square in rows CD=01 and 11, columns AB=11 and 10; 4 cells, 3 of them don't care.
- not B and C: 2-by-2 square wrapping around the left and right edges in rows CD=11 and 10, columns AB=10 and 00; 4 cells, 3 of them don't care.
Description: A four-variable Karnaugh map of Win with many X cells and three groups of four cells.
Each of the three groups holds exactly one 1 and three don't cares. The 2-by-2 square in rows CD=00 and 01, columns AB=01 and 11 is the paper-against-rock case, and its term is . The 2-by-2 square in rows CD=01 and 11, columns AB=11 and 10 is scissors against paper, . The 2-by-2 square wrapping around the left and right edges in rows CD=11 and 10, columns AB=10 and 00 is rock against scissors, . The don't cares are what make each term two literals: without them a single 1 would need a term of four.
Tie is 1 when the two poses are equal.
Tie =
- 2-by-2 square: rows 01 and 11, columns 01 and 11; 3 of the cells are don't care
- 2-by-2 square: rows 11 and 10, columns 11 and 10; 3 of the cells are don't care
- single cell: row 00, column 00
| AB=00 | AB=01 | AB=11 | AB=10 | |
|---|---|---|---|---|
| CD=00 | 1 | 0 | X | 0 |
| CD=01 | 0 | 1 | X | 0 |
| CD=11 | X | X | X | X |
| CD=10 | 0 | 0 | X | 1 |
Groups drawn:
- B and D: 2-by-2 square in rows CD=01 and 11, columns AB=01 and 11; 4 cells, 3 of them don't care.
- A and C: 2-by-2 square in rows CD=11 and 10, columns AB=11 and 10; 4 cells, 3 of them don't care.
- not A and not B and not C and not D: single cell in row CD=00, column AB=00; 1 cell.
Description: A four-variable Karnaugh map of Tie with two groups of four cells and one single cell.
Paper against paper and scissors against scissors each join three don't cares in a group of four, giving and . Rock against rock has no don't care neighbor, so it stays a single cell with all four variables, .
The module is the two equations, and the shown testbench tries each winning match-up, one loss and the three ties. It does not look at Win in a tie, because under the interface rule a reader ignores Win whenever Tie is 1.
// Rock-paper-scissors judge. {A, B} is player 1's pose and {C, D} is player 0's: rock 00, paper 01, scissors 10.module rps_judge(input logic A, B, C, D, output logic Win, Tie); assign Win = (B & ~C) | (A & D) | (~B & C); assign Tie = (B & D) | (A & C) | (~A & ~B & ~C & ~D);endmodule// Player 1 wins with rock, paper and scissors, loses once, and ties three ways. Win is not looked at in a tie.module rps_judge_tb(); logic A, B, C, D, Win, Tie;
rps_judge dut(.A, .B, .C, .D, .Win, .Tie);
initial begin {A, B} = 2'b00; {C, D} = 2'b10; #10; // expect: Win=1, Tie=0 {A, B} = 2'b01; {C, D} = 2'b00; #10; // expect: Win=1, Tie=0 {A, B} = 2'b10; {C, D} = 2'b01; #10; // expect: Win=1, Tie=0 {A, B} = 2'b00; {C, D} = 2'b01; #10; // expect: Win=0, Tie=0 {A, B} = 2'b00; {C, D} = 2'b00; #10; // expect: Tie=1 {A, B} = 2'b01; {C, D} = 2'b01; #10; // expect: Tie=1 {A, B} = 2'b10; {C, D} = 2'b10; #10; // expect: Tie=1 $stop; endendmoduleA 2-bit adder can be written two ways: from the three equations, or with the + operator and no equations at all. Both modules are checked against the same table, so they compute the same function.
// A 2-bit adder written from the three K-map equations: (A B) + (C D) = (X Y Z).module adder2(input logic A, B, C, D, output logic X, Y, Z); assign X = (A & C) | (B & C & D) | (A & B & D); assign Y = (~A & C & ~D) | (A & ~C & ~D) | (~A & ~B & C) | (A & ~B & ~C) | (~A & B & ~C & D) | (A & B & C & D); assign Z = (~B & D) | (B & ~D);endmodule// The same adder with the + operator: the tool picks the gates.module adder2_plus(input logic A, B, C, D, output logic X, Y, Z); assign {X, Y, Z} = {1'b0, A, B} + {1'b0, C, D};endmodulePitfalls
Section titled “Pitfalls”Common pitfall
- Trying to read all the outputs of a circuit from one K-map. A map shows one output, so draw one for each.
- Filling in the rock-paper-scissors table with the two players swapped. Write down which pair is which player, and what Win equal to 1 means, before you fill in the rows.
- Using the same don't-care choices on every output. Each map uses an X as a 1 only where it lets a group grow.
- Reading the bits of the decoder's output backward. Bit i of
ledsdrives segment Li, and a code is written with bit 6 first. - Treating the X in the
defaultarm as a particular output value. It means unknown, and nothing should depend on it.
Check your understanding
Section titled “Check your understanding”Take the quiz (5 questions)
Which expression is the low bit Z of the 2-bit sum?
How many of the sixteen input rows of the rock-paper-scissors judge are don't cares for Tie?
Which is a minimal sum of products for Win, where Win is 1 when player 1 wins?
For how many of the ten digits is segment L4, the lower left one, lit?
In simulation, what does the decoder's leds show when its input is 12?
7'bX and every bit of the output is unknown. The decoder does not subtract anything: it has one arm per digit and the default for the rest.Exercises
Section titled “Exercises”A thermometer code shows the size of a 2-bit number n, whose bits are A (high) and B (low). The output T1 is 1 when n is at least 1, T2 is 1 when n is at least 2, and T3 is 1 when n is 3. Here is the table.
| A | B | |||
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 | 0 |
| 1 | 0 | 1 | 1 | 0 |
| 1 | 1 | 1 | 1 | 1 |
Description: A truth table with inputs A and B and outputs T1, T2 and T3, four rows.
- Draw a map for each output and write a minimal sum of products.
- Write a module that uses a
casestatement.
Hint
Solution
The maps have two variables, with A on the rows and B on the columns.
T1 =
- horizontal pair: row 1 (2 cells)
- vertical pair: column 1 (2 cells)
| B=0 | B=1 | |
|---|---|---|
| A=0 | 0 | 1 |
| A=1 | 1 | 1 |
Groups drawn:
- A: horizontal pair in row A=1; 2 cells.
- B: vertical pair in column B=1; 2 cells.
Description: A two-variable Karnaugh map of T1 with two groups of two cells.
T2 =
- horizontal pair: row 1 (2 cells)
| B=0 | B=1 | |
|---|---|---|
| A=0 | 0 | 0 |
| A=1 | 1 | 1 |
Groups drawn:
- A: horizontal pair in row A=1; 2 cells.
Description: A two-variable Karnaugh map of T2 with one group of two cells.
T3 =
- single cell: row 1, column 1
| B=0 | B=1 | |
|---|---|---|
| A=0 | 0 | 0 |
| A=1 | 0 | 1 |
Groups drawn:
- A and B: single cell in row A=1, column B=1; 1 cell.
Description: A two-variable Karnaugh map of T3 with a single 1.
So gives T1, gives T2 and gives T3. A module with a case statement writes one line for each row of the table.
// A thermometer code for the 2-bit number {A, B}, written with a case statement.module thermo_case(input logic A, B, output logic T1, T2, T3); always_comb case ({A, B}) 2'b00: {T1, T2, T3} = 3'b000; 2'b01: {T1, T2, T3} = 3'b100; 2'b10: {T1, T2, T3} = 3'b110; default: {T1, T2, T3} = 3'b111; // the remaining input, 2'b11 endcaseendmoduleThe default arm stands for the one input that no earlier arm names. Every row of this table has a value, so the arm is the fourth row and not a placeholder.
A comparator takes two 2-bit numbers, the first with bits A (high) and B (low) and the second with bits C (high) and D (low). Its output GT is 1 when the first is greater than the second. Find a minimal sum of products.
| AB=00 | AB=01 | AB=11 | AB=10 | |
|---|---|---|---|---|
| CD=00 | 0 | 1 | 1 | 1 |
| CD=01 | 0 | 0 | 1 | 1 |
| CD=11 | 0 | 0 | 0 | 0 |
| CD=10 | 0 | 0 | 1 | 0 |
Description: A four-variable Karnaugh map of GT with six 1s and no groups.
Hint
Solution
The map has six 1s. The 2-by-2 square in rows CD=00 and 01, columns AB=11 and 10 covers the cases where the high bit of the first number is 1 and the high bit of the second is 0. The first number is then at least 2 and the second at most 1, so the low bits do not matter, and the term is . Two 1s are left over. One is the cell where A, B, C and D are 0, 1, 0, 0, whose only neighbor that is a 1 is the cell where they are 1, 1, 0, 0. The high bits are equal there, both 0, and the low bits decide: B is 1 and D is 0. That pair, the horizontal pair in row CD=00, columns AB=01 and 11, reads . The other is the cell where they are 1, 1, 1, 0. Its only neighbor that is a 1 is again the cell where they are 1, 1, 0, 0, and the pair is the vertical pair wrapping around the top and bottom edges in rows CD=10 and 00, column AB=11, which reads : the high bits are both 1 and the low bits decide again.
GT =
- 2-by-2 square: rows 00 and 01, columns 11 and 10
- horizontal pair: row 00, columns 01 and 11 (2 cells)
- vertical pair, wraps top and bottom: rows 10 and 00, column 11 (2 cells)
| AB=00 | AB=01 | AB=11 | AB=10 | |
|---|---|---|---|---|
| CD=00 | 0 | 1 | 1 | 1 |
| CD=01 | 0 | 0 | 1 | 1 |
| CD=11 | 0 | 0 | 0 | 0 |
| CD=10 | 0 | 0 | 1 | 0 |
Groups drawn:
- A and not C: 2-by-2 square in rows CD=00 and 01, columns AB=11 and 10; 4 cells.
- B and not C and not D: horizontal pair in row CD=00, columns AB=01 and 11; 2 cells.
- A and B and not D: vertical pair wrapping around the top and bottom edges in rows CD=10 and 00, column AB=11; 2 cells.
Description: The same map with three groups of two or four cells covering all six 1s.
Draw the map of segment L3, the bottom segment of the decoder, and find a minimal sum of products. Use the don't cares where they help.
| B3B2=00 | B3B2=01 | B3B2=11 | B3B2=10 | |
|---|---|---|---|---|
| B1B0=00 | 1 | 0 | X | 1 |
| B1B0=01 | 0 | 1 | X | 1 |
| B1B0=11 | 1 | 0 | X | X |
| B1B0=10 | 1 | 1 | X | X |
Description: A four-variable Karnaugh map of L3 with 1s, 0s and X cells.
Hint
Solution
The codes where B3 is 1 are the digits 8 and 9 and the six don't cares, and all of them fit in one group, so is a term. The 1s that remain are the digits 0, 2, 3, 5 and 6. The digit 5 is the hardest to cover. Its neighbors are the codes 4, 7 and 1, which are all 0 for L3, and the code 13, which is a don't care, so the only way to give 5 a group is to pair it with 13. That is the horizontal pair in row B1,B0=01, columns B3,B2=01 and 11, and it reads . Three groups of four cover the other digits. The term holds the codes 2, 6, 10 and 14, and holds 0, 2, 8 and 10. The term holds 2, 3, 10 and 11, which is where the digit 3 is covered.
L3 =
- group of eight: columns 11 and 10 (8 cells); 6 of the cells are don't care
- row of four: row 10 (4 cells); 2 of the cells are don't care
- four corners: rows 10 and 00, columns 10 and 00; 1 of the cells is a don't care
- 2-by-2 square, wraps left and right: rows 11 and 10, columns 10 and 00; 2 of the cells are don't care
- horizontal pair: row 01, columns 01 and 11 (2 cells); 1 of the cells is a don't care
| B3B2=00 | B3B2=01 | B3B2=11 | B3B2=10 | |
|---|---|---|---|---|
| B1B0=00 | 1 | 0 | X | 1 |
| B1B0=01 | 0 | 1 | X | 1 |
| B1B0=11 | 1 | 0 | X | X |
| B1B0=10 | 1 | 1 | X | X |
Groups drawn:
- B 3: group of eight in columns B3,B2=11 and 10; 8 cells, 6 of them don't care.
- B 1 and not B 0: row of four in row B1,B0=10; 4 cells, 2 of them don't care.
- not B 2 and not B 0: four corners in rows B1,B0=10 and 00, columns B3,B2=10 and 00; 4 cells, 1 of them don't care.
- not B 2 and B 1: 2-by-2 square wrapping around the left and right edges in rows B1,B0=11 and 10, columns B3,B2=10 and 00; 4 cells, 2 of them don't care.
- B 2 and not B 1 and B 0: horizontal pair in row B1,B0=01, columns B3,B2=01 and 11; 2 cells, 1 of them don't care.
Description: The same map with five groups, the largest covering the two columns where B3 is 1.
A multiplier takes two 2-bit numbers, the first with bits A (high) and B (low) and the second with bits C (high) and D (low), and gives their product on four outputs P3, P2, P1 and P0. The largest product is 3 times 3, which is 9. Fill in the table, draw a map for each output and find a minimal sum of products for each.
Hint
Solution
Here is the table.
| A | B | C | D | ||||
|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
| 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 1 | 0 | 1 | 1 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 | 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 1 | 1 | 1 | 0 | 0 |
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 0 | 0 | 1 | 0 | 1 | 0 | 0 |
| 1 | 0 | 1 | 0 | 0 | 0 | 1 | 0 |
| 1 | 0 | 1 | 1 | 0 | 1 | 1 | 0 |
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 1 | 0 | 1 | 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 0 | 0 | 1 | 1 | 0 |
| 1 | 1 | 1 | 1 | 1 | 0 | 0 | 1 |
P0 is 1 when the product is odd, which happens only when both numbers are odd, that is when both low bits are 1.
P0 =
- 2-by-2 square: rows 01 and 11, columns 01 and 11
| AB=00 | AB=01 | AB=11 | AB=10 | |
|---|---|---|---|---|
| CD=00 | 0 | 0 | 0 | 0 |
| CD=01 | 0 | 1 | 1 | 0 |
| CD=11 | 0 | 1 | 1 | 0 |
| CD=10 | 0 | 0 | 0 | 0 |
Groups drawn:
- B and D: 2-by-2 square in rows CD=01 and 11, columns AB=01 and 11; 4 cells.
Description: A four-variable Karnaugh map of P0 with one group of four cells.
P1 is 1 for the products 2, 3 and 6, and the 1s are scattered. Each of the four terms below is a pair that no larger group can absorb.
P1 =
- horizontal pair: row 10, columns 01 and 11 (2 cells)
- horizontal pair: row 01, columns 11 and 10 (2 cells)
- vertical pair: rows 01 and 11, column 10 (2 cells)
- vertical pair: rows 11 and 10, column 01 (2 cells)
| AB=00 | AB=01 | AB=11 | AB=10 | |
|---|---|---|---|---|
| CD=00 | 0 | 0 | 0 | 0 |
| CD=01 | 0 | 0 | 1 | 1 |
| CD=11 | 0 | 1 | 0 | 1 |
| CD=10 | 0 | 1 | 1 | 0 |
Groups drawn:
- B and C and not D: horizontal pair in row CD=10, columns AB=01 and 11; 2 cells.
- A and not C and D: horizontal pair in row CD=01, columns AB=11 and 10; 2 cells.
- A and not B and D: vertical pair in rows CD=01 and 11, column AB=10; 2 cells.
- not A and B and C: vertical pair in rows CD=11 and 10, column AB=01; 2 cells.
Description: A four-variable Karnaugh map of P1 with four groups of two cells each.
P2 is 1 for the products 4 and 6: two times two, two times three and three times two.
P2 =
- horizontal pair: row 10, columns 11 and 10 (2 cells)
- vertical pair: rows 11 and 10, column 10 (2 cells)
| AB=00 | AB=01 | AB=11 | AB=10 | |
|---|---|---|---|---|
| CD=00 | 0 | 0 | 0 | 0 |
| CD=01 | 0 | 0 | 0 | 0 |
| CD=11 | 0 | 0 | 0 | 1 |
| CD=10 | 0 | 0 | 1 | 1 |
Groups drawn:
- A and C and not D: horizontal pair in row CD=10, columns AB=11 and 10; 2 cells.
- A and not B and C: vertical pair in rows CD=11 and 10, column AB=10; 2 cells.
Description: A four-variable Karnaugh map of P2 with two groups of two cells.
P3 is 1 only for three times three, whose product is 9.
P3 =
- single cell: row 11, column 11
| AB=00 | AB=01 | AB=11 | AB=10 | |
|---|---|---|---|---|
| CD=00 | 0 | 0 | 0 | 0 |
| CD=01 | 0 | 0 | 0 | 0 |
| CD=11 | 0 | 0 | 1 | 0 |
| CD=10 | 0 | 0 | 0 | 0 |
Groups drawn:
- A and B and C and D: single cell in row CD=11, column AB=11; 1 cell.
Description: A four-variable Karnaugh map of P3 with a single 1 in the cell where all four inputs are 1.