|
@@ -6,6 +6,9 @@
|
|
|
#include "ti_msp_dl_config.h"
|
|
#include "ti_msp_dl_config.h"
|
|
|
#include "src/controller/controller.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 BatteryChargingState charging_state= STATE_IDLE; //Default value of the charging state
|
|
|
static bool battery_discharge= false;
|
|
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
|
|
// 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;
|
|
charging_state = STATE_CC_CHARGING;
|
|
|
printf("CC CHARGING\n");
|
|
printf("CC CHARGING\n");
|
|
|
cv_charging_started = false;
|
|
cv_charging_started = false;
|
|
@@ -87,12 +90,16 @@ void CC_CV_UpdateChargingState(uint8_t slot_id) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 5. State Discharging condition
|
|
// 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);
|
|
DL_GPIO_clearPins(GPIO_Battery_Discharging_PORT, GPIO_Battery_Discharging_PIN_PB6_PIN);
|
|
|
charging_state = STATE_CC_CHARGING;
|
|
charging_state = STATE_CC_CHARGING;
|
|
|
cv_charging_started = false;
|
|
cv_charging_started = false;
|
|
|
battery_discharge= false;
|
|
battery_discharge= false;
|
|
|
printf("DISCHARGE -> CC CHARGING\n");
|
|
printf("DISCHARGE -> CC CHARGING\n");
|
|
|
|
|
+ }else{
|
|
|
|
|
+ charging_state= STATE_DISCHARGING;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//6. Check if the battery is overcharged
|
|
//6. Check if the battery is overcharged
|
|
@@ -181,16 +188,18 @@ void CC_CV_ControlCharging(uint8_t slot_id) {
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
if(cvChargingPhaseCurrent >= BATTERY_THRESHOLD){
|
|
if(cvChargingPhaseCurrent >= BATTERY_THRESHOLD){
|
|
|
- cvChargingPhaseCurrent-= 5;
|
|
|
|
|
|
|
+ printf("DAC CV Current: %d\n", cvChargingPhaseCurrent);
|
|
|
|
|
+ cvChargingPhaseCurrent-= 5;
|
|
|
}else{
|
|
}else{
|
|
|
|
|
+ printf("Battery Current: %d\n", batt_current);
|
|
|
chargeCurrent_initialized= false;
|
|
chargeCurrent_initialized= false;
|
|
|
battery_discharge= true;
|
|
battery_discharge= true;
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- controller_SetCurrent(slot_id, cvChargingPhaseCurrent);
|
|
|
|
|
last_voltage = batt_voltage;
|
|
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;
|
|
break;
|
|
|
|
|
|
|
|
case STATE_DISCHARGING:
|
|
case STATE_DISCHARGING:
|