ABC of Electronics cosycom.com
EMBEDDED SYSTEMS & MICROCONTROLLERS · PAGE 35

Fixed-Point Maths

Decimals without a floating-point unit.

Small chips lack hardware for floats, so float maths is slow and bulky. Fixed-point stores a scaled integer instead: 2.5 volts becomes 2500 millivolts.

Multiply first, divide last, and use a wider type for intermediate results to avoid overflow. Division by a constant power of two can be a fast shift.

Lookup tables replace costly functions like sine.

EXAMPLE
uint16_t raw = 512;                       /* 10-bit ADC */
uint32_t mv  = (uint32_t)raw * 5000 / 1024; /* millivolts: 2500 */