|
|
@@ -7,7 +7,7 @@
|
|
|
#include "src/controller/controller.h"
|
|
|
|
|
|
|
|
|
-//w 3000 4200 20 2000 75 0
|
|
|
+//Pi: Battery Limits:: w 3000 4200 20 2000 75 0
|
|
|
|
|
|
static BatteryChargingState charging_state= STATE_IDLE; //Default value of the charging state
|
|
|
static bool battery_discharge= false;
|
|
|
@@ -81,7 +81,6 @@ void CC_CV_UpdateChargingState(uint8_t slot_id) {
|
|
|
else if(charging_state== STATE_CV_CHARGING && battery_discharge== true){
|
|
|
if(*cycle_count < MAX_CYCLES){
|
|
|
charging_state= STATE_DISCHARGING;
|
|
|
- (*cycle_count)++;
|
|
|
cv_charging_started= false;
|
|
|
printf("Transition to DISCHARGING, new cycle: %d\n", battery->cycle_number);
|
|
|
}else {
|
|
|
@@ -94,6 +93,7 @@ void CC_CV_UpdateChargingState(uint8_t slot_id) {
|
|
|
if(batt_voltage <= batt_min_voltage + BATTERY_THRESHOLD){
|
|
|
DL_GPIO_clearPins(GPIO_Battery_Discharging_PORT, GPIO_Battery_Discharging_PIN_PB6_PIN);
|
|
|
charging_state = STATE_CC_CHARGING;
|
|
|
+ (*cycle_count)++;
|
|
|
cv_charging_started = false;
|
|
|
battery_discharge= false;
|
|
|
printf("DISCHARGE -> CC CHARGING\n");
|
|
|
@@ -113,7 +113,7 @@ void CC_CV_UpdateChargingState(uint8_t slot_id) {
|
|
|
// CV_STATE was jumping directly to STATE_ERROR in else statement, to handle
|
|
|
// the condition better, else condition is being changed).
|
|
|
else {
|
|
|
- printf("[CC-CV] Current state: Voltage= %d mV, Current= %d mA\n, Current Cycle= %d\n",
|
|
|
+ printf("[CC-CV] Current state: Voltage= %d mV, Current= %d mA\n, Current Cycle= %c\n",
|
|
|
batt_voltage, batt_current, charging_state);
|
|
|
}
|
|
|
}
|
|
|
@@ -133,7 +133,6 @@ void CC_CV_ControlCharging(uint8_t slot_id) {
|
|
|
// Calling function to get all the conditional states
|
|
|
CC_CV_UpdateChargingState(slot_id);
|
|
|
|
|
|
- int16_t charge_current= 100;
|
|
|
// DAC channel value:
|
|
|
// dac_channel_value is for CV mode where the charge current is calibrated till battery current is less than (cutoff current+threshold)
|
|
|
// Adding a variable to check the stepness in the voltage drop in CV charging
|
|
|
@@ -151,8 +150,11 @@ void CC_CV_ControlCharging(uint8_t slot_id) {
|
|
|
uint16_t batt_max_voltage = battery->max_voltage;
|
|
|
uint8_t batt_cutoff_current = battery->cut_off_current;
|
|
|
uint16_t batt_capacitance = battery->capacitance;
|
|
|
-
|
|
|
+ uint8_t charge_fraction= battery->charge_fraction;
|
|
|
|
|
|
+ //setting charge and discharge current:
|
|
|
+ int16_t charge_current= 100;
|
|
|
+
|
|
|
switch (charging_state) {
|
|
|
// PRE CHARGE STATE: Battery Voltage is lesser than 3000 mVolts
|
|
|
case STATE_PRE_CHARGE:
|
|
|
@@ -182,14 +184,15 @@ void CC_CV_ControlCharging(uint8_t slot_id) {
|
|
|
//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) {
|
|
|
+ /*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 >= BATTERY_THRESHOLD){
|
|
|
printf("DAC CV Current: %d\n", cvChargingPhaseCurrent);
|
|
|
- cvChargingPhaseCurrent-= 5;
|
|
|
+ cvChargingPhaseCurrent-= 5;
|
|
|
+ controller_SetCurrent(slot_id, cvChargingPhaseCurrent);
|
|
|
}else{
|
|
|
printf("Battery Current: %d\n", batt_current);
|
|
|
chargeCurrent_initialized= false;
|
|
|
@@ -198,7 +201,6 @@ void CC_CV_ControlCharging(uint8_t slot_id) {
|
|
|
}
|
|
|
}
|
|
|
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;
|
|
|
|
|
|
@@ -216,12 +218,17 @@ void CC_CV_ControlCharging(uint8_t slot_id) {
|
|
|
break;
|
|
|
|
|
|
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_PB7_PIN);
|
|
|
- DL_GPIO_clearPins(GPIO_Battery_Discharging_PORT, GPIO_Battery_Discharging_PIN_PB6_PIN);
|
|
|
- controller_SetCurrent(slot_id, 0);
|
|
|
- charging_state = STATE_IDLE;
|
|
|
+ //IF atleast 3.8 Volts is maintained for healthy battery state, then Final discharge state, ELSE go back to the CC Charging to charge the battery:
|
|
|
+ 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);
|
|
|
+ printf("Final Discharge with charge current:%d\n", charge_current);
|
|
|
+ controller_SetCurrent(slot_id, 0);
|
|
|
+ }else{
|
|
|
+ charging_state= STATE_CC_CHARGING;
|
|
|
+ }
|
|
|
chargeCurrent_initialized= false;
|
|
|
break;
|
|
|
|
|
|
@@ -235,8 +242,6 @@ void CC_CV_ControlCharging(uint8_t slot_id) {
|
|
|
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);
|
|
|
- //charging_state = STATE_PRE_CHARGE;
|
|
|
- chargeCurrent_initialized= false;
|
|
|
break;
|
|
|
|
|
|
default:
|