HomeCDCDay 8 Enhanced

Metastability Simulation & Corner Cases

Advanced simulation techniques to stress-test CDC designs. Stochastic metastability injection, PVT corner analysis, timing violations, and production corner case validation.

By EcrioniX · Published June 13, 2026 · ~4500 words · 14 min read

1. Stochastic Metastability Injection

To meaningfully test metastability, we must inject it into simulation. Real metastability is random—we need to simulate it stochastically.

Approach 1: Random Clock Skew Injection

Introduce random phase offsets between clock domains:

// Stochastic clock skew injection for metastability testing

reg clk_a, clk_b;
real skew_ns;

initial begin
  clk_a = 0;
  forever #5 clk_a = ~clk_a;  // 100 MHz
end

initial begin
  clk_b = 0;
  forever begin
    // Random phase offset (0-10ns): shifts Clock B unpredictably
    // relative to Clock A, hitting setup/hold violations
    skew_ns = $urandom_range(0, 10);
    #(5 - skew_ns/2) clk_b = ~clk_b;
    #(5 + skew_ns/2) clk_b = ~clk_b;
  end
end

// Random input changes relative to Clock B edge (stress setup/hold)
always @(*) begin
  // 20% chance input toggles in metastable window
  if ($urandom < 0.2 * 2^32) begin
    async_input = ~async_input;
  end
end

Approach 2: Metastable State Injection

Directly force FF output to intermediate voltage during setup/hold violation:

// Inject metastable state into FF1 during violation window

always @(posedge clk_b or negedge rst_b) begin
  if (!rst_b) begin
    ff1 <= 1'b0;
  end else begin
    // Detect setup/hold violation window
    setup_violation = (async_in !== async_in_prev)
                    & ($time < SETUP_TIME);
    hold_violation = (async_in !== async_in_prev)
                    & ($time < HOLD_TIME);

    if (setup_violation || hold_violation) begin
      // Inject metastable state: ~50% probability of 0 vs 1
      if ($urandom < 2^31) begin
        ff1 <= 1'b0;  // May not fully settle
      end else begin
        ff1 <= 1'b1;  // Or settle to 1
      end
    end else begin
      ff1 <= async_in;  // Normal capture
    end
  end
end

2. PVT Corner Simulation

What is PVT?

Metastability is most likely at worst-case PVT: Slow process + High temperature + Low voltage.

Simulation Corners

Corner Process Voltage Temperature Metastability Risk
SS (Slow-Slow) Slow Low High ❌ WORST (slowest resolution)
FF (Fast-Fast) Fast High Low ✓ Best (fastest resolution)
TT (Typical-Typical) Typical Nominal Nominal ~ Medium (average case)
SF (Slow-Fast) Slow High Low ~ Medium
FS (Fast-Slow) Fast Low High ~ Medium

Critical insight: MTBF is worst at SS corner. If MTBF > 1 million years at SS, it's safe at all other corners.

3. Timing Stress Testing

Setup/Hold Window Testing

Intentionally violate setup/hold to stress-test synchronizers:

Expected result: Even under violation stress, FF2 output should be clean and metastability-free.

4. Clock Frequency Stress

Test CDC at extreme frequency combinations:

Frequency Stress Patterns

Pattern 1: Clock A >> Clock B - Clock A: 1 GHz - Clock B: 10 MHz (100x slower) - Test: Fast input changes, slow output sampling - Risk: Multiple input toggles before Clock B sees any change

Pattern 2: Clock B >> Clock A - Clock A: 10 MHz - Clock B: 1 GHz (100x faster) - Test: Slow input, fast output sampling - Risk: FF2 may capture metastable FF1 before resolution

Pattern 3: Asynchronous clocks (no common divisor) - Clock A: 100 MHz (period 10ns) - Clock B: 333 MHz (period 3ns) - Test: Phase relationship changes randomly - Risk: Worst-case metastability windows more likely

5. Dual-Clock FIFO Stress Testing

FIFO Fill/Empty Stress

Empty/Full Flag Testing

The flags are synchronized with dual-FF and 2-cycle latency. Test the edge cases:

6. Data Integrity Testing

Pattern-Based Testing

Write specific patterns to FIFO and verify read integrity:

After each test, verify every word read matches what was written.

7. Common Testing Mistakes

8. Coverage Metrics for CDC

Standard Coverage

CDC-Specific Coverage

9. Automated Testing Framework

Professional teams use automated regression suites:

10. Summary & Testing Checklist

Next (Day 9): Reset synchronization and multi-domain coordination.