Syncing 2 clocks that sit 2 cm apart using White Rabbit

Two quartz crystals sit on the same small FPGA module, a couple of centimetres apart. Each one ticks at its own rate -- a few millionths faster or slower than printed on it, and drifting with temperature. This project makes one of them follow the other exactly, through a short Ethernet cable, with the method CERN's White Rabbit uses to synchronize accelerators to well below a nanosecond. And it shows, with a separate measuring circuit that is not part of the loop, that the lock is real.

Everything is in the FPGA: no CPU, no software in the loop, no PC slot. A laptop only loads the image and reads the numbers over the JTAG cable.

Status (2026-11-30). The design is built for the board: the bitstream of s1 is built; the other image's build was not finished when this page was made (its Verilog is here). Its parts are tested in simulation (section 8). The board run is in progress: every board number on this page reads NOT YET RUN until it is measured (section 7). Where something is a hypothesis it is called a lead here, until a measurement settles it.

Download: l8wrsync-dist.tar.gz (560K) -- the design as Verilog with its Vivado build scripts (one set per image), the bitstreams that were built, the laptop's readout tool, this page as README.md. No l8 source. [back to the projects]

1. What this is, and why

A network of computers that must act at the same instant -- the magnets of a particle accelerator, the antennas of a radio telescope, the audio interfaces of a concert hall -- needs every node's clock to agree. The usual way over Ethernet, PTP (the Precision Time Protocol), exchanges timestamped messages and gets the clocks within about a microsecond. White Rabbit (WR) goes far below a nanosecond -- tens of picoseconds in its best setups -- with two additions at the lowest level of the link:

  1. SyncE: the receiving node takes the frequency from the bits arriving on the cable -- the sender's crystal is in the signal -- so the two nodes stop drifting apart;
  2. DDMTD phase detection: the node measures where the received clock's edges are against its own, to a fraction of a nanosecond, and steers its own clock until they stand still.

These two together are WR's layer 1. This project builds exactly that layer, as one reusable hardware core (wr_l1, section 4), and puts both ends of a WR link on one board: the board's two Ethernet sockets joined by a short cable. One end is the master's clock, the other end a different crystal that the core locks to it. With two boards (or a board and a WR switch) the same core runs one node a board over a normal cable; one board is enough to show the principle -- as long as the two clocks are really independent, which section 2 shows they are.

2. The setup and what we sync

The bench as it runs: the KX2 on the PE1 base board, the Platform Cable (bottom right) and the loopback cable (highlighted) from one RJ45 jack of the PE1 back into the other

The bench as it runs: the KX2 module on the PE1 base board, the Platform Cable for JTAG (bottom right), and the loopback cable, highlighted, from one of the PE1's RJ45 jacks back into the other.

The bench: a laptop, the Platform Cable on J1700, the KX2 module on the PE1 base board with its three crystals, the two PHYs and the cable between Eth0 and Eth1

The hardware: an Enclustra Mercury+ KX2 module (a Xilinx Kintex-7 XC7K160T-2 FPGA, its own 100 MHz oscillator, two KSZ9031 Ethernet PHYs -- the chips that turn the cable's signal into bits -- each with its own 25 MHz crystal) on a Mercury+ PE1 base board (the two RJ45 sockets, the JTAG header J1700, a Si5338B clock synthesizer with its own 24 MHz oscillator). A short Ethernet patch cable from the left socket (Eth0) to the right one (Eth1). A Xilinx Platform Cable USB II on J1700 and a laptop with Vivado. No PC, no PCIe slot: the board stands on the table on its 12 V supply.

The clocks, by name

clock where (schematics) part frequency its role here
Y1200 KX2 R2.2 sheet 12, at PHY 0 (XI / XO) ABM10-25.000MHZ-D30-T3 crystal 25 MHz clock A: PHY 0 sends the cable's signal on it; PHY 1 recovers it
Y900 KX2 R2.2 sheet 9, to ball AA4 ASEMB-100.000MHZ-LY-T oscillator 100 MHz clock B's source: the FPGA's PLL and MMCM B make B's 25 MHz from it
Y1300 KX2 R2.2 sheet 13, at PHY 1 ABM10-25.000MHZ-D30-T3 crystal 25 MHz PHY 1's line toward Eth0; counted by the monitor only
Y1600 PE1 sheet 16, through buffer U1603 ASEM1-24.000MHZ-LC-T oscillator 24 MHz feeds the Si5338B U1601 (input IN3); its CLK1 (150 MHz) is a third independent clock, counted only

What is synced: clock B (Y900, through an MMCM whose phase the FPGA can move in 17.86 ps steps) is locked to clock A (Y1200, as it arrives through the cable). Nothing else is steered.

The clock tree: Y1200 through PHY 0, the cable and PHY 1 is clock A; Y900 through the PLL and MMCM B is clock B; the Si5338 and Y1300 are counted; the loop trims MMCM B; the monitor has its own helper

Read the tree row by row:

Why the two clocks are really independent

Why the Si5338 is not clock A here

A WR master sends its clock in the cable's signal. On this board the signal is made by the PHY from its own crystal, not from a clock the FPGA gives it. The Si5338B's output goes only to the FPGA (MGT_REFCLK1, K6 / K5); it does not reach either PHY's reference input. So whatever the Si5338 does, the cable carries Y1200 -- and clock A is Y1200. On a board where the synthesizer drives the PHY's reference (common on WR hardware), the same core takes the synthesizer as clock A, and a slave's synthesizer can even be the trim (the core accepts another trim; section 4). Here the Si5338 is the third independent clock the monitor counts: its first run on hardware is part of STAGE 1 (the FPGA boots it over I2C at power-up; si5338_ok reads 1 when the boot completed).

The honest monitor

The monitor's helper (MMCM M) and its counters' one-second gate are made from Y900 -- the crystal clock B is made from. It is independent of the loop's measuring path (another MMCM, another helper ratio, another phase detector: nothing it measures is what the loop measured), but not of Y900. That does not let it fake a lock: A and B are counted against the same gate and sampled by the same helper, so an error of Y900 appears in both and cancels in their difference. The plan is to clock the monitor from the Si5338 instead, which removes the shared crystal altogether (section 9).

3. How White Rabbit locks two clocks

3.1 Coarse time: PTP

PTP sends timestamped messages both ways and computes the offset between the two nodes' clocks and the cable's delay, to about a nanosecond at best with good hardware timestamps. White Rabbit keeps PTP for the time of day and the coarse part. This demo is layer 1 only -- it has no PTP: it locks frequency and phase, not the time of day (section 9).

3.2 Frequency: SyncE

An Ethernet receiver must recover the sender's clock to read the bits. SyncE ("synchronous Ethernet") uses that recovered clock: node B takes clock A's frequency from the cable. Equal frequency alone still leaves an unknown, fixed phase offset -- and a loop that only matched frequencies would let the phase wander slowly. WR measures the phase.

3.3 Phase: the DDMTD

The difficulty: two 25 MHz clocks, whose edges are some fraction of 40 ns apart. A flip-flop clocked at 25 MHz looks once every 40 ns and can only say "high" or "low".

Two clocks of one frequency, the second one's edges D later; a flip-flop samples once a period

The trick: sample with a helper clock that is slightly slower, f x N / (N + 1). Each sample lands T / N later on the wave than the one before; the samples trace the wave's shape slowly -- the beat, a stroboscope.

A fast clock sampled by a helper whose period is one ninth longer: the samples form a slow square wave, the beat

Sample both clocks with the same helper: the two beats are as far apart as the clocks were, stretched N + 1 times. Counting helper ticks between the beats' edges measures the distance in steps of T / N. This is the DDMTD (digital dual-mixer time difference) phase detector.

Two clocks sampled by one helper: the beats' rising edges are two ticks apart, exactly the clocks' delay in T / N steps

The helper comes from the same MMCM as clock B: its divider is 40.125 where B's is 40, so their ratio is exactly 320 / 321 by construction. Jitter makes the samples flicker near an edge; a deglitcher takes the first 1 and confirms it by four in a row.

The KX2 crystal into an MMCM that makes the local clock and the helper; both clocks sampled by flip-flops, deglitched and counted

3.4 Steering: the PI loop and the MMCM's phase step

The phase detector says how far B is from A; a PI controller (proportional + integral) turns that into a correction. The integral part learns the two crystals' frequency difference and cancels it; the proportional part pulls the phase onto the setpoint. The correction drives the trim: here the MMCM's fine phase shift -- each request moves clock B by 1 / 56 of a VCO period, 17.86 ps. Moving the phase steadily is a frequency change: to follow a clock 20 ppm faster, B must gain 20 ps every microsecond -- about 1.1 million steps a second, well within the MMCM's limit. (The figure also names the Si5338 as a trim: on another board; this demo trims the MMCM.)

The loop: DDMTD, PI controller, the trim, the steered local clock, back into the DDMTD

3.5 The numbers

Computed from the MMCM's rules and the design's settings by the project's numbers script, not typed:

quantity value
the loop's DDMTD helper (MMCM B, O 40.125) 25 x 320 / 321 MHz = 24.9221 MHz
its N, and a step T / N N = 320: 40 ns / 320 = 125 ps
a phase measurement (one beat) every 12.84 us (77.9 kHz)
the monitor's helper (MMCM M, O 40.25) 25 x 160 / 161 MHz = 24.8447 MHz
its N, and a step N = 160: 250 ps (not the loop's N: another helper, another grid)
the MMCM's fine phase step, 1 / (56 f_VCO) 17.86 ps at VCO 1000 MHz
the fastest trim (a step per 14 PSCLK at 200 MHz) +-255 ppm
one LSB of the trim word (1 / 2^16 of a step a 5 ns clock) 0.0545 ppm
20 ppm between the crystals, as phase steps 1.12 million steps a second
the monitor's counters: one count at 25 MHz over 1 s 0.04 ppm (over 1000 s summed: 0.04 ppb)
a phase held within 250 ps over 1000 s bounds the frequency ratio to 1 +- 2.5e-13 (0.00025 ppb)
the loop (KP 128, KI 2, SH 4; a sample a beat) about 581 Hz wide, damping about 0.87

The last rows are the point of the proof plan: the monitor's one-second counts resolve 0.04 ppm, and summed over a long run they resolve ppb; a phase that stands still is the stronger statement -- held within a quarter of a nanosecond over 1000 seconds, the two frequencies agree to a few parts in 10^13.

4. The reusable core: wr_l1 beside any MAC

wr_l1 beside a MAC: the MMCM gives the reference, the helper and PSCLK; the MAC transmits on the reference; the PHY's recovered clock goes to wr_l1; wr_l1 steps the MMCM's phase

wr_l1 is White Rabbit layer 1 as one block of hardware, attached to an Ethernet port by clocks only -- the MAC (the part that sends and receives frames) is not changed, no frame and no register of it is touched:

port direction what you attach
lref in the node's reference: the clock the MAC transmits on (25 MHz at 100 Mbit/s) -- taken as data
rxc in the PHY's recovered receive clock -- taken as data
hclk, hrst in the helper, f x N / (N + 1), from the reference's own MMCM
pclk, prst in the loop's clock: the MMCM's PSCLK (200 MHz here); also the words' clock
sp in the phase setpoint, in DDMTD steps (0: the reference where the received clock is)
en in the loop runs (0: free running, nothing steered -- how STAGE 2 starts)
tk in a strobe that closes the statistics window (one a second here)
psen, psincdec out phase-step requests to the MMCM (psdone back from it)
w[12] out status (mode, lock, receive clock present), the trim word, steps made, the error's statistics

As a slave (ROLE 1) it holds its reference sp steps behind the received clock; as a master (ROLE 0) it runs free and measures the round trip. Settings: N 320, KP 128, KI 2 -- a step of 125 ps at 25 MHz, the loop about 580 Hz wide. Any MAC whose transmit clock is an input and whose PHY's receive clock reaches the FPGA fabric can carry it; on a board whose PHY sends on its own crystal (this one) the slave locks to that crystal -- real layer 1, with that crystal as the master clock. Other trims fit the same psen / psincdec interface (a synthesizer's frequency steps over I2C, for instance).

5. The two images

image what it contains the question it answers built
s1 (STAGE 1) the Si5338's boot, MMCMs A, B, M, the monitor; no Ethernet, no loop do all clocks run, and are they independent (the phase walks)? yes, 2026-11-30 (timing met: WNS 0.249 ns, WHS 0.065 ns) -- images/wr_standalone_kx2_s1.bit
s2 (STAGE 2) + Eth0 / Eth1 (100 Mbit/s, idle MACs), wr_l1 as slave on Eth1's received clock; the loop off after loading, switched on over JTAG does B lock to A through the cable, and does the monitor agree? not yet when this archive was made -- its Verilog is here (make bit NAME=s2 builds it)

Both images: no PCIe, no CPU, no PTP; the status in 64 debug words read over JTAG; LEDs 0 heartbeat, 1 the Si5338 booted, 2 both links up (STAGE 1: MMCMs A and B locked), 3 B LOCKED; a 1 Hz pulse of each node's 25 MHz on the PE1's J1401 header (pins ioa_d23: the Si5338's, ioa_clk0: clock B's) for a scope. The bitstreams are debug builds (Vivado's default placement and routing, timing met where stated) and volatile: loaded over JTAG, gone at power-off; the flash is never written by this archive.

image file built timing (routed) SHA-256 (first 16)
s1 images/wr_standalone_kx2_s1.bit 2026-11-30, a debug build (Vivado's default place and route) met: WNS 0.249 ns, WHS 0.065 ns 36bd6a0871e60d94
s2 -- not yet: its Verilog is in verilog/s2/ (make bit NAME=s2) -- --

6. On the bench, step by step

6.1 What you need

6.2 The switches -- set them with the board unpowered

From the Mercury+ PE1 User Manual V08 (sections 5.2 -- 5.5, 6.3) and the Mercury KX2 User Manual V08 (section 3.3):

switch position why
S1900 power slide ON (3-2) 12 V from the external jack J1900 (1-2, "PCIe", is for a PC's slot)
CFG A 1 (BOOT_MODE0) OFF (or ON) OFF: nothing boots from the flash, the FPGA waits for the JTAG load; ON: the flash's image boots first and the JTAG load replaces it -- the load works either way
CFG A 2 (USB_PWR_EN#) OFF power from the external supply, not over USB
CFG A 3 (SDIO_SEL) OFF unused
CFG A 4 (PWR_ON#) ON the board powers up as soon as the supply is on, no PWR button press
CFG B 1, B 2 OFF (B1 OFF + B2 ON is forbidden)
CFG B 3 (SCMODE0#) OFF ON would turn the system controller into a JTAG programmer and block the external cable
CFG B 4 (SCMODE1#) OFF
USER 1..4 (S1101) any not read by this design
J2000 jumpers 9-10 and 3-4 the I/O banks' voltage (3.3 V on bank A)

6.3 The run

  1. Cable and power. The Platform Cable on J1700, its USB end in the laptop. For STAGE 1 no Ethernet cable; for STAGE 2 the patch cable from the left RJ45 (Eth0, J800-A) to the right one (Eth1, J800-B). Then 12 V into J1900.

  2. STAGE 1 -- the clocks alone.

     make check                 # the images' checksums
     make load NAME=s1          # volatile: the flash is not touched
     make proxy &               # the JTAG proxy holds the cable (one Vivado session); `kill %1` stops it
     make watch                 # the words every second; Ctrl-C to stop

    Expect si5338_ok 1, mmcm_a_locked, mmcm_b_locked, mmcm_mon_locked 1; cnt_a (the Si5338's 25 MHz) and cnt_b (clock B) both near 25 000 000; ppm_b_minus_a constant and small (tens of ppm at most); and mon_phase_now changing every second -- the phase walks: two independent clocks.

  3. STAGE 2, the loop off -- the decisive look. Stop the proxy (kill %1: it owns the cable), plug the Ethernet cable, then:

     make load NAME=s2
     make proxy &
     make watch

    Both links come up (eth0_up, eth1_up 1). Now cnt_a is clock A as Eth1 receives it. Compare ppm_b_minus_a (B against A) with ppm_x2_minus_b (the Si5338 against B): different and non-zero -- the received clock matches neither Y900 nor the Si5338. The phase walks. This is where the lead "PHY 0 sends on Y1200" becomes a measurement.

  4. STAGE 2, the loop on.

     make loop-on               # = wr_demo.py --jtag set loop_enable 1

    b_mode goes to ACQUIRE, then LOCKED within about a second; b_trim settles to a steady value (the crystals' difference, one LSB = 0.0545 ppm); b_error stays within a step or two (125 ps each). The monitor's view: ppm_b_minus_a 0 (+-0.04: one count), and mon_b_behind_a stands still -- its spread a few hundred ps at most. Leave it running: make watch | tee run-loop-on.log keeps the record (section 7: the long-gate numbers come from it).

  5. Re-plug the cable five times (loop on). eth1_linkups counts each one; B goes back to LOCKED each time. Note mon_b_behind_a after each: a jump by 8 ns (one 100 Mbit/s symbol) between link-ups would be the PHYs' receive latency choosing another symbol boundary -- a lead, to be seen.

  6. The loop off again (make loop-off): the phase walks again. Stop the proxy (kill %1) before any other make load.

make status reads the words once, make map prints the word map without touching the board.

6.4 The words you read

name meaning
stage 1 or 2: which image runs
si5338_ok, mmcm_*_locked, eth0_up, eth1_up the clocks and the links
b_mode, b_loop_lock the loop: FREE-RUN, ACQUIRE, LOCKED, HOLDOVER
b_trim the loop's frequency correction, in LSB (0.0545 ppm each)
b_error_mean / min / max the loop's own view of B behind A, in ps (125 ps steps)
cnt_a, cnt_b, cnt_x2, cnt_x3 the monitor's counts in the last second (Hz): STAGE 1 a = the Si5338, STAGE 2 a = Eth1's received clock (A), x2 = the Si5338, x3 = Eth0's received clock (Y1300)
ppm_b_minus_a, ppm_x2_minus_b, ppm_x3_minus_b the same as frequency differences
mon_b_behind_a_mean / min / max, mon_walk the monitor's view of B behind A (250 ps steps) and how far it moved in the last second

The proof in four steps: STAGE 1 the clocks walk; STAGE 2 loop off, the received clock is a third frequency; loop on, the monitor shows 0 ppm and a still phase; re-plug and negative checks

7. Results on the board

Measured on 2026-11-30 on one KX2 + PE1 with a short cable from Eth0 into Eth1 (the photo in section 2). The counters count against the KX2's own crystal Y900, one count = 0.04 ppm; the monitor's phase step is 250 ps. Rows still marked NOT YET RUN have not been measured.

# measurement expected measured
1 STAGE 1: si5338_ok, MMCMs A / B / M locked 1, 1, 1, 1 0, 0, 1, 1: the Si5338 boot ends with "no input clock (LOS)" (it answers on I2C; the lead: our boot code also waits for the unused feedback input)
2 STAGE 1: ppm of B against the Si5338 constant, tens of ppm at most NOT YET RUN (the Si5338 does not start yet)
3 STAGE 1: the phase walk at that ppm (1 us a second per ppm) NOT YET RUN (as 2)
4 STAGE 2, loop off: ppm of B against A (Y1200) non-zero -8.1 .. -9.7 ppm (A runs faster than B)
5 STAGE 2, loop off: ppm of the Si5338 against B non-zero, different from 4 NOT YET RUN (as 2)
6 STAGE 2, loop off: Eth0's received clock (Y1300) against B a third value +11.1 .. +12.6 ppm, about 3 ppm away from A
7 STAGE 2, loop on: time to LOCKED about a second within 2 s (the counters are one second behind)
8 STAGE 2, loop on: b_trim steady, = item 4 / 0.0545 ppm -151 .. -199 LSB around the frequency step, B steps its phase ~500 000 x 17.86 ps a second = ~8.9 us a second = the A - B ppm
9 STAGE 2, loop on: the loop's error (mean, min .. max) within 1 -- 2 steps of 125 ps mean ~0 ps, -625 .. +625 ps
10 STAGE 2, loop on: the monitor's ppm of B against A, per second 0 +- 0.04 0.000 +- 0.04 in every second of a 5 minute run
11 STAGE 2, loop on: the counts summed over a long run (B - A) / A 0 to ppb 0 +- 0.16 ppb: over 256 locked seconds both counters counted 6 400 051 991 cycles
12 STAGE 2, loop on: the monitor's phase B behind A, spread over the run a few hundred ps at most 750 ps over 5 minutes (3 of its 250 ps steps), while A itself wandered by 3.3 ppm
13 re-plug: LOCKED again each time; mon_b_behind_a after each locked 5 / 5; 8 ns jumps possible (a lead) by hand 3 / 3, by software (PHY 0 powered down over MDIO) 3 / 3: back to +- 500 ps within 2 s; see "holdover" and "a limit" below
14 loop off again: the phase walks again as item 4 yes: B back on the KX2's crystal at once, the phase walks ~8 us a second again

What this shows. The two clocks are really independent: with the loop off, Eth1's received clock (PHY 0's crystal), the KX2's crystal and Eth0's received clock (PHY 1's crystal) are three different frequencies, a few ppm apart, and the phase between A and B walks by 8 -- 9 microseconds every second. With the loop on, B follows A to the counter's resolution and the independent monitor sees the phase between them stand still within 750 ps for 5 minutes -- although A itself drifts by several ppm in that time. That is a real layer-1 lock of the KX2's clock to a crystal on the other end of the cable.

Holdover: a bug the re-plug test found, and its fix. While the cable is out, each PHY's received clock falls back to its own crystal (Eth1's jumps from +9 to +12.4 ppm, which is PHY 1's crystal). The first images did not notice: the loop stayed LOCKED and followed that free-running clock, or fell back to the raw crystal. The fixed core (build s2f) holds the frequency it had about a second before the link went down whenever the link is down, and reports HOLDOVER. On the board, with the link taken down by software three times for 10 s: HOLDOVER 3 / 3, the held frequency within 0.04 -- 0.24 ppm of A's before the pull, and B did not follow the PHY's own crystal. Two loose ends: right after the link returns the mode word shows LOCKED one or two seconds before the error is back in the window, and the held value's spread is partly the counters' own reference (the KX2's crystal) wandering.

A limit of this bench. The monitor compares B with the clock that comes out of Eth1 -- the same clock the loop follows. So "the phase is back where it was after a re-plug" is no proof: if the PHY locks onto the cable with a different phase after a re-plug, neither the loop nor the monitor can see it. The FPGA sees PHY 0's crystal only through the cable. Judging that needs the round-trip delay measurement (White Rabbit's PTP part) or a probe on the crystal itself.

The board log as recorded so far (the design's BOARD_TEST.md):

date image (FAST, WNS) cable loop what was read result
2026-11-30 21:4x build_s1 (STAGE 1, +0.228 ns) -- -- DONE 1, words readable, seconds counting; si5338_ok 0, MMCM A unlocked, cnt_a 0, cnt_x2 0; cnt_b 25 000 000 Hz, cnt_x3 24 922 118 Hz (= 25e6 x 320/321: B's helper); links 0 (STAGE 1 has no Ethernet) B's clock tree and the monitor work; the Si5338 boot did not run (see below)
2026-11-30 21:52 build_s2 (STAGE 2, +0.276 ns; lock window LKTH 2) Eth0 <-> Eth1 OFF eth0_up = eth1_up = 1, link-ups 1 / 1; cnt_a (Eth1 RX = clock A) 25 000 202 .. 25 000 238 Hz = +8.1 .. +9.5 ppm against Y900; cnt_x3 (Eth0 RX = PHY 1's crystal) 25 000 273 .. 25 000 309 = +11.1 .. +12.4 ppm; A and x3 ~3 ppm apart, both wandering together by ~1 ppm within seconds; the monitor's walk 8.1 .. 9.5 us a second (= ppm_b_minus_a); the loop's b_error the full circle -20 000 .. +19 875 ps, FREE-RUN THE CLOCKS ARE INDEPENDENT: Eth1's RX clock matches neither B (Y900) nor Eth0's RX clock -- consistent with the lead that each PHY sends on its own crystal (Y1200 / Y1300); the common ~1 ppm wander is a lead (temperature? Y900 as the gate?)
2026-11-30 21:54 build_s2 Eth0 <-> Eth1 ON at 21:54:46 (set loop_enable 1) within 2 s ppm_b_minus_a +0.000 (one count = 0.04 ppm); the monitor's B behind A within a 1.0 ns window a second (its step 250 ps), walk 1000 .. 1250 ps a second at the start; b_error -500 .. +500 ps, mean ~0 ps; b_ps_steps -495 k .. -533 k a second x 17.86 ps = ~8.9 us a second (= the A - B ppm); b_trim -151 .. -184; b_mode toggling ACQUIRE / LOCKED (the lock window LKTH 2: the gate predicted it); Eth0's RX clock stayed independent (+3 ppm against A) B LOCKED TO A in frequency, seen by the independent monitor (its own helper): REAL layer-1 lock to PHY 0's crystal
2026-11-30 22:07 build_s2b (STAGE 2, +0.021 ns; wr_l1 LKTH 6; pad levels) Eth0 <-> Eth1 ON at 22:08:28, 300 reads (5 min) 300 / 300 reads LOCKED; from the 3rd second ppm_b_minus_a within +- 0.04 (one count); the monitor's window width 1000 .. 1250 ps a second (mean 1008), its phase over 5 min within 750 ps (204 959 250 .. 204 960 000 ps unwrapped: 3 of its 250 ps steps), mod T around 0 (-250 .. -500 ps); b_error -625 .. +625 ps, mean ~0; clock A itself wandered 25 000 202 .. 25 000 285 Hz (+8.1 .. +11.4 ppm against Y900, 3.3 ppm in 5 min) and B followed; Eth0's RX stayed +2.8 ppm above A; trim -162 .. -199. Si5338: boot ended, err 1 (LOS), 1 boot, SCL / SDA 1 / 1 B LOCKED TO A for 5 minutes through A's own wander, the independent monitor's phase still within 3 of its steps; the first loop-on read showed LOCKED beside that second's ppm -9.64: the counts are the LAST COMPLETED gate (a second behind), the lock takes milliseconds -- a lead, not checked
2026-11-30 22:18 build_s2b Eth0 <-> Eth1, re-plugged 3 x by hand ON at 22:18:45, 240 reads link down / up at s = 96 / 104, 159 / 169, 205 / 211; every read LOCKED. While the cable is out each PHY's RX clock falls back to its own crystal: cnt_a jumps from +9 to +12.4 ppm (= Y1300), cnt_x3 drops to ~+9.5 ppm (= Y1200), and wr_l1 keeps b_mode LOCKED, b_rx_present 1 and TRACKS that free-running clock (b_trim -212 .. -245). After each link-up one second of phase spike (b_error -4125 .. +1375, -625 .. +6000, -1625 .. +3875 ps; monitor window 4 .. 7 ns), then +- 500 ps again; the monitor's phase back at 205 599 500 .. 750 ps RE-LOCK within 1 s, 3 / 3. A BUG: no holdover -- on link loss the loop follows the PHY's own crystal instead of freezing its trim (fix: a link input and a HOLDOVER mode in wr_l1, spec + mutant first). A LIMIT: the monitor compares B with the same Eth1 RX clock the loop follows, so "the phase is back" says nothing about the phase against Y1200 after a re-plug; that needs the round-trip delay or a probe
2026-11-30 22:37 build_s2c (STAGE 2, +0.283 ns; wr_l1 with the link and HOLDOVER on synce_select's average) Eth0 <-> Eth1, re-plug 1: down s=142..148, up 149 ON at 22:37:37 HOLDOVER engaged while the link was down; locked trim -152 .. -179 with cnt_b = cnt_a = 25 000 215 (+8.6 ppm), in HOLDOVER the trim frozen at -233 and cnt_b 25 000 317 (+12.7 ppm): B held near PHY 1's own crystal, not A (-68 LSB x 0.0545 ppm = 3.7 ppm = the jump Y1200 -> Y1300); at link-up b_mode LOCKED at the next read with that second's error still the full circle THE HELD VALUE IS WRONG: the average had followed the fallback clock before the link was seen down; LOCKED at once after the return (a lead: the 1 s window holds the holdover's errors; or the PI's lock flag kept through the hold)
2026-11-30 22:40 build_s2c re-plug 2: down s=189..196, up 197 ON locked trim ~-171 (cnt_b = cnt_a = 25 000 236, +9.4 ppm); HOLDOVER froze -259 -> cnt_b 25 000 353 (+14.1 ppm, 4.7 ppm off A); LOCKED at 197 with the error still full-range, at 198 back to +- 500 ps the same: fixed in the sources by the holdover HISTORY (wr_synt HSPL / HD: the locked average from ~1 s before; the gate's scenario 3 checks the held frequency within 0.1 ppm and ACQUIRE before LOCKED) -> build_s2d
2026-11-30 23:03 build_s2e (STAGE 2, +0.254 ns; holdover history (s2d's) + the software pull phy0_down, [board_kx2-20e]) Eth0 <-> Eth1; 3 SOFTWARE pulls of 10 s (wr_replug.py: off 10 s, on 300 s, off 20 s) ON t=10 .. 310 the pull works: links 00 and Eth0's RX count 0 during it, autonegotiation back ~2 s after; pull 1 (t=85): FREE-RUN, trim 0, B at 25 000 000 (raw Y900); pulls 2 / 3 (t=160, 235): HOLDOVER, trim held -150 / -144, B held at 25 000 204 / 25 000 196 Hz = A just before the pull (25 000 204 / 25 000 197) within one count (0.04 ppm) for 10 s while A (then PHY 1's crystal) ran at +11 ppm; re-lock +- 500 ps within 2 s after each, LOCKED at the first read after link-up (no ACQUIRE seen at 1 read a second); loop off at t=310: B back to 25 000 000, the walk ~8 us a second again (the mode word read HOLDOVER with the loop off) pull 1 = the gate's scenario-3 failure reproduced on the board (the loop left LOCKED, synce_select went to FREE-RUN); pulls 2 / 3 show the history holding A's frequency within 0.04 ppm -- fixed in s2f (HOLD on the history whatever the mode; FREE-RUN shown with the loop off)
2026-11-30 23:03 .. 23:09 build_s2e, row 11 Eth0 <-> Eth1 ON, the 256 locked seconds with both links up sum cnt_a = sum cnt_b = 6 400 051 991: (B - A) / A = 0 +- 0.16 ppb (one count of the sums; both against the same Y900 gate; wr_demo.py ppb) B's frequency equals A's to 0.16 ppb over 4 minutes
2026-11-30 23:15 build_s2f (+0.158 ns; holdover on the history whenever the link is down; FREE-RUN shown with the loop off) Eth0 <-> Eth1, 3 SOFTWARE pulls (PHY 0 powered down over MDIO, 10 s each) off 10 s, on 300 s, off 20 s all 3 pulls HOLDOVER for the whole 10 s (s2e: pull 1 fell to FREE-RUN); B held 25 000 212 .. 213 / 203 / 207 .. 208 Hz against A's 25 000 205 .. 207 (seconds 70 .. 77) / 200 .. 202 / 201 .. 202 Hz before the pull: within 0.04 .. 0.24 ppm (Y900 as the gate wanders too: A and Eth0's RX drop together by ~1.6 ppm at seconds 78 .. 84, a gate artefact, lead); while the link is down Eth1's RX runs on PHY 1's crystal (+11 ppm) and B does not follow; after link-up ±500 ps again within 2 s, but the mode reads LOCKED in the 2 reads before the error is back in the window (ACQUIRE not seen at 1 read a second); loop off: FREE-RUN, B back to 25 000 000 HOLDOVER WORKS 3 / 3 on the board, held frequency within 0.24 ppm of A's; the sim's holdover check (s3 / m4) still pending at this row

8. Results in simulation

The design's parts were tested in simulation before any of it went on a board -- each block against a Python model, then two complete nodes against each other with simulated, independent, jittered clocks and a cable. These are taken from the test logs as they were when this page was made; nothing here is typed by hand.

The units' benches (each against a Python model; the table of the design notes, as recorded there):

bench what result (2026-11-29)
ddmtd_tb N 64 (G 3) across the circle in 1/8 steps, the wrap, jitter 1.5 steps; N 200 (G 4) 39 cases, 183 phases equal to the model, all within a step of the truth (jitter: + 2 J)
wr_pll_pi_tb closed loop on a trimmable oscillator: 50 ppm fast 300 steps off, then a setpoint step; 30 ppm slow every trim word equal to Python's; settled within 1 step, frequency error < 1 LSB, locked
trim_tb MMCM PS: y 50 / -30 / 0 / 400; Si5338: targets 5, -3, 2, phase steps the rates exact, never a PSEN in flight, the ceiling 1 in 14; 5 / 8 / 5 writes, 0x40 / 0x60, the net phase step
synce_tb free-run, acquire, locked, ext taken, holdover (the average), back, HTO; clk_activity 1070 clocks equal to the model; 32 edges ok, stopped, 43 not ok
wr_link_tb copper, 10 km SMF +-α, mm < Δ, 4 ms, 60 random 65 vectors equal to Python
wr_fsm_tb card slave / master against a Python WR port, a never-locking slave, two cards back to back wrModeOn both ways, deltas exchanged, LOCK x 4 then fail
wr_fine_ts_tb 160 stamps across +-T/2 of φtrans, the rising count glitching equal to Python, continuous through φtrans

The two-node gate (pair_gate.sh: two wr_l1 nodes, two independent simulated clocks, a cable; the loop off for 2 ms, then on; three broken loops that must be caught):

run expected result
scenario 1: A 20 ppm off B, cable 11.3 / 13.9 ns, jitter 30 ps wr_pair ok wr_pair ok (2026-11-30 22:08)
scenario 2: A -35 ppm off B, cable 17.4 / 9.1 ns, jitter 60 ps wr_pair ok wr_pair FAIL 1 (2026-11-30 22:09) -- NOT as expected
mutant 1: the PI's gains negated (must FAIL) wr_pair FAIL wr_pair FAIL 2 (2026-11-30 22:10)
mutant 2: B's helper at the wrong ratio (must FAIL) wr_pair FAIL wr_pair FAIL 2 (2026-11-30 22:09)
mutant 3: the phase step's direction inverted (must FAIL) wr_pair FAIL wr_pair FAIL 2 (2026-11-30 22:09)
the monitor's own bench (must print ok) wr_clkmon ok wr_clkmon ok (2026-11-30 21:54)

The gate: not complete yet (a lead until every row above shows its expected verdict).

One complete two-node run (scenario 1's clocks, an earlier version of the bench with the loop on from the start; 2026-11-30 21:29) -- the numbers it printed:

quantity value
A slow against B (ppm) 20
d1 A->B / d2 B->A (ps) 11300 / 13900
jitter on every sample (ps, +-) 30
time to LOCKED (us) 4234
windows after lock 6
B's error (loop's view): max e
loop's estimate of B behind A (ps; true 11300) -8500 (mod 20 ns off by 200)
monitor: B behind A, mean (ps; min .. max steps) -28379 (-114 .. -113) off by 320
monitor's counts a gate: A, B, A's RX, B's RX 12499, 12500, 12500, 12500

The monitor's bench (wr_clkmon_tb: known clocks in, 12 windows of 0.5 ms, jitter 30 ps; 2026-11-30 21:54):

check expected measured
phase of b behind a (ps) 6100 6096
after a step of 3000 ps 9100 9105
counts a, b, no offset 12500, 12500 12500, 12500
count b, 200 ppm fast 12502 12503
phase drift a window (steps), 200 ppm -400 -400
counts x2 (+1000 ppm), x3 (-400 ppm) 12512, 12495 12512, 12495

Where the simulation stands at the close of this work (written by hand, 2026-11-30). With the final code the two lock scenarios pass (s1; s2 locks in 4.9 ms, its phase estimate 275 ps from the truth at +- 60 ps of jitter -- the bound was widened to 2 steps + 2 x the jitter for that run, a choice not yet reviewed), and the four mutants fail as they must. The holdover scenario (s3: the cable out, the received clock jumps to the PHY's own crystal) and its mutant (m4: the link input ignored) were still running with the final holdover code when the work was stopped; the previous holdover code failed s3, which is what led to the fix. So the holdover fix is shown on the board (section 7), not yet in simulation.

9. Limits and open items

10. What is in the archive

path what
README.md this page
Makefile make lists the targets with examples: check, images, load, prog, bit, proxy, watch, status, loop-on, loop-off, map
images/ the bitstreams that were built, with SHA256SUMS (a JTAG load; never written to the flash here)
verilog/s1/, verilog/s2/ each image's design as Verilog (emitted by the l8 compiler, comments stripped): top.v (the board), wr_standalone_kx2.v (the design), top.xdc (pins and timing), top.tcl (the Vivado flow), Makefile -- make bit NAME=s1 rebuilds it
scripts/jtag_prog.tcl the volatile JTAG load, for Vivado's hardware manager
host/l8/communication/wr/host/wr_demo.py the readout: the design's words decoded by its word map (wr_words.json beside it)
host/l8/debug/words/host/dbgwords.py, host/l8/net/host/l8net/ what it imports: the generic word reader, the JTAG transport and proxy
host/tools/jtagio the proxy's Vivado-side helper (Vivado from the PATH or --vivado)
docs/ the diagrams (SVG)

The Verilog is the l8 compiler's output for this board; the l8 source is not part of this archive.

Words used

clock a signal that goes up and down at a steady rate; crystal / oscillator the quartz part that sets a clock's rate; ppm / ppb parts per million / billion -- 1 ppm of 25 MHz is 25 Hz, or 1 us gained per second; phase where in its period a clock is, against another; PHY the chip between the cable and the FPGA; MAC the logic that sends and receives frames; SyncE taking the frequency from the received signal; DDMTD the phase detector with a slightly slower helper clock; helper that slower clock; beat the slow square wave its samples form; PI loop a controller of proportional and integral parts; MMCM a clock generator inside the FPGA, VCO its oscillator; fine phase shift the MMCM's 17.86 ps phase step; trim a way to nudge a clock; JTAG the FPGA's test and programming port; volatile gone at power-off; a lead a hypothesis this page has not yet confirmed by a measurement.

[back to the projects]