Optical Quadrature Encoder

2D twin of the 3D encoder servo: the 3D page closes a PID loop around the encoder; here the encoder itself is the subject.

Presets

Playback

Disk, speed and electronics

Four edges per slot give a four times finer step than the slot count. The decoder must sample faster than the edges arrive, and the disk run-out limits the accuracy no matter how many slots it has.

Model checks

The science

What is modelled

A rotating disk with N slots modulates two photodiode signals that are a quarter slot pitch apart, so channel A follows sin(N theta) and B follows cos(N theta). A comparator with hysteresis turns them into digital A and B, and a transition table counts up or down at each of the four edges per slot. Speed is estimated either by counting edges in a gate or by timing the interval between edges.

Equations

  • Light signals A = 0.5 + 0.45 sin(N (theta + e sin(2 theta + 0.37))), B with cos; e = run-out / 112 mm.
  • Counts per turn 4 N; step 360 / (4 N) degrees.
  • Sampling must be well above the edge rate 4 N n / 60.
  • Count method error d_theta / T_gate; period method error w / (x - 1) - w, x = d_theta f_clk / w.
  • Crossover speed d_theta sqrt(f_clk / T_gate).

Checks run in the page

  • Four counts per slot, in both directions.
  • Position error bounded by run-out plus one count.
  • Swapped channels reverse the count; a blocked arc loses it.
  • Both speed estimators against their quantisation bounds.

Honest simplifications

A single-turn kinematic model at constant speed: no motor, no load and no control loop (the 3D page has those), no index pulse, a perfectly round disk apart from the eccentricity term, white Gaussian photodiode noise, an ideal comparator and decoder clock, and a fixed 112 mm pitch radius. A teaching model, not an encoder datasheet.

What to try
  • Press Fast shaft, slow sampling and watch invalid transitions appear; then press Fast shaft, fast sampling.
  • Press Channels swapped to see the count run backwards.
  • Raise the run-out and see the position error bound grow while the step stays the same.
Counted minus true angle over one turn
Needed sampling rate against shaft speed
Angular step against slots per turn
Speed error of the two estimators
Made with 🤖 ChatGPT