---
title: Sequential Logic Circuits
url: https://doc.liz6.com/en/hardware/05-digital-circuits/03-sequential-logic-circuits
locale: en
area: hardware
tags:
- hardware
- digital-circuits
date: 2026-06-30
modified: 2026-07-16
description: Sequential Logic Circuits What is Sequential Logic Sequential Logic — The output depends not only on the current inputs but also on the historical state. Core S…
---

# Sequential Logic Circuits

## What is Sequential Logic

**Sequential Logic** — The output depends not only on the current inputs but also on the **historical state**.

<svg viewBox="0 0 720 300" xmlns="http://www.w3.org/2000/svg" font-family="-apple-system,'Source Han Sans CN','Microsoft YaHei',sans-serif" role="img" aria-label="Core structure of sequential logic: Combinational logic and feedback storage form a circuit with memory">
  <defs>
    <marker id="seqfb1" markerWidth="10" markerHeight="8" refX="8" refY="3" orient="auto"><path d="M0,0 L8,3 L0,6 Z" fill="#475569"/></marker>
  </defs>
  <rect width="720" height="300" fill="#ffffff"/>
  <text x="360" y="28" text-anchor="middle" font-size="17" font-weight="700" fill="#1f2933">Core Structure of Sequential Logic: Combinational Logic + Feedback Storage = Circuit with Memory</text>

  <text x="55" y="97" font-size="13" fill="#475569">Input</text>
  <line x1="85" y1="92" x2="138" y2="92" stroke="#475569" stroke-width="1.7" marker-end="url(#seqfb1)"/>
  <rect x="140" y="70" width="170" height="44" rx="8" fill="#4f46e5"/>
  <text x="225" y="97" text-anchor="middle" font-size="13" font-weight="700" fill="#ffffff">Combinational Logic</text>
  <line x1="310" y1="92" x2="358" y2="92" stroke="#475569" stroke-width="1.7" marker-end="url(#seqfb1)"/>
  <text x="366" y="97" font-size="13" fill="#475569">Output</text>

  <line x1="270" y1="114" x2="270" y2="160" stroke="#475569" stroke-width="1.6" marker-end="url(#seqfb1)"/>
  <text x="280" y="142" font-size="11" fill="#64748b">↓ State Update</text>
  <line x1="180" y1="162" x2="180" y2="116" stroke="#475569" stroke-width="1.6" marker-end="url(#seqfb1)"/>
  <text x="120" y="142" font-size="11" fill="#64748b" text-anchor="end">Feedback (Read State) ↑</text>

  <rect x="140" y="162" width="170" height="44" rx="8" fill="#0d9488"/>
  <text x="225" y="189" text-anchor="middle" font-size="13" font-weight="700" fill="#ffffff">Storage Element</text>
  <text x="225" y="222" text-anchor="middle" font-size="11" fill="#0f766e">Sampled under Clock (CLK) control</text>

  <rect x="60" y="238" width="600" height="50" rx="7" fill="#eef2ff" stroke="#c7d2fe"/>
  <text x="76" y="260" font-size="12.5" fill="#3730a3">Core Features: Clock Signal + State Retention</text>
  <text x="76" y="280" font-size="12.5" fill="#3730a3">—— With feedback and a clock, the output depends not only on current inputs but also on historical states.</text>
</svg>

Core Features: **Clock Signal (Clock)** + **State Retention**

---

## Latches and Flip-Flops

### SR Latch (Basic Storage Unit)
```
NOR Implementation:
    ┌───┐
S ──┤   ├── Q
    │NOR│
    │   ├──┐
    └───┘  │
    ┌───┐  │
R ──┤   ├──┘── Q̄
    │NOR│
    └───┘

S=1, R=0 → Set   (Q=1)
R=1, S=0 → Reset (Q=0)
S=0, R=0 → Hold  (Hold State)
S=1, R=1 → Forbidden! (Q=Q̄=0, and indeterminate upon release)
```

### D Latch (Level-Triggered)
```
Level-Triggered: Follows D while CLK=1; Latches when CLK=0

D ────┬── Q
      │
CLK ──┘

Issue: If D changes while CLK=1, Q follows (Transparent Mode)
       This can cause oscillation in feedback loops.
```

### D Flip-Flop (Edge-Triggered) — Workhorse of Digital Circuits
```
Symbol:
    ┌───┐
D ──┤D  Q├── Q
CLK─┤>   │
    └───┘

Samples D only on the rising clock edge (↑); Q remains unchanged otherwise.

Key Timing Parameters:
  tsu (setup): Minimum time D must be stable before the CLK edge
  th  (hold):  Minimum time D must be maintained after the CLK edge
  tcq (clk→q): Delay from CLK edge to Q update

Violating tsu/th → Metastability → Q oscillates or becomes indeterminate!
```

### Other Flip-Flops
```
JK Flip-Flop:
  J=1, K=0 → Q=1  (Set)
  J=0, K=1 → Q=0  (Reset)
  J=1, K=1 → Q toggles (Toggle)
  J=0, K=0 → Hold

T Flip-Flop (Toggle):
  T=1 → Toggles on every clock edge
  T=0 → Holds state

Cascaded T Flip-Flops = Counter
```

---

## Register (Register)

```
n D Flip-Flops sharing the same clock = n-bit Register

    ┌───┐
D0 ─┤D  Q├── Q0
    │>  │
    └───┘
    ┌───┐
D1 ─┤D  Q├── Q1
    │>  │
    └───┘
    ...   ← Total n units
    ↑
   CLK

On every rising clock edge, all D inputs are sampled → Q updates.
This is the fundamental principle behind registers and pipeline registers in CPUs.
```

---

## Counter (Counter)

### Asynchronous (Ripple) Counter
```
Q0 → CLK1 → Q1 → CLK2 → Q2 ...
The Q output of the previous stage directly drives the CLK of the next stage.

Simple but slow (cascaded delay accumulates) + Glitches occur in intermediate states.
```

### Synchronous Counter
```
All flip-flops share the same clock.

Supports any counting sequence (Up/Down/Reversible).
Typical: 74HC161 (4-bit Synchronous), 74HC193 (Reversible)
```

### Common Counting Schemes
```
Binary: 0→1→2→...→2ⁿ-1→0
Decimal: 0→1→...→9→0 (BCD Code)
Gray Code: Only 1 bit changes at a time (Prevents Race Conditions)
  BCD:     000→001→010→011→100...
  Gray:    000→001→011→010→110...
  Only 1 bit toggles per step → Suitable for cross-clock-domain transmission.
```

---

## Finite State Machine (FSM)

### Moore Machine
<svg viewBox="0 0 720 330" xmlns="http://www.w3.org/2000/svg" font-family="-apple-system,'Source Han Sans CN','Microsoft YaHei',sans-serif" role="img" aria-label="Moore FSM: Output depends only on current state; state transitions occur on clock edges">
  <defs>
    <marker id="moorefsm1" markerWidth="10" markerHeight="8" refX="8" refY="3" orient="auto"><path d="M0,0 L8,3 L0,6 Z" fill="#475569"/></marker>
  </defs>
  <rect width="720" height="330" fill="#ffffff"/>
  <text x="360" y="28" text-anchor="middle" font-size="17" font-weight="700" fill="#1f2933">Moore FSM: Output depends only on current state</text>

  <rect x="280" y="62" width="160" height="66" rx="10" fill="#e0e7ff" stroke="#4f46e5"/>
  <text x="360" y="90" text-anchor="middle" font-size="13" font-weight="700" fill="#3730a3">S0</text>
  <text x="360" y="112" text-anchor="middle" font-size="11" fill="#4f46e5">out = A</text>

  <line x1="360" y1="128" x2="360" y2="182" stroke="#475569" stroke-width="1.7" marker-end="url(#moorefsm1)"/>
  <text x="372" y="158" font-size="11" fill="#64748b">Condition Met (Transition on Clock Edge)</text>

  <rect x="280" y="184" width="160" height="66" rx="10" fill="#ccfbf1" stroke="#0d9488"/>
  <text x="360" y="212" text-anchor="middle" font-size="13" font-weight="700" fill="#115e59">S1</text>
  <text x="360" y="234" text-anchor="middle" font-size="11" fill="#0f766e">out = B</text>

  <rect x="60" y="270" width="600" height="50" rx="7" fill="#eef2ff" stroke="#c7d2fe"/>
  <text x="76" y="292" font-size="12.5" fill="#3730a3">Output depends only on the current state; state transitions occur only on clock edges.</text>
  <text x="76" y="312" font-size="12.5" fill="#3730a3">—— Output changes only follow the clock, avoiding glitches.</text>
