SILICON · EPISODE 7

Logic from switches: gates, CMOS and the 555

Logic from switches: gates, CMOS and the 555" Here's something I never understood: the chip in your phone is basically purified rock. So how does rock end up doing maths? Episode 7 of Silicon, a series that follows silicon from sand to the data centre, one question at a time.

Logic from switches: gates, CMOS and the 555 video thumbnail▶

The idea in a minute

Last time, we learned to print switches by the million . But a switch only knows two things: on, and off . It can't decide anything. So how does a pile of switches add up your shopping, or check a password? The trick is that you don't need a switch to think. You need to arrange them, so the arrangement does the thinking . First, why only on and off ? A bit is a binary digit, 0 or 1, and any switch with two clear states can hold one . In a chip, a low voltage means 0 and a high voltage means 1 . But they're bands, not exact values . For classic five-volt TTL chips, anything under eight tenths of a volt counts as low, and anything over two volts counts as high . And every gate puts out a cleaner signal than it accepts, so noise gets scrubbed off at each step instead of piling up . The maths came first . In 1854, the English mathematician George Boole published rules for reasoning with values that can only be true or false, 1 or 0 . Three operations do most of the work . AND is true only if both inputs are true . OR is true if either one is, and NOT flips it . In 1937, an MIT master's student, Claude Shannon, noticed that switch circuits obey Boole's rules . Put two switches in a row, and the bulb lights only if A and B are both closed: that's AND . Put them side by side, and either one will do: that's OR . His switches were relays, switches flipped by an electromagnet, the workhorses of telephone exchanges . His thesis even sketched a circuit to add binary numbers . The same year, a Bell Labs mathematician, George Stibitz, took two relays from the company's scrap pile home . With strips cut from a tobacco tin, a couple of dry cells and some flashlight bulbs, he built a machine on his kitchen table that added two binary digits . His wife suggested calling it the Model K, for kitchen . Transistors do the same job as relays, with no moving parts, and far faster . And they come in two flavours. The n-type MOSFET from episode five turns on when its gate is high . Its mirror image, the p-type, turns on when its gate is low . Opposite tempers. That's the whole trick. Stack one of each . The p-type connects the output up to the supply, and the n-type connects it down to ground . Both gates are wired to the same input . Input 0: the top one's on, the bottom one's off, so the output is pulled up to 1 . Input 1: the reverse, and the output drops to 0 . That's a NOT gate, also called an inverter . Two transistors, and the answer is always the opposite . Now use four . Put two p-types side by side on top, and two n-types in a row underneath . The only way to pull the output down is for both bottom switches to be on, so the output is 0 only when A and B are both 1 . That's NOT-AND, or NAND . Swap the arrangement, two in a row on top and two side by side below, and you get NOT-OR, or NOR . Add an inverter and you have AND, or OR . Here's the remarkable part . Given enough of them, NAND gates alone can build any other gate, and so can NOR gates alone . Tie a NAND's two inputs together, and it's a NOT . Follow a NAND with a NOT, and it's an AND . Flip both inputs first, and it's an OR . And since AND, OR and NOT can express any rule at all, NAND can too . This isn't just theory. The computer that guided Apollo to the Moon did all its logic with NOR gates, two to a chip . So how do you add? In binary, there are only two digits, so one plus one is written one-zero: put down 0, carry 1 . For two single bits, the sum digit is 1 only when the inputs differ, a gate called exclusive-or . The carry is 1 only when both are 1, which is just AND . Those two gates together are a half adder . Built from NANDs, it's five gates, about twenty transistors . Chain full adders, which also take in a carry, and you can add numbers of any length . That pairing of opposite transistors has a name: CMOS, complementary MOS .

Read the full transcript

