The Circuit That Remembers: Master Flip-Flops & Build a 1-Bit Memory Machine

The Circuit That Remembers: Master Flip-Flops & Build a 1-Bit Memory Machine


📑Table of Contents
What You'll Need 6 items
SN74HC00N (NAND Gate)
Buy
Breadboard
Buy
Push Buttons
Buy
5mm LED
Buy
1kΩ Resistor
Buy
Jumper Wires
Buy

Affiliate links help support this site at no extra cost to you.

Welcome to Day 8 of our Electronics for Absolute Beginners series.

Yesterday, we built Logic. We built a machine that could make a decision. “If A AND B, then Action.” But there was a flaw. A fatal flaw. As soon as you let go of the buttons… the decision vanished. The output died. The machine had Amnesia.

Imagine a computer with no memory. It could calculate 2 + 2 = 4, but the instant it finished, it would forget the “4”. It couldn’t browse the web, because it couldn’t remember which pixels were on the screen a millisecond ago. It would be useless.

Today, we fix that. Today, we teach the silicon to Remember.

Digital Amnesia concept art

The Problem of logic

Logic gates (AND, OR, NOT) are “Combinational Logic.” Their output depends only on the current state of inputs. Input change -> Output change. Instantly. They have no sense of history. No “State”.

To create Memory, we need a circuit whose output depends on the Past. How do you make a circuit look backwards in time?

The Feedback Loop: Electronic Echoes

The secret is Feedback. You take the output of a gate, and you wire it back into its own input. It’s like looking in a mirror that reflects a mirror. Infinite loop. Or like a microphone pointed at a speaker—that screeching noise is the system feeding itself.

In a normal “Combinational” circuit (like an AND gate), the electrons flow in a straight line. River flows downstream. In a “Sequential” circuit (Memory), the river circles back. It becomes a whirlpool. Once the water starts spinning, it keeps spinning on its own momentum.

Positive Feedback allows a circuit to “lock” itself into a state and stay there.

  • Input 1: Push the swing (Set).
  • Feedback: The swing keeps moving.
  • Input 0: Stop pushing.
  • Result: The swing is still moving! It remembered the push.

Feedback Loop Visual Diagram

The SR Latch: The Trap

Let’s build the simplest possible memory cell roughly. It’s called the SR Latch (Set-Reset Latch). We build it using two NOR gates (or NAND gates) connected in a cross pattern. Gate A’s output goes to Gate B’s input. Gate B’s output goes to Gate A’s input. They are locked in an eternal staring contest.

  • SET (S): Turn the memory ON (Store a 1).
  • RESET (R): Turn the memory OFF (Store a 0).
  • Q: The Output (The stored data).
  • Q-Bar: The Inverse Output (If Q is 1, Q-Bar is 0).

How it Works (The Mechanics)

Imagine Gate A and Gate B. They are holding hands.

  1. Hit SET: You send a voltage spike to Gate A.
  2. Gate A outputs a “0” (because it’s a NOR gate).
  3. Gate B sees this “0”. Since its other input (Reset) is also 0, Gate B outputs a “1”.
  4. Crucial Step: This “1” travels back along the wire to Gate A’s input.
  5. Gate A now sees a “1” from Gate B.
  6. You release SET.
  7. Gate A still sees a “1” (from Gate B). So it keeps outputting “0”.
  8. Gate B still sees a “0” (from Gate A). So it keeps outputting “1”.
  9. Locked.

The value is trapped in the loop. It will stay trapped forever (as long as the battery lasts) until you hit RESET, which breaks the cycle and forces them to lock in the other direction.

SR Latch Internal Schematic

The Truth Table (Simplified)

Set (S)Reset (R)ActionOutput (Q)
10SET1 (On)
00HOLD (Memory!)Unchanged
01RESET0 (Off)
11ILLEGALExplosion (Sort of)

Wait, what is “Illegal”? If you push Set and Reset at the same time, you are asking the circuit to be On and Off simultaneously. The Laws of Physics get confused. The gates fight. The output becomes unpredictable. In the digital world, unpredictability is death. Ideally, we want a chip that prevents us from doing this stupid thing.

SR Latch Logic Table Chart

