Explorar el Código

CC CV GPIO pins updated here and config file update for PWM

namrota ghosh hace 6 meses
padre
commit
4c0e1647b3
Se han modificado 2 ficheros con 39 adiciones y 12 borrados
  1. 33 12
      src/cc_cv_charging.c
  2. 6 0
      src/config.h

+ 33 - 12
src/cc_cv_charging.c

@@ -91,7 +91,7 @@ void CC_CV_UpdateChargingState(uint8_t slot_id) {
         // 5. State Discharging condition
         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);
+                DL_GPIO_clearPins(GPIO_Battery_Discharging_PIN_PB6_PORT, GPIO_Battery_Discharging_PIN_PB6_PIN);
                 charging_state = STATE_CC_CHARGING;
                 (*cycle_count)++;
                 cv_charging_started = false;
@@ -158,7 +158,7 @@ void CC_CV_ControlCharging(uint8_t slot_id) {
     switch (charging_state) {
     // 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_PB7_PIN);
+      DL_GPIO_setPins(GPIO_Battery_Charging_PIN_PB7_PORT, GPIO_Battery_Charging_PIN_PB7_PIN);
       controller_SetCurrent(slot_id, charge_current);
       printf("PRE CHARGING: Slot %d at %d mA.\n", slot_id, charge_current);
       chargeCurrent_initialized= false;
@@ -167,7 +167,7 @@ void CC_CV_ControlCharging(uint8_t slot_id) {
     // CC CHARGING STATE: Keeps on checking the condition until battery voltage
     // reaches to (MAXIMUM_VOLTAGE(4200)-BATTERY_THRESHOLD(20))= 4180 mV
     case STATE_CC_CHARGING:
-      DL_GPIO_setPins(GPIO_Battery_Charging_PORT, GPIO_Battery_Charging_PIN_PB7_PIN);
+      DL_GPIO_setPins(GPIO_Battery_Charging_PIN_PB7_PORT, GPIO_Battery_Charging_PIN_PB7_PIN);
       controller_SetCurrent(slot_id, charge_current);
       printf("CC CHARGING: Slot %d, Current: %d mA, Voltage: %d mV.\n", slot_id, batt_current, batt_voltage);
       chargeCurrent_initialized= false;
@@ -176,7 +176,7 @@ void CC_CV_ControlCharging(uint8_t slot_id) {
     // CV CHARGING STATE: Keeps on checking the condition until battery current
     // decreases till it lowers to (CUTOFF_CURRENT_MA + BATTERY_THRESHOLD)
     case STATE_CV_CHARGING:
-      DL_GPIO_setPins(GPIO_Battery_Charging_PORT, GPIO_Battery_Charging_PIN_PB7_PIN);
+      DL_GPIO_setPins(GPIO_Battery_Charging_PIN_PB7_PORT, GPIO_Battery_Charging_PIN_PB7_PIN);
       if(!chargeCurrent_initialized){
         cvChargingPhaseCurrent= charge_current;
         chargeCurrent_initialized= true;
@@ -205,8 +205,8 @@ void CC_CV_ControlCharging(uint8_t slot_id) {
       break;
   
     case STATE_DISCHARGING:
-      DL_GPIO_setPins(GPIO_Battery_Charging_PORT, GPIO_Battery_Charging_PIN_PB7_PIN);
-      DL_GPIO_setPins(GPIO_Battery_Discharging_PORT, GPIO_Battery_Discharging_PIN_PB6_PIN);
+      DL_GPIO_setPins(GPIO_Battery_Charging_PIN_PB7_PORT, GPIO_Battery_Charging_PIN_PB7_PIN);
+      DL_GPIO_setPins(GPIO_Battery_Discharging_PIN_PB6_PORT, GPIO_Battery_Discharging_PIN_PB6_PIN);
       controller_SetCurrent(slot_id, (-1 * charge_current));
       printf("DISCHARGING: Slot %d at %d mA.\n", slot_id, batt_current);
       chargeCurrent_initialized= false;
@@ -222,8 +222,8 @@ void CC_CV_ControlCharging(uint8_t slot_id) {
       if((batt_voltage >= HEALTHY_BATTERY_VALUE) && (batt_voltage <= batt_max_voltage - BATTERY_THRESHOLD)){
         //Once the cycle gets done, the battery state transitions to "STATE_MEASUREMENT_DONE"
         battery_data[slot_id].battery_state= STATE_MEASUREMENT_DONE;
-        DL_GPIO_clearPins(GPIO_Battery_Charging_PORT, GPIO_Battery_Charging_PIN_PB7_PIN);
-        DL_GPIO_clearPins(GPIO_Battery_Discharging_PORT, GPIO_Battery_Discharging_PIN_PB6_PIN);
+        DL_GPIO_clearPins(GPIO_Battery_Charging_PIN_PB7_PORT, GPIO_Battery_Charging_PIN_PB7_PIN);
+        DL_GPIO_clearPins(GPIO_Battery_Discharging_PIN_PB6_PORT, GPIO_Battery_Discharging_PIN_PB6_PIN);
         printf("Final Discharge with charge current:%d\n", charge_current);
         controller_SetCurrent(slot_id, 0);
       }else{
@@ -233,15 +233,36 @@ void CC_CV_ControlCharging(uint8_t slot_id) {
       break;
   
     case STATE_ERROR:
-      DL_GPIO_clearPins(GPIO_Battery_Charging_PORT, GPIO_Battery_Charging_PIN_PB7_PIN);
-      DL_GPIO_clearPins(GPIO_Battery_Discharging_PORT, GPIO_Battery_Discharging_PIN_PB6_PIN);
+      DL_GPIO_clearPins(GPIO_Battery_Charging_PIN_PB7_PORT, GPIO_Battery_Charging_PIN_PB7_PIN);
+      DL_GPIO_clearPins(GPIO_Battery_Discharging_PIN_PB6_PORT, GPIO_Battery_Discharging_PIN_PB6_PIN);
       printf("ERROR: Slot %d.\n", slot_id);
       chargeCurrent_initialized= false;
       break;
   
     case STATE_IDLE:
-      DL_GPIO_clearPins(GPIO_Battery_Charging_PORT, GPIO_Battery_Charging_PIN_PB7_PIN);
-      DL_GPIO_clearPins(GPIO_Battery_Discharging_PORT, GPIO_Battery_Discharging_PIN_PB6_PIN);
+      DL_GPIO_clearPins(GPIO_Battery_Charging_PIN_PB7_PORT, GPIO_Battery_Charging_PIN_PB7_PIN);
+      DL_GPIO_clearPins(GPIO_Battery_Discharging_PIN_PB6_PORT, GPIO_Battery_Discharging_PIN_PB6_PIN);
+
+      DL_GPIO_clearPins(GPIO_Battery_Charging_PIN_PB9_PORT, GPIO_Battery_Charging_PIN_PB9_PIN);
+      DL_GPIO_clearPins(GPIO_Battery_Discharging_PIN_PB8_PORT, GPIO_Battery_Discharging_PIN_PB8_PIN);
+
+      DL_GPIO_clearPins(GPIO_Battery_Charging_PIN_PB15_PORT, GPIO_Battery_Charging_PIN_PB15_PIN);
+      DL_GPIO_clearPins(GPIO_Battery_Discharging_PIN_PB14_PORT, GPIO_Battery_Discharging_PIN_PB14_PIN);
+
+      DL_GPIO_clearPins(GPIO_Battery_Charging_PIN_PA12_PORT, GPIO_Battery_Charging_PIN_PA12_PIN);
+      DL_GPIO_clearPins(GPIO_Battery_Discharging_PIN_PB16_PORT, GPIO_Battery_Discharging_PIN_PB16_PIN);
+
+      DL_GPIO_clearPins(GPIO_Battery_Charging_PIN_PB19_PORT, GPIO_Battery_Charging_PIN_PB19_PIN);
+      DL_GPIO_clearPins(GPIO_Battery_Discharging_PIN_PB18_PORT, GPIO_Battery_Discharging_PIN_PB18_PIN);
+
+      DL_GPIO_clearPins(GPIO_Battery_Charging_PIN_PB20_PORT, GPIO_Battery_Charging_PIN_PB20_PIN);
+      DL_GPIO_clearPins(GPIO_Battery_Discharging_PIN_PA22_PORT, GPIO_Battery_Discharging_PIN_PA22_PIN);
+
+      DL_GPIO_clearPins(GPIO_Battery_Charging_PIN_PA24_PORT, GPIO_Battery_Charging_PIN_PA24_PIN);
+      DL_GPIO_clearPins(GPIO_Battery_Discharging_PIN_PB24_PORT, GPIO_Battery_Discharging_PIN_PB24_PIN);
+
+      DL_GPIO_clearPins(GPIO_Battery_Charging_PIN_PA26_PORT, GPIO_Battery_Charging_PIN_PA26_PIN);
+      DL_GPIO_clearPins(GPIO_Battery_Discharging_PIN_PA25_PORT, GPIO_Battery_Discharging_PIN_PA25_PIN);
       break;
 
     default:

+ 6 - 0
src/config.h

@@ -11,6 +11,12 @@
 #define MEASUREMENT_CHECK_INTERVAL 320000 //Do not know yet the exact timing
 #define HEALTHY_BATTERY_VALUE (3800)
 
+//PWM Value:
+#define INITIAL_PWM_VALUE (0)
+#define PWM_INCREMENT_VALUE (1)
+#define PWM_DECREMENT_VALUE (1)
+#define PWM_MAX_VALUE (320)
+
 // soft overvoltage treshold before getting into the soft overvoltage state
 #define SOV_THRESHOLD_MV 6000