Presentation is loading. Please wait.

Presentation is loading. Please wait.

It’s convenient for us to translate these analog

Similar presentations


Presentation on theme: "It’s convenient for us to translate these analog"— Presentation transcript:

0 Electronic circuits:an application of propositional logic
Why talk about chips when we’re really interested in logic? Show how propositional-logic expressions play a crucial part in the way chips (and hence computers) work Show how logical inference allows us to optimise the way in which electronic circuits are built Thereby highlight some computational aspects of propositional logic Our strategy: we’ll be looking over the shoulders of engineers, trying to understand what they are doing. We shall use slides adapted from a course on Computer Architecture by Luddy Harrison and Howard Huang, University of Illinois at Urbana Champaign, Spring 2006 (We shall be taking many liberties: leaving things out, making additions, and annotating existing slides.) Introduction to CS231

1 It’s convenient for us to translate these analog
Computers use voltages to represent information. In modern CPUs the voltage is usually limited to V to minimize power consumption. It’s convenient for us to translate these analog voltages into the discrete, or digital, values 1 and 0. But how can two lousy digits be useful for anything? First, we’ll see how to represent numbers with just 1s and 0s. Then we’ll introduce special operations for computing with 1s and 0s, by treating them as the logical values “true” and “false.” Volts 1.8 1 © Howard Huang

2 The Modest Switch At the heart of a computer lies one extremely simple component: A controllable switch The usual Electrical switch we use every day The electric switch we use turns current on and off But we need to turn it on and off by hand The result of turning the switch on? The “top end” in the figure becomes raised to a high voltage Which makes the current flow through the bulb The Controllable Switch No hands Voltage controls if the switch is on or off High voltage at input: switch on Otherwise it is off Introduction to CS231

3 Using the switch Input Output is high (voltage) if and only if the input is high Output Now we can make one circuit control another switch… Neat! This is getting boring.. Introduction to CS231

4 Lets use them creatively
Output is high if both the inputs input1 AND input2 are high If either of the inputs is low, the output is low. Input1 Output This is called an AND gate Input2 This is an electronic implementation of the  (i.e., conjunction) of propositional logic Now, can you make an OR gate with switches (i.e., inclusive disjunction)? Introduction to CS231

5 OR Gate Input1 Output Input2 Output is low iff both inputs are low
I.e. Output is high if either of the inputs (or both) are high (input1 OR input2) Introduction to CS231

6 The two diagrams simplified (without earth)
Current flows iff A is closed and B is closed: A B Input Output Current flows iff A is closed or B is closed (or both): A Input Output B Introduction to CS231

7 Basic Gates There are three basic kinds of logic gates Operation: AND
of two inputs OR of two inputs NOT (complement) on one input Logic gate: Two Questions: How can we implement them? What can we build with them? And How? Introduction to CS231

8 How to make switches? In principle one might use mechanical power or hydrolic pressure Most often: Complementary Metal-Oxide Semi-conductors (CMOS: These circuits work with separate sources of high and low power.) ... We leave all this to the engineers. Just remember: They can now manufacture millions of transistors on a single silicon chip Still, the size of chips is one of their main worries. The smaller the size, the smaller the propagation delay (typically) the less power is consumed the less heat is generated the cheaper it is to make the processor Introduction to CS231

9 What can we do with Gates?
Example: adding numbers automatically How to add numbers, depends on how they are represented. E.g., Roman XVII Decimal: 17 Try adding two long roman numbers! Decimal is better but We have only two “values”, high and low, in our gates Decimal system (and the idea of “0”) was invented in India around AD Why did they use 10? Anything special about it? Not really. Probably the fact that we have 10 fingers influenced this Introduction to CS231

10 Decimal review Numbers consist of a bunch of digits, each with a weight These weights are all powers of the base, which is 10: To find the decimal value of a number, multiply each digit by its weight and sum the products. (1 x 102) + (6 x 101) + (2 x 100) + (3 x 10-1) + (7 x 10-2) + (5 x 10-3) = Introduction to CS231

11 Converting binary to decimal
We can use the same trick to convert binary, or base 2, numbers to decimal. This time, the weights are powers of 2. Example: in binary The decimal value is: (1 x 23) + (1 x 22) + (0 x 21) + (1 x 20) + (0 x 2-1) + (1 x 2-2) = = 13.25 Introduction to CS231

