소스 검색

CC CV Charging condition working for Pre-Charge, CC, CV

namrota ghosh 6 달 전
부모
커밋
858c5757e3
2개의 변경된 파일18개의 추가작업 그리고 12개의 파일을 삭제
  1. 17 11
      src/cc_cv_charging.c
  2. 1 1
      src/cc_cv_charging.h

+ 17 - 11
src/cc_cv_charging.c

@@ -64,7 +64,7 @@ void CC_CV_UpdateChargingState(uint8_t slot_id) {
 
     // Once the battery limits are received then start with the charging
     if(battery_data[slot_id].batteryLimitReceived == 1){
-
+        printf("Battery Limit Received:%d\n", battery_data[slot_id].batteryLimitReceived);
         //1. Pre Charge: if the battery is deeply discharged
         if ((batt_voltage < batt_min_voltage)) {
             charging_state = STATE_PRE_CHARGE;
@@ -117,8 +117,8 @@ void CC_CV_UpdateChargingState(uint8_t slot_id) {
         // CV_STATE was jumping directly to STATE_ERROR in else statement, to handle
         // the condition better, else condition is being changed).
         else {
-        printf("[CC-CV] Current state: Voltage= %d mV, Current= %d mA\n",
-                batt_voltage, batt_current);
+        printf("[CC-CV] Current state: Voltage= %d mV, Current= %d mA\n, Current Cycle= %c\n",
+                batt_voltage, batt_current, charging_state);
         }
     }
 }
@@ -133,10 +133,10 @@ or floating voltage level
 voltage threshold is obtained.
 */
 
-void CC_CV_ControlCharging(uint8_t slot_id, int16_t charge_current) {
+void CC_CV_ControlCharging(uint8_t slot_id) {
     // Calling function to get all the conditional states
     CC_CV_UpdateChargingState(slot_id);
-    
+    int16_t charge_current= 50;
     batt_voltage = battery_data[slot_id].battery_measurement.voltage;
     batt_current= battery_data[slot_id].battery_measurement.current;
     batt_min_voltage= battery_data[slot_id].min_voltage;
@@ -150,8 +150,9 @@ void CC_CV_ControlCharging(uint8_t slot_id, int16_t charge_current) {
     // Adding a variable to check the stepness in the voltage drop in CV charging
     // mode:
     static uint16_t last_voltage = 0;
+    static int16_t cvChargingPhaseCurrent;
     //flag for DAC: so that the dac value is initialized only once and then can be decremented rather than resetting to the initial value
-    static bool dac_initialized= false;
+    static bool chargeCurrent_initialized= false; 
 
     switch (charging_state) {
   
@@ -177,19 +178,24 @@ void CC_CV_ControlCharging(uint8_t slot_id, int16_t charge_current) {
     // decreases till it exceeds (CUTOFF_CURRENT_MA + BATTERY_THRESHOLD)= 290 mAs
     case STATE_CV_CHARGING:
       DL_GPIO_setPins(GPIO_Battery_Charging_PORT, GPIO_Battery_Charging_PIN_PB7_PIN);
-      if (batt_current >= batt_cutoff_current + BATTERY_THRESHOLD) {
+      
+      if(!chargeCurrent_initialized){
+        cvChargingPhaseCurrent= charge_current;
+        chargeCurrent_initialized= true;
+      }
+      //battery current > 200 for 250 cut_off_current and 50 threshold
+      if (batt_current > batt_cutoff_current - BATTERY_THRESHOLD) {
         // Detect steep voltage drop:
         if (last_voltage != 0 && (last_voltage - batt_voltage) > 100) {
           printf("!!! CV CHARGING: Voltage dropped too fast: %d -> %d mV.\n", last_voltage, batt_voltage);
           charging_state= STATE_ERROR;
           break;
         }
-        controller_SetCurrent(slot_id, charge_current);
-      }else {
-        charging_state = STATE_FINAL_DISCHARGE;
-        dac_initialized= false;
+        cvChargingPhaseCurrent-= 5;
       }
+      
       last_voltage = batt_voltage;
+      controller_SetCurrent(slot_id, cvChargingPhaseCurrent);
       break;
   
     case STATE_DISCHARGING:

+ 1 - 1
src/cc_cv_charging.h

@@ -4,6 +4,6 @@
 #define CC_CV_CHARGING_H_
 
 void CC_CV_UpdateChargingState(uint8_t slot_id);
-void CC_CV_ControlCharging(uint8_t slot_id, int16_t charge_current);
+void CC_CV_ControlCharging(uint8_t slot_id);
 
 #endif