Digital Electronics · Sequential Logic

Flip-Flops &
Sequential Logic

The complete reference — from the bistable SR latch to edge-triggered VLSI storage. SR, JK, D, T flip-flops, master-slave, timing, metastability, and real-world CPU applications.

SR / JK / D / TMaster-SlaveSetup & HoldMetastabilityInteractive Lab
§01 · Foundation

What Is a Flip-Flop?

A flip-flop is a bistable multivibrator — a sequential circuit with exactly two stable states (0 and 1). Unlike combinational gates, a flip-flop retains its output until told to change by a clock edge. This ability to store one bit is the foundation of all digital memory.

Every processor — from an 8 MHz microcontroller to a 3 GHz server CPU — is composed of millions of flip-flops forming registers, pipeline stages, FSMs, FIFOs, and synchronizers. Understanding flip-flops deeply is not optional for a digital designer.

Key Insight

A single flip-flop stores 1 bit. An array of 64 flip-flops sharing a clock forms a 64-bit register — the fundamental storage unit in a 64-bit CPU.

The term flip-flop comes from the two-phase switching behavior described by Eccles and Jordan in 1918 using vacuum tubes. Modern CMOS implementations consume nanowatts in sub-10 nm nodes.

§02 · Theory

Sequential vs Combinational Logic

Every digital circuit belongs to one of two categories. Combinational: output depends only on current input, no memory — adders, MUXes, encoders. Sequential: output depends on current input AND stored state — counters, registers, FSMs.

Next State Q(n+1) = f [ Input, Present State Q(n) ]
Output = g [ Present State Q(n) ] ← Mealy also uses Input
PropertyCombinationalSequential
MemoryNoneFlip-flops / latches
ClockNot requiredRequired (sync)
FeedbackNeverAlways
Output depends onPresent input onlyInput + past state
ExamplesAdder, MUX, EncoderCounter, Register, FSM
§03 · Key Distinction

Latches vs Flip-Flops

A latch is level-triggered — it's transparent when the enable is active; any input change propagates directly to the output. A flip-flop is edge-triggered — it samples input only at the clock transition instant.

Industry Standard

VLSI synchronous design always uses edge-triggered flip-flops. Latches are used in specific low-power or half-cycle-borrowing scenarios but require specialised timing analysis. Default to flip-flops in RTL.

CLK D Latch FF Q
Latch (teal) follows D while CLK is HIGH. Edge-triggered FF (sky) samples only at the rising edge — one stable update per cycle.
§04 · Building Block

SR Latch — NOR & NAND

The SR latch is the simplest bistable and the conceptual core of every flip-flop. Two cross-coupled NOR (or NAND) gates create a feedback loop sustaining a 0 or 1 with no clock.

NOR-based SR Latch (Active HIGH)

S R Q Q' Cross-coupled NOR gates — feedback wires (dashed)
SRQ (next)Q' (next)Action
00QQ'HOLD
0101RESET
1010SET
1100INVALID
Critical Rule

The forbidden input (S=R=1 for NOR; S̄=R̄=0 for NAND) must be avoided. When simultaneously removed, the final state is unpredictable — this is the critical race condition.

§05 · Clocked Version

Clocked SR Flip-Flop

Adding a clock enable gates S and R through AND gates before the NOR pair. When CLK=0 both inputs are forced 0 (HOLD). When CLK=1 S and R can change state. The forbidden S=R=1 condition still exists — this is mostly a pedagogical stepping stone toward JK and D types.

Q(n+1) = S + R'·Q(n)  |  Constraint: S·R = 0 (forbidden)
§06 · Universal FF

JK Flip-Flop & Race-Around

The JK flip-flop solves the SR forbidden state by defining J=K=1 as toggle. Feedback from Q back to K's AND gate and Q' back to J's AND gate ensures only the currently-OFF path activates when J=K=1.

Q(n+1) = J·Q'(n) + K'·Q(n)
JKQ(n)Q(n+1)Operation
00XQHOLD
01X0RESET
10X1SET
1101TOGGLE
1110TOGGLE

Race-Around Condition

When J=K=1 and the clock stays HIGH longer than the FF's propagation delay, the toggled output feeds back and triggers another toggle — oscillating within a single clock pulse. Final state is indeterminate.

Race-Around

Occurs when J=K=1 and clock pulse width > propagation delay. Solution: master-slave architecture or edge-triggered design.

§07 · Architecture

Master-Slave Architecture

Two cascaded latches operating on complementary clock phases eliminate race-around. The Master reads inputs; the Slave transfers to the final output — in separate clock phases so feedback never completes within one phase.

