Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

The fundamental building block of sequential logic


Prerequisites

This tutorial assumes familiarity with:

  • Binary numbers — understanding 0s and 1s, HIGH and LOW voltage levels

  • Logic gates (AND, OR, NOT) — basic combinational building blocks

  • Truth tables — how to read input/output relationships

No prior knowledge of sequential logic or timing is required — we’ll build that understanding here.


Why Do We Need Flip-Flops?

Combinational circuits have no memory — their outputs depend only on current inputs. But real digital systems need to:

  • Store data (registers, memory)

  • Count events (counters)

  • Track state (state machines)

  • Synchronize signals (clock domain crossing)

Flip-flops are the solution: they’re 1-bit memory elements that store a value until told to change.


Latch vs Flip-Flop

Before diving into flip-flops, let’s understand how they differ from latches.

What is a Latch?

A latch is a simple 1-bit memory element that is level-sensitive:

  • When the enable signal is HIGH, the latch is “transparent” — output follows input

  • When enable goes LOW, the latch “holds” — output stays frozen at its last value

The problem: while enabled, any input change immediately affects the output. This makes timing unpredictable in complex circuits.

The Key Difference

TypeTriggered ByBehavior
LatchLevel (HIGH or LOW)Transparent when enabled, holds when disabled
Flip-FlopEdge (rising or falling)Captures input only at the clock edge

Flip-flops are preferred in synchronous design because:

  • Predictable timing — changes happen only at clock edges

  • Easier to analyze — one reference point per clock cycle

  • Avoids race conditions that plague level-sensitive latches


The D Flip-Flop

The D (Data) flip-flop is the most common type. It has:

  • D (Data input): The value to be stored

  • CLK (Clock): The timing signal that triggers capture

  • Q (Output): The stored value

  • Q̄ (Inverted output): The complement of Q — also written as /Q, Q’, or “NOT Q” (optional on many flip-flops)

Matplotlib is building the font cache; this may take a moment.
<Figure size 800x500 with 1 Axes>

Truth Table

In truth tables for sequential circuits, Q(next) represents the value Q will have after the clock edge — the “next state” of the output.

CLKDQ(next)Description
00Captures 0 on rising edge
11Captures 1 on rising edge
XQNo edge → Q unchanged

Key insight: Q only changes at the rising edge (↑) of CLK. At all other times, Q holds its value regardless of what D does.


How to Read a Timing Diagram

Throughout this tutorial, we’ll use timing diagrams to visualize flip-flop behavior. Here’s how to read them:

The basics:

  • Horizontal axis = Time (progressing left to right)

  • Vertical axis = Signal value (LOW=0 at bottom, HIGH=1 at top)

  • Each row = One signal (labeled on the left: CLK, D, Q, etc.)

  • Vertical dashed lines = Clock edges (reference points)

Signal shapes:

  • Square wave (CLK): Alternates HIGH/LOW periodically

  • Step changes: Signal transitions from one level to another

  • Flat sections: Signal holding steady

Reading tip: At each rising clock edge, note D’s value — that’s what Q will become. The clock edge is the cause; Q capturing D is the effect.


Edge-Triggered Behavior

The defining characteristic of a flip-flop is edge triggering. Let’s visualize this with a simple example:

  • D=1 before edge 1: Shows a value that IS captured at the rising edge

  • D=1 between edges 1-2: Shows that changes between clock edges are IGNORED

  • D=1 stable across edges 3-4: Shows normal capture of a stable signal

The core principle: only the value of D at the exact moment of the rising edge matters.

<Figure size 1000x500 with 3 Axes>

Notice:

  • D can change freely between clock edges — Q ignores it

  • Q only updates at rising edges, capturing whatever D was at that instant

  • Q holds its value until the next rising edge


Timing Parameters

For reliable operation, flip-flops have critical timing requirements. Let’s zoom in on a single clock edge to understand them:

<Figure size 1200x600 with 1 Axes>

Key Timing Parameters

ParameterSymbolDescriptionTypical Value
Setup timet_setupD must be stable before clock edge0.1-2 ns
Hold timet_holdD must remain stable after clock edge0.05-0.5 ns
Clock-to-Qt_clk-to-qTime from clock edge to Q change0.1-1 ns

Why do these exist?

Flip-flops are built from transistors, and transistors aren’t instant switches. The delays come from charging and discharging tiny capacitors inside the chip:

Setup time — The flip-flop’s internal nodes (tiny capacitors formed by transistor gates and wires) need time to charge or discharge to stable voltage levels before the clock edge samples them. If D is still changing, the internal voltages are unstable and the flip-flop may latch an undefined value.

Hold time — When the clock edge arrives, the flip-flop begins “closing the gate” between input and output. During this brief transition, the input still has some influence on the internal nodes. D must stay stable until the isolation is complete.

Clock-to-Q — After latching the value internally, the output transistors must switch state. This means charging/discharging the output node capacitance through the transistor’s resistance. The delay follows τ = RC (resistance × capacitance).

In short: Every signal change requires moving electrons to charge capacitors. This takes time — typically picoseconds to nanoseconds depending on the capacitance and the transistor’s drive strength.

What happens if you violate these?

  • Setup violation: D changes too close to clock edge → Q might capture wrong value

  • Hold violation: D changes too soon after clock edge → Q becomes metastable (indeterminate state)

Who ensures timing is correct?

The circuit designer is responsible, with help from Electronic Design Automation (EDA) tools:

  1. Static Timing Analysis (STA): Tools automatically check every path in your design and report violations before you fabricate the chip

  2. For setup violations (most common):

    • Reduce the clock frequency (more time for signals to settle)

    • Shorten combinational logic paths by adding pipeline stages

    • Use faster logic gates

  3. For hold violations:

    • Add delay buffers to slow down fast paths

    • Usually less common because gates have inherent delay

