Sequential logic & flip-flops

Digital logic & computing · tree view

Feedback turns gates into latches with memory; edge-triggered flip-flops (D, JK, T) restrict state changes to a clock edge, synchronize circuits, and halve frequency when toggled.

Prerequisites

flip-flop symbol
flip-flop
ttl-7400 symbol
ttl-7400
cmos-4000 symbol
cmos-4000
555-timer symbol
555-timer
sr-latch-nor.svg
sr-latch-nor.svg
d-flipflop-edges.svg
d-flipflop-edges.svg
divide-by-2-timing.svg
divide-by-2-timing.svg

Any digital circuit employing feedback is called a multivibrator. The example we just explored with the OR gate was a very simple example of what is called a bistable multivibrator. It is called "bistable" because it can hold stable in one of two possible output states, either 0 or 1.

— kuphaldt-linac DIGI, Vol. IV (Digital), ch. 10 — Digital logic with feedback source

The Q and not-Q outputs are supposed to be in opposite states. I say "supposed to" because making both the S and R inputs equal to 1 results in both Q and not-Q being 0. For this reason, having both S and R equal to 1 is called an invalid or illegal state for the S-R multivibrator.

— kuphaldt-linac DIGI, Vol. IV (Digital), ch. 10 — The S-R latch source

An application for the D latch is a 1-bit memory circuit. You can "write" (store) a 0 or 1 bit in this latch circuit by making the enable input high (1) and setting D to whatever you want the stored bit to be. When the enable input is made low (0), the latch ignores the status of the D input and merrily holds the stored bit value, outputting at the stored value at Q, and its inverse on output not-Q.

— kuphaldt-linac DIGI, Vol. IV (Digital), ch. 10 — The D latch source

Whenever we enable a multivibrator circuit on the transitional edge of a square-wave enable signal, we call it a flip-flop instead of a latch.

— kuphaldt-linac DIGI, Vol. IV (Digital), ch. 10 — Edge-triggered latches: Flip-Flops source

The triangle symbol next to the clock inputs tells us that these are edge-triggered devices, and consequently that these are flip-flops rather than latches.

— kuphaldt-linac DIGI, Vol. IV (Digital), ch. 10 — Edge-triggered latches: Flip-Flops source

The end result is that the S-R flip-flop's "invalid" state is eliminated (along with the race condition it engendered) and we get a useful feature as a bonus: the ability to toggle between the two (bistable) output states with every transition of the clock input signal.

— kuphaldt-linac DIGI, Vol. IV (Digital), ch. 10 — The J-K flip-flop source

There is no such thing as a J-K latch, only J-K flip-flops.

— kuphaldt-linac DIGI, Vol. IV (Digital), ch. 10 — The J-K flip-flop source

When the preset input is activated, the flip-flop will be set (Q=1, not-Q=0) regardless of any of the synchronous inputs or the clock. When the clear input is activated, the flip-flop will be reset (Q=0, not-Q=1), regardless of any of the synchronous inputs or the clock. So, what happens if both preset and clear inputs are activated? Surprise, surprise: we get an invalid state on the output, where Q and not-Q go to the same state, the same as our old friend, the S-R latch!

— kuphaldt-linac DIGI, Vol. IV (Digital), ch. 10 — Asynchronous flip-flop inputs source

Flip-flops (FFs) are devices used in the digital field for a variety of purposes. When properly connected, flip-flops may be used to store data temporarily, to multiply or divide, to count operations, or to receive and transfer information.

— NEETS Module 13, Module 13, ch. 3, p. 3-11 (Flip-flops)

To set the flip-flop requires a HIGH on the S input and a LOW on the R input. To reset, the opposite is required; S input LOW and R input HIGH. When both R and S are HIGH, the FF will hold or "latch" the condition that existed before both inputs went HIGH.

— NEETS Module 13, Module 13, ch. 3, p. 3-11 (R-S flip-flop)

Since the output cycle is one-half the input cycle, this device can be used to divide the input by 2.

— NEETS Module 13, Module 13, ch. 3, p. 3-15 (Toggle flip-flop)

The J-K FF is the most widely used FF because of its versatility. When properly used it may perform the function of an R-S, T, or D FF.

— NEETS Module 13, Module 13, ch. 3, p. 3-17 (J-K flip-flop)
Show alternative explanations

A race condition occurs when two mutually-exclusive events are simultaneously initiated through different circuit elements by a single cause.

— kuphaldt-linac DIGI, Vol. IV (Digital), ch. 10 — The S-R latch source

D FF is used to store data at a predetermined time.

— NEETS Module 13, Module 13, ch. 3 summary, p. 3-42

COUNTERS are used to count operations, quantities, or periods of time. They can be used to divide frequencies, to address information in storage, or as temporary storage.

— NEETS Module 13, Module 13, ch. 3 summary, p. 3-42

S-R latch (NOR pair) — including the forbidden row

Two cross-coupled NOR gates: Q = NOR(S, Q′), Q′ = NOR(R, Q). S=1 sets (Q=1), R=1 resets (Q=0), and S=R=0 makes the loop remember whatever it was doing. The S=R=1 row forces both NOR outputs low at once — Q and Q′ are no longer complements, which is why it is the forbidden state.