The Enemy: Switch Bounce (The Real World)

Before we look at the better chip, we need to address a harsh reality of physics. You think when you press a button, it makes contact once. Click.

Wrong. Inside the switch, two pieces of metal are slamming together. They are elastic. They bounce. Like a tennis ball dropped on the floor. Click-clack-click-clack-click.

To a human, it feels like one press. To a chip that operates at 10,000,000 times a second, it looks like you pressed the button 50 times in 1 millisecond.

If you use a simple latch as a counter (1, 2, 3…), one button press might count as 17. This is called Switch Bounce.

Switch Bounce Oscilloscope Diagram

How do we fix the Bounce?

We need a bouncer at the club door. We need to ignore the jittery “noise” and only let the clean signal through. There are two ways:

  1. Software Debouncing: (Used in Arduino). You write code that says “If I see a signal, wait 50ms. If it’s still there, it’s real.”
  2. Hardware Debouncing: pure physics.
    • We use a Capacitor and a Resistor (RC Circuit).
    • The capacitor acts like a shock absorber. It takes time to charge up.
    • The fast “flickers” of the bouncing switch are too fast to fill the capacitor, so the voltage stays low.
    • Only a solid, long press allows the capacitor to fill up and trigger the gate.

For today, we will skip the capacitor and rely on the “Clock” of the Flip-Flop to help us (mostly). But know this: All mechanical switches lie.

The Solution: The D Flip-Flop

The SR Latch is crude. It has an illegal state. It’s asynchronous (uncontrolled). Enter the D Flip-Flop (Data Flip-Flop).

It adds two massive improvements:

  1. The CLOCK (CLK): A strict manager. The chip ignores inputs 99% of the time. It only looks at the input at the exact moment the Clock signal goes High (The Rising Edge).
  2. No Illegal State: It only has one data input (D). D can be 1 or 0. You can’t be both.

How it works

  • D Input: You put your data here (Is the button pressed?).
  • Clock Input: The trigger.
  • Q Output: The memory.

You can change D all you want. Dance on the button. The output (Q) will not change. Only when the Clock goes from Low to High (Transition), the chip takes a “Snapshot” of D and copies it to Q. It filters out the noise between keypresses. It creates order.

D Flip-Flop Black Box Diagram

THIS is the building block of RAM. Your 16GB RAM stick is essentially 137 billion tiny D Flip-Flops and capacitors packing data.

Trivia: Why “Flip-Flop”?

It’s onomatopoeia. In early discrete transistor circuits, you could actually hear the relay click from one state to another. Flip… Flop… Flip… Flop. The name stuck. It sounds silly, but it describes the bistable action perfectly. It flips to 1, or flops to 0.

Deep Dive: Metastability (The Twilight Zone)

What happens if data arrives exactly at the same nanosecond the clock fires? The chip gets confused. It enters a state called Metastability. The output might hover at 2.5 Volts (halfway) for a few milliseconds before randomly picking 0 or 1. This is a nightmare for CPU designers. To prevent this, we must obey two rules found in the datasheet:

  1. Setup Time (tsut_{su}): Data must be stable before the clock edge. (e.g., 20ns).
  2. Hold Time (tht_h): Data must stay stable after the clock edge. (e.g., 5ns). If you violate these, your computer crashes.

Inside the Black Box: How to Build Your Own D Flip-Flop

You might wonder, “What is actually inside the 74HC74?” Is it magic? No. It is just logic gates. 6 NAND gates, to be precise.

If you really wanted to, you could build a D Flip-Flop using the chips from Day 7 (NAND gates). It uses a clever arrangement called the Master-Slave configuration.

  1. The Master Latch: Captures the input when the Clock is HIGH.
  2. The Slave Latch: Copies the Master when the Clock goes LOW.
  3. The Result: Data only moves to the output on the edge of the clock.

This complexity is why we buy the chip. Building one D Flip-Flop takes 6 NAND gates (1.5 chips). Building a 4-bit counter would take 6 chips and a spaghetti monster of wires. The 74HC74 gives you two of them for 50 cents.

Why not just use Transistors?