1
CLK HIGH — Master CapturesMaster latch is transparent; it reads J/K and computes next state. Slave is disabled — final Q is frozen.
2
CLK LOW — Slave TransfersMaster is disabled and freezes its result. Slave is enabled and copies Master's output to final Q.
3
Why Race-Around Is EliminatedQ changes only during the LOW phase; inputs are read only during HIGH. No feedback path completes within a single phase.
Pulse-Triggered vs Edge-Triggered

Master-slave JK FFs are pulse-triggered — they sample throughout the HIGH phase. Modern CMOS FFs are truly edge-triggered, sampling only at the clock transition instant for superior noise immunity.

§08 · Industry Standard

D Flip-Flop

Derived from JK by permanently wiring K = J'. On every rising clock edge, Q follows D. No forbidden state, no toggle ambiguity, no race condition — and the simplest possible RTL model.

Q(n+1) = D
CLK EdgeDQ(n+1)Action
↑ Rising00RESET
↑ Rising11SET
No edgeXQ(n)HOLD
Deep Dive Available
Gate-by-gate & transistor-by-transistor breakdown — SR latch → CMOS (20T) → metastability lab.
D Flip-Flop Deep Dive →

Preset, Clear & Scan

Real VLSI D FFs include asynchronous Preset (PRE) and Clear (CLR) overrides for power-on reset. Scan FFs (SDFF) add a 2:1 MUX before D — SE=0: normal operation; SE=1: scan chain input. This enables ATPG in production testing.

§09 · Counter Cell

T Flip-Flop & Frequency Division

JK with J=K=T. When T=1 on a clock edge, Q toggles; T=0 holds. Natural counter cell — with T=1 always it divides the clock by 2. Cascading N stages gives ÷2ᴺ.

Q(n+1) = T ⊕ Q(n)
TQ(n)Q(n+1)Action
0XQHOLD
101TOGGLE
110TOGGLE

Used in PLL feedback dividers, UART baud generators, watch crystal dividers (32,768 Hz → 1 Hz), and ripple counters.

§10 · Comparison

Flip-Flop Type Comparison

SR
Set-Reset
Simplest bistable. Forbidden state S=R=1. Used in debounce and basic latching.
JK
Universal
No forbidden state — J=K=1 toggles. Universal FF. Needs master-slave for correctness.
D
Data / Delay
Industry standard. Q=D on clock edge. Used everywhere in registers, pipelines, scan.
T
Toggle
Toggles on T=1. Natural counter cell. Used in frequency dividers and binary counters.
FeatureSRJKDT
InputsS, RJ, KDT
Forbidden StateS=R=1NoneNoneNone
Characteristic Eq.S+R'QJQ'+K'QDT⊕Q
Toggle CapableNoJ=K=1NoT=1
VLSI UsageRareModerateDominantCommon
§11 · Interactive

Flip-Flop Simulator Lab

Live Simulator
Select a type, set inputs, and pulse the clock to see real-time state transitions.
J: 0
K: 0
Output Q
0
Q'
1
Next: HOLD
Awaiting clock pulse...
D: 0
Output Q
0
Q'
1
Q captures D on ↑ clock edge
Awaiting clock pulse...
T: 0
Output Q
0
Q'
1
Next: HOLD
Awaiting clock pulse...
S: 0
R: 0
Output Q
0
Q'
1
Next: HOLD
Awaiting clock pulse...
§12 · Timing

Setup, Hold & Propagation Delay

Setup Time (tsu): Data must be stable this long before the clock edge. In 28nm, typically 20–50 ps. Violation can cause incorrect latching or metastability.

Hold Time (th): Data must remain stable this long after the clock edge. Cannot be fixed by reducing clock frequency — must insert delay buffers on the violating path.

Clock-to-Q (tcq): Time from clock edge until Q settles at its new value. Bounds maximum frequency:

Tclk ≥ tcq + tlogic + tsu + tskew
fmax = 1 / (tcq + tlogic + tsu + tskew)
CLK D Q t_su t_h t_cq ↑ CLK
Data must be stable during setup+hold window. Q updates after tcq.
STA Tools

Synopsys PrimeTime and Cadence Tempus verify timing across all PVT corners. Positive slack = constraint met; negative slack = timing violation to fix before tapeout.

§13 · Reliability

Metastability & Clock Domain Crossing

Metastability occurs when data transitions within the setup-hold window. The flip-flop's bistable element is poised at an unstable equilibrium — output voltage is between valid 0 and 1. It eventually resolves but the time follows an exponential distribution — always a non-zero probability of persisting past any deadline.

When It Occurs

Unavoidable when capturing asynchronous signals or crossing between unrelated clock domains. Cannot be eliminated — only statistically suppressed.

Two-Flop Synchronizer

