Quellcode durchsuchen

cc_cv charging logic change

namrota ghosh vor 7 Monaten
Ursprung
Commit
cc25d5994c
2 geänderte Dateien mit 9 neuen und 10 gelöschten Zeilen
  1. 8 9
      src/cc_cv_charging.c
  2. 1 1
      src/cc_cv_charging.h

+ 8 - 9
src/cc_cv_charging.c

@@ -21,11 +21,8 @@ static int16_t batt_charge_discharge;
 void CC_CV_UpdateChargingState(uint8_t slot_id) {
     //static variable to keep a log on the transition during charging and dischrging phases
     static ChargingState previous_state= STATE_IDLE;
-
     // Flag for CV charging, the charging mode flips back to CC mode
     static bool cv_charging_started = false;
-
-    
     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;
@@ -119,8 +116,8 @@ void CC_CV_ControlCharging(uint8_t slot_id, int16_t charge_current) {
     // Calling function to get all the conditional states
     CC_CV_UpdateChargingState(slot_id);
     
-    batt_voltage = battery_data[slot_id].battery_measurement.voltage;
-    batt_current= battery_data[slot_id].battery_measurement.current;
+    //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;
     batt_max_voltage= battery_data[slot_id].max_voltage;
     batt_cutoff_current = battery_data[slot_id].cut_off_current;
@@ -139,7 +136,8 @@ void CC_CV_ControlCharging(uint8_t slot_id, int16_t charge_current) {
   
     // PRE CHARGE STATE: Battery Voltage is lesser than 3000 mVolts
     case STATE_PRE_CHARGE:
-      DL_GPIO_setPins(GPIO_Battery_Charging_PORT, GPIO_Battery_Charging_PIN_PB6_PIN);
+      //DL_GPIO_setPins(GPIO_Battery_Charging_PORT, GPIO_Battery_Charging_PIN_PB6_PIN);
+      DL_GPIO_setPins(GPIO_Battery_Discharging_PORT, GPIO_Battery_Discharging_PIN_PB7_PIN);
       controller_SetCurrent(TARGET_MCU_ADDRESS, slot_id, charge_current);
       if (true) {
         printf("PRE CHARGING: Slot %d at %d mA.\n", slot_id, charge_current);
@@ -149,7 +147,7 @@ void CC_CV_ControlCharging(uint8_t slot_id, int16_t charge_current) {
     // CC CHARGING STATE: Keeps on checking the condition until battery voltage
     // reaches to (MAXIMUM_VOLTAGE-BATTERY_THRESHOLD)= 4150 mVolts
     case STATE_CC_CHARGING:
-      
+      DL_GPIO_setPins(GPIO_Battery_Discharging_PORT, GPIO_Battery_Discharging_PIN_PB7_PIN);
       controller_SetCurrent(TARGET_MCU_ADDRESS, slot_id, charge_current);
       printf("CC CHARGING: Slot %d, Current: %d mA, Voltage: %d mV.\n", slot_id, batt_current, batt_voltage);
       break;
@@ -157,6 +155,7 @@ void CC_CV_ControlCharging(uint8_t slot_id, int16_t charge_current) {
     // CV CHARGING STATE: Keeps on checking the condition until battery current
     // decreases till it exceeds (CUTOFF_CURRENT_MA + BATTERY_THRESHOLD)= 290 mAs
     case STATE_CV_CHARGING:
+      DL_GPIO_setPins(GPIO_Battery_Discharging_PORT, GPIO_Battery_Discharging_PIN_PB7_PIN);
       if (batt_current >= batt_cutoff_current + BATTERY_THRESHOLD) {
         // Detect steep voltage drop:
         if (last_voltage != 0 && (last_voltage - batt_voltage) > 100) {
@@ -173,13 +172,13 @@ void CC_CV_ControlCharging(uint8_t slot_id, int16_t charge_current) {
       break;
   
     case STATE_DISCHARGING:
-      //DL_GPIO_clearPins(GPIO_Battery_Charging_PORT, GPIO_Battery_Charging_PIN_PB6_PIN);
+      DL_GPIO_setPins(GPIO_Battery_Charging_PORT, GPIO_Battery_Charging_PIN_PB6_PIN);
       DL_GPIO_setPins(GPIO_Battery_Discharging_PORT, GPIO_Battery_Discharging_PIN_PB7_PIN);
       controller_SetCurrent(TARGET_MCU_ADDRESS, slot_id, charge_current);
       printf("DISCHARGING: Slot %d at %d mA.\n", slot_id, batt_current);
 
       //Safety Check
-      if(batt_voltage<batt_min_voltage){
+      if(batt_voltage< batt_min_voltage){
         charging_state= STATE_ERROR;
         printf("ERROR: Battery voltage below minimum voltage during discharge\n");
       }

+ 1 - 1
src/cc_cv_charging.h

@@ -2,7 +2,7 @@
 
 #ifndef CC_CV_CHARGING_H_
 #define CC_CV_CHARGING_H_
-#define TARGET_MCU_ADDRESS (0x48)
+
 
 typedef enum{
     STATE_PRE_CHARGE,