perf(power): scale CPU to 80MHz when radios idle (AI FYI, -25% idle) - #118
Open
johnbuckman wants to merge 1 commit into
Open
perf(power): scale CPU to 80MHz when radios idle (AI FYI, -25% idle)#118johnbuckman wants to merge 1 commit into
johnbuckman wants to merge 1 commit into
Conversation
Idle-ON draw is dominated by the CPU running at a pinned 240MHz. Drop to 80MHz at end of setup() when WiFi is not on at boot, and restore 240MHz on any WiFi bring-up (setupAP / connectToWifi); return to 80MHz in stopWifi(). 80MHz is the safe floor: APB stays 80MHz so serial and the BLE radio keep working. Measured -28mA / -25% idle on a V8.1 unit (see PR for method). AI-written change, posted as an FYI for review; not necessarily to merge. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Author
This was referenced Aug 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
The scale's CPU is pinned at 240 MHz all the time — there is no
setCpuFrequencyMhz()call anywhere in the tree. But most of the time the scale is idle and BLE-only (WiFi off by default), just polling a load cell. This drops the core to 80 MHz when radios are idle and restores 240 MHz whenever WiFi comes up:setup(): if!b_wifiOnBoot,setCpuFrequencyMhz(80)after init.connectToWifi()/setupAP():setCpuFrequencyMhz(240)before bringing WiFi up.stopWifi(): back tosetCpuFrequencyMhz(80).80 MHz is the safe floor: APB stays at 80 MHz, so the UART console and the BLE radio keep working; it is the documented minimum with Bluetooth active. Total change: 8 lines.
How it was found
Reading the ON/idle path (
power.h, theloop()inhds.ino,docs/AI_GPIO_NOTES.md): the deep-sleep OFF path is already well engineered (both rails gated, GPIO holds, EXT1 wake), but the idle-ON path runs wide open — CPU at 240 MHz, a ~200 Hz busy-poll loop, no light sleep, OLED + load cell up for the full 15-minute auto-off. The CPU clock stood out as the one large, zero-risk lever.How it was measured
Bench: a ChargerLAB POWER-Z KM003C USB-C power analyzer inline on the scale's USB (VBUS current at ~5.8 kHz, ~0.1 mA resolution), read over its vendor bulk interface. All measurements at 5.19 V, battery full (4.23 V) so charge current had terminated — otherwise it swamps the operating draw (V8.1 has no firmware charge-disable, so "charge to full first" is the only clean option).
Two findings worth noting: (1) the peripherals (ADS1232 + ADS1115 + a sparse OLED) draw only ~3 mA — the CPU dominates idle-ON; (2) the 15-min auto-off and any idle auto-timers are gated
if(!b_is_charging), and on V8.1b_is_chargingmeans "USB connected" — so those timers only run on battery and can't be metered over USB. This change is not so gated: it applies whenever radios are idle, on USB or battery.How it was tested
USB-serial functional regression (BLE/WiFi host tooling is unavailable non-interactively on the test Mac), run identically on baseline and on this build:
v→ battery voltageBoot log on this build confirms it is active:
[power] CPU 80 MHz (BLE-only idle).Known gap / what has NOT been verified
[power]serial line is left in for verification; drop it if merging.Update / scope clarification: this change keys the CPU frequency on WiFi only — a BLE-connected scale with WiFi off still runs at 80 MHz here. That's fine for normal weight streaming (it's light work), but the upcoming on-scale extension mechanism wants full speed during active use. That "pin 240 MHz when connected + live" behavior is implemented on the DFS/light-sleep path in #121 (via a PM lock), not here. This PR remains the simple, precompiled-build (no from-source rebuild) option; #121 is the fuller DFS-based alternative.