Max17205 calibration and capacity persistence#121
Conversation
Fixes to cleanup PR: - fix assert bug - enable debug print - enable NV update code - change NV register array to match Wizard output for all registers (not just the ones in the Google doc) - make prompt_nv_memory_write() return true if actually written - fix name of max17205Read() -- no longer max17205ReadRaw() - if nv was actually written, only then print the prompt to re-flash with update disabled and effectively halt Use correct parameter names in max17205.h to match c file. Make integer size conversions explicit.
Make shadow RAM changes affect operation: - Add a chip firmware reset function. - Use this in start, stop, hardware reset, and nv prompt code. - Add NFullSOCThr and nRippleCfg settings per datasheet. Remove trailing whitespace. Remove spaces in comment blocks at EOLs.
Consolidate the PACKCFG settings in one place. Also fix problem with logging of don't vs. do match values.
Clear POR bit in status register each time we reset. Add a small delay in the retry loops looking for POR. Be sure to check sentinel values on register array, not just length. Make matching vs. non-matching registers more clear/readable.
Add learning and capacity functions: - Add functions to read and write the learning state. - Add a function to write capacity. - Improve logging and add learning completion. - Dump learning history. - Dump volatile registers used by learning. The n* registers are not updated generally speaking unless a write to the limited user config NV occurs or unless the specific register is part of life logging, and that has been updated. - Periodically check for full condition and update learning. Improve behavior in low battery conditions: - Add function to check for charge complete and force transition to learning complete. - Add functions to check for critically low battery and wait for charging. - Improve startup to do as little as possible until battery state known. Update code based on full learning cycles: - Set nFullCapNom and nRComp0 to learned values. Improvements: - Print charge and discharge stat lines each update. - Print instantaneous current not just average, max, and min. - Update learning complete before possibly writing NV. - Separate printing volatile registers from printing non-volatile; only print volatile during thread loop. - Separate NV writing from NV RAM writing. - Update and display everything including learn state before possibly writing to flash. Cleanup: - Fix typo in current_battery_state_machine_state variable name. - Make local functions static. - Make update_battery_charging_state able to be re-enabled if necessary. - Remove unnecessary cell balancing stuff. - Move summary display of information after all register reads to improve readability. - Clean up logging for heater control. - Periodically dump registers. - Add check for out-of-writes to NV. - replace magic numbers with macros.
Rewrite duplicate code and data to use an array of packs. Duplicating code over and over for pack1 vs. pack2 opens the door to mistakes by failing to change both copies upon every code change. Also simplify main loop.
Place in common folder so can be used by multiple apps.
Use them for storing battery runtime data.
Need these for handling runtime battery data.
Periodically store runtime data to flash for restoration after daily reset by c3. This ensures the capacity and SoC estimates are more accurate than without them.
Add checking of CRC and validity of most recent entry before selecting it for use. Delay before applying most recent entry after restarting and initializing the MAX17205s. Separate out runtime entry printing. Log more during entry processing. Hide most verbose dumping behind a verbose flag.
a143eb7 to
7d54e6b
Compare
When a full pack is stored in shutdown for long periods, the pack can self-discharge. When started later, if then charged again, the capacity estimate can grow over the design limit. Clamp to the design limit before storing in application flash. This prevents out of range entries and corresponding debug error messages later when reading the history.
|
Sorry this took so long to review, and I'm still digging through it but in the interim can I request that the For a first piece on the code I'm generally not a fan of mutable globals (though I'm willing to be pragmatic, sometimes they need to exist). In |
Yes, I am planning to add something for this. Thanks for the nudge.
I'll take a look.
It's from the original app note from Maxim. The global |
Eliminate global data in max17205.c. Improve history handling in batt.c. Use better variable names, replace a full copy of latest entry with just what is needed (reset cycle count), and be more careful to distinguish last valid entry vs. last empty entry. Choosing not to eliminate these globals since they are shared between a few related functions.
|
@ThirteenFish in re-reviewing the It's not worth eliminating these pointers since a few related functions need them, and I don't want to bother pushing them up the call stack onto a higher level function and then passing them down to those functions as parameters. That just makes it more complicated. I was able to eliminate the |
Add information about the MAX17205, lessons learned, and improvements made.
|
@ThirteenFish I wrote an initial draft of readme improvements. |
Also add compile-time control over heaters. Needed for board v2.1 to not brownout and reset.
Add additional comments explaining meaning of Wizard results and identification of 2 new possible issues: 1. missing "must be 1" bit in AD_NMISCCFG --> fixed 2. potentially wrong AD_NIAVGEMPTY value compared to nVcfg2.enIAvg setting --> no change for now, but will test
ThirteenFish
left a comment
There was a problem hiding this comment.
I tried this out on the 2.1 card on the flatsat and it looked like it all worked. I like the compile time config messages.
|
OK to merge then, @ThirteenFish? |
|
Yep, go for it. Let me know if you don't have permissions and I'll try to fix it. |
Major improvements to battery fuel gauge: