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

  • RTL Foundations36
  • Combinational Design25
  • Sequential Design27
  • FSM & Control27
  • Timing & Clocking39
  • Reset & CDC34
    • Reset Architecture
    • Metastability and Synchronisation
    • Asynchronous FIFO
    • CDC Protocols
    • Reset Domain Crossing
    • CDC Verification
      • Rules
      • Simulation
      • Assertion Patterns
      • FIFO Tests
      • Signoff
      • Reading a CDC Report
      • A CDC Mini Project
  • Memory & Buses57
  • Advanced RTL28
  • Senior & Interview76
  • Glossary and Notation
Loading lesson

‹CDC Verification
  1. Topics
  2. RTL Design
  3. Reset & CDC
  4. CDC Verification
  5. Simulation

Part 6 · Reset & CDC · Intermediate

Simulation

Hostile CDC simulation with swept ratios, jitter, offsets and window-hit counts.

On this page

    Why this matters

    Clocks at an exact ratio can hide a broken synchroniser. The same exact-ratio clocks give 2,858 window hits or none, depending on a 0.4 ns start offset, so a test can pass a broken design by luck.

    After this lesson you can: build a hostile CDC simulation with unrelated periods, offsets, jitter and perturbation models, and judge it by window hits per crossing.

    Exact-ratio clocks mislead

    A source toggles every 5 cycles of a 10 ns clock. A metastability model on the destination flop counts data changes inside the setup/hold window.

    Four clock setups drive 20,000 source toggles each. The full models sit under Testbench below.

    Clocks

    Window hits in 20,000 source toggles

    Exact 10 ns / 7 ns, start offset 0.0 ns

    2,858 (every 7th toggle lands in the window)

    Exact 10 ns / 7 ns, start offset 0.4 ns

    0 (the same ratio never hits the window)

    10 ns / 7.13 ns

    1,265 (a finite set of sampled phases)

    10 ns / 7 ns with 0.6 ns jitter

    1,338

    Where the source toggles land within one 7 ns destination period: with a 0.0 ns start offset one of the 7 phases falls in the window, with 0.4 ns none does

    Read each row as every place a source toggle can land, measured from the last destination edge. The source toggles every 50 ns and 50 mod 7 = 1, so each toggle lands 1 ns later than the one before and the 7 phases repeat for ever.

    • Offset 0.0 ns: the phase 6.75 ns is 0.25 ns before the next edge, inside the 0.3 ns setup window. Every 7th toggle hits: 20,000 / 7 is about 2,858.

    • Offset 0.4 ns: every dot moves 0.4 ns left. The last one, at 6.35 ns, now misses the window, so none of the 20,000 toggles hits it.

    • Unrelated periods or jitter keep shifting the dots, so they eventually sweep through the window. That is why the last two rows of the table have hits.

    Warning

    The second row is the lesson. The same exact-ratio clocks give 2,858 hits or none, depending on a 0.4 ns start offset, because the relative phase only ever takes 7 values. A testbench with such clocks would 'pass' a broken design when the offset is unlucky, and fail it when it is not. Sweep the ratio or add jitter.

    Making simulation hostile

    Hostile timing has seven ingredients. Each one widens the set of phases the test reaches.

    • Unrelated periods: ratios that are not simple fractions, several per test.

    • Random start offsets: a fresh phase at the start of each test.

    • Jitter: random cycle-to-cycle variation on the clock edges.

    • Functional perturbation models with old/new or X outcomes in each synchroniser; separately characterize physical metastability reliability.

    • Random reset events during traffic.

    • Long runs: ten thousand toggles give hundreds of hits, while a hundred give almost none.

    • Hit coverage: count window hits per crossing and require a minimum.

    Common mistakes

    Tip

    Print per-crossing window-hit counts, seed, periods, offsets and time precision with protocol results. A zero-hit crossing leaves this coverage goal open. Nonzero hits establish exposure to this model's window, not physical failure probability or exhaustive phase coverage.

    Common pitfall

    Plain RTL simulation does not model analog metastability. SDF timing-check simulation can report setup/hold violations and inject notifier-driven X values; it does not simulate analog resolution or establish MTBF. The behavioural model below chooses old/new outcomes after fixed TCQ: it tests functional sensitivity but omits the physical tail of late resolution. Use characterized cell parameters and implemented settling time for reliability signoff.

    All phase sweeps here are finite: 1 ps precision, finite duration and chosen clocks/jitter visit only discrete phases, never every real-valued phase or analog trajectory. Retain functional perturbation/X checks and protocol assertions alongside structural analysis, physical constraints and the reliability budget.

    Check yourself A test shows 0 window hits at the end of the run. What should it report?

    Inconclusive, not pass. The stimulus never exercised the dangerous case. Change the ratio, offset or jitter and run longer until the hit count is meaningful.

    Testbench

    The metastability model, the stimulus and clock generators, and the testbench that counts the window hits.

    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
    33
    34
    35
    `timescale 1ns/1ps
    
    // Functional window exposure / old-new model only; TCQ is not a resolution distribution.
    module meta_ff #(parameter real TCQ = 0.25, TSU = 0.3, THD = 0.15) (input logic clk, d, output logic q, output int events);
      realtime t_d = -100.0, t_clk = -100.0;
      initial begin q = 1'b0; events = 0; end
      always @(d) begin
        t_d = $realtime;
        if ($realtime - t_clk < THD) begin events++; q <= #TCQ $urandom_range(0, 1); end
      end
      always @(posedge clk) begin
        t_clk = $realtime;
        if ($realtime - t_d < TSU) begin events++; q <= #TCQ $urandom_range(0, 1); end
        else                       q <= #TCQ d;
      end
    endmodule
    
    // A source that toggles every 5 clock cycles of its own clock
    module toggler (input logic clk, output logic q);
      int n = 0;
      initial q = 0;
      always @(posedge clk) begin n++; if (n % 5 == 0) q <= #0.25 ~q; end
    endmodule
    
    // Clock generator with a nominal period and optional cycle-to-cycle jitter (in ps units of 1 ps).
    module clk_gen #(parameter real PERIOD = 10.0, parameter real JITTER = 0.0, parameter real START = 0.0) (output logic clk);
      initial begin
        clk = 0;
        #(START);                                             // start offset
        forever begin
          #((PERIOD / 2.0) + (JITTER == 0.0 ? 0.0 : ($urandom_range(0, 1000) / 1000.0 - 0.5) * JITTER));
          clk = ~clk;
        end
      end
    endmodule
    

    Remember

    • Zero window hits on a crossing is inconclusive, not a pass. Change the ratio, offset or jitter and run longer.

    • Hostile timing has seven ingredients: unrelated periods, random offsets, jitter, perturbation models, random resets, long runs and hit coverage.

    • Plain RTL simulation does not model analog metastability. Hits show exposure to the model's window, not a failure probability.

    How this was checked

    Source test, run with Icarus Verilog 13.0 (2026-10-16): prints the four counts in the table, then PASS.

    Keep going

    • Practice: Waveform debug of a CDC glitch causing metastability

    • Interview: run a mock interview on this topic

    Related topics

    • Assertion patterns

    Previous

    183 / 350

    Next: Assertion Patterns

    Up next

    Up nextAssertion Patterns

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • FIFO Tests
    • Signoff
    • Reading a CDC Report