Last time, we learned to print switches by the million . But a switch only knows two things: on, and off . It can't decide anything. So how does a pile of switches add up your shopping, or check a password? The trick is that you don't need a switch to think. You need to arrange them, so the arrangement does the thinking . First, why only on and off ? A bit is a binary digit, 0 or 1, and any switch with two clear states can hold one . In a chip, a low voltage means 0 and a high voltage means 1 . But they're bands, not exact values . For classic five-volt TTL chips, anything under eight tenths of a volt counts as low, and anything over two volts counts as high . And every gate puts out a cleaner signal than it accepts, so noise gets scrubbed off at each step instead of piling up . The maths came first . In 1854, the English mathematician George Boole published rules for reasoning with values that can only be true or false, 1 or 0 . Three operations do most of the work . AND is true only if both inputs are true . OR is true if either one is, and NOT flips it . In 1937, an MIT master's student, Claude Shannon, noticed that switch circuits obey Boole's rules . Put two switches in a row, and the bulb lights only if A and B are both closed: that's AND . Put them side by side, and either one will do: that's OR . His switches were relays, switches flipped by an electromagnet, the workhorses of telephone exchanges . His thesis even sketched a circuit to add binary numbers . The same year, a Bell Labs mathematician, George Stibitz, took two relays from the company's scrap pile home . With strips cut from a tobacco tin, a couple of dry cells and some flashlight bulbs, he built a machine on his kitchen table that added two binary digits . His wife suggested calling it the Model K, for kitchen . Transistors do the same job as relays, with no moving parts, and far faster . And they come in two flavours. The n-type MOSFET from episode five turns on when its gate is high . Its mirror image, the p-type, turns on when its gate is low . Opposite tempers. That's the whole trick. Stack one of each . The p-type connects the output up to the supply, and the n-type connects it down to ground . Both gates are wired to the same input . Input 0: the top one's on, the bottom one's off, so the output is pulled up to 1 . Input 1: the reverse, and the output drops to 0 . That's a NOT gate, also called an inverter . Two transistors, and the answer is always the opposite . Now use four . Put two p-types side by side on top, and two n-types in a row underneath . The only way to pull the output down is for both bottom switches to be on, so the output is 0 only when A and B are both 1 . That's NOT-AND, or NAND . Swap the arrangement, two in a row on top and two side by side below, and you get NOT-OR, or NOR . Add an inverter and you have AND, or OR . Here's the remarkable part . Given enough of them, NAND gates alone can build any other gate, and so can NOR gates alone . Tie a NAND's two inputs together, and it's a NOT . Follow a NAND with a NOT, and it's an AND . Flip both inputs first, and it's an OR . And since AND, OR and NOT can express any rule at all, NAND can too . This isn't just theory. The computer that guided Apollo to the Moon did all its logic with NOR gates, two to a chip . So how do you add? In binary, there are only two digits, so one plus one is written one-zero: put down 0, carry 1 . For two single bits, the sum digit is 1 only when the inputs differ, a gate called exclusive-or . The carry is 1 only when both are 1, which is just AND . Those two gates together are a half adder . Built from NANDs, it's five gates, about twenty transistors . Chain full adders, which also take in a carry, and you can add numbers of any length . That pairing of opposite transistors has a name: CMOS, complementary MOS . In February 1963, Frank Wanlass and Chih-Tang Sah, at Fairchild, showed that complementary logic drew close to zero power while it sat still . Wanlass filed the patent that June . The patent put standby power at less than ten billionths of a watt per node . Why so little? Look at the inverter again . Whatever the input, one of the two transistors is off, so there's never a steady path from the supply to ground . And the gates themselves are insulated, so no current flows into them either . Held still, an ideal CMOS gate draws nothing at all . Real ones leak a trickle, and in today's tiniest transistors that leak is a real cost . So where does a chip's power go? Into switching . Every output is wired to the gates of the next transistors and a stretch of wire, and together they act like a tiny capacitor . Each time the output goes from 0 to 1, that capacitor is filled from the supply . Charging a capacitor through a resistance always loses half the energy as heat . The other half is stored, then dumped as heat when the output drops back to 0 . So switching power rises with the capacitance, the clock rate, and the square of the voltage . All of it ends up as heat , which is episode ten's problem. At first, CMOS was slower, so it went where power mattered more than speed . In 1968, RCA launched a popular family of CMOS logic chips . Watches were the big early market . In 1970, Hamilton unveiled the Pulsar, a two-thousand-one-hundred-dollar digital watch . Its first electronics took forty-four chips, and it was notoriously unreliable . By 1974, a whole watch, display drivers and all, fitted on one CMOS chip, and by 1976 Texas Instruments sold one for under twenty dollars . Then the shrinking from episode five caught up . By 1978, CMOS could compete on speed . And as chips grew to hundreds of thousands of transistors, heat became the limit, and CMOS was the best way to manage it . Today it's the basis of nearly every chip made . But gates aren't instant. Each one takes a moment to respond, and in a chain the delays add up . Watch a simple four-bit ripple counter go from seven to eight . Its bits flip one after another, so for an instant it reads six, then four, then zero, before it finally lands on eight . Read it mid-ripple, and you get garbage . The fix is a clock: a steady beat that everything marches to . Results are only captured at the instant the beat ticks, so outputs change together, not whenever their inputs wobble . The beat just has to be slow enough for the slowest chain of gates to settle . If that takes a billionth of a second, you can tick about a billion times a second: one gigahertz . And a faster clock means more switching, and more heat . And here's a twist. Feed a gate's output back into its input, and it can hold a state . Cross-connect two NOR gates, and give one a brief pulse. The output goes to 1, and stays there, even after the pulse ends, because each gate holds the other in place . Pulse the other side, and it flips to 0 and stays . That's a latch, and made to change only on the clock's tick, a flip-flop . It's one bit of memory . Flip-flops can count, too. Wired to toggle, each one halves the frequency of the beat it's fed . Nearly every quartz watch has a crystal vibrating thirty-two thousand, seven hundred and sixty-eight times a second, which is fifteen twos multiplied together . Halve it fifteen times, and out comes exactly one tick per second . Now a chip that mixes it all. In 1970, Hans Camenzind, working as a consultant to the chipmaker Signetics, came up with a simple timer . The company's engineers turned it down, but its marketing manager liked it . Camenzind spent nearly a year building it, cutting the masks by hand . It was on sale by 1972, with twenty-three transistors in an eight-pin package . And the name, 555 ? He said it was picked arbitrarily . Inside, a chain of resistors marks two levels: one-third and two-thirds of the supply, and two comparators watch for them . Trigger it, and a flip-flop switches the output on, while an outside capacitor charges through a resistor . When the capacitor reaches two-thirds, the flip-flop flips back, and a transistor dumps the charge . That's a one-shot, lasting about one point one times the resistance times the capacitance . Wire it to retrigger itself, and it bounces between one-third and two-thirds forever: an oscillator . Billions have been sold . So switches can decide, add, keep time, and even remember a single bit . But a flip-flop forgets the moment the power goes off, and it takes several transistors to hold one bit . So how does a phone keep billions of bits for years, even with a flat battery ? How does silicon remember? RAM, ROM and flash . That's next time.

← Previous

New to Silicon?

Start with Episode 1, then follow the chain from sand to supercomputers.

View the series roadmap