12 Binary addition example worked out
The trick when adding numbers: positional weights and carry ! Exercise: what are the black numbers equivalent to in decimal? The initial carry in is implicitly 0 (Carries) (Augend) (Addend) (Sum) most significant bit (MSB) least significant bit (LSB) Introduction to CS231

13 Doing addition with gates
Lets do simple stuff first: Can we add two numbers each with just 1 bit? Bit: binary digit 0+0 = 0, 0+1 = 1 , 1+0 = 1, and 1+1 = ??? 2. But 2 is not a symbol. 10 (just as is 10 in decimal) Result is 0 with 1 carried over to the next bit. So if we disregard the carry, then what we get is 0+0 = 0, 0+1 = 1 , 1+0 = 1, and 1+1 = 0 Does this remind you of something? Introduction to CS231

14 Doing addition with gates
Lets do simple stuff first: Can we add two numbers each with just 1 bit? Bit: binary digit 0+0 = 0, 0+1 = 1 , 1+0 = 1, and 1+1 = ??? 2. But 2 is not a symbol. 10 (just as is 10 in decimal) Result is 0 with 1 carried over to the next bit. So if we disregard the carry, then what we get is 0+0 = 0, 0+1 = 1 , 1+0 = 1, and 1+1 = 0 Does this remind you of something? It’s the exclusive disjunction! Introduction to CS231

15 Doing addition with gates
Lets do simple stuff first: Can we add two numbers each with just 1 bit? Bit: binary digit 0+0 = 0, 0+1 = 1 , 1+0 = 1, and 1+1 = ??? 2. But 2 is not a symbol. 10 (just as is 10 in decimal) Result is 0 with 1 carried over to the next bit. So if we disregard the carry, then what we get is 0+0 = 0, 0+1 = 1 , 1+0 = 1, and 1+1 = 0 What rule governs the carry? Carry=1 iff both inputs are 1 Introduction to CS231

16 Doing addition with gates
Lets do simple stuff first: Can we add two numbers each with just 1 bit? Bit: binary digit 0+0 = 0, 0+1 = 1 , 1+0 = 1, and 1+1 = ??? 2. But 2 is not a symbol. 10 (just as is 10 in decimal) Result is 0 with 1 carried over to the next bit. So if we disregard the carry, then what we get is 0+0 = 0, 0+1 = 1 , 1+0 = 1, and 1+1 = 0 What rule governs the carry? Carry=1 iff both inputs are 1 It’s the logical conjunction (i.e., ). Introduction to CS231

17 Doing addition with gates
What does addition look like in a circuit? Half adder Result Carry Introduction to CS231

18 Output is 1 iff exactly one of the 2 inputs is 1
Half adder: result Result Output is 1 iff exactly one of the 2 inputs is 1 Exclusive OR A special symbol for this gate: Introduction to CS231

19 XOR Introduction to CS231

20 Adding two bits A half adder is used to add two bits.
The result consists of two bits: a sum (the right bit) and a carry out (the left bit) Here is the circuit and its block symbol 0 + 0 = 0 0 + 1 = 1 1 + 0 = 1 1 + 1 = 10 But, half adders do not take into account that there may have been a pre-existing carry. We shall write Cin, short for “Carry in(put)” (as opposed to Cout, which is short for “Carry out(put)”). Introduction to CS231

21 Adding three bits What we really need to do is add three bits: the augend and addend, and the carry in from the right. = 00 = 01 = 01 = 10 = 01 = 10 = 10 = 11 (The bitstring on the right is the binary representation of the sum of the three numbers on the left) Introduction to CS231

22 Full adder circuit Why are these things called half adders and full adders? You can build a full adder by putting together two half adders. In this way, Cin (as well as X and Y) is used as an input. Introduction to CS231

23 An example of 4-bit addition
Let’s put our initial example into this circuit: A=1011, B=1110 1 Step 1: Fill in all the inputs, including CI=0 Step 2: The circuit produces C1 and S0 ( = 01) Step 3: Use C1 to find C2 and S1 ( = 10) Step 4: Use C2 to compute C3 and S2 ( = 10) Step 5: Use C3 to compute CO and S3 ( = 11) The final answer is 11001 Introduction to CS231

24 So, we have built a calculator
It is not a computer yet… Two new ideas and components are needed: Addressable memory Stored Program These are also based on electronic circuits (memory is achieved by feeding back the output of a gate to its input) Sorry to be a bit brief about this ... Introduction to CS231

25 Basic Boolean operations
There are three basic operations for logical values. NOT (complement) on one input Operation: AND (product) of two inputs OR (sum) of two inputs Expression: xy, or xy x + y x’ Truth table: Introduction to CS231

