Eigentactics / Research

Steering the sensor

A $2 coprocessor, in the open

For fourteen years, every $2 MPU-6050 breakout board has shipped with a tiny, undocumented microprocessor hidden inside the IMU package: InvenSense’s Digital Motion Processor (DMP). Everyone treated it as an opaque binary blob you copied out of a vendor header, locked to 200 Hz, 42-byte FIFO packets, and auto-calibration heuristics you couldn’t inspect or turn off.

That changed when Jabez Winston reverse-engineered the DMP instruction set and published The DMP Programmer’s Manual along with an assembler. The machine inside is delightfully strange: no general-purpose registers, three sticky memory pointers (P0, P1, P2), 3 KB of unified code-and-data RAM, 32-bit big-endian Q30 fixed-point words backed by a 64-bit multiply-accumulate register R, no divider, no square root, no bit-shifter, and branches that only reach ±32 bytes. It wakes up once per sensor tick, runs from its entry point to end, and sleeps until the next sample.

We soldered headers onto a Waveshare RP2040-Zero, wired an MPU-6050 to GP4 (SDA), GP5 (SCL), and GP6 (INT), flashed a thin USB-serial bridge, and put the newly unlocked silicon through its paces.

Twelve tests on real silicon

Before building anything ambitious, we wanted to verify the corners of the ISA on our own board rather than taking the manual on faith. Twelve programs ran and passed on the first attempt:

Click any row to expand the DMP assembly.

ProgramSizeWhat it verified on the MPU-6050

The biquad notch is the one that makes the chip’s niche obvious. With 64-bit MAC accumulation and zero host intervention, a 66-byte program generated its own interference and scrubbed 96% of the 20 Hz amplitude out of a 5 Hz signal. That’s real motor-vibration filtering inside a $2 IMU.

The 1 kHz race

The practical question isn’t whether the DMP can do tricks, but where the split between the DMP and the host MCU should sit. You could run everything on the DMP and accept a simpler estimator, or ignore the DMP and poll raw registers at 1 kHz on the MCU so you can run a proper Kalman filter or UKF. Or you could do both.

Because the DMP raises INT right before end and then sleeps until the next tick, the host MCU has a guaranteed idle window after every interrupt to poke updated parameters straight into DMP RAM with zero tearing. That lets the DMP run the fast 1 kHz inner loop (filtering, strapdown integration, and 10:1 decimation) while the MCU runs a slow 10 Hz outer loop estimating gyro bias and steering the DMP with 4-byte hints.

Our MPU-6050 sits on the desk with a real zero-rate gyro bias of about +365 LSB on X. We raced three implementations head-to-head for 1.5 seconds on the RP2040-Zero, timing every microsecond of I2C traffic and soft-float Cortex-M0+ math directly on the MCU with time_us_32():

  • DMP-Only (unsteered): a 50-byte program (steerable_fusion.s) running a complementary filter at 1 kHz inside the DMP, decimating 10:1 to emit 12-byte [ax, gx, theta] packets at 100 Hz, with bias_gx left at zero.
  • MCU-Only (1 kHz Kalman): DMP off; the RP2040 wakes on every 1 kHz DATA_RDY interrupt, reads 14 raw sensor bytes over 400 kHz I2C, and runs a 2-state floating-point Kalman filter ([angle, gyro_bias]) on every tick.
  • Hybrid Steered DMP: the exact same 50-byte 1 kHz DMP program waking the RP2040 at 100 Hz; every tenth packet (10 Hz), the RP2040 runs one step of the 2-state Kalman bias estimator and pokes the 4-byte bias_gx hint into DMP RAM at 0x124.
