Skip to content
DenseChip
Learn
PracticeCode labInterview

DenseChip

Navigate

Menu

LearnPracticeCode labInterview

Tools

All toolsSV editorCode repoResume
DenseChip

Practice, courses, and chip-design tools in one focused workspace.

LearnPracticeCode labInterviewToolsLearning paths

© 2026 DenseChip

AboutContactPrivacyTerms
Skip to lesson

Course contents

  • How to Use This Course
  • Reading Path
  • CDC/RDC Glossary
  • CDC/RDC Metrics Reference
  • CDC/RDC Interview Prep
  • CDC/RDC Signoff Cheatsheet
  • Clock Domains and Failure Modes8
  • Metastability and Synchronizers16
    • MTBF & Synchronizer Math
    • Two-Flop Synchronizers in Practice
      • Structure and Rules
      • No Logic Between Flops
      • Level and Pulse Signals
      • Simulation Models and X
    • Multi-bit CDC Hazards
    • Synchronizer Selection Guide
  • CDC Protocols and Handshakes16
  • Reconvergence and Gray Coding16
  • Reset Domain Crossing16
  • Architecture and Design Rules16
  • CDC Signoff Methodology24
  • RDC Signoff16
  • Debug and Case Studies11
  • CDC and RDC Interview Prep30
  • Capstone: Sign Off a Multi-clock Peripheral4
Loading lesson

‹Two-Flop Synchronizers in Practice
  1. Topics
  2. CDC & RDC
  3. Metastability and Synchronizers
  4. Two-Flop Synchronizers in Practice
  5. Simulation Models and X

Part 2 · Metastability and Synchronizers · All levels

Simulation Models and X

Modelling the metastable window in simulation, X-propagation pitfalls, and what a simulation can and cannot show.

On this page

    A plain RTL simulation never goes metastable: the flop model resolves every edge deterministically. To exercise CDC logic in simulation you must write the uncertainty into the model yourself, and then read the results knowing exactly what the model proves.

    A plain window model

    The standard teaching model watches for data changes inside a setup/hold window around the clock edge. Outside the window the flop is exact; inside it the output resolves randomly to the old or the new value. The randomness stands in for silicon's dice roll, and a fixed seed or an explicit stimulus pattern keeps the test repeatable.

    The testbench below uses that model for both synchroniser flops. It drives one hundred changes just inside the setup window, counts the window hits on the first flop, and checks that the second-stage output is always a clean 0 or 1 and finally equals the input.

    meta_ff.sv
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    `timescale 1ns/1ps
    
    // A flip-flop that models metastability: a data change inside the setup/hold
    // window around the clock edge resolves randomly to the old or the new value.
    module meta_ff #(parameter real TCQ = 0.3, TSU = 0.15, THD = 0.1) (
      input  logic clk, d,
      output logic q
    );
      realtime t_d = -100.0, t_clk = -100.0;
      int      meta_events = 0;
      initial q = 1'b0;
    
      always @(d) begin
        t_d = $realtime;
        if ($realtime - t_clk < THD) begin
          meta_events++;  q <= #TCQ $urandom_range(0, 1);
        end
      end
      always @(posedge clk) begin
        t_clk = $realtime;
        if ($realtime - t_d < TSU) begin
          meta_events++;  q <= #TCQ $urandom_range(0, 1);
        end else q <= #TCQ d;
      end
    endmodule
    
    // The standard two-flop synchroniser built from the model above.
    module sync2 (input logic clk, d, output logic q);
      logic q1;
      meta_ff f1 (.clk, .d, .q(q1));       // may go metastable and resolve randomly
      meta_ff f2 (.clk, .d(q1), .q(q));    // samples one period later: settled in this model; the silicon residual is the MTBF argument
    endmodule
    

    X-propagation pitfalls

    If the model drives X into the first flop instead of a random 0/1, optimistic simulators propagate X through everything downstream and the test drowns in X, while pessimistic flows mask real bugs. The random old/new model avoids both traps: it keeps the simulation two-valued while still exercising either resolution.

    What a simulation can and cannot show

    Question

    Simulation answers it?

    Does the logic handle either resolution of a window hit?

    Yes: this is what the testbench above checks.

    Does the protocol survive late resolution?

    Partly: the model resolves within the cycle, so it cannot show multi-cycle hangs.

    What is the MTBF?

    No: MTBF comes from the analytical model with library parameters, never from a testbench.

    Is the crossing structurally correct?

    No: that is the structural tool's job (flop count, clocks, no logic in the path).

    Common pitfall

    A passing metastability testbench proves the logic tolerates either resolution, not that the crossing is correct. A missing second flop passes the same testbench shape with fewer stages, so never accept simulation in place of the structural check.

    Check yourself The testbench reports 100 window hits and PASS. Does that bound the real failure rate?

    No. It shows the downstream logic tolerates either resolution of a hit. The failure rate is set by how often silicon is still unresolved a full period later, which only the MTBF model addresses.

    Check yourself Why does the model resolve to a random 0/1 rather than X?

    X would flood the simulation with unknowns the design would never actually produce, hiding whether the logic handles the two real outcomes. Random 0/1 exercises both genuine resolutions while staying two-valued.

    Related topics

    • Structure and Rules

    • Resolution Time and MTBF

    Previous

    22 / 179

    Next: Multi-bit CDC Hazards

    Up next

    Up nextMulti-bit CDC Hazards

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • Structure and Rules
    • No Logic Between Flops