[back to the soundcard] [back to the deck]
This chapter explains, from the start, how an FPGA board can tell how far apart two clocks are to a fraction of a nanosecond -- the trick at the heart of White Rabbit (WR), CERN's way to synchronize computers over Ethernet to better than a nanosecond. No prior knowledge is needed: every term is explained where it first appears.
Status. The building blocks are built and tested in simulation (each against a Python model). The soundcard image with the option WR=1 contains them (it is emitted and checked; its bitstream is built). Nothing of this has run on the board yet, and the two-node demonstration at the end is planned.
A clock in digital hardware is a signal that goes up and down at a steady rate. How many times a second it does so is its frequency: 125 MHz means 125 million times a second. One up-and-down is a period: at 125 MHz, 8 nanoseconds (ns). The moment the signal goes up is a rising edge.
Take two clocks of the same frequency -- the board's own (the local clock) and the one hidden in the data that arrives over the network cable (the received clock). Their edges do not line up: the received one's come a bit later. That distance is the phase difference, here called D. WR wants D to a few picoseconds (ps; 1 ns = 1000 ps).
Why that is hard: the basic memory cell of an FPGA, the flip-flop, looks at a signal once per clock edge and remembers 0 or 1. Sampling a 125 MHz clock with a 125 MHz flip-flop gives one look every 8 ns -- it can say "high" or "low", but never "the edge was 1.37 ns ago". A faster flip-flop clock does not save us: the fastest an FPGA can clock is a few hundred MHz, a few ns a look.
Here is the idea. Instead of a faster clock, sample with a clock that is slightly slower -- the helper clock. If the helper's period is a tiny bit longer than the clock's, each sample lands a tiny bit later on the wave than the one before. Over many samples the helper walks slowly along the wave, and the 0s and 1s it collects trace out the wave's shape -- slowly. The sampled sequence is a square wave again, but stretched in time: the beat.
This is the stroboscope effect (a wagon wheel in a film turning slowly because the camera samples it at almost the wheel's own rate), and it is the vernier of a caliper: a scale whose marks are slightly wider than the main scale's, so that one of them lines up exactly and shows the fraction.
In numbers: the helper runs at f x N / (N + 1), where f is the clock's frequency and N a whole number. Its period is then T + T / N (T the clock's period): each helper tick lands T / N later on the wave. After N ticks it has walked one whole period, so the beat is N ticks long. The drawing uses N = 8 (a 9-column helper against an 8-column clock); real hardware uses hundreds.
Now sample both clocks -- the local one and the received one -- with the same helper. Each gives a beat. The two beats are as far apart as the clocks were, but stretched: a clock delay of D shows up as D / (T / N) helper ticks between the beats' edges. So counting whole ticks between the two beats' edges measures D in steps of T / N.
A worked example at Ethernet's 125 MHz (T = 8 ns), with a helper of 125 x 511 / 512 MHz = 124.756 MHz (N = 511):
The soundcard's WR=1 image measures the 25 MHz clock of its 100 Mbit link: T = 40 ns, N = 320, one step = 125 ps, a measurement every 12.8 us.
Nothing in this needs a fast circuit: the counting runs at the helper's own rate, and the precision comes from the small difference between the two frequencies. The digital form of this method is called the DDMTD (digital dual-mixer time difference) phase detector.
Real clocks wobble a little: their edges come a few picoseconds early or late, at random -- jitter. Near the moment the helper crosses an edge of the wave, that wobble makes the samples flicker (0, 1, 0, 1, ...) for a few ticks before they settle. A deglitcher cleans that up: it takes the first 1 of a flicker as the edge's time, and accepts it only when it sees several 1s in a row (four in this design). Both channels are cleaned the same way, so their difference stays right.
The helper only has to be slightly slower by a known ratio. The FPGA can make it itself, from the board's crystal, with an MMCM -- a PLL (phase-locked loop: a circuit that makes a new clock locked to an input clock) built into the Kintex-7. Inside it runs a VCO (voltage-controlled oscillator) at a multiple of the input: its input x M / D, between 600 and 1440 MHz on this part (WR=1 feeds it the card's 200 MHz, itself made from the 100 MHz crystal); each output divides the VCO by its own number O. M and one output's O may have eighths (63.875, 40.125), which is exactly what makes "slightly slower" possible.
Values that the MMCM can really make (computed by the design's numbers script, not typed):
| clock | how | helper | N | one step |
|---|---|---|---|---|
| 25 MHz (today's WR=1) | one MMCM on the 200 MHz card clock: VCO 1000 MHz, local O 40, helper O 40.125 | 24.9221 MHz | 320 | 125 ps |
| 25 MHz | one MMCM: VCO 1425 MHz, O 57 / 57.125 | 24.9453 MHz | 456 | 88 ps |
| 125 MHz | one MMCM: VCO 1375 MHz, O 11 / 11.125 | 123.596 MHz | 88 | 91 ps |
| 125 MHz | a second MMCM fed by the 125 MHz clock: M 63.875, D 8, O 8 (VCO 998 MHz) | 124.756 MHz | 511 | 15.7 ps |
With one MMCM the step is always 1 / (8 x VCO): the helper's divider differs by an eighth. A second MMCM gives finer steps, but adds its own jitter (tens of ps) -- the measurement is then averaged over many beats. WR's own boards use a separate quartz oscillator for the helper and N = 16384 (half a picosecond at 125 MHz).
Because the local clock and the helper come from the same VCO, their ratio is exact by construction; WR's separate "helper loop" (which keeps an external helper oscillator at the right ratio) is not needed here.
Measuring D is half the job; WR then steers the local clock until D is where it should be (the setpoint) and keeps it there. A PI controller (proportional-integral) does that: it takes the error (the measured phase minus the setpoint), and outputs a correction made of two parts -- one proportional to the error now (P), one to the error summed over time (I, which learns the frequency difference and removes it). The correction drives a trim: a way to nudge a clock.
Two trims are available on this board:
The design's loop, simulated against a model of an oscillator 50 ppm off and 300 steps out of phase, settles in about 4 ms and then stays within one step (125 ps) of its setpoint.
| built in simulation | built into an image | measured on the board | |
|---|---|---|---|
| DDMTD, PI loop, trims, mode, link model, WR state machine, fine stamps | yes | WR=1 (the loop; not the protocol) | not yet |
| Si5338 trim over I2C | the register writer | no | no |
| WR over Eth0 (1000 Mbit) | -- | no | no |
| the sync demo below | -- | no | no |
Why it exists. A WR link always has two WR nodes: two boards, or a board and a WR switch or reference node, with a cable between them. The sync demo is for when you do not have a second board: it puts both nodes on one PE1 -- the master and the slave on two independent oscillators -- and joins them with a short loopback cable from the PE1's Eth0 socket to its Eth1 socket. With two boards, the same blocks run one node per board over a normal cable.
The setup. Node A, the WR master, runs on the Si5338B's own 24 MHz oscillator and sends on Eth0. Node B, the WR slave, runs on the KX2's 100 MHz crystal through an MMCM and receives on Eth1. These two oscillators have never met: each drifts on its own (tens of ppm apart, wandering with temperature). If B's clock ends up following A's -- same frequency, a steady phase -- that can only be because the WR blocks made it so, through the cable.
What "locked" means. B's loop has brought the frequency difference to zero on average (its trim word settles to the two crystals' difference and stays there) and holds the phase of A's clock, as B receives it, within one DDMTD step. Then the WR protocol measures the round trip and B's time base steers to A's time: the offset B - A.
Running it (planned).
WR=2; not yet written: the board needs the transmit clocks
of both ports taken from the design first).What the numbers should look like (expectations, not measurements): B's trim settles within milliseconds to a constant of a few tens of ppm (the two crystals' difference); B's phase stays within one step (125 ps); the offset B - A becomes a constant with a spread of a few hundred picoseconds; its absolute value includes the two network chips' own delays, which are not calibrated -- a few nanoseconds, possibly jumping by 8 ns between replugs (the 100 Mbit line's symbol time). At 100 Mbit (Eth1 can do no more) the received clock is 25 MHz; if both ends were gigabit, the 125 MHz clock and the second MMCM would give 15.7 ps steps.
Observing without an oscilloscope: everything above is counters inside the FPGA, read over the debug path. Optionally each node can put out one pulse a second (1PPS) on a pin of the PE1's J1401 header, so that a scope can later show the two pulses side by side.
clock a steady up-and-down signal; frequency how often a second; period one up-and-down; phase where in its period a clock is, against another; jitter the random wobble of an edge; flip-flop the 1-bit memory that samples a signal at a clock edge; helper the slightly slower sampling clock; beat the slow square wave the samples form; N the helper's ratio, f x N / (N + 1), and the number of steps in a period; DDMTD the digital dual-mixer time-difference phase detector; deglitcher the filter that takes one clean edge from a flicker; PLL / MMCM a circuit that makes clocks locked to an input; VCO the oscillator inside it; PI a controller: proportional + integral; trim a way to nudge a clock's frequency or phase; ppm / ppb parts per million / billion; syntonization equal frequency; synchronization equal time; holdover keeping the last good correction when the reference is lost; 1PPS one pulse per second.