</svg>

### Mealy Machine
<svg viewBox="0 0 720 240" xmlns="http://www.w3.org/2000/svg" font-family="-apple-system,'Source Han Sans CN','Microsoft YaHei',sans-serif" role="img" aria-label="Mealy FSM: Output depends on current state and input; output responds immediately when input changes">
  <defs>
    <marker id="mealyfsm1" markerWidth="10" markerHeight="8" refX="8" refY="3" orient="auto"><path d="M0,0 L8,3 L0,6 Z" fill="#475569"/></marker>
  </defs>
  <rect width="720" height="240" fill="#ffffff"/>
  <text x="360" y="28" text-anchor="middle" font-size="17" font-weight="700" fill="#1f2933">Mealy FSM: Output depends on Current State + Input</text>

  <rect x="250" y="70" width="170" height="64" rx="10" fill="#e0e7ff" stroke="#4f46e5"/>
  <text x="335" y="98" text-anchor="middle" font-size="13" font-weight="700" fill="#3730a3">S0</text>
  <text x="335" y="118" text-anchor="middle" font-size="11" fill="#4f46e5">Current State</text>

  <line x1="420" y1="102" x2="470" y2="102" stroke="#475569" stroke-width="1.7" marker-end="url(#mealyfsm1)"/>
  <text x="478" y="98" font-size="12" font-weight="700" fill="#9a3412">When Input = 1, Output = 1</text>
  <text x="478" y="116" font-size="11" fill="#c2410c">(Immediate Response, does not wait for clock edge)</text>

  <rect x="60" y="160" width="600" height="50" rx="7" fill="#eef2ff" stroke="#c7d2fe"/>
  <text x="76" y="182" font-size="12.5" fill="#3730a3">Output = Current State + Current Input; output changes immediately when input changes.</text>
  <text x="76" y="202" font-size="12.5" fill="#3730a3">—— Can occur at any time, posing a glitch risk; however, it typically requires fewer states than Moore machines.</text>
</svg>

### FSM Implementation
```
1. State Encoding (Binary / One-Hot / Gray)
2. Current State → Register
3. Next State → Combinational Logic (State + Input → Next State)
4. Output Logic → Moore/Mealy

One-Hot Encoding: N states = N bits, only 1 bit is '1' at a time.
  Pros: Simple output/next-state logic.
  Cons: Requires more flip-flops.
```

---

## Timing Analysis

### Setup and Hold Time
```
     tsu  th
     ├──┤├┤
D ───┘    └────────────
         ↑
CLK ─────┘    ─────────

tsu: Time D must be stable before the clock edge.
th:  Time D must be maintained after the clock edge.

Violation → Metastability!
```

### Maximum Frequency
```
fmax = 1 / (tcq + tcomb(max) + tsu)

tcq:    Flip-flop CLK→Q delay.
tcomb:  Combinational logic maximum delay (Critical Path).
tsu:    Setup time of the next flip-flop.

To increase fmax:
- Reduce the number of combinational logic stages.
- Insert pipeline registers (split long paths into segments).
```

### Metastability
```
When D changes within the tsu/th window:
  Q may enter an intermediate voltage level → Oscillate → Eventually settle to 0 or 1.

Mean Time Between Failures (MTBF):
  MTBF ∝ e^(t_wait/τ) / (f_clk × f_data)

Solution: Synchronizer (Double Flop)
  async_in → [DFF] → [DFF] → sync_out
             ↑CLK      ↑CLK
  
  The first stage may become metastable, but the second stage almost always resolves it.
```

---

## Clock Domain Crossing (CDC)

```
Golden Rules for Cross-Clock-Domain Signal Transmission:

1. Single-bit signals: Use a double-flop synchronizer.
2. Multi-bit buses: Use an Asynchronous FIFO or Handshake Protocol.
   Do NOT directly synchronize multi-bit signals! (Bits may be captured in different cycles.)
3. Slow-to-Fast: Signal must remain stable for at least 2 fast clock cycles.
4. Fast-to-Slow: Signal must remain stable long enough to be sampled by the slow clock.
```

---
*Keywords: Flip-Flop, DFF, Setup Time, Hold Time, Metastability, Finite State Machine, Moore, Mealy, CDC, Synchronizer*
