Transcription of Introduction to Digital Electronics - Agner
1 1 Introduction to Digital Electronics by Agner Fog, 2019-10-30. Contents 1. Number systems .. 3 Decimal, binary, and hexadecimal numbers .. 3 Conversion from another number system to decimal .. 4 Conversion from decimal to another number system .. 5 Addition of binary numbers .. 6 Signed binary numbers .. 7 Binary coded decimal numbers .. 9 Exercises .. 10 2. Boolean algebra .. 12 Laws and rules .. 13 Truth tables .. 14 Reducing a Boolean expression .. 15 Exercises .. 16 3. Digital circuits .. 18 How Boolean gates are made .. 18 Gate symbols .. 21 Exercises .. 23 4. Commonly used Boolean circuits .. 25 Decoders .. 25 Encoders .. 26 Seven segment decoders .. 27 Multiplexers .. 28 Adders .. 29 Subtracting binary numbers .. 30 Exercises .. 32 5. Flip-Flops .. 34 Basic feed back circuit .. 34 SR flip-flop .. 34 SR flip-flop with enable .. 35 2 D latch .. 36 Edge-triggered D flip-flop .. 36 Edge-triggered D Flip-Flop with set and reset.
2 38 Toggle flip-flop .. 39 Ripple counter .. 40 Exercises .. 41 6. State machines .. 45 Synchronous design .. 52 Exercises .. 55 7. Interfacing Digital circuits .. 57 Pushbuttons .. 57 Button with debouncing .. 58 Automatic power-on reset .. 61 LED output .. 62 Relay output .. 63 Optocouplers .. 64 Digital -to-analog converters .. 65 Analog-to- Digital converters .. 66 Exercises .. 69 8. Microprocessors and microcontrollers .. 70 Input ports and output ports .. 71 Interrupt .. 73 9. Appendix A: List of Digital integrated circuits .. 75 3 1. Number systems Decimal, binary, and hexadecimal numbers We all know the decimal number system. For example, 2019 means 2*1000 + 0*100 + 1*10 + 9*1. The numbers 2, 0, 1, 9 are called the digits of the number 2019. If we want to describe this mathematically, we will call the rightmost digit d0, the next digit d1, etc. If there are n digits: d0, d1, d2, .. dn-1, then the value v can be calculated by the formula v= 10 1 =0 In the example of 2019, we have d0 = 9, d1 = 1, d2 = 0, d3 = 2, n = 4.
3 This gives v = 2019. 10 is the base or radix of the number system. The reason why we are using ten as the radix is that this makes it easy to use our ten fingers for counting. The name decimal comes from Latin decem which means ten. The word digit means finger. If we use a number system with radix r then the above formula becomes v= 1 =0 For example, if the radix r is sixteen then 2019 does not mean two thousand and nineteen. Instead the value becomes 2019(base 16) = 9*160 + 1*161 + 0*162 + 2*163 = 8217(base 10). Binary numbers Computers do not have ten fingers so the decimal number system is not the most efficient system to use in computers. Instead, the binary system with radix 2 is used. For example, 1101(base 2) = 1*20 + 0*21 + 1*22 + 1*23 = 13(base 10). The rightmost digit is the least significant digit with the worth 20 = 1. We can call the least significant the 1's, the next digit from the right is the 2's. Next comes the 4's, the 8's, etc.
4 The calculation is illustrated in this table: 8's 4's 2's 1's 1 1 0 1 1 * 8 = 8 1 * 4 = 4 0 * 2 = 0 1 * 1 = 1 8 + 4 + 0 + 1 = 13 Each digit in a binary number can have only two different values: 0 and 1. These are conveniently represented in an electrical wire as two different voltages. The lower of the two voltages represents 0 and the higher voltage represents 1. For example, we may choose 0V and 5V for the numbers 0 and 1, respectively. A binary number with four digits, as in the example above, can be represented by four wires, where each wire has either 0V or 5V. 4 A binary digit is also called a bit. A bit can be 0 or 1. This is the smallest piece of information that you can store in any system. Hexadecimal numbers The hexadecimal number system has radix 16. The sixteen possible digits are written as this: Digit Value 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 A 10 B 11 C 12 D 13 E 14 F 15 For example 4AD1(base 16) = 1*160 + 13*161 + 10*162 + 4*163 = 19153(base 10).
5 The hexadecimal system is often used as a short way to represent binary numbers with many digits. Each hexadecimal digit corresponds to four binary digits, because 16 = 24. For example, the binary number 0100101011010001(base 2) is easily converted to the hexadecimal number 4AD1(base 16) by dividing the bits into groups of four: 0100 1010 1101 0001 4 A D 1 Conversion from another number system to decimal There are two convenient ways to convert from any other number system to decimal. The first method starts with the rightmost digit (least significant digit) and multiplies by powers of the radix. We used this method above to convert the number 4AD1 from hexadecimal to decimal: 4AD1(base 16) = 1*160 + 13*161 + 10*162 + 4*163 = 19153(base 10). The second method starts with the leftmost digit (most significant digit). Multiply the leftmost digit by the radix. Add the next digit. Multiply the result by the radix. Add the next digit, and so on.
6 Stop after adding the last digit. Do not multiply by the radix after adding the last digit. 5 If we apply this method to the same example, we get: 4AD1(base 16) = ((4 * 16 + 10) * 16 + 13) * 16 + 1 = 19153(base 10). The second method is convenient to use with a pocket calculator. Conversion from decimal to another number system There are also two ways to convert from decimal to another number system. The first method gives the rightmost digit (least significant digit) first: Divide the number repeatedly by the radix and get the integer part of each result. Save the remainders from each division. The remainders represent the converted number with the least significant digit first. This method is illustrated with the same example as above: Convert 19153 from decimal to hexadecimal: Number Division Fraction Remainder 19153 19153 / 16 = 1197, remainder 1 1197 1 1197 1197 / 16 = 74, remainder 13 74 13 74 74 / 16 = 4, remainder 10 4 10 4 4 / 16 = 0, remainder 4 0 4 You get the result from the remainders in reverse order: 4 : 10 : 13 : 1 gives 4AD1(base 16).
7 The second method gives the leftmost digit (most significant digit) first: Find the highest power of the radix that is not bigger than the number you want to convert. Divide by the highest power of the radix first. The result of the first division is the most significant digit of the result. Divide the remainder by the next lower power of the radix, and so no. Our example gives these results: Convert 19153 from decimal to hexadecimal: Number Division Fraction Remainder 19153 19153 / 163 = 4, remainder 2769 4 2769 2769 2769 / 162 = 10, remainder 209 10 209 209 209 / 161 = 13, remainder 1 13 1 1 1 / 160 = 1, remainder 0 1 0 You get the result from the fractions : 4 : 10 : 13 : 1 gives 4AD1(base 16). You can choose the method you think is most logical or easiest to remember. Conversion from hexadecimal to binary It is easy to convert a number from hexadecimal to binary. Just convert each hexadecimal digit to four bits. If any digit gives less than four bits then you must remember to put zeroes in front of the number to get four bits.
8 Converting 4AD1 from hexadecimal to binary: 6 4 A D 1 0100 1010 1101 0001 0100 : 1010 : 1101 : 0001 gives 0100101011010001 = 100101011010001. Conversion from binary to hexadecimal To convert from binary to hexadecimal, you divide the bits into groups of four. If the number of bits is not divisible by four then add extra zeroes in front of the number. Remember that you can add zeroes to the left of the number without changing the value. You cannot add a zero to the right of the number because this would multiply the number by two. To convert 100101011010001 from binary to hexadecimal, we divide it into groups of four. The leftmost group has only three bits so we add a zero in the front: 0100 1010 1101 0001 4 A D 1 It is easier to write 4AD1 than 100101011010001 and it is easy to convert between these two number systems. This is the reason why hexadecimal numbers are often used in Digital systems. It is convenient to use the hexadecimal representation as an intermediate if you want to convert from binary to decimal or from decimal to binary.
9 The conversion: binary hexadecimal decimal is easier than binary decimal. Likewise, the conversion: decimal hexadecimal binary is faster than decimal binary because you need fewer divisions. Addition of binary numbers Addition of binary numbers goes the same way as for decimal numbers, as we learned at school. This example calculates 7 + 21, using binary numbers: 111 00111 7 +10101 +21 11100 28 In the example above, we start with the 1's place which is the rightmost column. 1 + 1 = 2. The number 2 in binary is 10, so we get zero and a carry which goes to the 2's place. The carries are indicated in red here. The second column from the right is the 2's place. Here we have 1+1+0 = 2. This gives a zero in the 2's place and a carry to the 4's place. The third column from the right is the 4's place. Here we have 1+1+1 = 3. The binary code for 3 is 11, so we get 1 in the 4's place and a 7 carry to the 8's place. There are no more carries, so the result is 00111 + 10101 = 11100, or in decimal: 7 + 21 = 28.
10 Signed binary numbers There are several different ways of representing negative numbers. Today, almost all computers use a system called two's complement for representing numbers that can be both positive and negative. We will explain this system shortly. A Digital system typically has a fixed number of bits to represent a binary number. For example, if we have four bits, we can have the numbers from 0 to 15: binary decimal 0000 0 0001 1 0010 2 0011 3 0100 4 0101 5 0110 6 0111 7 1000 8 1001 9 1010 10 1011 11 1100 12 1101 13 1110 14 1111 15 We can add 1 by going one step down in this table. The maximum number we can have with four bits is 15. If we try to add 1 to 15 we get the binary number 10000. Since we have only four bits in this example, we will not see the extra bit, but only 0000. In other words, if we add 1 to 15 in a four-bit system we get an overflow and the result will be 0. Likewise, if we try to subtract 1 from 0 we get an underflow and we will see the result 15.