26 Boolean expressions We can use these basic operations to form more complex expressions. For example: f(x,y,z) = (x + y’)z + x’ Some terminology and notation: f is the name of the function. (x,y,z) are the input variables, each representing 1 or 0. A literal is any occurrence of an input variable or its complement. The function above has four literals: x, y’, z, and x’. Introduction to CS231

27 Truth tables A truth table shows all possible inputs and outputs of a function. Inputs are listed in binary order—in this example, from 000 to 111. f(0,0,0) = (0 + 1)0 + 1 = 1 f(0,0,1) = (0 + 1)1 + 1 = 1 f(0,1,0) = (0 + 0)0 + 1 = 1 f(0,1,1) = (0 + 0)1 + 1 = 1 f(1,0,0) = (1 + 1)0 + 0 = 0 f(1,0,1) = (1 + 1)1 + 0 = 1 f(1,1,0) = (1 + 0)0 + 0 = 0 f(1,1,1) = (1 + 0)1 + 0 = 1 f(x,y,z) = (x + y’)z + x’ Introduction to CS231

28 Primitive logic gates Each of our basic operations can be implemented in hardware using a primitive logic gate. NOT (complement) on one input Operation: AND (product) of two inputs OR (sum) of two inputs Expression: xy, or xy x + y x’ Logic gate: Introduction to CS231

29 Expressions and circuits
Any Boolean expression can be converted into a circuit by combining basic gates. This follows from functional completeness! The diagram below shows the inputs and outputs of each gate. The precedences are explicit in a circuit. (x + y’)z + x’ Introduction to CS231

30 Standard forms of expressions
We can write expressions in many ways, but some ways are more useful than others A sum of products (SOP) expression contains: Only OR (sum) operations at the “outermost” level Each term that is summed must be a product of literals Any sum of products expression can be implemented using a two-level circuit literals and their complements at the “0th” level AND gates at the first level a single OR gate at the second level This diagram uses some shorthands… NOT gates are implicit literals are reused f(x,y,z) = y’ + x’yz’ + xz Introduction to CS231

31 Minterms A minterm is a special product of literals, in which each input variable appears exactly once. A three-variable function, such as f(x,y,z), has 23 = 8 minterms: Each minterm is true for exactly one combination of inputs: x’y’z’ x’y’z x’yz’ x’yz xy’z’ xy’z xyz’ xyz Minterm Is true when… Shorthand x’y’z’ x=0, y=0, z=0 m0 x’y’z x=0, y=0, z=1 m1 x’yz’ x=0, y=1, z=0 m2 x’yz x=0, y=1, z=1 m3 xy’z’ x=1, y=0, z=0 m4 xy’z x=1, y=0, z=1 m5 xyz’ x=1, y=1, z=0 m6 xyz x=1, y=1, z=1 m7 Introduction to CS231

32 Minterms You have encountered these before ... Introduction to CS231

33 Minterms You have encountered these before ...
... when we proved that every truth function could be expressed using only  and  ( i.e., functional completeness of { ,} ) Recall: every T-row of the truth table gave rise to a minterm we then formed the disjunction (“sum”) of these minterms ... ... replacing pq by  (p  q) Introduction to CS231

34 Sum of minterms form So: Every function can be written as a sum of minterms, in a unique way If you have a truth table for a function, you can write a “sum of minterms” expression just by picking out the rows of the table where the function output is 1. f = x’y’z’ + x’y’z + x’yz’ + x’yz + xyz’ = m0 + m1 + m2 + m3 + m6 = m(0,1,2,3,6) f’ = xy’z’ + xy’z + xyz = m4 + m5 + m7 = m(4,5,7) f’ contains all the minterms not in f Introduction to CS231

35 (The dual idea: products of sums)
A product of sums (POS) expression contains: Only AND (product) operations at the “outermost” level Each term must be a sum of literals Product of sums expressions can be implemented with two-level circuits literals and their complements at the “0th” level OR gates at the first level a single AND gate at the second level Compare this with sums of products f(x,y,z) = y’ (x’ + y + z’) (x + z) Analogous to minterms, one can now define maxterms (Let’s not further pursue these in our logic class). Introduction to CS231

36 Circuit analysis Circuit analysis involves figuring out what some circuit does. Every circuit computes some function, which can be described with Boolean expressions or truth tables. So, the goal is to find an expression or truth table for the circuit. The first thing to do is figure out what the inputs and outputs of the overall circuit are. This step is often overlooked! The example circuit here has three inputs x, y, z and one output f. Introduction to CS231

