Prechádzať zdrojové kódy

Pre-Charge->CC->CV->Discharge->CC

namrota ghosh 6 mesiacov pred
rodič
commit
0a5e6d1284
1 zmenil súbory, kde vykonal 14 pridanie a 5 odobranie
  1. 14 5
      src/cc_cv_charging.c

+ 14 - 5
src/cc_cv_charging.c

@@ -6,6 +6,9 @@
 #include "ti_msp_dl_config.h"
 #include "src/controller/controller.h"
 
+
+//w 3000 4200 20 2000 75 0
+
 static BatteryChargingState charging_state= STATE_IDLE; //Default value of the charging state
 static bool battery_discharge= false;
 
@@ -61,7 +64,7 @@ void CC_CV_UpdateChargingState(uint8_t slot_id) {
         }
 
         // 2. Fast Charging Condition: CC Charging: cv_charging_started condition added to avoid toggling back to CC after CV state is reached
-        else if (!cv_charging_started && (batt_voltage >= batt_min_voltage) && (batt_voltage < batt_max_voltage - BATTERY_THRESHOLD)){
+        else if ((!battery_discharge) && (!cv_charging_started) && (batt_voltage >= batt_min_voltage) && (batt_voltage < batt_max_voltage - BATTERY_THRESHOLD)){
             charging_state = STATE_CC_CHARGING;
             printf("CC CHARGING\n");
             cv_charging_started = false;
@@ -87,12 +90,16 @@ void CC_CV_UpdateChargingState(uint8_t slot_id) {
         }
 
         // 5. State Discharging condition
-        else if ((charging_state == STATE_DISCHARGING)&& (batt_voltage <= batt_min_voltage + BATTERY_THRESHOLD)){
+        else if (charging_state == STATE_DISCHARGING){
+            if(batt_voltage <= batt_min_voltage + BATTERY_THRESHOLD){
                 DL_GPIO_clearPins(GPIO_Battery_Discharging_PORT, GPIO_Battery_Discharging_PIN_PB6_PIN);
                 charging_state = STATE_CC_CHARGING;
                 cv_charging_started = false;
                 battery_discharge= false;
                 printf("DISCHARGE -> CC CHARGING\n");
+            }else{
+                charging_state= STATE_DISCHARGING;
+            }
         }
         
         //6. Check if the battery is overcharged
@@ -181,16 +188,18 @@ void CC_CV_ControlCharging(uint8_t slot_id) {
           break;
         }
         if(cvChargingPhaseCurrent >= BATTERY_THRESHOLD){
-            cvChargingPhaseCurrent-= 5;     
+            printf("DAC CV Current: %d\n", cvChargingPhaseCurrent);
+            cvChargingPhaseCurrent-= 5;          
         }else{
+            printf("Battery Current: %d\n", batt_current);
             chargeCurrent_initialized= false;
             battery_discharge= true;
             break;
         }
       }
-
-      controller_SetCurrent(slot_id, cvChargingPhaseCurrent);
       last_voltage = batt_voltage;
+      controller_SetCurrent(slot_id, cvChargingPhaseCurrent);
+      printf("CV CHARGING: Slot %d, Current: %d mA, Voltage: %d mV.\n", slot_id, batt_current, batt_voltage);
       break;
   
     case STATE_DISCHARGING: