Chapter 14 · Semiconductor Electronics: Materials, Devices and Simple Circuits
14.13 Digital Electronics and Logic Gates
A phone stores a song, a photograph and this page as long strings of just two symbols, 0 and 1. Everything it does with them is built up from a few simple circuits, each of which takes in 0s and 1s and gives out a 0 or a 1 by a fixed rule.
The voltages in electronic circuits are of two kinds (Fig. 14.35). An can take any value within a range and changes smoothly, like the voltage from a microphone, which follows the pressure of the sound wave. A takes only two values, such as 0 V and 5 V, and jumps between them. The two levels stand for the two digits of the binary system: the low level for 0 and the high level for 1.
Fig. 14.35 (a) An analog signal. (b) The digital signal made from it: 1 while the analog voltage is above the dashed level, 0 while it is below.
A digital circuit reads any voltage above a set level as 1 and any voltage below it as 0. Noise of a fraction of a volt picked up on the way cannot turn a 0 into a 1, so digital signals can be copied, stored and sent far with very few errors. An analog signal carries every bit of noise along with its message.
A is a digital circuit with one or more inputs and one output, whose output is set by its inputs according to a fixed logical rule. The inputs are called A and B, and the output Y; each is either 0 or 1. A gate’s rule can be given in two ways. Its lists the output for every combination of inputs; a gate with two inputs has four rows, for the inputs 00, 01, 10 and 11. Its gives the output as a formula in the inputs, in the algebra of logic that George Boole set out in the nineteenth century. Inside a chip each gate is a small circuit of transistors working as switches; here only the rule each gate follows matters.
14.13.1 The NOT gate
The simplest gate has one input, and its output is always the opposite of the input: 1 when the input is 0, and 0 when the input is 1. This is the , also called an inverter. Its output is NOT A, written in a Boolean expression with a bar over the input:
Its symbol, in Fig. 14.36(a), is a triangle pointing towards the output with a small circle at its tip; in every gate symbol the small circle means NOT. Table 14.4 is its truth table.
Table 14.4 Truth table of the NOT gate.
Input A
Output Y
0
1
1
0
A switch and a lamp can act out the same rule (Fig. 14.36(b)). Take a closed switch, or a glowing lamp, as 1. The switch is connected across the lamp, and a resistor in series keeps the battery from being short-circuited when the switch is closed. With the switch open, current flows through the lamp and it glows: input 0, output 1. Closing the switch gives the current an easy path round the lamp, which goes dark: input 1, output 0.
Fig. 14.36 (a) The NOT gate. (b) A switch connected across a lamp follows the same rule: switch closed, lamp off.
14.13.2 The OR gate
The has two inputs. Its output is 1 if A is 1, or B is 1, or both are; it is 0 only when both inputs are 0. Its Boolean expression is
read as “Y equals A OR B”. The plus sign here means OR, not addition: in this algebra 1 + 1 = 1. Two switches in parallel, in series with a lamp and a battery, behave as an OR gate (Fig. 14.37(a)). The lamp glows if either switch is closed, or both, because either one completes the circuit.
Fig. 14.37 Switches acting out logic. (a) In parallel they make an OR gate. (b) In series they make an AND gate.
Table 14.5 Truth table of the OR gate.
A
B
Y = A OR B
0
0
0
0
1
1
1
0
1
1
1
1
The symbol of the OR gate, drawn in Fig. 14.38 with the other two-input gates, has a curved back and a pointed front.
14.13.3 The AND gate
The gives 1 only when both A and B are 1; if either input is 0, the output is 0. Its Boolean expression uses a dot for AND:
read as “Y equals A AND B”. In this algebra 1 · 1 = 1 and 1 · 0 = 0, just as in ordinary multiplication of 0s and 1s. Two switches in series with a lamp make an AND gate (Fig. 14.37(b)): current flows only when both are closed. The symbol has a straight back and a round front.
Table 14.6 Truth table of the AND gate.
A
B
Y = A AND B
0
0
0
0
1
0
1
0
0
1
1
1
14.13.4 The NAND and NOR gates
An AND gate followed by a NOT gate makes the , short for NOT AND. Its output is the opposite of the AND output: 0 only when both inputs are 1, and 1 otherwise.
Its symbol is the AND symbol with the small circle of NOT at the output. Table 14.7 finds its truth table in two steps, first the AND of the inputs and then the opposite of that.
Table 14.7 Truth table of the NAND gate: the AND output, then its opposite.
A, B
A AND B
Y = NOT (A AND B)
0, 0
0
1
0, 1
0
1
1, 0
0
1
1, 1
1
0
In the same way, an OR gate followed by a NOT gate makes the , short for NOT OR. Its output is 1 only when both inputs are 0, and its symbol is the OR symbol with a small circle at the output:
Table 14.8 Truth table of the NOR gate: the OR output, then its opposite.
A, B
A OR B
Y = NOT (A OR B)
0, 0
0
1
0, 1
1
0
1, 0
1
0
1, 1
1
0
Fig. 14.38 collects the four two-input gates. Each gate has exactly one input pair that stands out, which makes the four easy to tell apart: OR is 0 only for 00, AND is 1 only for 11, NAND is 0 only for 11, and NOR is 1 only for 00.
Fig. 14.38 The four two-input gates, each with an equivalent circuit and its output for the four input pairs. Click a chip to choose a gate.
Check yourself
A two-input gate gives an output of 0 only when both its inputs are 1. Which gate is it?
A centimetre is smaller than a metre, so the number should get bigger, not smaller.
That’s right
A NAND gate is an AND gate followed by NOT. The AND output is 1 only for inputs 1 and 1, so the NAND output is 0 only then, and 1 in the other three cases.
14.13.5 Combining gates
Gates are joined so that the output of one feeds an input of the next. With enough of them a circuit can be given any truth table at all. To find the output of a combination, name the output of each gate along the way, then work through the circuit gate by gate, one row of the truth table at a time.
Example 14.31
Inputs A and B are fed both to an OR gate, with output Y₁, and to a NAND gate, with output Y₂. These two outputs are the inputs of an AND gate, whose output is Y. (a) Write the Boolean expression for Y. (b) Find Y for all four pairs of inputs. (c) In words, when is Y equal to 1?
Given
First gate: OR, output Y₁ Second gate: NAND, output Y₂ Third gate: AND of Y₁ and Y₂, output Y
Solution
(a) Write the output of each gate in turn.
(b) For each row, find the two intermediate outputs first, then their AND:
(c) Y is 1 when exactly one input is 1, and 0 when the inputs are equal. The OR gate passes every case with at least one 1, and the NAND gate then removes the case in which both are 1.
Answer
Y = 0, 1, 1, 0 for inputs 00, 01, 10, 11
Did you know?
The exclusive-OR gate
The circuit of Example 14.31 is so useful that it is made as a single gate, the . Its output is 1 when one input or the other is 1, but not both: for inputs 00, 01, 10 and 11 it gives 0, 1, 1 and 0. In other words it gives 1 exactly when its two inputs differ. It can also be built as (NOT A AND B) OR (A AND NOT B). In ordinary binary arithmetic, as opposed to the algebra of logic, 1 + 1 = 10: the XOR of two digits is their sum digit, and their AND is the digit carried, which is how a computer starts to add.
14.13.6 Universal gates and De Morgan’s theorems
A NAND gate can be wired to do the work of every other gate, and so can a NOR gate. A gate with this property is called a : in principle a whole computer could be built from NAND gates alone.
NOT from NAND. Join the two inputs of a NAND gate and feed A to both. When A is 0 the gate sees 0 and 0 and gives 1; when A is 1 it sees 1 and 1 and gives 0. Since A AND A is just A, this is the NOT gate:
AND from NAND. A NAND gate gives the opposite of AND. A second NAND gate, wired as a NOT gate, turns the output round again and restores AND (Table 14.9):
Table 14.9 AND from two NAND gates; the second gate has its inputs joined. The last column is the AND column of Table 14.6.
A, B
First NAND output
Second NAND output, Y
0, 0
1
0
0, 1
1
0
1, 0
1
0
1, 1
0
1
OR from NAND. Pass A and B through two NAND gates wired as NOT gates, and feed the results to a third NAND gate (Table 14.10):
Table 14.10 OR from three NAND gates: the inputs are inverted, then NANDed. The last column is the OR column of Table 14.5.
A, B
NOT A, NOT B
NAND of these, Y
0, 0
1, 1
0
0, 1
1, 0
1
1, 0
0, 1
1
1, 1
0, 0
1
The NOR gate is universal in the same way. With its inputs joined it is a NOT gate, since NOT (A OR A) is NOT A. A NOR gate followed by such a NOT gate is an OR gate, and Example 14.32 shows that NOT gates on the inputs of a NOR gate make an AND gate.
The OR built from NAND gates and the AND built from NOR gates are both cases of two rules for taking NOT of a whole expression, known as . The first says that NOT of an OR is the AND of the NOTs:
(14.24)
and the second that NOT of an AND is the OR of the NOTs:
(14.25)
To take NOT of a whole expression, then, take NOT of each part and change OR into AND, or AND into OR. Each theorem is proved by checking all four rows of its truth table (Tables 14.11 and 14.12).
Table 14.11 De Morgan’s first theorem: the two sides agree in every row.
A, B
NOT (A OR B)
(NOT A) AND (NOT B)
0, 0
1
1 AND 1 = 1
0, 1
0
1 AND 0 = 0
1, 0
0
0 AND 1 = 0
1, 1
0
0 AND 0 = 0
Table 14.12 De Morgan’s second theorem: the two sides agree in every row.
A, B
NOT (A AND B)
(NOT A) OR (NOT B)
0, 0
1
1 OR 1 = 1
0, 1
1
1 OR 0 = 1
1, 0
1
0 OR 1 = 1
1, 1
0
0 OR 0 = 0
The second theorem shows at once why NOT gates on the inputs of a NAND gate make an OR gate. By Eq. (14.25), NOT ((NOT A) AND (NOT B)) is (NOT NOT A) OR (NOT NOT B), and since two NOTs cancel, this is A OR B.
Example 14.32
Each of the inputs A and B passes through a NOT gate, and the two outputs are fed to a NOR gate. Which single gate does the whole circuit act as? Use a truth table, and check the result with De Morgan’s theorems.
Given
Outputs of the NOT gates: NOT A and NOT B Output of the NOR gate: Y
Solution
Write the Boolean expression.
Work through the four rows:
The output is 1 only when both inputs are 1, so the circuit is an AND gate. Check with De Morgan’s first theorem, Eq. (14.24), with NOT A and NOT B in place of A and B:
Two NOTs cancel. If the NOT gates are themselves NOR gates with their inputs joined, this AND gate is built from NOR gates alone.
Answer
An AND gate
Check yourself
Which of these is always equal to NOT (A AND B)?
A centimetre is smaller than a metre, so the number should get bigger, not smaller.
That’s right
By De Morgan’s second theorem, NOT of an AND is the OR of the NOTs. Both expressions are 0 only when A and B are both 1.
14.13.7 Timing diagrams
In a working circuit the inputs change with time. A draws each input and the output as a waveform that steps between 0 and 1, one below another on a common time axis. A gate responds almost at once, so its output at any moment follows from its inputs at that moment.
Fig. 14.39 shows two inputs over eight equal time slots and the output of a NAND gate. To draw the output, go slot by slot. The output drops to 0 only in the fourth and sixth slots, the two in which both inputs are 1, and it is 1 in every other slot.
Fig. 14.39 Inputs and output of a NAND gate over eight equal time slots.
Example 14.33
The inputs A and B of Fig. 14.39 are fed instead to a NOR gate. Find its output in each of the eight time slots, and describe the output waveform.
Given
Slot by slot, A = 0, 0, 1, 1, 0, 1, 1, 0 Slot by slot, B = 0, 1, 0, 1, 1, 1, 0, 0
Solution
A NOR gate gives 1 only when both inputs are 0. Find A OR B in each slot, then its opposite:
Both inputs are 0 only in the first and the last slots. The output is a pulse of 1 in slot 1, stays at 0 from slot 2 to slot 7, and rises to 1 again in slot 8. In every slot where the NAND output of Fig. 14.39 is 0, the NOR output is 0 as well.
Answer
Y = 1, 0, 0, 0, 0, 0, 0, 1