|
@@ -91,7 +91,7 @@ void CC_CV_UpdateChargingState(uint8_t slot_id) {
|
|
|
// 5. State Discharging condition
|
|
// 5. State Discharging condition
|
|
|
else if (charging_state == STATE_DISCHARGING){
|
|
else if (charging_state == STATE_DISCHARGING){
|
|
|
if(batt_voltage <= batt_min_voltage + BATTERY_THRESHOLD){
|
|
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;
|
|
charging_state = STATE_CC_CHARGING;
|
|
|
(*cycle_count)++;
|
|
(*cycle_count)++;
|
|
|
cv_charging_started = false;
|
|
cv_charging_started = false;
|
|
@@ -158,7 +158,7 @@ void CC_CV_ControlCharging(uint8_t slot_id) {
|
|
|
switch (charging_state) {
|
|
switch (charging_state) {
|
|
|
// PRE CHARGE STATE: Battery Voltage is lesser than 3000 mVolts
|
|
// PRE CHARGE STATE: Battery Voltage is lesser than 3000 mVolts
|
|
|
case STATE_PRE_CHARGE:
|
|
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);
|
|
controller_SetCurrent(slot_id, charge_current);
|
|
|
printf("PRE CHARGING: Slot %d at %d mA.\n", slot_id, charge_current);
|
|
printf("PRE CHARGING: Slot %d at %d mA.\n", slot_id, charge_current);
|
|
|
chargeCurrent_initialized= false;
|
|
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
|
|
// CC CHARGING STATE: Keeps on checking the condition until battery voltage
|
|
|
// reaches to (MAXIMUM_VOLTAGE(4200)-BATTERY_THRESHOLD(20))= 4180 mV
|
|
// reaches to (MAXIMUM_VOLTAGE(4200)-BATTERY_THRESHOLD(20))= 4180 mV
|
|
|
case STATE_CC_CHARGING:
|
|
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);
|
|
controller_SetCurrent(slot_id, charge_current);
|
|
|
printf("CC CHARGING: Slot %d, Current: %d mA, Voltage: %d mV.\n", slot_id, batt_current, batt_voltage);
|
|
printf("CC CHARGING: Slot %d, Current: %d mA, Voltage: %d mV.\n", slot_id, batt_current, batt_voltage);
|
|
|
chargeCurrent_initialized= false;
|
|
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
|
|
// CV CHARGING STATE: Keeps on checking the condition until battery current
|
|
|
// decreases till it lowers to (CUTOFF_CURRENT_MA + BATTERY_THRESHOLD)
|
|
// decreases till it lowers to (CUTOFF_CURRENT_MA + BATTERY_THRESHOLD)
|
|
|
case STATE_CV_CHARGING:
|
|
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){
|
|
if(!chargeCurrent_initialized){
|
|
|
cvChargingPhaseCurrent= charge_current;
|
|
cvChargingPhaseCurrent= charge_current;
|
|
|
chargeCurrent_initialized= true;
|
|
chargeCurrent_initialized= true;
|
|
@@ -205,8 +205,8 @@ void CC_CV_ControlCharging(uint8_t slot_id) {
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
case STATE_DISCHARGING:
|
|
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));
|
|
controller_SetCurrent(slot_id, (-1 * charge_current));
|
|
|
printf("DISCHARGING: Slot %d at %d mA.\n", slot_id, batt_current);
|
|
printf("DISCHARGING: Slot %d at %d mA.\n", slot_id, batt_current);
|
|
|
chargeCurrent_initialized= false;
|
|
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)){
|
|
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"
|
|
//Once the cycle gets done, the battery state transitions to "STATE_MEASUREMENT_DONE"
|
|
|
battery_data[slot_id].battery_state= 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);
|
|
printf("Final Discharge with charge current:%d\n", charge_current);
|
|
|
controller_SetCurrent(slot_id, 0);
|
|
controller_SetCurrent(slot_id, 0);
|
|
|
}else{
|
|
}else{
|
|
@@ -233,15 +233,36 @@ void CC_CV_ControlCharging(uint8_t slot_id) {
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
case STATE_ERROR:
|
|
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);
|
|
printf("ERROR: Slot %d.\n", slot_id);
|
|
|
chargeCurrent_initialized= false;
|
|
chargeCurrent_initialized= false;
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
case STATE_IDLE:
|
|
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;
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
default:
|