|
|
@@ -2,6 +2,7 @@
|
|
|
#include "ti/driverlib/dl_i2c.h"
|
|
|
#include "ti_msp_dl_config.h"
|
|
|
|
|
|
+
|
|
|
Battery batteries[NUM_SLOTS];
|
|
|
|
|
|
// Permissible charge temperature for LiIon battery is 0.0 degree Celsius to 45.0 degree Celsius
|
|
|
@@ -23,19 +24,54 @@ void Battery_Init(){
|
|
|
batteries[i].max_voltage= 0;
|
|
|
batteries[i].cut_off_current= 0;
|
|
|
batteries[i].capacitance= 0;
|
|
|
-
|
|
|
+ batteries[i].charge_fraction= 0;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void Battery_SafetyCheck(uint8_t slot){
|
|
|
- if(slot>= NUM_SLOTS){
|
|
|
- return;
|
|
|
- }
|
|
|
+void Battery_Discharge_SafetyCheck(uint8_t slot_id){
|
|
|
+ //As of now declared a varaible with 0, in future it will call a function to read the output volatge of the boost converter
|
|
|
+ uint16_t boost_vout_mv= 0;
|
|
|
+ DischargeSafetyCondition condition;
|
|
|
+ Battery *battery= &batteries[slot_id];
|
|
|
|
|
|
- if (batteries[slot].temperature > TEMP_THRESHOLD){
|
|
|
- batteries[slot].state= STATE_OVERCHARGING;
|
|
|
- //How to exit? Disable the DAC channel?
|
|
|
+ if(battery->temperature > TEMPERATURE_MAX_C){
|
|
|
+ battery->condition= STATE_OVERTEMPERATURE;
|
|
|
+
|
|
|
+ }
|
|
|
+ //if battery
|
|
|
+ else if(boost_vout_mv >= BOOST_HOV_THRESHOLD_MV-HYSTERISIS){
|
|
|
+ battery->condition= STATE_HOV;
|
|
|
+ }
|
|
|
+ else if(boost_vout_mv <= BOOST_SOV_THRESHOLD_MV-HYSTERISIS){
|
|
|
+ battery->condition= STATE_SOV;
|
|
|
}
|
|
|
+ else{
|
|
|
+ battery->condition= STATE_OK;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void Battery_ReadState(uint8_t slot_id) {
|
|
|
+
|
|
|
+ uint16_t voltage_mv = batteries[slot_id].voltage;
|
|
|
+ uint16_t min_voltage = batteries[slot_id].min_voltage;
|
|
|
+ uint16_t max_voltage = batteries[slot_id].max_voltage;
|
|
|
+
|
|
|
+ /*
|
|
|
+ Added another state: STATE_WAITING_FOR_LIMITS (0x03) so that Pi is aware that battery limits needs to be sent to the MCU
|
|
|
+ */
|
|
|
+ if(min_voltage == 0 || max_voltage == 0){
|
|
|
+ batteries[slot_id].state= STATE_WAITING_FOR_LIMITS;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (voltage_mv < BATTERY_THRESHOLD) {
|
|
|
+ batteries[slot_id].state = STATE_EMPTY;
|
|
|
+ } else if (voltage_mv >= BATTERY_THRESHOLD && voltage_mv < min_voltage) {
|
|
|
+ batteries[slot_id].state = STATE_BATTERY_DETECTED;
|
|
|
+ } else if (voltage_mv >= min_voltage && voltage_mv < max_voltage) {
|
|
|
+ batteries[slot_id].state = STATE_MEASUREMENT_IN_PROGRESS;
|
|
|
+ } else {
|
|
|
+ batteries[slot_id].state = STATE_OVERHEATING;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|