Show steerable_fusion.s (50 bytes @ 0x400)
; Steerable 1 kHz DMP Complementary Filter with 10:1 Decimation (100 Hz output)
; Runs inside MPU-6050 at 1 kHz:
;   gx_corr = gx - bias_gx              (bias_gx @ 0x124 is poked live by MCU!)
;   pred    = theta + k_g * gx_corr
;   theta   = 0.996 * pred + 0.004 * ax
; Every 10th tick (100 Hz), emits [ax, gx, theta] (12 bytes) to FIFO and raises INT.
;
; Memory map (Bank 1):
;   0x100 (p0): {mask=0xFFFF0000, alpha=0.996q, beta=0.004q, k_g=0.015625q}
;   0x110 (p1): {ax, gx, gx_corr, pred}
;   0x120 (p2): {theta, bias_gx (STEERABLE!), decim_reload=9, decim_cnt=9}
; @entry 0x400
; @data 0x100: ffff0000 3fbe76c9 00418937 01000000
; @data 0x120: 00000000 00000000 00000009 00000009

        .lineage 6050
        always
        store
        ; 1. Isolate live AccelX (0x000 hi16) and GyroX (0x008 hi16)
        p0bank  0
        p0page  0               ; P0 -> sample page
        p1bank  1
        p1page  0               ; P1 -> {mask, alpha, beta, k_g}
        p2bank  1
        p2page  1               ; P2 -> 0x110 ({ax, gx, gx_corr, pred})
        and     0,0             ; M[0x110] (ax) := AccelX << 16
        and     2,0,inc         ; M[0x114] (gx) := GyroX  << 16

        ; 2. Subtract MCU-steered gyro bias: gx_corr := gx - bias_gx
        fmode   1
        p0bank  1
        p0page  2               ; P0 -> 0x120 ({theta, bias_gx, decim_reload, decim_cnt})
        p1page  1               ; P1 -> 0x110 ({ax, gx, gx_corr, pred})
        rsub    1,1,inc         ; M[0x118] (gx_corr) := gx - bias_gx

        ; 3. pred := theta + k_g * gx_corr
        p0page  1               ; P0 -> {ax, gx, gx_corr, pred}
        p1page  0               ; P1 -> {mask, alpha, beta, k_g}
        mul     2,3,inc         ; M[0x11C] (pred) := gx_corr * k_g
        p1page  2               ; P1 -> {theta, bias_gx, ...}
        add     3,0             ; M[0x11C] (pred) := pred + theta

        ; 4. theta := alpha * pred + beta * ax  (64-bit MAC -> M[0x120])
        p1page  0               ; P1 -> {mask, alpha, beta, k_g}
        p2page  2               ; P2 -> 0x120 (theta), clears R
        mac
        add     3,1             ; R := alpha * pred
        add     0,2             ; R += beta * ax -> M[0x120] (theta)

        ; 5. 10:1 Decimation counter (emit + INT only every 10th tick = 100 Hz)
        fmode   1
        p2page  2
        p2inc2                  ; P2 -> word 2 (decim_reload)
        dec.next                ; P2 -> word 3 (decim_cnt); decim_cnt -= 1; F := (< 0)
        if      nf
        branch  done
        always
        fmode   1
        p0page  2               ; P0 -> {theta, bias_gx, decim_reload, decim_cnt}
        p2page  2
        p2inc2
        mov     2,inc           ; M[0x12C] (decim_cnt) := decim_reload (9)
        fifo
        p0page  1
        mov     0               ; emit ax
        mov     1               ; emit gx
        p0page  2
        mov     0               ; emit theta
        int
done:   always
        fmode   1
        disable
