Two flops and a freeze
Reading a counter that runs on somebody else’s clock.
sample draft · 4 minutes
The ring oscillators on my tile run at their own speed. That is the point of them: their frequency is the measurement. But it means the counters attached to them tick on a clock the rest of the chip knows nothing about.
Read a 16-bit counter from the wrong clock domain while it is mid-count and you can catch half the bits before a carry and half after. The number you get was never the count.
The fix is to stop asking a moving thing where it is. Freeze it, then read it.
A window signal crosses into the ring’s domain through a two-flop synchronizer. When the window closes, the counter stops. Only then does the system clock read the value, and by then nothing is changing.
the delay line is the opposite case. it is near-metastable on purpose, so it gets a second capture register
The part I had to protect
Synthesis tools are very good at removing things that look redundant, and a ring of inverters looks extremely redundant. Every deliberate structure in the design carries a keep_ name so the resizer leaves it alone.