|
@@ -21,11 +21,8 @@ static int16_t batt_charge_discharge;
|
|
|
void CC_CV_UpdateChargingState(uint8_t slot_id) {
|
|
void CC_CV_UpdateChargingState(uint8_t slot_id) {
|
|
|
//static variable to keep a log on the transition during charging and dischrging phases
|
|
//static variable to keep a log on the transition during charging and dischrging phases
|
|
|
static ChargingState previous_state= STATE_IDLE;
|
|
static ChargingState previous_state= STATE_IDLE;
|
|
|
-
|
|
|
|
|
// Flag for CV charging, the charging mode flips back to CC mode
|
|
// Flag for CV charging, the charging mode flips back to CC mode
|
|
|
static bool cv_charging_started = false;
|
|
static bool cv_charging_started = false;
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
batt_voltage = battery_data[slot_id].battery_measurement.voltage;
|
|
batt_voltage = battery_data[slot_id].battery_measurement.voltage;
|
|
|
batt_current = battery_data[slot_id].battery_measurement.current;
|
|
batt_current = battery_data[slot_id].battery_measurement.current;
|
|
|
batt_min_voltage = battery_data[slot_id].min_voltage;
|
|
batt_min_voltage = battery_data[slot_id].min_voltage;
|
|
@@ -119,8 +116,8 @@ void CC_CV_ControlCharging(uint8_t slot_id, int16_t charge_current) {
|
|
|
// Calling function to get all the conditional states
|
|
// Calling function to get all the conditional states
|
|
|
CC_CV_UpdateChargingState(slot_id);
|
|
CC_CV_UpdateChargingState(slot_id);
|
|
|
|
|
|
|
|
- batt_voltage = battery_data[slot_id].battery_measurement.voltage;
|
|
|
|
|
- batt_current= battery_data[slot_id].battery_measurement.current;
|
|
|
|
|
|
|
+ //batt_voltage = battery_data[slot_id].battery_measurement.voltage;
|
|
|
|
|
+ //batt_current= battery_data[slot_id].battery_measurement.current;
|
|
|
batt_min_voltage= battery_data[slot_id].min_voltage;
|
|
batt_min_voltage= battery_data[slot_id].min_voltage;
|
|
|
batt_max_voltage= battery_data[slot_id].max_voltage;
|
|
batt_max_voltage= battery_data[slot_id].max_voltage;
|
|
|
batt_cutoff_current = battery_data[slot_id].cut_off_current;
|
|
batt_cutoff_current = battery_data[slot_id].cut_off_current;
|
|
@@ -139,7 +136,8 @@ void CC_CV_ControlCharging(uint8_t slot_id, int16_t charge_current) {
|
|
|
|
|
|
|
|
// 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_PB6_PIN);
|
|
|
|
|
|
|
+ //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);
|
|
|
controller_SetCurrent(TARGET_MCU_ADDRESS, slot_id, charge_current);
|
|
controller_SetCurrent(TARGET_MCU_ADDRESS, slot_id, charge_current);
|
|
|
if (true) {
|
|
if (true) {
|
|
|
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);
|
|
@@ -149,7 +147,7 @@ void CC_CV_ControlCharging(uint8_t slot_id, int16_t charge_current) {
|
|
|
// 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-BATTERY_THRESHOLD)= 4150 mVolts
|
|
// reaches to (MAXIMUM_VOLTAGE-BATTERY_THRESHOLD)= 4150 mVolts
|
|
|
case STATE_CC_CHARGING:
|
|
case STATE_CC_CHARGING:
|
|
|
-
|
|
|
|
|
|
|
+ DL_GPIO_setPins(GPIO_Battery_Discharging_PORT, GPIO_Battery_Discharging_PIN_PB7_PIN);
|
|
|
controller_SetCurrent(TARGET_MCU_ADDRESS, slot_id, charge_current);
|
|
controller_SetCurrent(TARGET_MCU_ADDRESS, 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);
|
|
|
break;
|
|
break;
|
|
@@ -157,6 +155,7 @@ void CC_CV_ControlCharging(uint8_t slot_id, int16_t charge_current) {
|
|
|
// 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 exceeds (CUTOFF_CURRENT_MA + BATTERY_THRESHOLD)= 290 mAs
|
|
// decreases till it exceeds (CUTOFF_CURRENT_MA + BATTERY_THRESHOLD)= 290 mAs
|
|
|
case STATE_CV_CHARGING:
|
|
case STATE_CV_CHARGING:
|
|
|
|
|
+ DL_GPIO_setPins(GPIO_Battery_Discharging_PORT, GPIO_Battery_Discharging_PIN_PB7_PIN);
|
|
|
if (batt_current >= batt_cutoff_current + BATTERY_THRESHOLD) {
|
|
if (batt_current >= batt_cutoff_current + BATTERY_THRESHOLD) {
|
|
|
// Detect steep voltage drop:
|
|
// Detect steep voltage drop:
|
|
|
if (last_voltage != 0 && (last_voltage - batt_voltage) > 100) {
|
|
if (last_voltage != 0 && (last_voltage - batt_voltage) > 100) {
|
|
@@ -173,13 +172,13 @@ void CC_CV_ControlCharging(uint8_t slot_id, int16_t charge_current) {
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
case STATE_DISCHARGING:
|
|
case STATE_DISCHARGING:
|
|
|
- //DL_GPIO_clearPins(GPIO_Battery_Charging_PORT, GPIO_Battery_Charging_PIN_PB6_PIN);
|
|
|
|
|
|
|
+ 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_Discharging_PORT, GPIO_Battery_Discharging_PIN_PB7_PIN);
|
|
|
controller_SetCurrent(TARGET_MCU_ADDRESS, slot_id, charge_current);
|
|
controller_SetCurrent(TARGET_MCU_ADDRESS, slot_id, 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);
|
|
|
|
|
|
|
|
//Safety Check
|
|
//Safety Check
|
|
|
- if(batt_voltage<batt_min_voltage){
|
|
|
|
|
|
|
+ if(batt_voltage< batt_min_voltage){
|
|
|
charging_state= STATE_ERROR;
|
|
charging_state= STATE_ERROR;
|
|
|
printf("ERROR: Battery voltage below minimum voltage during discharge\n");
|
|
printf("ERROR: Battery voltage below minimum voltage during discharge\n");
|
|
|
}
|
|
}
|