
This is a complete all-digital phase-locked loop (ADPLL) used as a frequency synthesizer: it produces FOUT = N x REF and keeps FOUT phase-locked to the reference. The loop gains are set with DIP switches, so the same chip can show a well-damped lock, a loop that overshoots and rings, and how the loop reacts to a change in DCO gain. It is meant as a hands-on demonstrator of PLL sizing, stability and peaking.
+-------------------+ e +----------------+ FCW +-----------------+
REF ------>| phase detector |----------->| PI loop filter |-------->| NCO ("DCO") |----> FOUT
(1 kHz) | R += N per REF | | kp, ki on DIPs | | acc += FCW @clk |
| e = R - NCO phase | +----------------+ +-----------------+
+-------------------+ |
^ NCO phase (cycles + fraction) |
+----------------------------------------------------------+

Reference. By default the reference is the system clock divided by 8192. With the recommended
8.192 MHz clock that is exactly 1 kHz, so FOUT is simply N kHz. An external reference can be used instead
(REF_SEL = 1, signal on REF_EXT).
Oscillator (the "DCO"). A ring oscillator is hard to build reliably from standard cells inside one tile
and would be impossible to verify in simulation, so the controlled oscillator is a numerically controlled
oscillator: a 24-bit phase accumulator that adds the frequency control word (FCW) every clock. FOUT is the
accumulator MSB. Its gain is exactly known (one FCW LSB = 2^-11 cycles per reference period), which is what
makes the loop gains below exact. FOUT edges are quantized to the system clock, so FOUT carries up to one
clock period (122 ns) of deterministic jitter: a nice talking point about DDS/NCO spurs. The DCO gain can be
doubled with KDCO_X2, which models a VCO/DCO whose gain has drifted.
Phase detector. Instead of dividing FOUT and comparing edges, it works in the phase domain (as in
commercial ADPLLs): on every reference edge the expected phase advances by N cycles, the NCO counts completed
cycles, and the difference plus the NCO fractional phase gives a linear phase error with 1/256 cycle
resolution and a range of +-128 cycles. When the error is larger it saturates (SLIP lights), which makes
the detector behave like a phase-frequency detector, so the loop always acquires, even from FCW = 0 at reset.
Loop filter. A proportional-integral filter, updated once per reference period: FCW = integral + kp·e, integral += ki·e (with anti-windup clamping). This makes a type-II, second-order loop. With the DCO gain folded in, the per-update gains are:
| switch | 00 | 01 | 10 | 11 |
|---|---|---|---|---|
| KP_SEL → kp | 1/2 | 1/4 | 1/8 | 1/16 |
| KI_SEL → ki | 1/16 | 1/64 | 1/256 | 1/1024 |
Continuous-time approximation: natural frequency ωn ≈ √ki rad per reference period (40, 20, 10, 5 Hz at a 1 kHz reference) and damping ζ ≈ kp / (2·√ki). Measured in RTL simulation, overshoot of FOUT's frequency after a step from N = 4 to N = 8:
| overshoot | KI 00 | KI 01 | KI 10 | KI 11 |
|---|---|---|---|---|
| KP 00 | 15 % | 5 % | 1 % | 0 % |
| KP 01 | 32 % | 14 % | 5 % | 1 % |
| KP 10 | 54 % | 31 % | 14 % | 5 % |
| KP 11 | 72 % | 52 % | 30 % | 14 % |
All switches off (KP 00, KI 00) is ζ ≈ 1, the fast default. Moving down the table lowers the damping (more overshoot, ringing, and closed-loop peaking); moving right makes the loop slower and better damped. The diagonal has equal ζ, so the same overshoot at different bandwidths. Every setting is stable; the type-II zero is why even ζ = 1 overshoots by ~15 %.
Lock detector. LOCK goes high after 15 consecutive reference periods with |phase error| < 1/4 cycle,
and drops on the first larger error. FB is FOUT divided by N, aligned to REF while locked, for the classic
"REF and FB on top of each other" scope picture.
Debug DACs. DAC_F and DAC_E are first-order sigma-delta outputs. Through a simple RC filter they give
analog voltages of the frequency word (8 codes per step of N, so N = 16 is mid-scale; 4 codes per step with
KDCO_X2, because the tuning word halves) and of the phase error
(mid-scale = zero error, 32 codes per cycle, clipped at +-4 cycles). This lets a plain oscilloscope show the
loop's step response directly.
REF_SEL,
KICK and KDCO_X2 (uio[1..3]) low. Reset.LOCK
goes high and FOUT is N kHz. Check FOUT with a scope or frequency counter.KICK (uio[2]) to jump the oscillator phase by half a cycle and watch the phase-step response on
DAC_E. Set KDCO_X2 to double the DCO gain and repeat: the loop gets faster and better damped
(ωn and ζ both scale with √2), which is why PLL designs must be sized for the whole DCO/VCO gain range.
KICK takes effect at the next reference update, so even a short pulse works.REF_SEL = 1 and feed a 3.3 V square wave on REF_EXT. The loop gains above
assume a reference period of 8192 clocks, and both kp and ki scale with the actual period. A faster
reference makes the loop slower (lower ωn) and less damped (ζ scales with the square root); a much slower
reference raises the gains and can make the loop unstable, so stay within about 0.5x to 2x of clock/8192
or compensate with the gain switches. FOUT is limited to clock/8 (1 MHz at 8.192 MHz).The 7-segment display on the demo board is driven by uo[7:0], so with nothing else attached: segment D steady on = locked, segment E = slipping, segments A/B/C glow from FOUT/FB/REF.
Minimum: an oscilloscope (two channels is enough) or a frequency counter.
Recommended extras (all on 3.3 V, a breadboard is fine):

| # | Input | Output | Bidirectional |
|---|---|---|---|
| 0 | N bit 0 (multiplier, 0 = 16) | FOUT (synthesized clock, N x REF) | REF_EXT (in, external reference) |
| 1 | N bit 1 | FB (FOUT divided by N) | REF_SEL (in, 0 internal / 1 external, tie low if unused) |
| 2 | N bit 2 | REF (reference in use) | KICK (in, rising edge = half-cycle phase jump) |
| 3 | N bit 3 | LOCK | KDCO_X2 (in, doubles the DCO gain, tie low if unused) |
| 4 | KP_SEL bit 0 (proportional gain 1/2,1/4,1/8,1/16) | SLIP (phase detector saturated) | FOUT_N (out, inverted FOUT for a piezo) |
| 5 | KP_SEL bit 1 | UP (phase error positive, NCO speeding up) | TICK (out, loop update strobe, scope trigger) |
| 6 | KI_SEL bit 0 (integral gain 1/16,1/64,1/256,1/1024) | DAC_F (sigma-delta of frequency word, RC filter) | |
| 7 | KI_SEL bit 1 | DAC_E (sigma-delta of phase error, RC filter) |