Code_ The Hidden Language of Computer Hardware and Software - Charles Petzold [57]
Closing the bottom switch causes the lightbulb to go off, and it stays off when the bottom switch is opened.
The strangeness of this circuit is that sometimes when both switches are open the light is on, and sometimes when both switches are open, the light is off. We can say that this circuit has two stable states when both switches are open. Such a circuit is called a flip-flop, a word also used for beach sandals and the tactics of politicians. The flip-flop dates from 1918 with the work of English radio physicist William Henry Eccles (1875–1966) and F.W. Jordan (about whom not much seems to be known).
A flip-flop circuit retains information. It "remembers." In particular, the flip-flop shown previously remembers which switch was most recently closed. If you happen to come upon such a flip-flop in your travels and you see that the light is on, you can surmise that it was the upper switch that was most recently closed; if the light is off, the lower switch was most recently closed.
A flip-flop is very much like a seesaw. A seesaw has two stable states, never staying long in that precarious middle position. You can always tell from looking at a seesaw which side was pushed down most recently.
Although it might not be apparent yet, flip-flops are essential tools. They add memory to a circuit to give it a history of what's gone on before. Imagine trying to count if you couldn't remember anything. You wouldn't know what number you were up to and what number comes next! Similarly, a circuit that counts (which I'll show you later in this chapter) needs flip-flops.
There are a couple of different types of flip-flops. What I've just shown is the simplest and is called an R-S (or Reset-Set) flip-flop. The two NOR gates are more commonly drawn and labeled as in the diagram at the top of the next page to give it a symmetrical look.
The output that we used for the lightbulb is traditionally called Q. In addition, there's a second output called (pronounced Q bar) that's the opposite of Q. If Q is 0, then is 1, and vice versa. The two inputs are called S for set and R for reset. You can think of these verbs as meaning "set Q to 1" and "reset Q to 0." When S is 1 (which corresponds to closing the top switch in the earlier diagram), Q becomes 1 and becomes 0. When R is 1 (corresponding to closing the bottom switch in the earlier diagram), Q becomes 0 and becomes 1. When both inputs are 0, the output indicates whether Q was last set or reset. These results are summed up in the following table:
Inputs
Outputs
S
R
Q
1
0
1
0
0
1
0
1
0
0
Q
1
1
Disallowd
This is called a function table or a logic table or a truth table. It shows the outputs that result from particular combinations of inputs. Because there are only two inputs to the R-S flip-flop, the number of combinations of inputs is four. These correspond to the four rows of the table under the headings.
Notice the row second from the bottom when S and R are both 0: The outputs are indicated as Q and . This means that the Q and outputs remain what they were before both the S and R inputs became 0. The final row of the table indicates that a situation in which the S and R inputs are both 1 is disallowed or illegal. This doesn't mean you'll get arrested for doing it, but if both inputs are 1 in this circuit, both outputs are 0, which violates the notion of being the opposite of Q. So when you're designing circuitry that uses the R-S flip-flop, avoid situations in which the S and R inputs are both 1.
The R-S flip-flop is often drawn as a little box with the two inputs and two outputs labeled like this:
The R-S flip-flop is certainly interesting as a first example of a circuit that seems to "remember" which of two inputs was last a voltage. What turns out to be much more useful, however, is a circuit that remembers whether a particular signal was 0 or 1 at a particular point in time.
Let's think about how such a circuit should behave before we actually