Skip to content

Conversation

@mark9064
Copy link
Member

@mark9064 mark9064 commented Jan 6, 2026

  • Use SAADC oversampling and higher bit depth to get more precise measurements
    • Currently the sampling resolution means that some percentage values are impossible! [1]
  • Sample battery every minute rather than every 10 minutes
  • The power usage from running the ADC more often should be negligible (calculated to be the equivalent of constantly drawing <400nA)

This removes the battery smoothing that prevents the reported percentage from going up while off charge. I'm personally not a fan of it, as if someone uses high brightness than if the battery is measured while the screen is on the battery charge is underestimated significantly, and this results in the percentage staying at this underestimate for a long time since it's not allowed back up. But maybe this will be confusing to users? I'm not sure what the best choice is here. We could also keep the clamping but have some smoothing applied to the battery value so the occasional measurement while the screen is on doesn't tank it too much?

ceebd5c5-b579-400d-9182-ecd2418c3bf5

Example of how it looks, note there are a few spots of missing data as out of range on bluetooth. AOD is used here.

[1]

Battery measured from 4180mV-3500mV, so 680mV range. ADC ref: 0.6v, ADC gain: 1/4, HW gain: 1/2, so the ADC can measure from 0V to 0.6*4*2=4.8V, 4800mV total. So about 14.2% of the measurement range is used ~(2-3). So with 10bit ADC (current resolution), assuming no measurement noise (unrealistic, expect at least 1bit noise), we have 10 bit - 3 bit = 7 bits of resolution or 128 possible values (just more than the 100 percentage points).

However, the mapping from voltage to percentage is nonlinear. 3776mV-3723mV accounts for 26%, actual range 53mV (2-6.5). 10 bit - 6.5bit = 3.5 bit or 11 values, which is less than the 26 percentage points it is mapped to. So some of the percentages are impossible.

@mark9064 mark9064 added the enhancement Enhancement to an existing app/feature label Jan 6, 2026
@github-actions
Copy link

github-actions bot commented Jan 6, 2026

Build size and comparison to main:

Section Size Difference
text 384912B -320B
data 944B 0B
bss 22640B 0B

Run in InfiniEmu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Enhancement to an existing app/feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant