arduino-libraries / Arduino_PowerManagement

Mozilla Public License 2.0
11 stars 2 forks source link

Portenta C33 stalls while charging battery #5

Closed aliphys closed 2 months ago

aliphys commented 4 months ago

While running the sketch below, during test case the Serial Monitor stalls and no further output is given while battery charging is in progress (replicated across two different Windows PCs with two Portenta C33 boards)-


---------
Test Scenario ID: TPL-ARD-PWRM-001-C33-ChargingState08
---------

---
Test Case ID: TPL-ARD-PWRM-001-C33-ChargingState08-Initialize
PMIC initialized.
---
Test Case ID: TPL-ARD-PWRM-001-C33-ChargingState08-ReadBattery
Reading battery parameters...
Battery Voltage: 4.20 V
Floor Battery Voltage: 4.18 V
Set Battery Voltage: 4.34 V
---
Test Case ID: TPL-ARD-PWRM-001-C33-ChargingState08-SetChargeParameters
Setting charger parameters...
Final charge voltage: 4.34 V
Charging current: 100 mA
End charge current: 5 mA
---
Test Case ID: TPL-ARD-PWRM-001-C33-ChargingState08-ChargeStatus
fast-charge constant voltage- Battery Voltage: 4.20 V
fast-charge constant voltage- Battery Voltage: 4.30 V
fast-charge constant voltage- Battery Voltage: 4.30 V
fast-charge constant voltage- Battery Voltage: 4.30 V
TPL-ARD-PWRM-001-C33-ChargingState08 ``` /** * Test Scenario ID : TPL-ARD-PWRM-001-C33-ChargingState08 * * This sketch demonstrates the three charging states that can be applied to a battery. It does this by reading the voltage, * and then setting the charging voltage to be 2 steps (2*0.02V) above the battery voltage. * * Test Case IDs : * TPL-ARD-PWRM-001-C33-ChargingState08-Initialize -> Initialize the PMIC * TPL-ARD-PWRM-001-C33-ChargingState08-ReadBattery -> Read battery voltage and set charging voltage * TPL-ARD-PWRM-001-C33-ChargingState08-SetChargeParameters -> Set charging parameters * TPL-ARD-PWRM-001-C33-ChargingState08-ChargeStatus -> Switch status to done when charging complete * * NOTE: The battery voltage must be under 4.1V for the charging to start * * * Initial author: Ali Jahangiri @aliphys */ #include "Arduino_PowerManagement.h" /* #include #include #include */ const char testScenarioID[] = "TPL-ARD-PWRM-001-C33-ChargingState08"; Battery battery; Charger charger; /* std::array VoltListArray = { "V_3_50", "V_3_52", "V_3_54", "V_3_56", "V_3_58", "V_3_60", "V_3_62", "V_3_64", "V_3_66", "V_3_68", "V_3_70", "V_3_72", "V_3_74", "V_3_76", "V_3_78", "V_3_80", "V_3_82", "V_3_84", "V_3_86", "V_3_88", "V_3_90", "V_3_92", "V_3_94", "V_3_96", "V_3_98", "V_4_00", "V_4_02", "V_4_04", "V_4_06", "V_4_08", "V_4_10", "V_4_12", "V_4_14", "V_4_16", "V_4_18", "V_4_20", "V_4_22", "V_4_24", "V_4_26", "V_4_28", "V_4_30", "V_4_32", "V_4_34", "V_4_36", "V_4_38", "V_4_40", "V_4_42", "V_4_44" }; enum class VoltList { V_3_50, V_3_52, V_3_54, V_3_56, V_3_58, V_3_60, V_3_62, V_3_64, V_3_66, V_3_68, V_3_70, V_3_72, V_3_74, V_3_76, V_3_78, V_3_80, V_3_82, V_3_84, V_3_86, V_3_88, V_3_90, V_3_92, V_3_94, V_3_96, V_3_98, V_4_00, V_4_02, V_4_04, V_4_06, V_4_08, V_4_10, V_4_12, V_4_14, V_4_16, V_4_18, V_4_20, V_4_22, V_4_24, V_4_26, V_4_28, V_4_30, V_4_32, V_4_34, V_4_36, V_4_38, V_4_40, V_4_42, V_4_44 }; */ float floorVoltage(float voltage, int stepSize = 0) { // Check voltage is within the correct range if (voltage < 3.50 || voltage > (4.3 - (0.02 * stepSize))) { //throw std::out_of_range("Voltage/step size is out of range"); Serial.println("Voltage/step size is out of range"); } // Get the rounded number (to 0.02) of the voltage float roundedVoltage = floor(voltage / 0.02) * 0.02 + (0.02 * stepSize); return roundedVoltage; } String getChargerState(){ ChargingState status = charger.getState(); switch (status) { case ChargingState::preCharge: return "precharge"; break; case ChargingState::fastChargeConstantCurrent: return "fast-charge constant current"; break; case ChargingState::fastChargeConstantVoltage: return "fast-charge constant voltage"; break; case ChargingState::endOfCharge: return "end-of-charge"; break; case ChargingState::done: return "done"; break; case ChargingState::timerFaultError: return "timer fault"; break; case ChargingState::thermistorSuspendError: return "thermistor suspend"; break; case ChargingState::chargerDisabled: return "off"; break; case ChargingState::batteryOvervoltageError: return "overvoltage condition"; break; case ChargingState::chargerBypassed: return "disabled"; break; default: return "unknown"; break; } } void setup(){ Serial.begin(115200); while (!Serial); Serial.println(); Serial.println("---------"); Serial.print("Test Scenario ID: "); Serial.println(testScenarioID); Serial.println("---------"); Serial.println(); Serial.println("---"); Serial.print("Test Case ID: "); Serial.println("TPL-ARD-PWRM-001-C33-ChargingState08-Initialize"); if (charger.begin()) { Serial.println("PMIC initialized."); } else { Serial.println("PMIC failed to initialize."); } Serial.println("---"); Serial.print("Test Case ID: "); Serial.println("TPL-ARD-PWRM-001-C33-ChargingState08-ReadBattery"); Serial.println("Reading battery parameters..."); float batteryVoltage = battery.voltage(); Serial.println("Battery Voltage: " + String(batteryVoltage) + " V"); float batteryVoltageFloor = floorVoltage(batteryVoltage, 0); Serial.println("Floor Battery Voltage: " + String(batteryVoltageFloor) + " V"); float batterySetVoltage = floorVoltage(batteryVoltage, 8); Serial.println("Set Battery Voltage: " + String(batterySetVoltage) + " V"); Serial.println("---"); Serial.print("Test Case ID: "); Serial.println("TPL-ARD-PWRM-001-C33-ChargingState08-SetChargeParameters"); Serial.println("Setting charger parameters..."); charger.setChargeVoltage(batterySetVoltage); auto chargeVoltage = charger.getChargeVoltage(); Serial.println("Final charge voltage: " + String(chargeVoltage) + " V"); charger.setChargeCurrent(100); auto chargeCurrent = charger.getChargeCurrent(); Serial.println("Charging current: " + String(chargeCurrent) + " mA"); charger.setEndOfChargeCurrent(5); auto endOfChargeCurrent = charger.getEndOfChargeCurrent(); Serial.println("End charge current: " + String(endOfChargeCurrent) + " mA"); Serial.println("---"); Serial.print("Test Case ID: "); Serial.println("TPL-ARD-PWRM-001-C33-ChargingState08-ChargeStatus"); static ChargingState status = ChargingState::none; status = charger.getState(); batteryVoltage = battery.voltage(); while (batteryVoltage < chargeVoltage) { status = charger.getState(); batteryVoltage = battery.voltage(); Serial.println(getChargerState() + "- Battery Voltage: " + String(batteryVoltage) + " V"); delay(5000); } if (batteryVoltage >= chargeVoltage) { Serial.println("Charging complete."); status = charger.getState(); Serial.println("Final Charger Status: " + getChargerState()); batteryVoltage = battery.voltage(); Serial.println("Final Battery Voltage: " + String(batteryVoltage) + " V"); } Serial.println("---"); Serial.println("---"); Serial.println(); Serial.println("---------"); Serial.print("End of Test Scenario ID: "); Serial.println(testScenarioID); Serial.println("---------"); Serial.println(); } void loop(){ // Empty loop } ```

