-
Notifications
You must be signed in to change notification settings - Fork 6.1k
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
sensor: battery voltage -> SoC conversions #72966
base: main
Are you sure you want to change the base?
sensor: battery voltage -> SoC conversions #72966
Conversation
5329ec1
to
31e87c8
Compare
Thanks @JordanYates, this is definitely a great addition to Zephyr, given it targets IoT, handling battery SoC is something important. That said I wonder if the voltage divider is the right place for that. On one side not all voltage divider are used for battery sensing (but the battery feature is optional, so it's probably fine), and on the other side, not all voltage battery sensors are voltage dividers (for instance STM32 vref or vbat driver, but there are probably more on I2C or SPI bus, for instance the ina2xx). One way to solve that would be to add a battery sensor driver, that references a sensor device used to get the voltage, and then present it as a voltage / SoC gauge. I am not 100% sure it could work, but if needed I can give it a try. |
That is a good point that I didn't consider, but as you say this feature is optional and should not affect those use cases.
True, but this PR provides all the infrastructure needed to add the same conversion functionality with a minimum of effort. I generally try to avoid nested devices as they tend not to be as flexible as you'd hope when devices implement differing levels of functionality. |
Add linear interpolation function that respects floating point rounding rules (away from zero). Signed-off-by: Jordan Yates <jordan@embeint.com>
Add tests for the linear interpolation math functions. Signed-off-by: Jordan Yates <jordan@embeint.com>
Support additional properties from the linux `battery.yaml`. The `ocv-capacity-table-0` definition differs from the Linux version as we do not have a good way to generate variable length arrays in our config structs, or a good way to separate out the percentage vs voltage in the mapping. We reduce the flexibility by enforcing a step size of 10%, which removes the need for the percentage to be in the array and solves the variable length problem. To simplify the effort of defining these voltage curves, default curves for a variety of chemistries have been added, extracted from datasheet graphs of discharge curves from reputable manufacturers. Signed-off-by: Jordan Yates <jordan@embeint.com>
Perform data conversion in the `fetch` call as documented in the sensor API. Signed-off-by: Jordan Yates <jordan@embeint.com>
Support SoC lookup through the use of the `ocv-capacity-table-0` devicetree property. Signed-off-by: Jordan Yates <jordan@embeint.com>
Define a battery curve for the lithium ion polymer battery shipped with the board. Signed-off-by: Jordan Yates <jordan@embeint.com>
31e87c8
to
2ff23bd
Compare
I have the same concern about putting this within voltage divider, doesn't seem right, what alternatives are there |
Provide a mechanism for sensors that can only measure battery voltage to report a charge percentage through an open circuit voltage lookup table. 5 default tables are provided for different battery chemistries, application specific curves can easily be used instead.
This conversion is added to the voltage-divider driver and configured on the Thingy53 platform.
A custom linear interpolation function is provided to avoid any dependency on CMSIS-DSP.