In this lesson, you will learn how to drastically reduce your microcontroller’s energy footprint by replacing power-intensive floating-point arithmetic with efficient fixed-point integer operations.
The Power Cost of FPU Cycles
In many low-power microcontrollers, the Floating Point Unit (FPU) is a specialized hardware block that consumes significant dynamic power due to its complex gate logic and high switching activity. Even if your MCU has hardware floating-point support, every float or double operation requires more clock cycles and higher instantaneous current than a standard integer operation. When optimizing for battery-operated devices, we can often bypass the FPU entirely by using fixed-point arithmetic.
Representing Fractions with Integers
Fixed-point arithmetic treats an integer as if it has a decimal point at a fixed position. For example, if we want to represent values with three decimal places of precision, we can store the number 1.234 as the integer 1234. We define a scaling factor, typically a power of two to allow for fast bit-shifting instead of expensive division.
Consider calculating a sensor threshold result = input * 0.75. Using floating-point, the CPU must perform a multiplication involving the mantissa and exponent. With fixed-point, we choose a scaling factor of 256 ():
// Floating-point (Slow)
float result = input * 0.75f;
// Fixed-point (Fast)
// Multiply by 192 (0.75 * 256) then shift right by 8
int32_t result = (input * 192) >> 8;
Why This Saves Power
By using integer arithmetic, the CPU utilizes the standard ALU (Arithmetic Logic Unit) rather than powering up the FPU. Because integer operations are simpler, the CPU can finish the task faster—allowing it to return to a low-power sleep state sooner. Furthermore, you avoid the overhead of loading floating-point registers, which reduces memory bus traffic and instruction cache misses. When scaled across thousands of sensor readings in a duty-cycled loop, this optimization significantly extends the time between battery recharges.
Key Takeaway: By mapping fractional values to integers using bit-shifts, you shift the computational burden from the power-hungry FPU to the highly efficient integer ALU, allowing your system to complete tasks faster and spend more time in low-power states.