Additional information

aliphys commented 3 months ago

Cross check with values over FTDI

aliphys commented 2 months ago

Reproduction issue. Given that the USB protocol should negotiate the power draw, it could be that the USB hub is part of the issue.

Retest with the Joulescope.

aliphys commented 2 months ago

Tested multiple times over several devices. And directly connected to laptop, USB hub and monitor hub.

Likely, a fix in Arduino_PowerManagement, Arduino_LowPowerPortentaC33 or the renesas core has fixed this issue, so closing.

Example of Serial output ``` --------- Test Scenario ID: TPL-ARD-PWRM-001-C33-ChargingState04 --------- --- Test Case ID: TPL-ARD-PWRM-001-C33-ChargingState04-Initialize PMIC initialized. --- Test Case ID: TPL-ARD-PWRM-001-C33-ChargingState04-ReadBattery Reading battery parameters... Battery Voltage: 3.92 V Floor Battery Voltage: 3.92 V Set Battery Voltage: 4.00 V --- Test Case ID: TPL-ARD-PWRM-001-C33-ChargingState04-SetChargeParameters Setting charger parameters... Final charge voltage: 4.00 V Charging current: 100 mA End charge current: 5 mA --- Test Case ID: TPL-ARD-PWRM-001-C33-ChargingState04-ChargeStatus fast-charge constant voltage- Battery Voltage: 3.92 V fast-charge constant voltage- Battery Voltage: 3.97 V fast-charge constant voltage- Battery Voltage: 3.97 V fast-charge constant voltage- Battery Voltage: 3.97 V fast-charge constant voltage- Battery Voltage: 3.97 V fast-charge constant voltage- Battery Voltage: 3.97 V fast-charge constant voltage- Battery Voltage: 3.97 V fast-charge constant voltage- Battery Voltage: 3.97 V fast-charge constant voltage- Battery Voltage: 3.97 V fast-charge constant voltage- Battery Voltage: 3.97 V fast-charge constant voltage- Battery Voltage: 3.97 V fast-charge constant voltage- Battery Voltage: 3.97 V fast-charge constant voltage- Battery Voltage: 3.97 V fast-charge constant voltage- Battery Voltage: 3.97 V fast-charge constant voltage- Battery Voltage: 3.97 V fast-charge constant voltage- Battery Voltage: 3.97 V fast-charge constant voltage- Battery Voltage: 3.97 V fast-charge constant voltage- Battery Voltage: 3.97 V fast-charge constant voltage- Battery Voltage: 3.97 V fast-charge constant voltage- Battery Voltage: 3.97 V fast-charge constant voltage- Battery Voltage: 3.97 V fast-charge constant voltage- Battery Voltage: 3.97 V fast-charge constant voltage- Battery Voltage: 3.97 V fast-charge constant voltage- Battery Voltage: 3.97 V fast-charge constant voltage- Battery Voltage: 3.97 V fast-charge constant voltage- Battery Voltage: 3.97 V fast-charge constant voltage- Battery Voltage: 3.97 V fast-charge constant voltage- Battery Voltage: 3.97 V fast-charge constant voltage- Battery Voltage: 3.98 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 3.99 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 3.99 V fast-charge constant voltage- Battery Voltage: 3.99 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 3.99 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 4.00 V fast-charge constant voltage- Battery Voltage: 4.00 V Charging complete. Final Charger Status: fast-charge constant voltage Final Battery Voltage: 4.00 V --- --- --------- End of Test Scenario ID: TPL-ARD-PWRM-001-C33-ChargingState04 --------- ```