To predict the outcome:

  1. Identify S and R first: exactly one of them active usually decides the state.
  2. S=1 → set: Q goes to 1. R=1 → reset: Q goes to 0.
  3. Both inactive → no change: the feedback loop holds the previous Q.
  4. Both active → invalid: both outputs sit at 0, and after release the final state is unpredictable (race).
srqq_notstate
00Q (previous)Q′ (previous)hold / memory
1010set
0101reset
1100forbidden — outputs not complementary

D flip-flop — capture only on the rising edge

An edge-triggered D flip-flop samples D at the clock's rising edge (triangle symbol, no bubble) and holds it until the next edge. Between edges the clock level does nothing at all — that is what separates a flip-flop from a transparent D latch.

To predict the outcome:

  1. Look only at the moment the clock goes 0 → 1.
  2. Copy whatever D is at that instant into Q.
  3. After the edge, D may change freely — Q ignores it until the next rising edge.
  4. If D wobbles inside the brief sampling window, the captured value is unreliable (see the timing table below).
clockd_at_edgeq_nextnote
↑ (0→1)00clean capture of 0
↑ (0→1)11clean capture of 1
0 level / 1 level / ↓anyno changeedge-triggered — levels are ignored
↑ (0→1)changing inside the sampling window1 or 0 (unpredictable)timing violation — possible metastability

J-K flip-flop — the forbidden row becomes a feature

Feedback from Q and Q′ gates the J and K inputs so they can never both reach the latch at once. The result: J=K=1 toggles Q on every active clock edge instead of entering the S-R illegal state.

To predict the outcome:

  1. J=1, K=0 → set on the edge. J=0, K=1 → reset on the edge.
  2. J=K=0 → the edge does nothing (hold).
  3. J=K=1 → toggle: Q swaps to its complement at every active edge.
jkq_oldq_nextaction
0000hold
0011hold
0100reset (stays 0)
0110reset
1001set
1011set (stays 1)
1101toggle
1110toggle

Divide-by-2 — a T flip-flop halves the clock frequency

Wire J=K=1 (or use a T flip-flop) and Q flips on every rising clock edge. One full output cycle then needs two input cycles, so Q toggles at exactly half the clock frequency — the elementary frequency divider, and the reason flip-flops "multiply or divide" in NEETS' words.

To predict the outcome:

  1. Start with Q=0.
  2. At each rising edge, invert Q (toggle).
  3. Count clock edges between Q rising-edge events — there are always two, so f(out) = f(clock) / 2.
  4. Cascade: each extra toggle stage halves again (f/4, f/8, …), and the stages' Q outputs count in binary.
clock_edgesq_afterq_notoutput_note
0 (start)01output low — f/2 waveform low
110Q rises after 1 input edge
201one complete Q cycle after 2 input edges
310second output cycle begins
401two output cycles per four edges — always f/2

Setup and hold — what a violated window actually does

An edge-triggered flip-flop needs D to be stable for a setup time before the active edge and a hold time after it. These windows are brief (a few nanoseconds) and specific values are data-sheet numbers — neither Kuphaldt nor NEETS tabulates them — but the outcome logic below follows directly from the edge-sampling principle.

To predict the outcome:

  1. Mark the danger zone: the span from t_setup before the edge to t_hold after it.
  2. D quiet across the whole zone → clean, guaranteed capture.
  3. D moving inside the zone → the internal latch pair may both hover — metastability: Q can land on 0, 1, or oscillate briefly before settling, and downstream gates may see garbage.
  4. D moving well outside the zone → irrelevant: only the value at the edge matters.
eventtimingoutcome
D stable before and after the edgebeyond both t_setup and t_holdclean capture — Q = D reliably
D changes just before the edgeinside the setup windowcapture uncertain — Q may settle wrong or go metastable
D changes just after the edgeinside the hold windowold value may or may not hold — data-sheet dependent
D changes long after the edgeoutside both windowsignored — Q keeps the captured bit until the next edge

Candidate projects — awaiting review

  • Gated D latch from four NANDs, then a true edge-triggered D flip-flop from six NANDs (74LS00 or CD4011); clock it slowly from a 555 astable and use switches for D — verify with LEDs that only the rising edge moves Q. (https://www.reddit.com/r/beneater/comments/kon6uk/ideas_for_improved_clock_module/, community)
  • Frequency-divider chain: two JK flip-flops (74LS76 or CD4027) wired to toggle, clocked from one 555 — confirm with two LEDs (or a scope) that stage 1 runs at f/2 and stage 2 at f/4, and that the two stages read the clock count in binary. (NEETS Module 13, ch. 3 (Toggle flip-flop divides by 2), curriculum)
  • Motor start/stop seal-in latch: reproduce the book's relay "seal-in" contact circuit (a physical S-R latch) with a relay and two pushbuttons, then build the NOR-gate S-R latch beside it and compare behaviour — including what happens when both buttons are pressed. (https://www.ibiblio.org/kuphaldt/electricCircuits/DIGI/DIGI_10.html (The S-R latch), book)
  • Switch debouncer: feed a noisy pushbutton into a retriggerable one-shot (555 monostable, ~10–50 ms) exactly as Kuphaldt suggests, and show a counter fed by the debounced clock advances exactly once per press. (https://www.ibiblio.org/kuphaldt/electricCircuits/DIGI/DIGI_10.html (Monostable multivibrators), book)