Every circuit in this series so far forgets. Its output depends only on its inputs at this moment: let go of a button and the LED goes out. A light switch is different. You press it once and the light stays on, because the switch holds its position. To build a circuit that holds a state, you need one new idea: feedback, feeding an output back into an input.
Feedback with gates can do odd things. A NOT gate whose output is fed back to its own input is told to be the opposite of itself, which neither 0 nor 1 can satisfy, so it ends up stranded in the forbidden middle band from part 3. But two inverting gates in a ring are perfectly happy. If the first gate’s output is 1, the second gate turns it into 0, and the first gate, seeing 0, keeps its output at 1. Each holds the other in place. Start it the other way round and it stays that way instead. The ring has two stable states, and it stays in whichever one it is put in. That is one bit of memory.
To make the ring useful, each gate gets a second input that can push it into a state. With two NAND gates, the result is the SR latch, for set and reset, the simplest memory circuit there is. The British physicists William Eccles and F. W. Jordan patented the first electronic version, with two vacuum valves, in 1918.
A NAND’s output is forced to 1 whenever either input is 0. So:
- Pressing Set pulls the top gate’s free input low, and its output, called Q, is forced to 1. The bottom gate now sees 1 and 1, so its output falls to 0, and that 0 holds the top gate at 1.
- Letting go returns the input to 1. But the top gate’s other input is still being held at 0 by the bottom gate, so Q stays 1. The latch remembers.
- Pressing Reset does the same to the bottom gate, and Q falls to 0, and stays there.
Notice that the inputs work backwards: a gate is pushed by a 0, not a 1. They are . So the buttons connect each input to ground when pressed, and a 10 kΩ pull-up holds it at 1 otherwise, the mirror image of the pull-downs in part 3.
An active-low name carries a bar: the inputs are and , said “S bar” and “R bar”. The bar is the NOT from part 6, so means “not S”. When it is 0, S is true and the latch is set; the rest of the time it rests at 1. Datasheets mark pins the same way, so a pin’s name tells you which level makes it act: without a bar, 1; with a bar, 0. On an output the bar means NOT as well: the latch’s second output, , is always the opposite of Q, apart from one awkward exception.
The latch
Hold Set, then release it, and watch Q in the timing diagram after you let go. Do the same with Reset. Then hold both, and release both at once.
Press Set, then let go. Watch Q after you let go.
Two NAND gates with active-low inputs, as on the breadboard below. The buttons here stay down until you press them again, so you can hold both.
The forbidden state
Hold both buttons and both gates are forced to 1: Q and are both high. Nothing breaks, but the latch is no longer telling the truth, because is supposed to be the opposite of Q. Datasheets and textbooks call this the forbidden, or invalid, state.
The real trouble comes when you let go. If you release one button first, the other wins and the latch settles cleanly. But if both are released at exactly the same instant, each gate starts to fall back towards 0, and whichever is a fraction of a nanosecond faster decides the outcome. It might be Q one time and the next. A latch caught balanced between its two states can even hover there for a moment before it falls one way, a condition called metastability. The rule is simple: design so that both inputs are never active together.
- The 74HC00 at f14, powered and decoupled as always. Tie the unused inputs, pins 9, 10, 12 and 13, to the top − rail.
- Set button across columns 3 and 5: wire j3 to the bottom − rail, fit a 10 kΩ pull-up from a5 to the top + rail, and run a yellow wire from h5 to h14, pin 1 ().
- Reset button across columns 8 and 10: j8 to −, a 10 kΩ from a10 to +, and a green wire from g10 to g18, pin 5 ().
- The feedback: a blue wire from h19 (pin 6, ) to h15 (pin 2), and a white wire from i16 (pin 3, Q) to i17 (pin 4).
- The LED on Q: a wire from h16 to h23, 330 Ω from g23 to g26, the LED from i26 to i27, and j27 to −.
Press Set: the LED lights, and stays lit when you let go. Press Reset: it goes out, and stays out. Press Set several times in a row: nothing changes after the first. When you first switch on, the LED may be on or off: a latch starts in whichever state it falls into.
The SR latch has two problems. It needs two inputs to store one bit, and it reacts the instant they change. Larger circuits need memory that takes in a value only when told to, at a moment of their choosing. That is the D flip-flop, and the 74HC74 holds two of them.
A has a data input, D, and a clock input, CLK. It ignores D almost all the time. At the instant the clock goes from low to high, its , it copies whatever D is at that moment to its output Q, and holds it until the next rising edge. D can change as often as it likes in between, and Q pays no attention. is its opposite.
Each flip-flop also has two override inputs, both active low: , preset, forces Q to 1, and , clear, forces Q to 0, both immediately, whatever the clock is doing. When you do not need them, tie them to +5 V. If you leave them floating, part 3’s trap returns in its most confusing form: the flip-flop seems to ignore its clock.
The first flip-flop of a 74HC74 uses pins 1 to 6: on 1, D on 2, CLK on 3, on 4, Q on 5 and on 6. The second mirrors it on pins 8 to 13, and power is on 14 and 7 as usual. The interactive pinout in part 7 has the details.
Catching a bit
Set D, then hold the clock button for a pulse: Q copies D at the rising edge. Change D again without a clock pulse and watch Q ignore it. Try Preset and Clear, then run the clock and change D while it ticks.
Set D, then pulse the clock. Change D again without a clock pulse and see what Q does.
One flip-flop of a 74HC74. Rising edges are marked under the clock trace. Pin numbers are for the first flip-flop in the chip.
Do not simply drop the 74HC74 into the test rig: the rig ties pins 5 and 9 to ground, and on this chip those are outputs. Build it fresh:
- The 74HC74 at f14, notch to the left, powered (a14 to +, j20 to −) and decoupled.
- Tie both flip-flops’ overrides high: pin 1 (j14) and pin 4 (j17) to the bottom + rail, pins 10 (a18) and 13 (a15) to the top + rail. Tie the spare flip-flop’s D and CLK, pins 12 (a16) and 11 (a17), to the top − rail.
- Button D across columns 3 and 5, with a3 to +, a 10 kΩ pull-down from j5 to −, and a yellow wire from h5 to h15, pin 2.
- Button CLK across columns 8 and 10, with a8 to +, a 10 kΩ from j10 to −, and a green wire from g10 to g16, pin 3.
- The LED on Q: a wire from h18 (pin 5) to h23, then 330 Ω, the LED and the wire to − as on the rig.
Hold D and tap the clock button: the LED lights. Release D: it stays lit. Tap the clock again: it goes out. The LED changes only at the moment you press the clock button, never when you press or release D.
A flip-flop does its work at each rising edge. Pressing a button for every edge is slow work, and the button has a surprise in store. The next part builds a clock that ticks by itself, and deals with the surprise.
Sources for this part
Latches and flip-flops
History