Introduction to Digital Electronics

Introduction to Digital Electronics

by Agner Fog, 2019-10-30.

Contents 1. Number systems ............................................................................................................................... 3

1.1. Decimal, binary, and hexadecimal numbers ............................................................................ 3 1.2. Conversion from another number system to decimal...............................................................4 1.3. Conversion from decimal to another number system...............................................................5 1.4. Addition of binary numbers ...................................................................................................... 6 1.5. Signed binary numbers ............................................................................................................ 7 1.6. Binary coded decimal numbers................................................................................................9 1.7. Exercises ............................................................................................................................... 10 2. Boolean algebra .............................................................................................................................. 12 2.1. Laws and rules.......................................................................................................................13 2.2. Truth tables ............................................................................................................................ 14 2.3. Reducing a Boolean expression ............................................................................................ 15 2.4. Exercises ............................................................................................................................... 16 3. Digital circuits .................................................................................................................................. 18 3.1. How Boolean gates are made................................................................................................18 3.2. Gate symbols ......................................................................................................................... 21 3.1. Exercises ............................................................................................................................... 23 4. Commonly used Boolean circuits .................................................................................................... 25 4.1. Decoders ............................................................................................................................... 25 4.2. Encoders................................................................................................................................26 4.3. Seven segment decoders ...................................................................................................... 27 4.4. Multiplexers............................................................................................................................28 4.5. Adders ................................................................................................................................... 29 4.6. Subtracting binary numbers ................................................................................................... 30 4.7. Exercises ............................................................................................................................... 32 5. Flip-Flops ........................................................................................................................................ 34 5.1. Basic feed back circuit ........................................................................................................... 34 5.2. SR flip-flop ............................................................................................................................. 34 5.3. SR flip-flop with enable .......................................................................................................... 35

1

5.4. D latch....................................................................................................................................36 5.5. Edge-triggered D flip-flop ....................................................................................................... 36 5.1. Edge-triggered D Flip-Flop with set and reset........................................................................38 5.2. Toggle flip-flop ....................................................................................................................... 39 5.1. Ripple counter........................................................................................................................40 5.2. Exercises ............................................................................................................................... 41 6. State machines ............................................................................................................................... 45 6.1. Synchronous design .............................................................................................................. 52 6.2. Exercises ............................................................................................................................... 55 7. Interfacing digital circuits.................................................................................................................57 7.1. Pushbuttons ........................................................................................................................... 57 7.2. Button with debouncing..........................................................................................................58 7.3. Automatic power-on reset ...................................................................................................... 61 7.4. LED output ............................................................................................................................. 62 7.5. Relay output...........................................................................................................................63 7.6. Optocouplers ......................................................................................................................... 64 7.7. Digital-to-analog converters ................................................................................................... 65 7.8. Analog-to-digital converters ................................................................................................... 66 7.9. Exercises ............................................................................................................................... 69 8. Microprocessors and microcontrollers ............................................................................................ 70 8.1. Input ports and output ports ................................................................................................... 71 8.2. Interrupt ................................................................................................................................. 73 9. Appendix A: List of digital integrated circuits ................................................................................... 75

2

1. Number systems

1.1. 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

-1

v = 10

=0

In the example of 2019, we have d0 = 9, d1 = 1, d2 = 0, d3 = 2, n = 4. 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

-1

v =

=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).

1.1.1. 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. The calculation is illustrated in this table:

8's 1 1 * 8 = 8

4's

2's

1

0

1*4=4 0*2=0

8 + 4 + 0 + 1 = 13

1's 1 1 * 1 = 1

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.

3

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.

1.1.2. Hexadecimal numbers The hexadecimal number system has radix 16. The sixteen possible digits are written as this:

Digit

0 1 2 3 4 5 6 7 8 9 A B C D E F

Value

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

For example 4AD1(base 16) = 1*160 + 13*161 + 10*162 + 4*163 = 19153(base 10).

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

1.2. 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. Stop after adding the last digit. Do not multiply by the radix after adding the last digit.

4

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.

1.3. 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 19153 1197 74 4

Division 19153 / 16 = 1197, remainder 1 1197 / 16 = 74, remainder 13 74 / 16 = 4, remainder 10 4 / 16 = 0, remainder 4

Fraction 1197 74 4 0

Remainder 1 13 10 4

You get the result from the remainders in reverse order: 4 : 10 : 13 : 1 gives 4AD1(base 16).

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 19153 2769 209 1

Division 19153 / 163 = 4, remainder 2769 2769 / 162 = 10, remainder 209 209 / 161 = 13, remainder 1 1 / 160 = 1, remainder 0

Fraction 4 10 13 1

Remainder 2769 209 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.

1.3.1. 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.

Converting 4AD1 from hexadecimal to binary:

5

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download