|
@@ -3,6 +3,8 @@
|
|
|
#include "src/battery_data/battery.h"
|
|
#include "src/battery_data/battery.h"
|
|
|
#include <stdio.h>
|
|
#include <stdio.h>
|
|
|
#include "ti/driverlib/dl_gpio.h"
|
|
#include "ti/driverlib/dl_gpio.h"
|
|
|
|
|
+#include "ti_msp_dl_config.h"
|
|
|
|
|
+#include "src/controller/controller.h"
|
|
|
|
|
|
|
|
static ChargingState charging_state= STATE_IDLE;
|
|
static ChargingState charging_state= STATE_IDLE;
|
|
|
static uint16_t cycle_count = 0;
|
|
static uint16_t cycle_count = 0;
|
|
@@ -111,7 +113,6 @@ void CC_CV_ControlCharging(uint8_t slot_id, int16_t charge_current) {
|
|
|
batt_cutoff_current = battery_data[slot_id].battery_limits.cut_off_current;
|
|
batt_cutoff_current = battery_data[slot_id].battery_limits.cut_off_current;
|
|
|
batt_capacitance= battery_data[slot_id].battery_limits.capacitance;
|
|
batt_capacitance= battery_data[slot_id].battery_limits.capacitance;
|
|
|
batt_charge_discharge= battery_data[slot_id].charge_discharge;
|
|
batt_charge_discharge= battery_data[slot_id].charge_discharge;
|
|
|
-
|
|
|
|
|
|
|
|
|
|
// DAC channel value:
|
|
// 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)
|
|
// dac_channel_value is for CV mode where the charge current is calibrated till battery current is less than (cutoff current+threshold)
|
|
@@ -125,11 +126,10 @@ 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_PB4_PIN);
|
|
DL_GPIO_setPins(GPIO_Battery_Charging_PORT, GPIO_Battery_Charging_PIN_PB4_PIN);
|
|
|
- controller_SetCurrent(TARGET_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, );
|
|
|
|
|
|
|
+ printf("PRE CHARGING: Slot %d at %d mA.\n", slot_id, charge_current);
|
|
|
}
|
|
}
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
@@ -137,7 +137,7 @@ void CC_CV_ControlCharging(uint8_t slot_id, int16_t charge_current) {
|
|
|
// reaches to (MAXIMUM_VOLTAGE-BATTERY_THRESHOLD)= 4150 mVolts
|
|
// reaches to (MAXIMUM_VOLTAGE-BATTERY_THRESHOLD)= 4150 mVolts
|
|
|
case STATE_CC_CHARGING:
|
|
case STATE_CC_CHARGING:
|
|
|
|
|
|
|
|
- controller_SetCurrent(TARGET_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;
|
|
|
|
|
|
|
@@ -154,22 +154,22 @@ void CC_CV_ControlCharging(uint8_t slot_id, int16_t charge_current) {
|
|
|
dac_initialized= false;
|
|
dac_initialized= false;
|
|
|
}
|
|
}
|
|
|
last_voltage = batt_voltage;
|
|
last_voltage = batt_voltage;
|
|
|
- controller_SetCurrent(TARGET_ADDRESS, slot_id, charge_current);
|
|
|
|
|
|
|
+ controller_SetCurrent(TARGET_MCU_ADDRESS, slot_id, charge_current);
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
case STATE_DISCHARGING:
|
|
case STATE_DISCHARGING:
|
|
|
DL_GPIO_clearPins(GPIO_Battery_Charging_PORT, GPIO_Battery_Charging_PIN_PB4_PIN);
|
|
DL_GPIO_clearPins(GPIO_Battery_Charging_PORT, GPIO_Battery_Charging_PIN_PB4_PIN);
|
|
|
DL_GPIO_setPins(GPIO_Battery_Discharging_PORT, GPIO_Battery_Discharging_PIN_PB12_PIN);
|
|
DL_GPIO_setPins(GPIO_Battery_Discharging_PORT, GPIO_Battery_Discharging_PIN_PB12_PIN);
|
|
|
- controller_SetCurrent(TARGET_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_voltage);
|
|
printf("DISCHARGING: Slot %d at %d mA.\n", slot_id, batt_voltage);
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
case STATE_FINAL_DISCHARGE:
|
|
case STATE_FINAL_DISCHARGE:
|
|
|
//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"
|
|
|
- batteries[slot_id].state= STATE_MEASUREMENT_DONE;
|
|
|
|
|
|
|
+ battery_data[slot_id].battery_state= STATE_MEASUREMENT_DONE;
|
|
|
DL_GPIO_clearPins(GPIO_Battery_Charging_PORT, GPIO_Battery_Charging_PIN_PB4_PIN);
|
|
DL_GPIO_clearPins(GPIO_Battery_Charging_PORT, GPIO_Battery_Charging_PIN_PB4_PIN);
|
|
|
DL_GPIO_clearPins(GPIO_Battery_Discharging_PORT, GPIO_Battery_Discharging_PIN_PB12_PIN);
|
|
DL_GPIO_clearPins(GPIO_Battery_Discharging_PORT, GPIO_Battery_Discharging_PIN_PB12_PIN);
|
|
|
- controller_SetCurrent(TARGET_ADDRESS, slot_id, 0);
|
|
|
|
|
|
|
+ controller_SetCurrent(TARGET_MCU_ADDRESS, slot_id, 0);
|
|
|
charging_state = STATE_IDLE;
|
|
charging_state = STATE_IDLE;
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
@@ -184,7 +184,7 @@ void CC_CV_ControlCharging(uint8_t slot_id, int16_t charge_current) {
|
|
|
DL_GPIO_clearPins(GPIO_Battery_Discharging_PORT, GPIO_Battery_Discharging_PIN_PB12_PIN);
|
|
DL_GPIO_clearPins(GPIO_Battery_Discharging_PORT, GPIO_Battery_Discharging_PIN_PB12_PIN);
|
|
|
charging_state = STATE_PRE_CHARGE;
|
|
charging_state = STATE_PRE_CHARGE;
|
|
|
break;
|
|
break;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
default:
|
|
default:
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|