Networks on microcontrollers
Fitting the sensing network on a microcontroller
Stored as 8-bit integers, the study 1 network takes 10.9 KB instead of 35.0 KB, and its accuracy changed by 12.6 %. By our estimate one position takes about 77.9 µs on a 170 MHz microcontroller.
Every result here comes from simulations of our own simplified models, run with fixed random seeds so they repeat exactly. Nothing has been measured on hardware yet. We report what came out, including where our approach did not win.
The question
A position estimate is no use if it cannot run inside the control loop, on the stage's own small processor. How much do memory and accuracy suffer when the network is squeezed into 8-bit integers?
What we did
We took the best network from study 1 (72 → 64 → 64 → 2, 8,962 parameters) and quantised it after training, without retraining, in two ways. The simplest: one scale per layer, one input scale, 256-entry tanh table. The refined version: one scale per neuron, one per input, 1,024-entry tanh table. In both, activations are 8-bit with scales from 1,000 calibration samples, and sums stay in 32-bit integers.
Symbols
- 8-bit integer weights and activations
- weight scale: one per layer (simplest) or one per output neuron (refined)
- input scale: one for all inputs (simplest) or one per input (refined)
- 99.9th percentile over 1,000 calibration samples, so rare outliers don't waste range
- summed exactly in 32-bit integers; tanh by lookup table (256 or 1,024 entries)
In plain words
Every weight and activation becomes a whole number from −127 to 127 times a scale. With one scale per layer, a single large weight sets the step size for all of them, so small weights lose precision. One scale per output neuron and per input keeps each set's full range. The sums stay exact in 32-bit integers, and a finer tanh table removes most of the rounding at each neuron.
What we found
| Error, rms (mm) | 95th percentile (mm) | Memory | |
|---|---|---|---|
| 64-bit float | 0.244 | 0.444 | 35.0 KB as 32-bit |
| 8-bit, simplest | 0.604 | 1.136 | 9.4 KB |
| 8-bit, refined | 0.275 | 0.483 | 10.9 KB |
The simplest version made the error 147.8 % worse: one scale per layer wastes most of the 8 bits on the few largest weights, and a coarse tanh table adds a step error at every neuron. Giving each neuron and each input its own scale, and using a finer table, brought the change to 12.6 % for a few hundred extra bytes.
Each estimate is 8,832 multiply-accumulates. At 170 MHz that is about 77.9 µs; At 480 MHz that is about 27.6 µs. These are estimates (one multiply-accumulate per clock plus 50 % overhead), not measurements. At 5,000 estimates a second, the loop has 200 µs per cycle.
What it means
The network fits comfortably in a microcontroller's memory and, by estimate, inside a fast control loop. Combined with the event-driven approach in study N2, most cycles would need only a small part of that work.
Limits: timing estimated, not measured; post-training quantisation only. Training with quantisation in mind could close any remaining gap.