On Day 4, we learned that transistors are switches. Can’t we just wire two transistors back-to-back to store data? Yes. This is called a Bi-Stable Multivibrator.

  • Transistor A forces Transistor B off.
  • Transistor B forces Transistor A on. It works perfectly. So why do we use logic gates? Reliability. Discrete transistor latches are finicky. They depend on exact resistor values. They are sensitive to temperature. Logic gates (and Flip-Flops) are Digital. They snap to 0 or 1. They are robust. Unless you are building a fuzz pedal for a guitar, stick to the chips.

74HC74 Pinout Render

Pinout Breakdown:

  • 1D (Pin 2): Input for Cell 1.
  • 1CLK (Pin 3): Clock for Cell 1.
  • 1Q (Pin 5): Output for Cell 1.
  • 1Q-Bar (Pin 6): Inverted Output (Always opposite of Q).
  • PRE (Preset) & CLR (Clear): These are “Overrides”. They act like the old Set/Reset. usually, we tie them to High (+5V) to disable them so they don’t interfere.

Project: The 1-Bit Recorder

We are going to build a machine that “Saves” the state of a button.

  • Button A (Data): The information we want to save.
  • Button B (Shutter): The “Save” command (Clock).

If you press Button A: Nothing happens. The LED ignores you. If you HOLD Button A and tap Button B: Snap. The LED turns ON. Now you can release Button A. The LED stays ON. It remembers that you were pressing A when the photo was taken.

Components Needed

  • 1x 74HC74 (or 74LS74) IC
  • 2x Push Buttons (Tactile)
  • 1x LED (Red)
  • 3x 10kΩ Resistors (Pull-Downs and Pull-Ups)
  • 1x 330Ω Resistor (LED limit)
  • 3x AA Battery Pack (4.5V) or USB (5V)

The Schematic

This looks complex, but follow the wires one by one.

Project Schematic Diagram

Critical Wiring Details:

  1. Power: Pin 14 to +5V, Pin 7 to GND.
  2. Disable Overrides: Connect Pin 1 (CLR) and Pin 4 (PRE) directly to +5V. (Active Low pins need High to stay quiet).
  3. Data Input: Button A connects to Pin 2 (D). (Use a 10k Pull-Down to GND).
  4. Clock Input: Button B connects to Pin 3 (CLK). (Use a 10k Pull-Down to GND).
  5. Output: Pin 5 (Q) goes to LED -> 330Ω -> GND.

Step-by-Step

  1. Place the Chip. Bridge the gap. Notch to the left.
  2. Power Rails. Pin 14 Red, Pin 7 Blue.
  3. Lock the Doors. Connect Pin 1 and Pin 4 straight to Red (+). If you forget this, the chip will reset randomly.
  4. Wire Button A (Data). One leg to +, other leg to Pin 2. Same leg on Pin 2 gets a 10k resistor to -.
  5. Wire Button B (Clock). One leg to +, other leg to Pin 3. Same leg on Pin 3 gets a 10k resistor to -.
  6. Wire the LED. Pin 5 -> LED (+) -> Resistor -> GND.

Breadboard Render

Testing the Machine

  1. Power Up. LED might be random (On or Off).
  2. Press Button A (Data). Nothing happens.
  3. Hold Button A + Tap Button B (Clock). LED turns ON.
  4. Release Everything. LED STAYS ON.
    • System Status: You have trapped a “1”.
  5. Don’t Touch A + Tap Button B. LED turns OFF.
    • System Status: You trapped a “0” (because A was 0 when you clocked).

It works exactly like a camera. Button B is the Shutter. Button A is the Scene. The film (Q) only changes when the Shutter clicks.

The Safety Checklist (Don’t Fry Your Chip)

Before you power up, quadruple check these:

  1. VCC and GND: Pin 14 is +5V. Pin 7 is Ground. Reversed = Dead Chip.
  2. Floating Inputs: Do not leave ANY input floating. If you aren’t using the second Flip-Flop (Pins 8-13), ground its inputs! (Connect Pins 10, 11, 12, 13 to GND).
  3. Voltage Level: Are you using a 9V battery directly? STOP. 74HC chips melt at 7V. Use 3xAA batteries (4.5V) or a USB breakout (5V).