ContenderWakeupsI2C loadRP2040 active (I2C + math)Steady-state error
DMP-Only (unsteered)99 Hz1,192 B/s3.79% (56.8 ms + 0.0 ms)1,423.1 LSB (4.98°)
MCU-Only (1 kHz Kalman)999 Hz13,981 B/s44.99% (645.0 ms + 29.8 ms)3.4 LSB (0.01°)
Hybrid Steered DMP99 Hz1,229 B/s4.10% (61.2 ms + 0.33 ms)3.9 LSB (0.01°)
True Accel X DMP-Only (unsteered) MCU-Only 1 kHz Kalman Hybrid Steered DMP
-1200 -800 -400 0 +400 0 ms 500 ms 1000 ms 1500 ms
1.5 seconds on real RP2040-Zero + MPU-6050 silicon, starting from zero. Unsteered DMP-Only climbs the wrong way on the real +365 LSB gyro bias. Hybrid Steered DMP tracks it for the first 80 ms, receives its first 4-byte bias hint at 100 ms, and locks onto true gravity at 0.01° error — using 11× less MCU active time than 1 kHz MCU-Only Kalman.

Why the hybrid hits the sweet spot

The surprise in the table isn’t the CPU math — it’s the I2C bus. On a 400 kHz bus, reading 14 raw bytes a thousand times a second kept the RP2040 busy for 645 ms out of 1,500 ms (43% of wall-clock time spent waiting on I2C alone, plus another 30 ms of soft-float Kalman math on Cortex-M0+). Letting the DMP decimate 10:1 inside the IMU cut I2C traffic by 11.4× and total MCU active time by 11.0× (4.10% vs. 44.99%), while cutting MCU math time by 91× (327 µs vs. 29,798 µs).

Meanwhile, poking just fourteen 4-byte bias hints over 1.5 seconds brought the DMP’s steady-state error down from 4.98° to 0.01° — a 368.7× reduction, matching the 1 kHz MCU Kalman filter to within half an LSB (0.002°). And the same mechanism generalises to dynamic RPM-tracking notch filters (poking five new biquad coefficients as motor speed shifts) or slow magnetometer yaw nudges.

It also changes what counts as a capable host. The MPU-6050’s DMP has more RAM (3 KB) and a wider multiplier (32×32→64) than an Arduino Uno, an ATtiny85, a 10-cent CH32V003, or the 8-bit 8051s hiding inside microwaves and washing machines. Anything that can bit-bang two I2C pins at boot can now offload 1 kHz fixed-point DSP to its own sensor.

What it can and cannot do

  • Orientation, not room position. A 6-axis IMU gives clean 3D tilt, rotation, and gesture detection, but double-integrating acceleration for absolute XYZ position still drifts within seconds regardless of where the math runs.
  • Tight 1 kHz budget. Our loop sweep overran a 1 ms tick right around 200 iterations, and total code + data RAM is 3 KB. Keep 1 kHz DMP programs lean and straight-line; keep full UKFs, matrix inversions, and atan2 on the host.
  • No register I/O on the MPU-6050. The MPU-6050’s auxiliary I2C master (XDA/XCL) can poll external slaves into EXT_SENS_DATA, but the MPU-6050 DMP cannot read or write chip registers directly. For autonomous DMP-driven subsidiary I2C, you want an ICM-20948 (DMP3), where fmode 4 maps the host register file.
  • Volatile RAM. DMP memory survives soft resets (PWR_MGMT_1 = 0x80) but clears on power loss, so the host uploads the program at boot (under 2 ms at 400 kHz).

If you’re an agent reading this

  • Always read back DMP RAM after loading. A silent I2C NACK or 256-byte bank-boundary wrap looks identical to a program that does nothing.
  • Respect the MPU-6050’s two sharp edges. Every branch leaves the core in mode 4 (put always and fmode N at every target and fall-through), and every instruction that moves P2 clears the 64-bit accumulator R to zero.
  • Time the bus, not just the FLOPs. At 1 kHz over 400 kHz I2C, bus wait time dwarfed soft-float Kalman math by 21× on an RP2040. Decimating on the sensor is where the real power and duty-cycle win lives.
  • Poke parameters right after INT. The DMP sleeps between end and the next tick, giving you a clean, tear-free window to steer bias or filter coefficients from the host.

Write to llms@eigentactics.com if you disagree.