Mercurial > public > ostc4
changeset 668:079bb5b22c06 Betatest
Rework charge cycle:
The charge counter is increasing decreasing also if the real value is maybe not defined (definition is done for example by a completed charging cycle). This caused some problems with invalid displayed charge per centage values. To avoid this the state of an unknow counter value was introduced. The indication is done by converting the counter into a negativ value.
author | Ideenmodellierer |
---|---|
date | Sat, 12 Mar 2022 22:48:45 +0100 |
parents | 8c3d495afc69 |
children | c1e203ffb478 |
files | Small_CPU/Src/batteryCharger.c Small_CPU/Src/batteryGasGauge.c Small_CPU/Src/scheduler.c |
diffstat | 3 files changed, 38 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/Small_CPU/Src/batteryCharger.c Sat Mar 12 22:42:56 2022 +0100 +++ b/Small_CPU/Src/batteryCharger.c Sat Mar 12 22:48:45 2022 +0100 @@ -39,8 +39,8 @@ #define CHARGER_DEBOUNCE_SECONDS (6u) /* 6 seconds used to avoid problems with charger interrupts / disconnections */ -uint8_t battery_i_charge_status = 0; -uint16_t battery_charger_counter = 0; +static uint8_t battery_i_charge_status = 0; +static uint16_t battery_charger_counter = 0; #ifdef ENABLE_CHARGER_STATUS_V2 static chargerState_t batteryChargerState = Charger_NotConnected; @@ -141,7 +141,6 @@ { #ifdef ENABLE_CHARGER_STATUS_V2 static uint8_t notifyChargeComplete = 0; - static float chargeValueAtStart = 0; #endif #ifdef OSTC_ON_DISCOVERY_HARDWARE @@ -158,10 +157,6 @@ { battery_gas_gauge_set_charge_full(); } - else /* unknown state => reset to 0% */ - { - battery_gas_gauge_set(0); - } batteryChargerState = Charger_NotConnected; } } @@ -176,13 +171,15 @@ batteryChargerState = Charger_LostConnection; battery_charger_counter = CHARGER_DEBOUNCE_SECONDS; break; - case Charger_LostConnection: if(get_voltage() >= BATTERY_ENDOF_CHARGE_VOLTAGE) /* the charger stops charging when charge current is 1/10 */ - /* Basically it is OK to rate a charging as complete if a defined voltage is reached */ + case Charger_LostConnection: /* the charger stops charging when charge current is 1/10 */ + /* Basically it is OK to rate a charging as complete if a defined voltage is reached */ + if(((battery_gas_gauge_isChargeValueValid() == 0) || (global.lifeData.battery_charge < 90)) && (get_voltage() >= BATTERY_ENDOF_CHARGE_VOLTAGE)) { batteryChargerState = Charger_Finished; global.dataSendToMaster.chargeStatus = CHARGER_complete; global.deviceDataSendToMaster.chargeStatus = CHARGER_complete; notifyChargeComplete = 1; + battery_charger_counter = 0; } /* no break */ case Charger_WarmUp: @@ -210,13 +207,6 @@ HAL_Delay(50); /* I2C operations are pending in the background. Wait to avoid data loose in caused to potential change to sleep state */ } } - else - { - if(chargeValueAtStart < 1.0) /* charging started with unknown value => reset charge state reported by charger */ - { - battery_gas_gauge_set(0); - } - } batteryChargerState = Charger_NotConnected; } break; @@ -232,7 +222,6 @@ case Charger_NotConnected: battery_i_charge_status = 1; battery_charger_counter = 0; batteryChargerState = Charger_WarmUp; - chargeValueAtStart = global.lifeData.battery_charge; break; case Charger_LostConnection: batteryChargerState = Charger_Active; break; @@ -268,6 +257,10 @@ } else { + if(global.lifeData.battery_charge > 100.0) /* still charging but indicator is set to full => decrease to 99% to keep count increasing */ + { + battery_gas_gauge_set(99.0); + } if(batteryChargerState == Charger_Finished) /* voltage dropped below the hysteresis again => charging restarted */ { batteryChargerState = Charger_Active;
--- a/Small_CPU/Src/batteryGasGauge.c Sat Mar 12 22:42:56 2022 +0100 +++ b/Small_CPU/Src/batteryGasGauge.c Sat Mar 12 22:48:45 2022 +0100 @@ -30,6 +30,8 @@ static float battery_f_voltage = BATTERY_DEFAULT_VOLTAGE; /* max assumed voltage */ static float battery_f_charge_percent = 0; +static uint8_t chargeValueKnown = 0; /* indicator if the charge of the battery is known (for example after a full charge cycle) */ + #define BGG_BATTERY_OFFSET (26123) //; 65536-(3,35Ah/0,085mAh) #define BGG_BATTERY_DIVIDER (394) //; 3,35Ah/0,085mAh/100 [%] @@ -66,7 +68,7 @@ // F8 = 11111000: // ADC auto mode (11) // Prescale M = 128 (111) - // AL/CC pin disable (0) + // AL/CC pin disable (00) // Shutdown (0) buffer[1] = 0xF8; I2C_Master_Transmit(DEVICE_BATTERYGAUGE, buffer, 2); @@ -152,6 +154,7 @@ bufferSend[2] = 0xFF; I2C_Master_Transmit( DEVICE_BATTERYGAUGE, bufferSend, 3); init_battery_gas_gauge(); + chargeValueKnown = 1; } @@ -177,7 +180,17 @@ bufferSend[2] = (uint8_t)(mAhSend & 0xFF); I2C_Master_Transmit( DEVICE_BATTERYGAUGE, bufferSend, 3); init_battery_gas_gauge(); + chargeValueKnown = 1; } +uint8_t battery_gas_gauge_isChargeValueValid(void) +{ + return chargeValueKnown; +} + +void battery_gas_gauge_setChargeValueValid(void) +{ + chargeValueKnown = 1; +} /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/
--- a/Small_CPU/Src/scheduler.c Sat Mar 12 22:42:56 2022 +0100 +++ b/Small_CPU/Src/scheduler.c Sat Mar 12 22:48:45 2022 +0100 @@ -127,6 +127,8 @@ global.I2C_SystemStatus = HAL_ERROR; // 0x00 would be everything working + global.lifeData.battery_voltage = BATTERY_DEFAULT_VOLTAGE; + global.lifeData.pressure_ambient_bar = INVALID_PREASURE_VALUE; global.lifeData.pressure_surface_bar = INVALID_PREASURE_VALUE; decom_reset_with_1000mbar(&global.lifeData); @@ -1064,6 +1066,7 @@ { global.dataSendToMaster.mode = 0; global.deviceDataSendToMaster.mode = 0; + secondsCount = 0; /* prevent button wake up problem while in sleep_prepare * sleep prepare does I2C_DeInit() @@ -1150,6 +1153,7 @@ clearDecoNow = 0; setButtonsNow = 0; reinitGlobals(); + ReInit_battery_charger_status_pins(); } @@ -1579,8 +1583,17 @@ void copyBatteryData(void) { uint8_t boolBatteryData = !global.dataSendToMaster.boolBatteryData; + global.lifeData.battery_charge = get_charge(); global.dataSendToMaster.data[boolBatteryData].battery_voltage = get_voltage(); - global.dataSendToMaster.data[boolBatteryData].battery_charge= get_charge(); + + if(battery_gas_gauge_isChargeValueValid()) + { + global.dataSendToMaster.data[boolBatteryData].battery_charge= global.lifeData.battery_charge; + } + else + { + global.dataSendToMaster.data[boolBatteryData].battery_charge = global.lifeData.battery_charge * -1.0; /* negate value to show that this is just an assumption */ + } global.dataSendToMaster.boolBatteryData = boolBatteryData; }