The Bill of Materials (BOM)

To build the memory cell, you need:

ComponentQuantitySpecsNotes
74HC741Dual D-Flip FlopThe Core Brain
Push Button2Momentary Tactile1 for Data, 1 for Clock
LED1Red or GreenTo see the output
Resistor1330ΩCurrent Limiting
Resistor310kΩPull-Down / Pull-Up
Power15V SourceUSB or 3xAA
Breadboard1Size doesn’t matter-

The Engineer’s Glossary (Day 8 Edition)

  • Sequential Logic: Circuits where output depends on history (Memory).
  • Combinational Logic: Circuits where output depends only on now (Logic Gates).
  • Latch: A primitive memory cell (Level Triggered).
  • Flip-Flop: An advanced memory cell (Edge Triggered).
  • Clock (CLK): A heartbeat signal that synchronizes data.
  • Rising Edge: The specific instant a signal goes from Low (0) to High (1).
  • Volatile Memory: Memory that forgets when power is lost (RAM).
  • Debounce: Cleaning up a noisy switch signal.

A Blast from the Past: Magnetic Core Memory

Before chips like the 74HC74, how did computers remember? In the 1950s and 60s (including the Apollo Mission), they used Magnetic Core Memory. Imagine a woven blanket of copper wires. At every intersection, there was a tiny donut made of ferrite (iron).

  • Magnetize the donut Clockwise = 1.
  • Magnetize the donut Counter-Clockwise = 0.

To read a bit, you had to try to flip the magnet. If it flipped, you knew it was a 1. If it didn’t, it was a 0. This “Destructive Read” meant the computer had to immediately write the data back after reading it! It was heavy. It was expensive. It was woven by hand by seamstresses. But it was Non-Volatile. If the power went out, the magnets stayed magnetized. Today, we can store gigabytes in a chip the size of a fingernail, but we should respect the donut-weavers who got us to the moon.

Deep Dive: RAM vs SSD

You just built SRAM (Static RAM).

  • Fast: It switches instantly.
  • Expensive: It takes 4-6 transistors to store ONE bit.
  • Volatile: If you pull the battery… Poof. The data is gone. The electrons flow back home.

This is why your computer needs a hard drive (SSD). SSDs use Floating Gate Transistors (Flash Memory) which physically trap electrons in a cage of glass. They stay there for years without power. But Flash is slow. So computers use both:

  • Flip-Flops (RAM) for thinking fast.
  • Flash (SSD) for sleeping long.

The Day 8 Challenge

Proof of understanding. Can you modify your “1-Bit Recorder” to be a “Toggle Switch”? Goal: Press the button once -> LED ON. Press again -> LED OFF. (Like a real light switch). Hint: You need to connect the Q-Bar output back to the D input. Every time the clock fires, it loads the inverse of what it currently is. If it’s ON, it loads OFF. If it’s OFF, it loads ON. Try it. It’s magic.

Troubleshooting

  • LED Flickers? Switch bounce! We simplified the clock button. In a pro circuit, we would add a capacitor to Button B to smooth the signal.
  • Reset Randomly? Check Pins 1 and 4. They MUST be connected to +5V. If they float, they pick up ghosts.
  • Nothing Happens? Did you confuse D and CLK? D prepares the value, CLK saves it.

Conclusion: The Philosophy of Memory

Think about what defines “You”. Is it your logic? Your ability to make decisions? Or is it your memory? Your history? Without memory, logic is hollow. It reacts, but it cannot learn. Today, you gave your circuits a soul. You gave them a past. By trapping that single electron in a loop, you created a machine that exists in time, not just in the moment. That is profound.

The Future: Counting

One bit of memory is cool. But what if we chain them? What if the output of Flip-Flop A triggers Flip-Flop B? A -> B -> C -> D. 0001 0010 0011 0100

That is a Binary Counter. Tomorrow, on Day 9, we will chain these chips together to teach our machine to Count. We will build a 4-bit Binary Counter that counts from 0 to 15. From there, it’s a short hop to building a clock, a timer, and eventually… a CPU. The complexity is ramping up. But so is the fun.

Keep that data safe. See you tomorrow.

Comments