Digital electronics – from Boole to the microprocessor

In digital electronics there are only two values: 0 and 1, low and high voltage. With them and a few logic gates one can build anything from a pocket calculator to a computer. The course “Elementary digital electronics” sat in the middle of the 1980s revolution, when home computers and microprocessors made digital technology everyone’s property. The page has an interactive adder and a counter you can clock.

DTH, course 4303 (1985), 6 points: Elementary digital electronics. In those days one built with TTL chips of the 74 series on a breadboard; today the same logic sits billions of times over in a single chip.

Boole and Shannon

George Boole, a schoolteacher in Lincoln and later professor at Cork, published The Laws of Thought in 1854, treating logical statements with algebra: true and false became 1 and 0, “and” became multiplication and “or” addition. For 83 years it was pure mathematics. Then Claude Shannon showed in his master’s thesis at MIT in 1937 that Boole’s algebra exactly describes circuits of relays and switches – and conversely, that any logical function can be built from switches. It has been called the most important master’s thesis of the 20th century. (On logic itself: see logic.)

Binary numbers

In the binary system each digit (bit) has the weight $2^n$: $1011_2 = 8 + 2 + 1 = 11$. Four bits can be written as one hexadecimal digit 0–F. Negative numbers are represented in two’s complement: with $n$ bits, $-x$ is the same as $2^n - x$; one inverts all the bits and adds 1. The advantage is that addition and subtraction become the same operation in hardware, and there is only one zero. With 4 bits the range is −8 (1000) to +7 (0111); adding 1 to 7 makes the number “roll over” to −8 – overflow, a classic source of program errors.

Logic gates

ABAND $AB$OR $A+B$XOR $A\oplus B$NAND $\overline{AB}$NOR $\overline{A+B}$
0000011
0101110
1001110
1111000

The NAND gate is universal: all other gates can be built from NAND alone – NOT is a NAND with its inputs joined, AND is NAND followed by NOT, and so on. The same holds for NOR. The Apollo guidance computer was built entirely from about 5600 NOR gates.

De Morgan and Karnaugh

Augustus De Morgan’s laws state that $\overline{A\cdot B} = \bar A + \bar B$ and $\overline{A+B} = \bar A\cdot\bar B$ – AND and OR can be swapped by inverting inputs and outputs. To simplify a logical expression with up to four or five variables one draws a Karnaugh map (Maurice Karnaugh, Bell Labs, 1953): the truth table arranged in Gray code so that neighbouring cells differ in only one variable. Groups of 1s in rectangles of 1, 2, 4 or 8 cells give the simplest terms directly. Larger problems use computer algorithms (Quine–McCluskey, Espresso).

The adder

A half adder adds two bits: the sum is $A\oplus B$, the carry $AB$. A full adder also adds a carry from the previous position: $S = A\oplus B\oplus C_\mathrm{in}$ and $C_\mathrm{out} = AB + C_\mathrm{in}(A\oplus B)$. Chaining four full adders, so that the carry “ripples” from position to position, gives a 4-bit adder – the heart of a microprocessor’s arithmetic unit (ALU). Ripple carry is slow because the last bit must wait for all the others; fast processors use carry-lookahead, which computes the carries in parallel.

Try it: Here is one full adder drawn with logic gates. Click the inputs A, B and Cin. Wires carrying logic 1 glow gold, and gates whose output is 1 are filled. Go through all eight combinations and compare with the truth table: the sum S is 1 when an odd number of inputs are 1, and the carry is 1 when at least two are. Four such full adders in a chain make the 4-bit adder below.
Try it: Click the bits of A and B to toggle between 0 and 1. The carries (C) are shown between the full adders. Add 0111 and 0001 – how does the carry ripple? Try 0101 + 1011: as unsigned numbers this is 5 + 11 = 16, which needs five bits; in two’s complement it is 5 + (−5) = 0. Both readings are correct – it is the program that decides what the bits mean.

Flip-flops and counters

Combinational circuits have no memory: the output depends only on the inputs right now. Cross-coupling two NAND gates gives a latch that remembers one bit. An edge-triggered D flip-flop copies the input D to the output Q exactly when the clock goes from 0 to 1, and holds it otherwise. With flip-flops one builds registers, shift registers, memory and counters. A simple binary counter is a chain of toggle flip-flops, each dividing the frequency by two – that is how a digital watch gets 1 Hz from a 32 768 Hz quartz crystal ($2^{15}$).

A synchronous system, in which all flip-flops are driven by the same clock, is a state machine: the next state is a combinational function of the present state and the inputs. Every processor is at bottom a large state machine.

Try it: Two cross-coupled NOR gates form an SR latch – the simplest memory there is. Click S (set) to make it 1, and click again to release: Q stays 1. The circuit remembers. Click R (reset) to clear it. Try setting both S and R to 1 – the “forbidden” state, in which both Q and Q̄ become 0, and what the latch settles into when both are released is a matter of chance.
Try it: Give clock pulses and watch the timing diagram. Each output toggles at half the frequency of the previous one. The decade counter resets itself when it reaches 1010 (ten) – in the 7490 chip of the 1980s a NAND gate did exactly that.

TTL and CMOS

Texas Instruments’ 7400 series of TTL chips (transistor–transistor logic), from the mid-1960s, became the industry standard: the 7400 with four NAND gates, the 7474 with two D flip-flops, the 7490 decade counter. TTL works at 5 V; below 0.8 V counts as 0 and above 2.0 V as 1, and the margin to the guaranteed output levels is the noise margin. A TTL gate delays the signal by about 10 ns and uses a few milliwatts. CMOS logic (RCA’s 4000 series from 1968) uses almost no power when not switching, because one transistor is always off. That is why CMOS won completely: a modern processor with billions of transistors would melt in TTL.

From analogue to digital

A D/A converter turns a binary number into a voltage, for example with an R–2R resistor network in which each bit contributes half the current of the one before. An A/D converter goes the other way: the successive-approximation converter tries its way bit by bit with a D/A converter and a comparator, just as one guesses a number with “higher or lower”. With $n$ bits the quantisation error is at most half a step, and the ideal signal-to-noise ratio for a sine wave is $6.02n + 1.76$ dB – about 98 dB for the CD’s 16 bits (see sampling).

Since 1989

Further reading