mirror of
https://github.com/liquidraver/ZephCore.git
synced 2026-10-23 12:12:46 +00:00
battery: centralized LiPo OCV curve + ADC multiplier corrections
Add a board-aware battery SOC system replacing the two independent
linear approximations that existed in the UI helpers.
New helpers/battery_curve.{h,c}: a 21-point (5% step) OCV lookup table
with integer linear interpolation. The default generic LiPo curve is a
weak symbol — any board can override it by dropping a battery_curve.c
into its board directory. CMakeLists.txt selects the board-specific file
when present, falling back to the generic.
Board.h gains getBattPercent() (default 0); ZephyrBoard implements it
via battery_curve_lookup().
Board-specific curves added for boards with measured cell data:
t1000_e, rak_wismesh_tag, thinknode_m6, sensecap_solar, wio_tracker_l1.
ADC multiplier corrections applied across all nRF52840 boards:
- Boards using a correctly-derived 3600×ratio formula get +0.5% to
compensate for nRF SAADC gain error (7200→7236, 6300→6332, etc.)
- rak_wismesh_tag, rak3401_1watt, gat562_30s had multipliers copied
from Arduino's 3.0V AREF formula; corrected to 3600×1.73×1.005=6259
- xiao_nrf52840 (10911) left unchanged — empirically calibrated value
above the theoretical, assumed already correct for that hardware
get adc.multiplier now reports current mV reading and the board's
curve 100% target, making field calibration self-guiding.
This commit is contained in:
1 parent
8761a82d93
commit
d37b401033
26 files changed
+266
-15
No files matched your search
@@ -3,6 +3,7 @@
|
||||
*/
|
||||
|
||||
#include "ZephyrBoard.h"
|
||||
#include "battery_curve.h"
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/sys/reboot.h>
|
||||
#include <zephyr/drivers/sensor.h>
|
||||
@@ -146,6 +147,11 @@ uint16_t ZephyrBoard::getBattMilliVolts()
|
||||
#endif
|
||||
}
|
||||
|
||||
uint8_t ZephyrBoard::getBattPercent()
|
||||
{
|
||||
return battery_curve_lookup(&battery_curve_default, getBattMilliVolts());
|
||||
}
|
||||
|
||||
bool ZephyrBoard::setAdcMultiplier(float multiplier)
|
||||
{
|
||||
#if DT_NODE_EXISTS(DT_PATH(zephyr_user)) && \
|
||||
|
||||
Reference in new issue
Block a user