37 Write algebraic expressions...
Next, write expressions for the outputs of each individual gate, based on that gate’s inputs. Start from the inputs and work towards the outputs. It might help to do some algebraic simplification along the way. Introduction to CS231

38 Write algebraic expressions...
Next, write expressions for the outputs of each individual gate, based on that gate’s inputs. Start from the inputs and work towards the outputs. It might help to do some algebraic simplification along the way. Here is the example again. We did a little simplification for the top AND gate. You can see the circuit computes f(x,y,z) = xz + y’z + x’yz’ Introduction to CS231

39 ...or make a truth table It’s also possible to find a truth table directly from the circuit. Once you know the number of inputs and outputs, list all the possible input combinations in your truth table. A circuit with n inputs should have a truth table with 2n rows. Our example has three inputs, so the truth table will have 23 = 8 rows. All the possible input combinations are shown. Introduction to CS231

40 Simulating the circuit
Then you can simulate the circuit, either by hand or with a program like LogicWorks, to find the output for each possible combination of inputs. For example, when xyz = 101, the gate outputs would be as shown below. Use truth tables for AND, OR and NOT to find the gate outputs. For the final output, we find that f(1,0,1) = 1. 1 Introduction to CS231

41 Finishing the truth table
Doing the same thing for all the other input combinations yields the complete truth table. This is simple, but tedious. Introduction to CS231

42 Truth tables and expressions
It’s easy to come up with an expression if you have a truth table. We saw that you can quickly convert a truth table into a “sum of minterms” expression. The minterms correspond to the truth table rows where the output is 1. Compare the proof that {, } is functionally complete (second lecture, also in tutorial exercise)! You can then simplify this sum of minterms if desired. f(x,y,z) = x’y’z + x’yz’ + xy’z + xyz = m1 + m2 + m5 + m7 Introduction to CS231

43 Let’s compare the resulting circuits
Here are two different but equivalent circuits. In general the one with fewer gates is “better”: It costs less to build It requires less power But we had to do some work to find the second form Introduction to CS231

44 Karnaugh maps K-maps are a graphical technique for simplifying an expression into a minimal sum of products (MSP) form: There are a minimal number of product terms in the expression. Each term has a minimal number of literals. Circuit-wise, this leads to a minimal two-level implementation. Introduction to CS231

45 Re-arranging the truth table
A two-variable function has four possible minterms. We can re-arrange these minterms into a Karnaugh map. Now we can easily see which minterms contain common literals. Minterms on the left and right sides contain y’ and y respectively. Minterms in the top and bottom rows contain x’ and x respectively. Introduction to CS231

46 Karnaugh map simplifications
Imagine a two-variable sum of minterms: x’y’ + x’y Both of these minterms appear in the top row of a Karnaugh map, which means that they both contain the literal x’. This expression can be simplified using equivalence laws: x’y’ + x’y = x’(y’ + y) [ Distributive ] = x’  1 [ y + y’ = 1 ] = x’ [ x  1 = x ] Introduction to CS231

47 More two-variable examples
Another example expression is x’y + xy. Both minterms appear in the right side, where y is uncomplemented. Thus, we can reduce x’y + xy to just y. How about x’y’ + x’y + xy? We have x’y’ + x’y in the top row, corresponding to x’. There’s also x’y + xy in the right side, corresponding to y. This whole expression can be reduced to x’ + y. Introduction to CS231

48 Summing: K-maps applied to 2 variables
Karnaugh-maps are applied to sums of minterms They can help you find simpler sums of minterm that are equivalent to the original ones, because some of their disjuncts (i.e., minterms) contain literals that are negations of each other We’ve seen examples involving minterms ... xy’ xy ... = ... x ... ... x’y’ x’y ... = ... x’ ... ... x’y xy ... = ... y ... ... x’y’ xy’ ... = ... y’ ... More complex cases can be handled too: Introduction to CS231

49 A three-variable Karnaugh map
For a three-variable expression with inputs x, y, z, the arrangement of minterms is more tricky: Another way to label the K-map (use whichever you like): Introduction to CS231

50 Why the funny ordering? With this ordering, any group of 2, 4 or 8 adjacent squares on the map contains common literals that can be factored out. “Adjacency” includes wrapping around the left and right sides: We’ll use this property of adjacent squares to do our simplifications. x’y’z + x’yz = x’z(y’ + y) = x’z  1 = x’z x’y’z’ + xy’z’ + x’yz’ + xyz’ = z’(x’y’ + xy’ + x’y + xy) = z’(y’(x’ + x) + y(x’ + x)) = z’(y’+y) = z’ Introduction to CS231

51 Example K-map simplification
Let’s consider simplifying f(x,y,z) = xy + y’z + xz. First, you should convert the expression into a sum of minterms form, if it’s not already. The easiest way to do this is to make a truth table for the function, and then read off the minterms. You can either write out the literals or use the minterm shorthand. Here is the truth table and sum of minterms for our example: f(x,y,z) = x’y’z + xy’z + xyz’ + xyz = m1 + m5 + m6 + m7 Introduction to CS231

52 Making the example K-map
Next up is drawing and filling in the K-map. Put 1s in the map for each minterm, and 0s in the other squares. You can use either the minterm products or the shorthand to show you where the 1s and 0s belong. In our example, we can write f(x,y,z) in two equivalent ways. In either case, the resulting K-map is shown below. f(x,y,z) = x’y’z + xy’z + xyz’ + xyz f(x,y,z) = m1 + m5 + m6 + m7 Introduction to CS231

53 Grouping the minterms together
The most difficult step is grouping together all the 1s in the K-map. Make rectangles around groups of one, two, four or eight 1s. All of the 1s in the map should be included in at least one rectangle. Do not include any of the 0s. Each group corresponds to one product term. For the simplest result: Make as few rectangles as possible, to minimize the number of products in the final expression. Make each rectangle as large as possible, to minimize the number of literals in each term. It’s all right for rectangles to overlap, if that makes them larger. Introduction to CS231

54 Reading the MSP from the K-map
Finally, you can find the MSP. Each rectangle corresponds to one product term. The product is determined by finding the common literals in that rectangle. For our example, we find that xy + y’z + xz = y’z + xy. Introduction to CS231

55 Practice K-map 1 Simplify the sum of minterms m1 + m3 + m5 + m6.
Introduction to CS231

56 Solutions for practice K-map 1
Here is the filled in K-map, with all groups shown. The magenta and green groups overlap, which makes each of them as large as possible. Minterm m6 is in a group all by its lonesome. The final MSP here is x’z + y’z + xyz’. Introduction to CS231

57 Four-variable K-maps We can do four-variable expressions too!
The minterms in the third and fourth columns, and in the third and fourth rows, are switched around. Again, this ensures that adjacent squares have common literals. Grouping minterms is similar to the three-variable case, but: You can have rectangular groups of 1, 2, 4, 8 or 16 minterms. You can wrap around all four sides. Introduction to CS231

58 Example: Simplify m0+m2+m5+m8+m10+m13
The expression is already a sum of minterms, so here’s the K-map: We can make the following groups, resulting in the MSP x’z’ + xy’z. Introduction to CS231

59 K-maps can be tricky! There may not necessarily be a unique MSP. The K-map below yields two valid and equivalent MSPs, because there are two possible ways to include minterm m7. Remember that overlapping groups is possible, as shown above. y’z + yz’ + xy y’z + yz’ + xz Introduction to CS231

60 Limitations of K(arnaugh) -maps
A postscript from Aberdeen ... Simpification using K-maps is an essentially visual method intended for use by people. It’s not an algorithm and cannot be mechanised directly. With more than 5-or-so variables, the method is no longer visually appealing for people. Real algorithms have also been developed and implemented. Best known: the Quine-McClusky algorithm, which can handle any number of variables, and always results in a minimal-size expression equivalent with the input. Introduction to CS231

61 Am algorithm for circuit simplification
Quine-McClusky algorithm (a very rough sketch!) Input: a “sum of products” representation of a given function (e.g., obtained via the truth table, as above). Then two steps: 1. List all the minterms in this representation, trying all their pairwise simplifications (e.g., wxyz’ + wx’yz’ = wyz’), then all their pairwise simplifications, and so on. This gives you a set of candidate products, whose sum is equivalent to the input. 2. Then check which of these products is actually needed. This is done by checking which of the original minterms are “covered” by each of these products, then removing products that are not needed. (This is nondeterministic, since different choices may be possible.) Algorithm originally invented for the teaching of logic! Details: Ken Rosen, “Discrete Mathematics and its Applications”, (fifth edition) chapter 10. Implementations on the web (e.g., from Oefai, an AI institute at the University of Vienna) Introduction to CS231


Download ppt "It’s convenient for us to translate these analog"

Similar presentations


Ads by Google