Chain 2–3 D FFs in the destination domain. The first may go metastable, but given one full clock period the probability of not resolving before the second FF samples is extremely small.

MTBF = eTr / (fclk · fdata · Tw)

Where τ ≈ 20–100 ps in deep submicron CMOS. A 3-FF synchronizer in 28nm at 1 GHz can achieve MTBF exceeding 10 million years.

§14 · Conversion

Flip-Flop Conversion Techniques

Express the target FF's characteristic equation in terms of the available FF's excitation inputs using excitation tables.

JK → D:  J = D,  K = D'
JK → T:  J = T,  K = T
D → T:   D = T ⊕ Q(n)
D → JK:  D = J·Q' + K'·Q
GoalAvailable FFRequired Logic
D from JKJKJ = D, K = D'
T from JKJKJ = T, K = T
SR from JKJKJ = S, K = R
D from TTT = D ⊕ Q
JK from DDD = JQ' + K'Q
T from DDD = T ⊕ Q
§15 · Real World

Practical VLSI Applications

📦

Register Files

A CPU's 64-bit × 32-register file = 2,048 D flip-flops with shared write clocks and MUX-based read ports.

Pipeline Registers

IF→ID→EX→MEM→WB stage barriers are D flip-flop arrays holding partial results between clock cycles.

🔢

Binary Counters

Ripple counters use T FFs in series. Synchronous counters add carry-lookahead for GHz-range operation.

🔄

Shift Registers

SIPO / PISO / SISO chains of D FFs. Used in SPI/I²C/UART, barrel shifters, and LFSR-based PRBS generators.

🧠

Finite State Machines

Moore and Mealy FSMs hold current state in D FFs. Next-state combinational logic feeds back to D inputs.

🔗

CDC Synchronizers

Two-flop synchronizers pass signals safely between different clock domains, suppressing metastability to sub-PPB.

🏭

Scan Chains (DFT)

Scan FFs link into a shift register for ATPG. A 1M FF chip tested in milliseconds at 100 MHz scan rate.

📡

DRAM Row Address

D latches hold row addresses during RAS cycles, enabling full-row access with minimal address pin count.

The Apple M4 (3nm TSMC, ~28B transistors) allocates a significant fraction to flip-flops across 8-wide OOO pipelines, 32 MB L3 tag arrays, 192-entry reorder buffers, and scan chains. Clock gating and power gating keep dynamic power (C·V²·f) within thermal limits.

§16 · FAQ

Frequently Asked Questions

What is the difference between a latch and a flip-flop? +
A latch is level-triggered — output follows input whenever enable is active. A flip-flop is edge-triggered — it samples only at the clock transition. FFs are preferred in synchronous VLSI because outputs change exactly once per cycle, making timing analysis straightforward.
Why does the SR flip-flop have a forbidden state? +
S=R=1 forces both cross-coupled gate outputs to 0 simultaneously — Q and Q' can't both be 0 if they're supposed to be complements. When removed simultaneously, whichever gate wins the race determines the final state, making the output unpredictable.
What is the race-around condition in JK flip-flops? +
When J=K=1 and clock pulse width > propagation delay, the toggled output feeds back and triggers another toggle — oscillating within one clock pulse. Solved by master-slave configuration or true edge-triggered design.
Why is the D flip-flop the most widely used in VLSI? +
No forbidden states, trivial RTL model (every non-blocking Verilog assignment synthesises to a D FF), scan compatibility with just a 2:1 MUX addition, and ~20 transistors in CMOS achieving picosecond setup times.
Can metastability be completely eliminated? +
No — it's fundamental to bistable physics. A properly designed 2-flop synchronizer in 28nm running at 1 GHz can achieve MTBF >10 million years, which is functionally negligible.
What is a hold time violation and how is it fixed? +
Data changes too quickly after the clock edge — before hold time elapses. Cannot be fixed by slowing the clock. Fix: insert delay buffers on the violating data path. STA tools flag hold violations; P&R tools (Innovus) insert buffers automatically.
How many transistors does a CMOS flip-flop use? +
A transmission-gate master-slave D FF uses ~20 transistors. Async set/reset adds 4–8; a scan MUX adds 4–6 more. At 3nm nodes these cells occupy ~0.01–0.05 µm².
← Combinational Circuits FEC & Error Correction →

Related Topics

Deep Dive
D Flip-Flop Internals
Gate-level to CMOS, 20 transistors, waveform lab
Sequential
LFSR
Shift register + XOR feedback → pseudo-random sequences
RTL
Metastability Deep Dive
MTBF, synchronizer design, CDC strategies
STA
Setup & Hold Analysis
Timing constraints verified across all PVT corners