Rockbox Technical Forums

Rockbox Development => Starting Development and Compiling => Topic started by: testdasi on May 04, 2007, 03:03:46 PM

Title: Sansa e200 voltage
Post by: testdasi on May 04, 2007, 03:03:46 PM
I was looking through the sourcecode today to find a way to recalibrate the voltage. I think I found the place for the volage in powermgmt.c
Code: [Select]
#elif CONFIG_BATTERY == BATT_LIION750
    /* Sansa Li Ion 750mAH FIXME this is a first linear approach */
    { 330, 339, 348, 357, 366, 375, 384, 393, 402, 411, 420 },
and
Code: [Select]
#elif CONFIG_BATTERY == BATT_LIION750
    /* Sansa Li Ion 750mAH FIXME*/
    330, 339, 348, 357, 366, 375, 384, 393, 402, 411, 420
The first is for discharge, the second is for charging I believe. There are 11 values so I guess each represents a percentage, from 0% to 100%. So changing the values = recalibrate the battery percentage level reading. Am I right?
I then tried to get the time reading right too but was completely overwhelmed by the code which I believed would return a time value according to battery level.
Code: [Select]
static void battery_status_update(void)
{
    int level = voltage_to_battery_level(battery_centivolts);


    /* calculate estimated remaining running time */
    /* discharging: remaining running time */
    /* charging:    remaining charging time */
#if CONFIG_CHARGING >= CHARGING_MONITOR
    if (charge_state == CHARGING) {
        powermgmt_est_runningtime_min = (100 - level) * battery_capacity * 60
                                      / 100 / (CURRENT_MAX_CHG - runcurrent());
    }
    else
#elif CONFIG_CHARGING && CONFIG_BATTERY == BATT_LIPOL1300
    if (charger_inserted()) {
#ifdef IRIVER_H300_SERIES
        /* H300_SERIES use CURRENT_MAX_CHG for basic charge time (80%)
         * plus 110 min top off charge time */
        powermgmt_est_runningtime_min = ((100-level) * battery_capacity * 80
                                         /100 / CURRENT_MAX_CHG) + 110;
#else
        /* H100_SERIES scaled for 160 min basic charge time (80%) on
         * 1600 mAh battery plus 110 min top off charge time */
        powermgmt_est_runningtime_min = ((100 - level) * battery_capacity
                                         / 993) + 110;
#endif
        level = (level * 80) / 100;
        if (level > 72) { /* > 91% */
            int i = POWER_HISTORY_LEN;
            int d = 1;
#ifdef HAVE_CHARGE_STATE
            if (charge_state == DISCHARGING)
                d = -2;
#endif
            while ((i > 2) && (d > 0)) /* search zero or neg. delta */
                d = power_history[0] - power_history[--i];
            if ((((d == 0) && (i > 6)) || (d == -1)) && (i < 118)) {
                /* top off charging */
                level = MIN(80 + (i*19 / 113), 99);  /* show 81% .. 99% */
                powermgmt_est_runningtime_min = MAX(116 - i, 0);
            }
            else if ((d < 0) || (i > 117)) {
                /* charging finished */
                level = 100;
                powermgmt_est_runningtime_min = battery_capacity * 60
                                                / runcurrent();
            }
        }
    }
    else
#endif /* BATT_LIPOL1300 */
    {
        if ((battery_centivolts + 2) > percent_to_volt_discharge[0][0])
            powermgmt_est_runningtime_min = (level + battery_percent) * 60 *
                                         battery_capacity / 200 / runcurrent();
        else
            powermgmt_est_runningtime_min = (battery_centivolts -
                                             battery_level_shutoff[0]) / 2;
    }

    battery_percent = level;
}
I believe there must be a max time constant or variable defined somewhere for each type of battery. Then we just get the battery % multiply by the max time to get the remaining time. However, looking through the code, I can't pinpoint where this max time value is stored. So if anyone knows, please let me know. Even if I'm wrong, let me know too. Actually, now that I've looked through it for the um-teen times, I think the time is also dependent on current. Totally confused.  ???
I am trying to write a patch to recalibrate the battery level and time for the Sansa. Maybe it can save the developers time so that they can work with other more important things. I'm a newbie so any help is greatly appreciated. Thanks in advanced.