In practice, you design your circuit, run STA, fix any reported violations, and repeat until clean.

<Figure size 1200x400 with 2 Axes>

D Flip-Flop with Reset

Most flip-flops include a reset input to initialize to a known state. Two types exist:

Asynchronous Reset

  • Resets Q immediately when asserted, regardless of clock

  • Higher priority than clock

  • Can cause timing issues if not handled carefully

About the example timing: The signals were chosen to highlight asynchronous behavior:

  • RST_N asserted at cycle 2.3 (mid-cycle): Notice Q goes to 0 immediately — it doesn’t wait for a clock edge. This is the defining characteristic of async reset.

  • RST_N released at ~cycle 4.2 (also mid-cycle): Normal operation resumes at the next clock edge

  • D has values during reset: Even though D=1 during cycles 4-5, Q stays 0 because reset has priority

  • After reset: Q captures D normally starting at edge 5

The key insight: asynchronous means “ignores the clock” — reset takes effect the instant it’s asserted.

<Figure size 1000x600 with 4 Axes>

Synchronous Reset

  • Resets Q only at the clock edge when reset is asserted

  • Cleaner timing behavior

  • Preferred in most modern designs

About the example timing: Compare this directly to the async reset above — same D pattern, same reset window:

  • RST asserted at cycle 2.3 (mid-cycle): Unlike async, Q does NOT immediately go to 0. Q was 1 at edge 2, and it stays 1!

  • Q resets at edge 3: Only when the clock edge arrives AND reset is still active does Q go to 0

  • Reset still active at edge 4: Q stays 0 because reset overrides D

  • Normal operation at edge 5: Reset was released at ~4.2, so now D is captured normally

The key difference: Q stays at 1 from edge 2 until edge 3, even though reset was asserted at 2.3. Synchronous reset respects clock boundaries.

<Figure size 1000x600 with 4 Axes>

Comparison:

AspectAsynchronousSynchronous
Reset timingImmediateAt clock edge
PriorityHigher than clockSame as data
Timing analysisMore complexSimpler
Use casePower-on resetNormal operation

D Flip-Flop with Enable

An enable input allows you to selectively update the flip-flop.

About the example values:

  • D pattern [1,0,1,0,1,0]: Alternating values to clearly show when D is captured vs ignored

  • EN pattern: High at edges 0, 1, 4, and 5 (two separate update windows)

Why this matters — trace through the diagram:

  • Edges 0 and 1 (EN=1): Q follows D → captures 1, then 0

  • Edges 2 and 3 (EN=0): D changes to 1, then 0, but Q stays at 0 (its last captured value)

  • Edges 4 and 5 (EN=1): Q captures again → gets 1, then 0

The Q values [1,0,0,0,1,0] follow directly from the rule: “capture D when EN=1, hold when EN=0”.

<Figure size 1000x600 with 4 Axes>

Enable behavior:

  • EN=1 at clock edge: Q captures D (normal operation)

  • EN=0 at clock edge: Q holds its current value (D ignored)

Use cases:

  • Selective register updates

  • Building larger registers with load enable

  • Power saving (clock gating)


Building Registers from Flip-Flops

A register is simply multiple flip-flops sharing the same clock, storing multi-bit values:

<Figure size 1400x600 with 1 Axes>

Register properties:

  • All bits update atomically at the same clock edge

  • Adding enable creates a “load” function

  • Adding reset initializes all bits to 0 (or preset to 1)

  • Common widths: 8, 16, 32, 64 bits


Common Applications

  1. Data Storage — Registers hold values between operations in processors and digital systems. Every CPU register (like the program counter, instruction register, or general-purpose registers) is built from flip-flops. When you read “32-bit processor,” those are 32 flip-flops working together to store each register value.

  2. Pipelining — Flip-flops separate pipeline stages, allowing multiple operations in flight simultaneously. Modern CPUs break instruction execution into stages (fetch, decode, execute, memory, write-back), with registers between each stage. This lets the CPU work on five different instructions at once, dramatically increasing throughput.

  3. Counters — Chained flip-flops with feedback create binary counters for timers, frequency dividers, and address generation. A 4-bit counter cycles through 0→1→2→...→15→0 by connecting each flip-flop’s Q output to the next flip-flop’s clock input. These are everywhere: timers in microcontrollers, clock dividers in PLLs, and memory address counters.

  4. Shift Registers — Serial-to-parallel or parallel-to-serial conversion for data transmission and signal processing. By connecting flip-flops in a chain (Q of one feeds D of the next), data “shifts” one position per clock cycle. Used in serial communication (UART, SPI), LED matrix control, and implementing delays in signal processing.

<Figure size 1400x500 with 1 Axes>

Key Takeaways

  1. D flip-flops are 1-bit memory elements — the building block of all sequential logic

  2. Edge triggering is key — Q only changes at clock edges, providing predictable timing

  3. Timing parameters matter:

    • Setup time: Data must arrive before the clock edge

    • Hold time: Data must stay stable after the clock edge

    • Clock-to-Q: Output delay after the clock edge

  4. Reset options:

    • Asynchronous: Immediate, for power-on

    • Synchronous: At clock edge, cleaner timing

  5. Enable allows selective updates — Q holds when disabled

  6. Registers are just multiple flip-flops sharing a clock


Every counter, state machine, processor register, and memory cell uses flip-flops. Master the D flip-flop, and you’ve mastered the atom of digital memory.