Encoders: incremental, absolute, magnetic
How your robot knows where its joints are. Resolutions, drift, and the gotchas of each type. The sensor that ties firmware to the physical world.
An encoder turns mechanical motion into a digital signal. Without one, your robot has no idea where its joints actually are. Three types dominate hobby and industrial robotics; each has a different sweet spot, different failure modes, and different quirks. Picking the right one for each joint matters as much as picking the right motor.
Type 1: Incremental optical / quadrature
A disk with alternating dark and light slots, two photo-detectors offset 90°. Each transition produces a pulse; the phase between channels A and B tells you direction.
- Resolution: typically 100–10,000 PPR (pulses per revolution). With 4× quadrature decoding (count both edges of both channels), you get 4× that in counts.
- Output: digital pulse trains; needs a microcontroller pin with edge interrupts or hardware quadrature decoder.
- Strengths: cheap (~$5–30), high-resolution, widely supported.
- Weaknesses: relative only — needs a "home" reference at startup; can miss counts at high speeds; fragile (light path can be obscured by dust).
Common in: hobby DC motors with built-in encoders (Pololu metal-gearmotors), Dynamixel-class servos with add-on encoders, retrofitted lab arms.
Type 2: Absolute encoder
The disk has a coded pattern (binary, gray code, or analog) such that any single position is uniquely identified. No homing needed.
- Resolution: 12–22 bits per revolution (4096 to 4M positions).
- Output: SSI, BiSS-C, EnDat, SPI — serial protocols specific to the encoder.
- Strengths: knows position immediately on power-up; no missed counts; multi-turn variants track total rotations.
- Weaknesses: expensive ($50–500); proprietary protocols add complexity.
Common in: industrial servos, joint encoders on serious arms (Franka, UR), aerospace.
Type 3: Magnetic (Hall-effect or magnetoresistive)
A small magnet on the rotor; sensor chip(s) detect rotation. Most modern hobby BLDCs use these.
- Resolution: 12–14 bits typical (4096–16384 positions per revolution).
- Output: SPI (AS5048, AS5047), I²C, or analog. Often integrated into BLDC motor controllers.
- Strengths: cheap (~$3–20), no optics to fail, dust-immune, contactless (no wear).
- Weaknesses: lower resolution than optical; sensitive to magnetic interference.
The 2026 hobby default for BLDC motors is AS5048A or its successors. Used in ODrive, MJBots Moteus, SimpleFOC.
Other types worth knowing
- Resolvers: absolute, military-grade, sine/cosine analog output. Robust to vibration and temperature; common in aerospace and industrial servos.
- Inductive (Inductosyn): like resolvers but linear; precision machine-tool stages.
- Tachometer: velocity-only output (a small DC generator). Used in legacy systems; rare in 2026.
The decision matrix
| Need | Pick |
|---|---|
| Hobby diff-drive wheels | Incremental optical (built into motor) |
| BLDC motor commutation | Magnetic (AS5048) |
| Industrial arm joints | Absolute (BiSS-C) |
| Aerospace, harsh environments | Resolver |
Reading the encoder
Quadrature in firmware
Two GPIO pins, edge interrupts on both. Decoder logic:
volatile int32_t count = 0;
void on_a_change() {
if (digitalRead(PIN_B) == digitalRead(PIN_A)) count++;
else count--;
}
void on_b_change() {
if (digitalRead(PIN_A) != digitalRead(PIN_B)) count++;
else count--;
}
Software decoding works up to ~10 kHz before missed pulses. For higher rates use a hardware quadrature decoder peripheral (STM32 timers, ESP32-S3 PCNT, RP2040 PIO).
SPI absolute encoder
Read a register over SPI; convert to angle.
SPI.transferBytes(query, buf, 2);
uint16_t raw = (buf[0] << 8) | buf[1];
float angle_rad = (raw & 0x3FFF) * 2.0 * M_PI / 16384.0;
Keep the SPI clock fast (10+ MHz) so the read doesn't latency-limit the control loop. AS5048A datasheet has the magic bytes.
The gotchas
- Backlash: between motor encoder and joint output (through a gearbox), there's mechanical backlash. The encoder reports motor angle; joint angle is offset. Either: put the encoder on the joint output, or model + compensate the backlash.
- Magnet placement: magnetic encoders need the magnet within 0.5–1 mm of the chip and aligned to ~1°. Misalignment → wrong readings.
- Aliasing at high speed: at >100 kHz pulse rate, even hardware decoders can miss. Use higher-rate timers or upgrade to absolute.
- Index pulse for homing: incremental encoders often have a Z (index) pulse once per revolution. Use it for homing.
- Multi-turn vs single-turn absolute: a single-turn absolute knows position within 1 revolution; loses count on power cycle if the joint moves more than 360°. Multi-turn tracks total revolutions in non-volatile memory.
What goes wrong in production
- Encoder cable break: noise on the lines. Filter; check for sudden jumps; trigger a fault.
- Slipped magnet: AS5048 magnet glued to a shaft can slip after thermal cycling. Re-mount with stronger adhesive or a press-fit collar.
- EMI from motor: BLDC's switching noise can corrupt encoder signals. Twisted-pair cables, ferrite beads, shielded cables.
- Software counts overflow: 32-bit counter at 1000 RPM × 10000 PPR overflows in days. Use 64-bit, or reset / handle wraparound.
Multi-rate filtering
Raw encoder reads are positions. To get velocity, you take a finite difference. Common implementations:
- Period method: time between consecutive pulses. Accurate at low speed; noisy at high speed.
- Pulse-count method: count pulses per fixed time window. Accurate at high speed; quantized at low speed.
- M/T method: switch between the two based on speed. Standard in production servo drives.
Exercise
Wire a hobby DC motor with quadrature encoder to an ESP32. Implement quadrature decoding via interrupts; print position and velocity at 100 Hz. Spin the motor by hand; watch the count go up and down. Then implement a position PID loop. The first time the motor goes to a commanded angle and stops there is the moment encoder feedback becomes intuitive.
Next
IMUs, magnetometers, and sensor quality — the inertial sensors that complement encoders for body pose estimation.
Comments
Sign in to post a comment.