Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Battery level with proportional filter and lookup table #3216

Merged
merged 12 commits into from
Feb 16, 2024
Merged

Battery level with proportional filter and lookup table #3216

merged 12 commits into from
Feb 16, 2024

Conversation

Gabrielerusso
Copy link
Contributor

Add a more precise battery level estimation based on a Open Circuit Voltage table.

A P controller acts as a low pass filter to smooth out the voltage readings and on that is applied a OCV table to estimate more precisely different kind of cells chemistry.

Now supported:

  1. LiFePO4
  2. Lead Acid
  3. LiIon/LiPo
    With a variable number of cells.

A valid voltage reading counter was added to avoid doing an ADC average on incorrect values.

Heltec V2.1 voltage multiplier was corrected.

@Gabrielerusso
Copy link
Contributor Author

Gabrielerusso commented Feb 12, 2024

Those are the curve used, may look weird as they are on different scales and the end value is limited (like liion could arrive to 2.5V sually)

Single cell

image

12V (3s LiIon/ 4s LifePO4/ 6s PB)

image

I pubblished those for visual reference and could be usefull in documentation.

now uses a lookup table to better calculate battery level of different cells
removed delay from adc reading, added a software filter to smooth out voltage readings. In those applications battery would last hours to days, no sudden change should be expected so a less frequent voltage reading or a more aggressive filtering could be done.
Note: to speed up convergence i initiliazied the last value to the minimum voltage, there are other and better ways to init the filter.

Added LiFePO4 and PB  open circuit volta battery tables,
line 230/386 For heltec v3 and heltec tracker a different approach was used with the ADC_CTRL pin, now is more uniform using the same code for the 3 boards.

line 236 Check if the raw reading we are getting is Valid or not, count only the valid readings. This could lead to a division by 0 (improbable) so that's why at line 258 there is a check for that.
updated value to not OCV but to very low current, almost the same anyway
thebentern added a commit to meshtastic/artifacts that referenced this pull request Feb 12, 2024
Copy link
Contributor

@code8buster code8buster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Voltage ranges look good. Could you modify any other variant.h files that might be using the existing BAT_FULLVOLT or other similar macros? I think variants/station-g1 might be using it

Run trunk fmt as well, to make the CI checks happy.

thebentern added a commit to meshtastic/artifacts that referenced this pull request Feb 14, 2024
@Gabrielerusso
Copy link
Contributor Author

Voltage ranges look good. Could you modify any other variant.h files that might be using the existing BAT_FULLVOLT or other similar macros? I think variants/station-g1 might be using it

Ok, added also Nimh/Alkaline cells that were used by another variant

Run trunk fmt as well, to make the CI checks happy.

Done but some checks still don't pass, if i run trunk fmt won't it reformat every file?

@code8buster
Copy link
Contributor

Nicely done, I'll take a look at the trunk stuff tonight to see if I can't roundhouse kick it into working.

@code8buster
Copy link
Contributor

code8buster commented Feb 16, 2024

@thebentern OK should be ready for your discerning eye.

thebentern added a commit to meshtastic/artifacts that referenced this pull request Feb 16, 2024
thebentern added a commit to meshtastic/artifacts that referenced this pull request Feb 16, 2024
@thebentern thebentern merged commit 7c9d1b0 into meshtastic:master Feb 16, 2024
62 checks passed
@wnagele wnagele mentioned this pull request Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants