Exercise 3.2: Flip-Flops

You are not logged in.

Please Log In for full access to this page.

1) Designing a D Latch: Solving the "Invalid State"

In our previous SR Latch, we had a small problem. We had to use two buttons (Set and Reset) to control one bit of memory. Even worse, if we accidentally pressed both buttons at once (S=0, R=0), the circuit entered a "forbidden state" where both outputs went High, breaking the logic that Q and Q' must be opposites.

The forbidden state is a consequence of our intention to use this as a memory block. Assume the latch is initially reset with both inputs 0 and EN as 1(and stays 1 for now). To set the latch we input the bits as SR = 10, and to store the bit we go SR = 00; To reset the latch again, we input the bits as SR = 01, and to store the bit, we got SR = 00; Now if we input SR = 11, both the outputs are high. If we go back to SR = 00 from here, in practical circuits, either S or R will go to 0 first and then the other with microsecond level of time difference. But our circuits catch this and store either set or reset depending on which one is faster. And it is very unpredictable which will be faster, so the storage is essentially random. Therefore, to have a more predictible and functional circuit, we assign SR = 11 as forbidden.

We can fix this by ensuring that Set and Reset are always opposites. If Set is 1, Reset must be 0. If Set is 0, Reset must be 1.

How do we do this? We use an Inverter (NOT Gate)! This new circuit is called the D Latch (Data Latch).

Hardware Setup: The 7404 Hex Inverter

To build this, we will add a new chip to our board: the 7404 Hex Inverter IC.

Pinout diagram of the 7404 Hex Inverter IC showing 6 independent NOT gates

Components You'll Need

  • Existing Circuit: Your Gated SR Latch (7400 IC)
  • New Logic: 1x 7404 IC (Contains 6 Inverters)
  • Input: 1x Push Button (Data)

Step-by-Step Assembly

  1. Place the 7404 IC: Insert the 7404 chip into the breadboard. Connect Pin 14 to VCC and Pin 7 to GND.
  2. Modify Inputs: Remove the old Set and Reset push buttons.
  3. Add Data Button: Place a new button (Data). Connect one side to VCC and the other to a 10k pull-down resistor.
  4. Connect to Set: Connect the Data button signal to the Set input of your NAND latch.
  5. Connect to Inverter: Connect the same Data signal to Pin 1 (Input) of the 7404.
  6. Connect to Reset: Connect Pin 2 (Output) of the 7404 to the Reset input of your NAND latch.
  7. Keep Enable: Ensure your Enable button is still connected to the latch's enable pins.
Circuit diagram of a D Latch using NAND gates and an inverter The D Latch Logic Now we have only one data input (D).
When **Enable is High**: The output Q copies input D.
When **Enable is Low**: The output Q is frozen (Memory).

Why do we add an inverter between the Set and Reset inputs to create a D-Latch?

If the Enable pin is HIGH (1) and the Data input is HIGH (1), what will be the value of Q?

2) The 7474 IC: The Professional D Flip-Flop

Building flip-flops from NAND gates is great for learning, but messy for big projects. Engineers use dedicated chips. The most famous one is the 7474 Dual D Flip-Flop.

Pinout diagram of the 7474 Dual D Flip-Flop IC

What makes the 7474 special?

  • Edge-Triggered: It only updates memory when the clock goes from Low to High (Rising Edge).
  • Preset and Clear: Special pins to force the memory to 1 or 0 instantly, ignoring the clock.

Components You'll Need

  • 1x 7474 Dual D Flip-Flop IC
  • 2x Push Buttons (Clock and Data)
  • 2x LEDs (Red for Q, Green for Q')

Step-by-Step Assembly

  1. Power: Connect Pin 14 to VCC and Pin 7 to GND.
  2. Disable Overrides: Connect Pin 1 (CLR) and Pin 4 (PRE) directly to VCC (+5V).
    • Note: These pins are "Active Low". If you leave them unconnected (floating) or ground them, the chip will get stuck.
  3. Inputs: Connect a button to Pin 2 (D) and another to Pin 3 (CLK).
  4. Outputs: Connect LEDs to Pin 5 (Q) and Pin 6 (Q').

Verification Experiment:

  • Hold D button DOWN (Data = 1).
  • Tap the CLK button. The Q LED should turn ON.
  • Release D button (Data = 0).
  • Tap the CLK button. The Q LED should turn OFF.
  • The "Edge" Test: Hold D down, but don't press Clock. The LED should NOT change. It waits for the "rising edge" of the clock.

Refer to the datasheet of the D flip-flop IC and answer.

On the 7474 IC, what must you do with the Preset (PRE) and Clear (CLR) pins if you don't want to use them?

If you hold the Data button (D=1) but never press the Clock button, does the output Q change? (Yes/No)

3) Building a Frequency Divider

Now for a cool trick. What happens if we make the Flip-Flop feed itself? By connecting the inverted output (Q') back to the input (D), the flip-flop will flip its state every single time the clock ticks.

Circuit diagram showing Q-bar connected to D input on a 7474 Flip-Flop

Components You'll Need

  • Your working 7474 circuit from the previous step.

Step-by-Step Assembly

  1. Remove the Data Button: Disconnect the button from Pin 2.
  2. Add Feedback Wire: Connect a wire directly from Pin 6 (Q') to Pin 2 (D).
  3. Test: Press the Clock button repeatedly. The LED should toggle On-Off-On-Off.

Why is this useful? If you tap the clock button 10 times per second, the LED will blink 5 times per second. You have just built a Frequency Divider (Divide-by-2 Counter)!

The Math of Division
  • Input Frequency (Clock): f
  • Output Frequency (Q): f / 2

If we connect a 100 Hz clock signal to this frequency divider circuit, what will be the frequency of the output Q in Hz?

4) Final Activity: The T Flip-Flop (Toggle with Control)

The Frequency Divider we just built toggles forever. But what if we want to control whether it toggles or holds? We want a "Toggle Enable" switch. This is called a T Flip-Flop.

To do this, we need a controlled inverter. The XOR Gate (7486 IC) is perfect for this!

  • XOR(A, 0) = A (Buffer / Hold)
  • XOR(A, 1) = A' (Inverter / Toggle)
Circuit diagram of a T Flip-Flop using a 7474 D Flip-Flop and 7486 XOR gate

Components You'll Need

  • Your 7474 D Flip-Flop
  • 1x 7486 XOR Gate IC
  • 1x Toggle Switch (This will be T)

Step-by-Step Assembly

  1. Place 7486: Insert the XOR chip and power it (Pin 14 VCC, Pin 7 GND).
  2. Feedback Logic: Connect Pin 5 (Q) of the 7474 to Input A (Pin 1) of the XOR.
  3. Control Logic: Connect your Toggle Switch (T) to Input B (Pin 2) of the XOR.
  4. Drive the D Input: Connect the Output (Pin 3) of the XOR to the D Input (Pin 2) of the 7474.
  5. Clock: Keep your Clock button connected to Pin 3 of the 7474.

Experiment:

  • Set T = 0: Tap the clock. The LED should not change. (Hold Mode)
  • Set T = 1: Tap the clock. The LED should flip every time. (Toggle Mode)

Upload a video of your T Flip-Flop. Show that when T=0, the clock does nothing (LED stays still). When T=1, the clock makes the LED toggle.
 No file selected

In the next module, we will chain multiple T Flip-Flops together to build the multi-digit counter for our digital clock project!