In my computer architecture class we spent a fair bit of time on circuits used in the computer, including how memory circuits work. It's really cool and kind of mind-bending that it works at all. The goal of a bit of digital memory is three fold:
- To be able to set a memory bit high or low.
- For the memory to continue to stay high or low without having to be held there.
- To be able to retrieve the value of the memory without disrupting it.
First try: the SR latch.
The SR latch is nice and simple (and cheap) but R and S could be asynchronous, and if both are on the output is inconsistent.
Second try: the Unclocked D latch.
Now there's a single input, which fixes the problem of asynchronous input, but Q is always equal to D. Our second requirement is broken.
Third try: the Clocked D latch.
Now the value is only set (based on D) when the clock signal is pulsed. Much improved. However, the clock signal tends to be high for about half the time, so it would be better if we could limit updating the circuit to the instant the clock signal turns high.
Fourth try: the D Flip-Flop.
This uses an edge trigger, which isolates the instant that the clock signal turns high.
In the diagram above, yellow represents the electrical signal being "high" and no yellow represents "low."
Looking at the circuit, I wouldn't have expected it to work. But it does. The edge trigger will activate at all because it takes the electric signal slightly longer to go through the gate than it takes to go through the wire.
Modern memory circuits probably don't use this particular flip-flop anymore; nevertheless, it is an interesting topic to explore and programming/animating the circuitry helped me to understand it thoroughly.
Download the jar file here