|
|
@@ -23,8 +23,9 @@ static uint16_t batt_cutoff_current;
|
|
|
static uint16_t batt_capacitance;
|
|
|
static int16_t batt_charge_discharge;
|
|
|
static uint8_t previous_cycle_number;
|
|
|
-// Functions for Charging and Discharging State
|
|
|
|
|
|
+
|
|
|
+// Functions for Charging and Discharging State
|
|
|
void CC_CV_UpdateChargingState(uint8_t slot_id) {
|
|
|
//static variable to keep a log on the transition during charging and discharging phases
|
|
|
static BatteryChargingState previous_state= STATE_IDLE;
|
|
|
@@ -102,7 +103,7 @@ void CC_CV_UpdateChargingState(uint8_t slot_id) {
|
|
|
|
|
|
else if (charging_state == STATE_DISCHARGING &&
|
|
|
batt_voltage <= batt_min_voltage + BATTERY_THRESHOLD) {
|
|
|
- DL_GPIO_clearPins(GPIO_Battery_Discharging_PORT, GPIO_Battery_Discharging_PIN_PB7_PIN);
|
|
|
+ DL_GPIO_clearPins(GPIO_Battery_Discharging_PORT, GPIO_Battery_Discharging_PIN_PB6_PIN);
|
|
|
charging_state = STATE_CC_CHARGING;
|
|
|
cv_charging_started = false;
|
|
|
}
|
|
|
@@ -156,8 +157,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_Discharging_PORT, GPIO_Battery_Discharging_PIN_PB7_PIN);
|
|
|
+
|
|
|
+ DL_GPIO_setPins(GPIO_Battery_Charging_PORT, GPIO_Battery_Charging_PIN_PB7_PIN);
|
|
|
controller_SetCurrent(TARGET_BASE_ADDRESS, slot_id, charge_current);
|
|
|
if (true) {
|
|
|
printf("PRE CHARGING: Slot %d at %d mA.\n", slot_id, charge_current);
|
|
|
@@ -167,7 +168,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);
|
|
|
+ DL_GPIO_setPins(GPIO_Battery_Charging_PORT, GPIO_Battery_Charging_PIN_PB7_PIN);
|
|
|
controller_SetCurrent(TARGET_BASE_ADDRESS, slot_id, charge_current);
|
|
|
printf("CC CHARGING: Slot %d, Current: %d mA, Voltage: %d mV.\n", slot_id, batt_current, batt_voltage);
|
|
|
break;
|
|
|
@@ -175,7 +176,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);
|
|
|
+ DL_GPIO_setPins(GPIO_Battery_Charging_PORT, GPIO_Battery_Charging_PIN_PB7_PIN);
|
|
|
if (batt_current >= batt_cutoff_current + BATTERY_THRESHOLD) {
|
|
|
// Detect steep voltage drop:
|
|
|
if (last_voltage != 0 && (last_voltage - batt_voltage) > 100) {
|
|
|
@@ -192,8 +193,8 @@ void CC_CV_ControlCharging(uint8_t slot_id, int16_t charge_current) {
|
|
|
break;
|
|
|
|
|
|
case STATE_DISCHARGING:
|
|
|
- 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);
|
|
|
+ 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);
|
|
|
//controller_EvaluateBatterySlotState(slot_id, BatteryMeasurement *measurement);
|
|
|
controller_SetCurrent(TARGET_BASE_ADDRESS, slot_id, charge_current);
|
|
|
printf("DISCHARGING: Slot %d at %d mA.\n", slot_id, batt_current);
|
|
|
@@ -208,21 +209,21 @@ void CC_CV_ControlCharging(uint8_t slot_id, int16_t charge_current) {
|
|
|
case STATE_FINAL_DISCHARGE:
|
|
|
//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_PB6_PIN);
|
|
|
- DL_GPIO_clearPins(GPIO_Battery_Discharging_PORT, GPIO_Battery_Discharging_PIN_PB7_PIN);
|
|
|
+ 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);
|
|
|
controller_SetCurrent(TARGET_BASE_ADDRESS, slot_id, 0);
|
|
|
charging_state = STATE_IDLE;
|
|
|
break;
|
|
|
|
|
|
case STATE_ERROR:
|
|
|
- DL_GPIO_clearPins(GPIO_Battery_Charging_PORT, GPIO_Battery_Charging_PIN_PB6_PIN);
|
|
|
- DL_GPIO_clearPins(GPIO_Battery_Discharging_PORT, GPIO_Battery_Discharging_PIN_PB7_PIN);
|
|
|
+ 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);
|
|
|
printf("ERROR: Slot %d.\n", slot_id);
|
|
|
break;
|
|
|
|
|
|
case STATE_IDLE:
|
|
|
- DL_GPIO_clearPins(GPIO_Battery_Charging_PORT, GPIO_Battery_Charging_PIN_PB6_PIN);
|
|
|
- DL_GPIO_clearPins(GPIO_Battery_Discharging_PORT, GPIO_Battery_Discharging_PIN_PB7_PIN);
|
|
|
+ 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);
|
|
|
//charging_state = STATE_PRE_CHARGE;
|
|
|
break;
|
|
|
|