Temperature compensation for charging target voltage added
This commit is contained in:
@@ -40,6 +40,11 @@ void battery_conf_init(battery_conf_t *bat, bat_type type, int num_cells, float
|
||||
bat->time_limit_recharge = 60; // sec
|
||||
bat->time_limit_CV = 120*60; // sec
|
||||
|
||||
bat->charge_temp_max = 50;
|
||||
bat->charge_temp_min = -10;
|
||||
bat->discharge_temp_max = 50;
|
||||
bat->discharge_temp_min = -10;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case BAT_TYPE_FLOODED:
|
||||
@@ -97,6 +102,7 @@ void battery_conf_init(battery_conf_t *bat, bat_type type, int num_cells, float
|
||||
bat->trickle_enabled = false;
|
||||
bat->equalization_enabled = false;
|
||||
bat->temperature_compensation = 0.0;
|
||||
bat->charge_temp_min = 0;
|
||||
break;
|
||||
|
||||
case BAT_TYPE_NMC:
|
||||
@@ -118,6 +124,7 @@ void battery_conf_init(battery_conf_t *bat, bat_type type, int num_cells, float
|
||||
bat->trickle_enabled = false;
|
||||
bat->equalization_enabled = false;
|
||||
bat->temperature_compensation = 0.0;
|
||||
bat->charge_temp_min = 0;
|
||||
break;
|
||||
|
||||
case BAT_TYPE_NONE:
|
||||
@@ -177,6 +184,10 @@ void battery_conf_overwrite(battery_conf_t *source, battery_conf_t *destination,
|
||||
destination->trickle_enabled = source->trickle_enabled;
|
||||
destination->voltage_trickle = source->voltage_trickle;
|
||||
destination->time_trickle_recharge = source->time_trickle_recharge;
|
||||
destination->charge_temp_max = source->charge_temp_max;
|
||||
destination->charge_temp_min = source->charge_temp_min;
|
||||
destination->discharge_temp_max = source->discharge_temp_max;
|
||||
destination->discharge_temp_min = source->discharge_temp_min;
|
||||
destination->temperature_compensation = source->temperature_compensation;
|
||||
destination->internal_resistance = source->internal_resistance;
|
||||
destination->wire_resistance = source->wire_resistance;
|
||||
|
||||
+18
-4
@@ -192,11 +192,25 @@ typedef struct
|
||||
float ocv_full;
|
||||
float ocv_empty;
|
||||
|
||||
/** Voltage compensation based on battery temperature
|
||||
/** Maximum allowed charging temperature of the battery (°C)
|
||||
*/
|
||||
float charge_temp_max;
|
||||
|
||||
/** Minimum allowed charging temperature of the battery (°C)
|
||||
*/
|
||||
float charge_temp_min;
|
||||
|
||||
/** Maximum allowed discharging temperature of the battery (°C)
|
||||
*/
|
||||
float discharge_temp_max;
|
||||
|
||||
/** Minimum allowed discharging temperature of the battery (°C)
|
||||
*/
|
||||
float discharge_temp_min;
|
||||
|
||||
/** Voltage compensation based on battery temperature (mV/K/cell)
|
||||
*
|
||||
* Suggested value: -3 mV/°C/cell
|
||||
*
|
||||
* TODO: Not yet implemented
|
||||
* Suggested value: -3 mV/K/cell
|
||||
*/
|
||||
float temperature_compensation;
|
||||
|
||||
|
||||
+35
-8
@@ -34,8 +34,8 @@ void charger_state_machine(power_port_t *port, battery_conf_t *bat_conf, battery
|
||||
|
||||
// Load management
|
||||
// battery port input state (i.e. battery discharging direction) defines load state
|
||||
if (port->input_allowed == true &&
|
||||
voltage < bat_conf->voltage_load_disconnect - current * port->droop_res_input)
|
||||
if (port->input_allowed == true
|
||||
&& voltage < bat_conf->voltage_load_disconnect - current * port->droop_res_input)
|
||||
{
|
||||
port->input_allowed = false;
|
||||
bat_state->num_deep_discharges++;
|
||||
@@ -50,17 +50,37 @@ void charger_state_machine(power_port_t *port, battery_conf_t *bat_conf, battery
|
||||
// simple SOH estimation
|
||||
bat_state->soh = bat_state->usable_capacity / bat_conf->nominal_capacity;
|
||||
}
|
||||
if (voltage >= bat_conf->voltage_load_reconnect - current * port->droop_res_input) {
|
||||
else if (port->input_allowed == true
|
||||
&& (bat_state->temperature > bat_conf->discharge_temp_max
|
||||
|| bat_state->temperature < bat_conf->discharge_temp_min))
|
||||
{
|
||||
port->input_allowed = false;
|
||||
}
|
||||
|
||||
if (voltage >= bat_conf->voltage_load_reconnect - current * port->droop_res_input
|
||||
&& bat_state->temperature < bat_conf->discharge_temp_max - 1
|
||||
&& bat_state->temperature > bat_conf->discharge_temp_min + 1)
|
||||
{
|
||||
port->input_allowed = true;
|
||||
}
|
||||
|
||||
// check battery temperature
|
||||
if (bat_state->temperature > bat_conf->charge_temp_max
|
||||
|| bat_state->temperature < bat_conf->charge_temp_min)
|
||||
{
|
||||
port->output_allowed = false;
|
||||
_enter_state(bat_state, CHG_STATE_IDLE);
|
||||
}
|
||||
|
||||
// state machine
|
||||
switch (bat_state->chg_state) {
|
||||
case CHG_STATE_IDLE: {
|
||||
if (voltage < bat_conf->voltage_recharge
|
||||
&& (time(NULL) - bat_state->time_state_changed) > bat_conf->time_limit_recharge)
|
||||
&& (time(NULL) - bat_state->time_state_changed) > bat_conf->time_limit_recharge
|
||||
&& bat_state->temperature < bat_conf->charge_temp_max - 1
|
||||
&& bat_state->temperature > bat_conf->charge_temp_min + 1)
|
||||
{
|
||||
port->voltage_output_target = bat_conf->voltage_max;
|
||||
port->voltage_output_target = bat_conf->voltage_max + bat_conf->temperature_compensation * (bat_state->temperature - 25);
|
||||
port->current_output_max = bat_conf->charge_current_max;
|
||||
port->output_allowed = true;
|
||||
bat_state->full = false;
|
||||
@@ -69,13 +89,18 @@ void charger_state_machine(power_port_t *port, battery_conf_t *bat_conf, battery
|
||||
break;
|
||||
}
|
||||
case CHG_STATE_BULK: {
|
||||
// continuously adjust voltage setting for temperature compensation
|
||||
port->voltage_output_target = bat_conf->voltage_max + bat_conf->temperature_compensation * (bat_state->temperature - 25);
|
||||
|
||||
if (voltage > port->voltage_output_target - current * port->droop_res_output) {
|
||||
port->voltage_output_target = bat_conf->voltage_max;
|
||||
_enter_state(bat_state, CHG_STATE_TOPPING);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case CHG_STATE_TOPPING: {
|
||||
// continuously adjust voltage setting for temperature compensation
|
||||
port->voltage_output_target = bat_conf->voltage_max + bat_conf->temperature_compensation * (bat_state->temperature - 25);
|
||||
|
||||
if (voltage >= port->voltage_output_target - current * port->droop_res_output) {
|
||||
bat_state->time_voltage_limit_reached = time(NULL);
|
||||
}
|
||||
@@ -96,7 +121,7 @@ void charger_state_machine(power_port_t *port, battery_conf_t *bat_conf, battery
|
||||
_enter_state(bat_state, CHG_STATE_EQUALIZATION);
|
||||
}
|
||||
else */if (bat_conf->trickle_enabled) {
|
||||
port->voltage_output_target = bat_conf->voltage_trickle;
|
||||
port->voltage_output_target = bat_conf->voltage_trickle + bat_conf->temperature_compensation * (bat_state->temperature - 25);
|
||||
_enter_state(bat_state, CHG_STATE_TRICKLE);
|
||||
}
|
||||
else {
|
||||
@@ -108,6 +133,9 @@ void charger_state_machine(power_port_t *port, battery_conf_t *bat_conf, battery
|
||||
break;
|
||||
}
|
||||
case CHG_STATE_TRICKLE: {
|
||||
// continuously adjust voltage setting for temperature compensation
|
||||
port->voltage_output_target = bat_conf->voltage_trickle + bat_conf->temperature_compensation * (bat_state->temperature - 25);
|
||||
|
||||
if (voltage >= port->voltage_output_target - current * port->droop_res_output) {
|
||||
bat_state->time_voltage_limit_reached = time(NULL);
|
||||
}
|
||||
@@ -115,7 +143,6 @@ void charger_state_machine(power_port_t *port, battery_conf_t *bat_conf, battery
|
||||
if (time(NULL) - bat_state->time_voltage_limit_reached > bat_conf->time_trickle_recharge)
|
||||
{
|
||||
port->current_output_max = bat_conf->charge_current_max;
|
||||
port->voltage_output_target = bat_conf->voltage_max;
|
||||
bat_state->full = false;
|
||||
_enter_state(bat_state, CHG_STATE_BULK);
|
||||
}
|
||||
|
||||
@@ -88,18 +88,22 @@ const data_object_t data_objects[] = {
|
||||
//{0x3B, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 2, (void*) &(bat_conf_user.voltage_equalization), "Equal_V"},
|
||||
// 0x3A-0x3E reserved for equalization charging
|
||||
{0x3F, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 2, (void*) &(bat_conf_user.temperature_compensation), "TempFactor"},
|
||||
|
||||
{0x50, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 3, (void*) &(bat_conf_user.internal_resistance), "BatInt_Ohm"},
|
||||
{0x51, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 3, (void*) &(bat_conf_user.wire_resistance), "BatWire_Ohm"},
|
||||
{0x52, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 1, (void*) &(bat_conf_user.charge_temp_max), "BatChgMax_degC"},
|
||||
{0x53, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 1, (void*) &(bat_conf_user.charge_temp_min), "BatChgMin_degC"},
|
||||
{0x54, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 1, (void*) &(bat_conf_user.discharge_temp_max), "BatDisMax_degC"},
|
||||
{0x55, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 1, (void*) &(bat_conf_user.discharge_temp_min), "BatDisMin_degC"},
|
||||
|
||||
// load settings
|
||||
{0x40, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_BOOL, 0, (void*) &(load.enabled_target), "LoadEnDefault"},
|
||||
{0x41, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_BOOL, 0, (void*) &(load.usb_enabled_target), "USBEnDefault"},
|
||||
{0x42, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 2, (void*) &(bat_conf_user.voltage_load_disconnect), "LoadDisconnect_V"},
|
||||
{0x43, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 2, (void*) &(bat_conf_user.voltage_load_reconnect), "LoadReconnect_V"},
|
||||
{0x44, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 3, (void*) &(bat_conf_user.internal_resistance), "BatInt_Ohm"},
|
||||
{0x45, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 3, (void*) &(bat_conf_user.wire_resistance), "BatWire_Ohm"},
|
||||
//{0x44, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 2, (void*) &(bat_conf_user.voltage_load_disconnect), "USBDisconnect_V"},
|
||||
//{0x45, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 2, (void*) &(bat_conf_user.voltage_load_reconnect), "USBReconnect_V"},
|
||||
|
||||
|
||||
// other configuration items
|
||||
//{0x33, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_BOOL, 2, (void*) &(??), "WarningIndicator"}, // can be set externally
|
||||
//{0x33, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_BOOL, 2, (void*) &(??), "ErrorIndicator"},
|
||||
@@ -137,6 +141,8 @@ const data_object_t data_objects[] = {
|
||||
{0x78, TS_CAT_OUTPUT, TS_ACCESS_READ, TS_T_UINT16, 0, (void*) &(bat_state.chg_state), "ChgState"},
|
||||
{0x79, TS_CAT_OUTPUT, TS_ACCESS_READ, TS_T_UINT16, 0, (void*) &(dcdc.state), "DCDCState"},
|
||||
{0x7A, TS_CAT_OUTPUT, TS_ACCESS_READ, TS_T_FLOAT32, 2, (void*) &(hs_port.current), "Solar_A"},
|
||||
{0x7B, TS_CAT_OUTPUT, TS_ACCESS_READ, TS_T_FLOAT32, 2, (void*) &(ls_port.voltage_output_target), "BatTarget_V"},
|
||||
{0x7C, TS_CAT_OUTPUT, TS_ACCESS_READ, TS_T_FLOAT32, 2, (void*) &(ls_port.current_output_max), "BatTarget_A"},
|
||||
|
||||
// others
|
||||
{0x90, TS_CAT_OUTPUT, TS_ACCESS_READ, TS_T_FLOAT32, 0, (void*) &(latitude), "Latitude"},
|
||||
|
||||
@@ -22,6 +22,7 @@ const uint16_t eeprom_data_objects[] = {
|
||||
0x08, 0x09, 0x0A, 0x0B, // input / output wh
|
||||
0x0C, 0x0D, 0x0E, // num full charge / deep-discharge / usable Ah
|
||||
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3F, // battery settings
|
||||
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, // resistances and min/max temperatures
|
||||
0x40, 0x41, 0x42, 0x43, // load settings
|
||||
0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, // V, I, T max
|
||||
0xA6 // day count
|
||||
|
||||
Reference in New Issue
Block a user