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

[AE-74] Revamp Battery API for Nicla Sense ME #680

Merged
merged 48 commits into from
May 12, 2023

Conversation

sebromero
Copy link
Collaborator

@sebromero sebromero commented May 4, 2023

Change log

🐛 Fixed Bugs

  • Fixed the incorrect calculation of the battery voltage percentage.
  • Fixed incorrect voltage reading by adding a tiny delay to give the chip time to wake up from High Impedance mode.
  • Fixed a slightly incorrect interpretation of the NTC values (introduced a new state 'Extreme' which indicates the charging has been suspended).
  • Fixed edge case in the charging current setting that could cause an external value to be used instead of a programmatic one.
  • Fixed incorrect TS and interrupt disable in enableCharging function
  • Fixed an issue that would prevent the battery charge percentage from being updated continuously.
  • Fixed a bug that would constrain the charge current setting due to the 8 bit data type.

🚀 Enhancements

  • Added documentation to all functions related to power management.
  • Added error handling to catch error cases
  • Introduced Enums for battery charge level, temperature and operating status.
  • Avoided high impedance mode when connected through VIN to to correctly report charging status
  • Improved accuracy of battery voltage reading (disable charging while reading)

🆕 New Features

  • Implemented a WebBLE based battery monitor + sketch for easy testing without external power supply
  • Remove battery status function and replace with temp and charge level.
  • Added function for toggling battery NTC.
  • Added API for operating system status (e.g. charging).
  • Added API to set regulated battery voltage.
  • Added function to determine power source
  • Added function to disable charging state
  • Added function to configure the charging safety timer (30 min, 3h, 9h, disabled).
  • Added sketch to demonstrate how to charge the battery and simply display the charging state.

Screenshot 2023-05-04 at 13 25 31

@manchoz
Copy link
Contributor

manchoz commented May 4, 2023

LATM – Looks Awesome To Me

@aliphys
Copy link
Contributor

aliphys commented May 4, 2023

LATM!

😃 Nicla - PC WebBLE communication works as described.
😃 Connection is stable, even after several hours
😃 Battery graphic is cute / informative

😔 Reported battery voltage differs between WebBLE interface (3.86V) and scope


  • Webpage running locally on Chrome in Ubuntu 22.04. Voltage reported as 3.86V
    • image
  • Voltage between VBAT pin and USB ground is 3.32V
    • img_20230504_180717_720
    • NIC-BAT

This difference could be due to internal resistance of the ground plane.

@sebromero sebromero requested a review from aliphys May 9, 2023 11:27
@sebromero
Copy link
Collaborator Author

@aliphys Found another bug and fixed it. Basically the battery reading was not done correctly so it would only ever use what is measured when you plug it in.

@sebromero sebromero force-pushed the sebromero/pmic-fix branch 3 times, most recently from 4de1f9d to 34b9666 Compare May 10, 2023 14:06
@sebromero
Copy link
Collaborator Author

sebromero commented May 10, 2023

@facchinm
Some observations:

  • 📖 A write operation was gonna be used to kick the watchdog previously, however the way it was implemented didn't seem to trigger a write operation. Conclusion: A read operation seems to be enough to reset the watchdog timer.
  • ⚡ Battery seems to charge even when NTC settings are enabled but the battery doesn't have one. Conclusion: Accidentally enabling NTC on a non-NTC battery doesn't prevent it from being charged.
  • 🔋 If the battery doesn't have an NTC, the speed is automatically reduced to 16mA no matter the setting. This one may need some more investigation. See nicla-system: Enhance documentation for charging speed limits. #685
  • 🐶 The Watchdog mechanism seems to be redundant now after reworking the library:
    • The watchdog is disabled in High-Z mode. Now, by default the PMIC doesn't ever leave High-Z mode when powered through VIN (CD only used to toggle the charging). When powered with a battery it only leaves it very shortly to read some bytes from the PMIC within the 50s timeout of the watchdog. The new disableCharging() function was implemented by modifying a register, not by using CD. Conclusion: We could probably delete all code related to the watchdog timer.

That aside, I think I'm done here. Waiting for @aliphys ' green light 🟢

Copy link
Contributor

@aliphys aliphys left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for the detailed PR and comments: we should try to strive for this level of quality.
Battery voltage updates correctly 👍

Co-authored-by: Ali Jahangiri <75624145+aliphys@users.noreply.github.com>
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