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

Automatically discover the current battery capacity. #10

Open
Tjoms99 opened this issue Jun 23, 2024 · 0 comments
Open

Automatically discover the current battery capacity. #10

Tjoms99 opened this issue Jun 23, 2024 · 0 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@Tjoms99
Copy link
Owner

Tjoms99 commented Jun 23, 2024

Battery State Determination and Capacity Calculation Enhancement

Summary

Currently, a lookup table is used to determine the battery's charge level based on voltage. This feature can be enhanced by allowing the MCU to determine the battery state dynamically.

Existing Implementation

The lookup table for voltage and capacity in percentage:

static BatteryState battery_states[BATTERY_STATES_COUNT] = {
    {4200, 100},
    {4160, 99},
    {4090, 91},
    {4030, 78},
    {3890, 63},
    {3830, 53},
    {3680, 36},
    {3660, 35},
    {3480, 14},
    {3420, 11},
    {3150, 1}, // 3240
    {0000, 0}  // Below safe level
};

Proposed Feature

Enable the MCU to determine the battery state by running a fully charged battery and discharging it down to just before a safe level. The safe level must be user-defined before running the test.

Discharge Functionality:

  • Discharge could be achieved by either powering all the LEDs or activating the BLE.
  • The MCU should monitor and record the voltage drop rate at specific voltages.

Improving Capacity Calculation:
Currently, the capacity is determined using linear interpolation:

for (uint16_t i = 0; i < BATTERY_STATES_COUNT - 1; i++)
{
    // Find the two points battery_millivolt is between
    if (battery_states[i].voltage >= battery_millivolt && battery_millivolt >= battery_states[i + 1].voltage)
    {
        // Linear interpolation
        *battery_percentage = battery_states[i].percentage +
                              ((float)(battery_millivolt - battery_states[i].voltage) *
                               ((float)(battery_states[i + 1].percentage - battery_states[i].percentage) /
                                (float)(battery_states[i + 1].voltage - battery_states[i].voltage)));

        LOG_DBG("%d %%", *battery_percentage);
        return 0;
    }
}

Expected Outcome

  • Dynamic Battery State Determination: The MCU can determine the battery state dynamically, improving accuracy.
  • Enhanced Capacity Calculation: More accurate capacity calculation by considering the actual discharge rate instead of linear interpolation.
@Tjoms99 Tjoms99 added enhancement New feature or request help wanted Extra attention is needed labels Jun 23, 2024
@Tjoms99 Tjoms99 changed the title Automatically discover the current battery's capacity. Automatically discover the current battery capacity. Jun 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant