Picture two runners, each on their own treadmill, each set to a different speed. One has to hand a baton to the other — but they can only reach across at the exact instant their strides happen to line up. Time it right, clean handoff. Time it wrong, the baton tumbles to the floor. And here's the catch: neither runner is allowed to change speed.
That fumbled handoff — happening billions of times a second, deep inside a chip — is exactly what Clock Domain Crossing is about. This lesson builds the whole idea from the ground up. By the end, you'll be able to run a live simulation and watch a handoff fumble with your own eyes.
Every synchronous digital circuit runs on a clock — a signal that ticks high, low, high, low, over and over, like a metronome. On each tick, every flip-flop in the circuit takes a snapshot of its input and holds it. The clock is the heartbeat that keeps all the logic marching in step.
A clock domain is simply all the logic driven by one particular clock. Every flip-flop inside that domain samples on the same edge, at the same instant. Because they all share one heartbeat, the timing between them is completely predictable — and the design tools can mathematically guarantee that every signal arrives on time.
A clock domain crossing happens the moment a signal born under one clock travels into logic that lives under a different clock. The sender ticks to Clock A. The receiver ticks to Clock B. And critically — those two clocks have no agreement with each other. Different speeds. Drifting phase. No coordination whatsoever.
Clock Domain Crossing (CDC) is any path where a signal launched by one clock is captured by a different, unrelated clock.
Domain A is one runner, Domain B is the other. The baton is your signal. The clocks are their strides — and because the treadmills run at unrelated speeds, the perfect moment to hand off never lines up on a fixed schedule. It's left to chance.
It's a fair question — one clock would make this whole problem disappear. But in any real chip, multiple clocks aren't a design choice you can avoid. They're forced on you:
A CPU core wants to run at gigahertz. An I²C sensor bus crawls at 100 kHz. One clock can't serve both well.
USB, PCIe, Ethernet, HDMI, an audio codec — each arrives with its own clock, defined by a standard you don't control.
Running idle blocks on a slower clock (or a separate one you can switch off) is one of the biggest levers for battery life.
You simply can't distribute one perfectly-aligned clock across a large die. Separate clocks for separate regions are unavoidable.
So multiple clock domains are the norm, not the exception. Almost every modern SoC has many — and every place their signals meet is a crossing you must handle correctly.
Every flip-flop has one simple rule: its input must stay steady for a tiny window around the clock edge — a sliver of time just before it (called setup) and just after (called hold). Break that rule and the flop can't cleanly decide what it saw.
Inside a single domain, this rule is never broken — the tools arrange all the timing so every signal is rock-steady before each edge. But across domains, nobody is enforcing anything. The incoming signal marches to Clock A and can change at literally any moment — including right in the middle of Clock B's forbidden setup/hold window.
When a change lands in that window, the receiving flop is asked to capture a signal that's moving underneath it. The result is metastability: the flop's output hangs at an undefined level — not a clean 0, not a clean 1, but somewhere in between — and stays there for an unpredictable amount of time before eventually toppling one way or the other.
This is the core hazard of CDC. It isn't about the signal being fast or slow — even a single bit crossing once can trigger it. It's purely that the two clocks have no fixed relationship, so sooner or later a transition will land in the danger window. The only question is when.
Here's what makes CDC bugs so feared: they don't fail cleanly or repeatably. A metastable event might happen once in a million cycles, under one specific combination of temperature, voltage, and timing. Which means:
A single unsynchronized bit has bricked real, shipping products. That's why every serious design flow treats CDC as a mandatory sign-off step — not an afterthought.
Enough words. You've got the concept — now let's make it happen and watch a crossing fumble in real time. 👇
FF A (Domain A) drives a signal into FF B (Domain B). Adjust each clock's speed below, then click Run to watch the signal cross over — and see what happens when it arrives too close to a Clock B edge.
The animation above is a model of the idea. Below is the real thing — a tiny design with the
exact same unsafe crossing, plus a testbench that drives two unrelated clocks. Paste both into our
Verilog Simulator, hit Run, and open the waveform —
you'll see data_a toggling cleanly on Clock A, and
data_b capturing it with zero synchronization on Clock B.
Heads up: ordinary RTL simulators (this one included) don't model real analog metastability — they just pick a value deterministically. So you won't see the flop "hang" mid-voltage. What you will see is the raw, unguarded crossing itself: two clocks with no fixed relationship, and a signal sampled with no synchronizer between them. That's the part this lesson is about — the fix comes in Module 3.
// ------------------------------------------------------------
// cdc_demo.v
// A signal crossing from Domain A (clk_a) into Domain B (clk_b)
// with NO synchronizer -- the unsafe crossing this lesson covers.
// (We fix this properly with a 2-flop synchronizer in Module 3.)
// ------------------------------------------------------------
module cdc_demo (
input clk_a,
input clk_b,
input rst,
output reg data_a, // toggles inside Domain A
output reg data_b // captured directly in Domain B (unsafe!)
);
// Domain A: source flip-flop
always @(posedge clk_a or posedge rst) begin
if (rst)
data_a <= 1'b0;
else
data_a <= ~data_a;
end
// Domain B: captures data_a DIRECTLY across the clock boundary.
// No synchronizer in between -> classic single-flop CDC crossing.
always @(posedge clk_b or posedge rst) begin
if (rst)
data_b <= 1'b0;
else
data_b <= data_a;
end
endmodule
// ------------------------------------------------------------
// tb.v -- drives two unrelated clocks and dumps waves
// ------------------------------------------------------------
module tb;
reg clk_a = 0;
reg clk_b = 0;
reg rst = 1;
wire data_a, data_b;
cdc_demo dut (
.clk_a (clk_a),
.clk_b (clk_b),
.rst (rst),
.data_a (data_a),
.data_b (data_b)
);
// Clock A: 10ns period
always #5 clk_a = ~clk_a;
// Clock B: 13ns period -- deliberately unrelated to Clock A
always #6.5 clk_b = ~clk_b;
initial begin
$dumpfile("dump.vcd");
$dumpvars(0, tb);
rst = 1;
#20 rst = 0;
#500 $finish;
end
endmodule