Page 2 · Why codes exist
Foundations
The three physical problems every line code solves: AC coupling, clock recovery and alignment. Each one gives a number a code has to meet.
1. DC balance and baseline wander
Most links pass through a series capacitor or a transformer. Both block DC: a capacitor because its impedance 1/(2πfC) is infinite at f = 0, a transformer because a constant current produces no changing flux. Together with the termination they form a high-pass filter with time constant τ.
The measure is running digital sum (RDS): add +1 for each one and −1 for each zero. A DC-balanced code keeps RDS inside fixed bounds forever. 8b/10b bounds it to a few bits; Manchester returns to zero every bit; a scrambler only makes large excursions unlikely.
2. Run length and clock recovery
A serial receiver has no clock wire. Its clock-and-data-recovery (CDR) loop learns the phase from data edges.
Between edges the CDR coasts at its own frequency, which differs from the transmitter's by the two reference oscillators' error. During a run with no transitions, the sampling point drifts.
Run length also matters for the CDR loop's stability: the phase detector's gain depends on transition density. A code with a guaranteed minimum density gives a predictable loop bandwidth and jitter tolerance.
3. Scrambling
A scrambler XORs the data with a pseudo-random sequence from a linear feedback shift register (LFSR). The output looks random: half ones on average, runs that are exponentially unlikely to be long (probability ~2⁻ᴺ for a run of N), and a flat, noise-like spectrum. It adds no overhead, but it guarantees nothing; it only makes bad patterns improbable.
| Type | How it works | Pros | Cons | Used in |
|---|---|---|---|---|
| Additive (frame-synchronous) | XOR with an LFSR that runs independently and is reset at known points | No error multiplication | Both ends must reset the LFSR together (needs framing) | PCIe 1–5, SATA, DisplayPort, USB 3 |
| Multiplicative (self-synchronous) | Output feeds back into the LFSR; descrambler uses received bits | Locks by itself after one register length | One line error causes (1 + number of taps) output errors | 64b/66b (10GBASE-R), SONET payload, some modems |
Scrambling has a second benefit: it spreads repetitive data (an all-black screen, an idle link) across the spectrum instead of putting it into spectral lines, which lowers peak EMI. That is why PCIe Gen 1 and 2 scrambled even under 8b/10b, and why HDMI 2.0 added scrambling.
4. Bit stuffing, the cheap alternative
CAN and USB 2.0 (with NRZI) insert a complementary bit after a fixed number of identical bits: after 5 in CAN, after six 1s in USB 2.0. The receiver removes it. Overhead depends on the data (worst case ~20% in CAN), which makes frame length variable. It bounds run length but does not balance DC; CAN and USB 2.0 are DC-coupled.
Putting it together
| Method | DC balance | Run length | Alignment | Overhead |
|---|---|---|---|---|
| Manchester | perfect (every bit) | ≤ 2 half-bits | needs a preamble | 100% (2× bandwidth) |
| 4b/5b + NRZI | no | ≤ 3 zeros | J/K symbols | 25% |
| 8b/10b | bounded RDS | ≤ 5 | K28.5 comma | 25% |
| 64b/66b + scrambler | statistical | ≤ 66 (header edge), usually short | sync header | 3.1% |
| 128b/130b + scrambler | statistical | bounded by headers, usually short | sync header + ordered sets | 1.6% |
| Bit stuffing | no | ≤ 5 or 6 | start of frame | data-dependent |
| Plain scrambling | statistical | unbounded, rare | needs framing | 0% |