|
|
@@ -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_L0_PORT, GPIO_Battery_Discharging_PIN_L0_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_0_PORT, GPIO_Battery_Charging_PIN_0_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_0_PORT, GPIO_Battery_Charging_PIN_0_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,19 +176,14 @@ 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_0_PORT, GPIO_Battery_Charging_PIN_0_PIN);
|
|
|
if(!chargeCurrent_initialized){
|
|
|
cvChargingPhaseCurrent= charge_current;
|
|
|
chargeCurrent_initialized= true;
|
|
|
}
|
|
|
//batt_cutoff_current: 75, BATTERY_THRESHOLD: 20
|
|
|
if (batt_current >= batt_cutoff_current + BATTERY_THRESHOLD) {
|
|
|
- // Detect steep voltage drop:
|
|
|
- /*if (last_voltage != 0 && (last_voltage - batt_voltage) > 250) {
|
|
|
- printf("!!! CV CHARGING: Voltage dropped too fast: %d -> %d mV.\n", last_voltage, batt_voltage);
|
|
|
- charging_state= STATE_ERROR;
|
|
|
- break;
|
|
|
- }*/
|
|
|
+
|
|
|
if(cvChargingPhaseCurrent >= batt_cutoff_current){
|
|
|
printf("DAC CV Current: %d\n", cvChargingPhaseCurrent);
|
|
|
cvChargingPhaseCurrent-= 5;
|
|
|
@@ -205,8 +200,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_0_PORT, GPIO_Battery_Charging_PIN_0_PIN);
|
|
|
+ DL_GPIO_setPins(GPIO_Battery_Discharging_PIN_L0_PORT, GPIO_Battery_Discharging_PIN_L0_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 +217,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_0_PORT, GPIO_Battery_Charging_PIN_0_PIN);
|
|
|
+ DL_GPIO_clearPins(GPIO_Battery_Discharging_PIN_L0_PORT, GPIO_Battery_Discharging_PIN_L0_PIN);
|
|
|
printf("Final Discharge with charge current:%d\n", charge_current);
|
|
|
controller_SetCurrent(slot_id, 0);
|
|
|
}else{
|
|
|
@@ -233,15 +228,15 @@ 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_0_PORT, GPIO_Battery_Charging_PIN_0_PIN);
|
|
|
+ DL_GPIO_clearPins(GPIO_Battery_Discharging_PIN_L0_PORT, GPIO_Battery_Discharging_PIN_L0_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_0_PORT, GPIO_Battery_Charging_PIN_0_PIN);
|
|
|
+ DL_GPIO_clearPins(GPIO_Battery_Discharging_PIN_L0_PORT, GPIO_Battery_Discharging_PIN_L0_PIN);
|
|
|
break;
|
|
|
|
|
|
default:
|