Improved load overcurrent and overvoltage diagnosis and protection
This commit is contained in:
@@ -83,6 +83,7 @@ void update_measurements(dcdc_t *dcdc, battery_state_t *bat, load_output_t *load
|
||||
ls->voltage =
|
||||
(float)(((adc_filtered[ADC_POS_V_BAT] >> (4 + ADC_FILTER_CONST)) * vcc) / 4096) *
|
||||
ADC_GAIN_V_BAT / 1000.0;
|
||||
load->voltage = ls->voltage;
|
||||
|
||||
hs->voltage =
|
||||
(float)(((adc_filtered[ADC_POS_V_SOLAR] >> (4 + ADC_FILTER_CONST)) * vcc) / 4096) *
|
||||
|
||||
+19
-15
@@ -38,7 +38,7 @@ void battery_conf_init(battery_conf_t *bat, bat_type type, int num_cells, float
|
||||
bat->charge_current_max = bat->nominal_capacity; // 1C should be safe for all batteries
|
||||
|
||||
bat->time_limit_recharge = 60; // sec
|
||||
bat->time_limit_CV = 120*60; // sec
|
||||
bat->time_limit_topping = 120*60; // sec
|
||||
|
||||
bat->charge_temp_max = 50;
|
||||
bat->charge_temp_min = -10;
|
||||
@@ -50,7 +50,8 @@ void battery_conf_init(battery_conf_t *bat, bat_type type, int num_cells, float
|
||||
case BAT_TYPE_FLOODED:
|
||||
case BAT_TYPE_AGM:
|
||||
case BAT_TYPE_GEL:
|
||||
bat->voltage_max = num_cells * 2.4;
|
||||
bat->voltage_absolute_max = num_cells * 2.45;
|
||||
bat->voltage_topping = num_cells * 2.4;
|
||||
bat->voltage_recharge = num_cells * 2.3;
|
||||
|
||||
// Cell-level thresholds based on EN 62509:2011 (both thresholds current-compensated)
|
||||
@@ -64,7 +65,7 @@ void battery_conf_init(battery_conf_t *bat, bat_type type, int num_cells, float
|
||||
bat->ocv_empty = num_cells * 1.95;
|
||||
|
||||
// https://batteryuniversity.com/learn/article/charging_the_lead_acid_battery
|
||||
bat->current_cutoff_CV = bat->nominal_capacity * 0.04; // 3-5 % of C/1
|
||||
bat->current_cutoff_topping = bat->nominal_capacity * 0.04; // 3-5 % of C/1
|
||||
|
||||
bat->trickle_enabled = true;
|
||||
bat->time_trickle_recharge = 30*60;
|
||||
@@ -86,7 +87,8 @@ void battery_conf_init(battery_conf_t *bat, bat_type type, int num_cells, float
|
||||
break;
|
||||
|
||||
case BAT_TYPE_LFP:
|
||||
bat->voltage_max = num_cells * 3.55; // CV voltage
|
||||
bat->voltage_absolute_max = num_cells * 3.60;
|
||||
bat->voltage_topping = num_cells * 3.55; // CV voltage
|
||||
bat->voltage_recharge = num_cells * 3.35;
|
||||
|
||||
bat->voltage_load_disconnect = num_cells * 3.0;
|
||||
@@ -97,7 +99,7 @@ void battery_conf_init(battery_conf_t *bat, bat_type type, int num_cells, float
|
||||
bat->ocv_full = num_cells * 3.4; // will give really bad SOC calculation
|
||||
bat->ocv_empty = num_cells * 3.0; // because of flat OCV of LFP cells...
|
||||
|
||||
bat->current_cutoff_CV = bat->nominal_capacity / 10; // C/10 cut-off at end of CV phase by default
|
||||
bat->current_cutoff_topping = bat->nominal_capacity / 10; // C/10 cut-off at end of CV phase by default
|
||||
|
||||
bat->trickle_enabled = false;
|
||||
bat->equalization_enabled = false;
|
||||
@@ -107,7 +109,8 @@ void battery_conf_init(battery_conf_t *bat, bat_type type, int num_cells, float
|
||||
|
||||
case BAT_TYPE_NMC:
|
||||
case BAT_TYPE_NMC_HV:
|
||||
bat->voltage_max = (type == BAT_TYPE_NMC_HV) ? 4.35 : 4.20;
|
||||
bat->voltage_topping = (type == BAT_TYPE_NMC_HV) ? 4.35 : 4.20;
|
||||
bat->voltage_absolute_max = bat->voltage_topping + 0.05;
|
||||
bat->voltage_recharge = num_cells * 3.9;
|
||||
|
||||
bat->voltage_load_disconnect = num_cells * 3.3;
|
||||
@@ -119,7 +122,7 @@ void battery_conf_init(battery_conf_t *bat, bat_type type, int num_cells, float
|
||||
bat->ocv_full = num_cells * 4.0;
|
||||
bat->ocv_empty = num_cells * 3.0;
|
||||
|
||||
bat->current_cutoff_CV = bat->nominal_capacity / 10; // C/10 cut-off at end of CV phase by default
|
||||
bat->current_cutoff_topping = bat->nominal_capacity / 10; // C/10 cut-off at end of CV phase by default
|
||||
|
||||
bat->trickle_enabled = false;
|
||||
bat->equalization_enabled = false;
|
||||
@@ -156,15 +159,15 @@ bool battery_conf_check(battery_conf_t *bat_conf)
|
||||
|
||||
return
|
||||
(bat_conf->voltage_load_reconnect > (bat_conf->voltage_load_disconnect + 0.6) &&
|
||||
bat_conf->voltage_recharge < (bat_conf->voltage_max - 0.4) &&
|
||||
bat_conf->voltage_recharge < (bat_conf->voltage_topping - 0.4) &&
|
||||
bat_conf->voltage_recharge > (bat_conf->voltage_load_disconnect + 1) &&
|
||||
bat_conf->voltage_load_disconnect > (bat_conf->voltage_absolute_min + 0.4) &&
|
||||
bat_conf->internal_resistance < bat_conf->voltage_load_disconnect * 0.1 / LOAD_CURRENT_MAX && // max. 10% drop
|
||||
bat_conf->wire_resistance < bat_conf->voltage_max * 0.03 / LOAD_CURRENT_MAX && // max. 3% loss
|
||||
bat_conf->current_cutoff_CV < (bat_conf->nominal_capacity / 10.0) && // C/10 or lower allowed
|
||||
bat_conf->current_cutoff_CV > 0.01 &&
|
||||
bat_conf->wire_resistance < bat_conf->voltage_topping * 0.03 / LOAD_CURRENT_MAX && // max. 3% loss
|
||||
bat_conf->current_cutoff_topping < (bat_conf->nominal_capacity / 10.0) && // C/10 or lower allowed
|
||||
bat_conf->current_cutoff_topping > 0.01 &&
|
||||
(bat_conf->trickle_enabled == false ||
|
||||
(bat_conf->voltage_trickle < bat_conf->voltage_max &&
|
||||
(bat_conf->voltage_trickle < bat_conf->voltage_topping &&
|
||||
bat_conf->voltage_trickle > bat_conf->voltage_load_disconnect))
|
||||
);
|
||||
}
|
||||
@@ -173,14 +176,15 @@ void battery_conf_overwrite(battery_conf_t *source, battery_conf_t *destination,
|
||||
{
|
||||
// TODO: stop DC/DC
|
||||
|
||||
destination->voltage_max = source->voltage_max;
|
||||
destination->voltage_topping = source->voltage_topping;
|
||||
destination->voltage_recharge = source->voltage_recharge;
|
||||
destination->voltage_load_reconnect = source->voltage_load_reconnect;
|
||||
destination->voltage_load_disconnect = source->voltage_load_disconnect;
|
||||
destination->voltage_absolute_max = source->voltage_absolute_max;
|
||||
destination->voltage_absolute_min = source->voltage_absolute_min;
|
||||
destination->charge_current_max = source->charge_current_max;
|
||||
destination->current_cutoff_CV = source->current_cutoff_CV;
|
||||
destination->time_limit_CV = source->time_limit_CV;
|
||||
destination->current_cutoff_topping = source->current_cutoff_topping;
|
||||
destination->time_limit_topping = source->time_limit_topping;
|
||||
destination->trickle_enabled = source->trickle_enabled;
|
||||
destination->voltage_trickle = source->voltage_trickle;
|
||||
destination->time_trickle_recharge = source->time_trickle_recharge;
|
||||
|
||||
+9
-3
@@ -64,6 +64,12 @@ typedef struct
|
||||
*/
|
||||
int time_limit_recharge;
|
||||
|
||||
/** Absolute maximum voltage (V)
|
||||
*
|
||||
* Above this voltage the battery or loads might get damaged.
|
||||
*/
|
||||
float voltage_absolute_max;
|
||||
|
||||
/** Absolute minimum voltage (V)
|
||||
*
|
||||
* Below this voltage the battery is considered damaged.
|
||||
@@ -80,19 +86,19 @@ typedef struct
|
||||
*
|
||||
* Charger target voltage, switching from CC to CV at this voltage threshold.
|
||||
*/
|
||||
float voltage_max;
|
||||
float voltage_topping;
|
||||
|
||||
/** CV phase cut-off current limit (A)
|
||||
*
|
||||
* Constant voltage charging phase stopped if current is below this value.
|
||||
*/
|
||||
float current_cutoff_CV;
|
||||
float current_cutoff_topping;
|
||||
|
||||
/** CV phase cut-off time limit (s)
|
||||
*
|
||||
* After this time, CV charging is stopped independent of current.
|
||||
*/
|
||||
int time_limit_CV;
|
||||
int time_limit_topping;
|
||||
|
||||
/** Enable float/trickle charging
|
||||
*
|
||||
|
||||
+5
-5
@@ -80,7 +80,7 @@ void charger_state_machine(power_port_t *port, battery_conf_t *bat_conf, battery
|
||||
&& 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 + bat_conf->temperature_compensation * (bat_state->temperature - 25);
|
||||
port->voltage_output_target = bat_conf->voltage_topping + 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;
|
||||
@@ -90,7 +90,7 @@ void charger_state_machine(power_port_t *port, battery_conf_t *bat_conf, battery
|
||||
}
|
||||
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);
|
||||
port->voltage_output_target = bat_conf->voltage_topping + bat_conf->temperature_compensation * (bat_state->temperature - 25);
|
||||
|
||||
if (voltage > port->voltage_output_target - current * port->droop_res_output) {
|
||||
_enter_state(bat_state, CHG_STATE_TOPPING);
|
||||
@@ -99,7 +99,7 @@ void charger_state_machine(power_port_t *port, battery_conf_t *bat_conf, battery
|
||||
}
|
||||
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);
|
||||
port->voltage_output_target = bat_conf->voltage_topping + 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);
|
||||
@@ -107,8 +107,8 @@ void charger_state_machine(power_port_t *port, battery_conf_t *bat_conf, battery
|
||||
|
||||
// cut-off limit reached because battery full (i.e. CV limit still
|
||||
// reached by available solar power within last 2s) or CV period long enough?
|
||||
if ((current < bat_conf->current_cutoff_CV && (time(NULL) - bat_state->time_voltage_limit_reached) < 2)
|
||||
|| (time(NULL) - bat_state->time_state_changed) > bat_conf->time_limit_CV)
|
||||
if ((current < bat_conf->current_cutoff_topping && (time(NULL) - bat_state->time_voltage_limit_reached) < 2)
|
||||
|| (time(NULL) - bat_state->time_state_changed) > bat_conf->time_limit_topping)
|
||||
{
|
||||
bat_state->full = true;
|
||||
bat_state->num_full_charges++;
|
||||
|
||||
@@ -78,9 +78,9 @@ const data_object_t data_objects[] = {
|
||||
{0x31, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 2, (void*) &(bat_conf_user.voltage_recharge), "BatRecharge_V"},
|
||||
{0x32, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 2, (void*) &(bat_conf_user.voltage_absolute_min), "BatAbsMin_V"},
|
||||
{0x33, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 1, (void*) &(bat_conf_user.charge_current_max), "BatChgMax_A"},
|
||||
{0x34, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 2, (void*) &(bat_conf_user.voltage_max), "BatTarget_V"},
|
||||
{0x35, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 1, (void*) &(bat_conf_user.current_cutoff_CV), "BatCutoff_A"},
|
||||
{0x36, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_INT32, 0, (void*) &(bat_conf_user.time_limit_CV), "BatCutoff_s"},
|
||||
{0x34, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 2, (void*) &(bat_conf_user.voltage_topping), "BatTarget_V"},
|
||||
{0x35, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 1, (void*) &(bat_conf_user.current_cutoff_topping), "BatCutoff_A"},
|
||||
{0x36, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_INT32, 0, (void*) &(bat_conf_user.time_limit_topping), "BatCutoff_s"},
|
||||
{0x37, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_BOOL, 0, (void*) &(bat_conf_user.trickle_enabled), "TrickleEn"},
|
||||
{0x38, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 2, (void*) &(bat_conf_user.voltage_trickle), "Trickle_V"},
|
||||
{0x39, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_INT32, 0, (void*) &(bat_conf_user.time_trickle_recharge), "TrickleRecharge_s"},
|
||||
@@ -180,6 +180,7 @@ const data_object_t data_objects[] = {
|
||||
{0xB7, TS_CAT_REC, TS_ACCESS_READ, TS_T_INT32, 1, (void*) &(log_data.bat_temp_max), "BatMax_degC"},
|
||||
{0xB8, TS_CAT_REC, TS_ACCESS_READ, TS_T_INT32, 1, (void*) &(log_data.int_temp_max), "IntMax_degC"},
|
||||
{0xB9, TS_CAT_REC, TS_ACCESS_READ, TS_T_INT32, 1, (void*) &(log_data.mosfet_temp_max), "MosfetMax_degC"},
|
||||
{0xBA, TS_CAT_REC, TS_ACCESS_READ, TS_T_UINT32, 1, (void*) &(log_data.error_flags), "ErrorFlags"},
|
||||
|
||||
// CALIBRATION DATA ///////////////////////////////////////////////////////
|
||||
// using IDs >= 0xD0
|
||||
|
||||
+27
-6
@@ -17,12 +17,15 @@
|
||||
#include "dcdc.h"
|
||||
#include "config.h"
|
||||
#include "pcb.h"
|
||||
#include "log.h"
|
||||
|
||||
#include "half_bridge.h"
|
||||
|
||||
#include <time.h> // for time(NULL) function
|
||||
#include <math.h> // for fabs function
|
||||
|
||||
extern log_data_t log_data;
|
||||
|
||||
void dcdc_init(dcdc_t *dcdc)
|
||||
{
|
||||
dcdc->mode = DCDC_MODE_INIT;
|
||||
@@ -89,7 +92,8 @@ int _dcdc_output_control(dcdc_t *dcdc, power_port_t *out, power_port_t *in)
|
||||
|
||||
bool _dcdc_check_start_conditions(dcdc_t *dcdc, power_port_t *out, power_port_t *in)
|
||||
{
|
||||
return out->output_allowed == true
|
||||
return dcdc->enabled == true
|
||||
&& out->output_allowed == true
|
||||
&& out->voltage < out->voltage_output_target
|
||||
&& out->voltage > out->voltage_output_min
|
||||
&& in->input_allowed == true
|
||||
@@ -132,20 +136,37 @@ void dcdc_control(dcdc_t *dcdc, power_port_t *hs, power_port_t *ls)
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (dcdc->enabled == false ||
|
||||
ls->voltage > dcdc->ls_voltage_max ||
|
||||
hs->voltage > dcdc->hs_voltage_max) {
|
||||
static int debounce_counter = 0;
|
||||
if (dcdc->ls_current > 0.5) {
|
||||
// if there is current even though the DC/DC is switched off, the
|
||||
// high-side MOSFET must be broken --> set flag and let main() decide
|
||||
// what to do... (e.g. call dcdc_self_destruction)
|
||||
debounce_counter++;
|
||||
if (debounce_counter > CONTROL_FREQUENCY) { // waited 1s before setting the flag
|
||||
log_data.error_flags |= (1 << ERR_HS_MOSFET_SHORT);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (_dcdc_check_start_conditions(dcdc, ls, hs)) {
|
||||
debounce_counter = 0;
|
||||
|
||||
if (_dcdc_check_start_conditions(dcdc, ls, hs) && ls->voltage < dcdc->ls_voltage_max) {
|
||||
// Vmpp at approx. 0.8 * Voc --> take 0.9 as starting point for MPP tracking
|
||||
half_bridge_start(ls->voltage / (hs->voltage * 0.9));
|
||||
printf("DC/DC buck mode start.\n");
|
||||
}
|
||||
else if (_dcdc_check_start_conditions(dcdc, hs, ls)) {
|
||||
else if (_dcdc_check_start_conditions(dcdc, hs, ls) && hs->voltage < dcdc->hs_voltage_max) {
|
||||
// will automatically start with max. duty (0.97) if connected to a nanogrid not yet started up (zero voltage)
|
||||
half_bridge_start((ls->voltage * 0.9) / hs->voltage);
|
||||
printf("DC/DC boost mode start.\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void dcdc_self_destruction()
|
||||
{
|
||||
printf("Charge controller self-destruction called!\n");
|
||||
//half_bridge_stop();
|
||||
//half_bridge_init(50, 0, 0, 0.98); // reset safety limits to allow 0% duty cycle
|
||||
//half_bridge_start(0);
|
||||
// now the fuse should be triggered and we disappear
|
||||
}
|
||||
|
||||
@@ -101,4 +101,12 @@ void dcdc_init(dcdc_t *dcdc);
|
||||
*/
|
||||
void dcdc_control(dcdc_t *dcdc, power_port_t *high_side, power_port_t *low_side);
|
||||
|
||||
/** Prevent overcharging of battery in case of shorted HS MOSFET
|
||||
*
|
||||
* This function switches the LS MOSFET continuously on to blow the battery input fuse. The reason for self destruction should
|
||||
* be logged and stored to EEPROM prior to calling this function, as the charge controller power supply will be cut after the
|
||||
* fuse is destroyed.
|
||||
*/
|
||||
void dcdc_self_destruction();
|
||||
|
||||
#endif /* DCDC_H */
|
||||
|
||||
+2
-2
@@ -24,7 +24,7 @@ const uint16_t eeprom_data_objects[] = {
|
||||
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
|
||||
0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, // V, I, T max
|
||||
0xA6 // day count
|
||||
};
|
||||
|
||||
@@ -220,7 +220,7 @@ void eeprom_restore_data()
|
||||
|
||||
void eeprom_store_data()
|
||||
{
|
||||
uint8_t buf[200] = {0}; // initialize with zeros
|
||||
uint8_t buf[300] = {0}; // initialize with zeros
|
||||
|
||||
int len = ts.pub_msg_cbor(buf + EEPROM_HEADER_SIZE, sizeof(buf) - EEPROM_HEADER_SIZE, eeprom_data_objects, sizeof(eeprom_data_objects)/sizeof(uint16_t));
|
||||
uint32_t crc = _calc_crc(buf + EEPROM_HEADER_SIZE, len);
|
||||
|
||||
+1
-1
@@ -131,7 +131,7 @@ void leds_init()
|
||||
}
|
||||
}
|
||||
|
||||
void update_dcdc_led(bool enabled)
|
||||
void leds_set_charging(bool enabled)
|
||||
{
|
||||
charging = enabled;
|
||||
#ifdef LED_DCDC
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ void leds_init();
|
||||
void led_timer_start(int freq_Hz);
|
||||
void charlieplexing();
|
||||
|
||||
void update_dcdc_led(bool enabled);
|
||||
void leds_set_charging(bool enabled);
|
||||
void update_rxtx_led();
|
||||
void trigger_tx_led();
|
||||
void trigger_rx_led();
|
||||
|
||||
+32
-2
@@ -17,6 +17,7 @@
|
||||
#include "load.h"
|
||||
#include "pcb.h"
|
||||
#include "hardware.h"
|
||||
#include "log.h"
|
||||
|
||||
void load_init(load_output_t *load)
|
||||
{
|
||||
@@ -28,6 +29,7 @@ void load_init(load_output_t *load)
|
||||
hw_usb_out(false);
|
||||
load->switch_state = LOAD_STATE_DISABLED;
|
||||
load->usb_state = LOAD_STATE_DISABLED;
|
||||
load->junction_temperature = 25;
|
||||
}
|
||||
|
||||
|
||||
@@ -115,20 +117,48 @@ void load_state_machine(load_output_t *load, bool source_enabled)
|
||||
load->switch_state = LOAD_STATE_DISABLED; // switch to normal mode again
|
||||
}
|
||||
break;
|
||||
case LOAD_STATE_OFF_OVERVOLTAGE:
|
||||
if (load->voltage < LOW_SIDE_VOLTAGE_MAX) { // TODO: add hysteresis?
|
||||
load->switch_state = LOAD_STATE_DISABLED; // switch to normal mode again
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
usb_state_machine(load);
|
||||
}
|
||||
|
||||
extern log_data_t log_data;
|
||||
extern float mcu_temp;
|
||||
|
||||
// this function is called more often than the state machine
|
||||
void load_check_overcurrent(load_output_t *load)
|
||||
void load_control(load_output_t *load)
|
||||
{
|
||||
if (load->current > load->current_max) {
|
||||
// junction temperature calculation model for overcurrent detection
|
||||
load->junction_temperature = load->junction_temperature + (
|
||||
mcu_temp - load->junction_temperature +
|
||||
load->current * load->current / (LOAD_CURRENT_MAX * LOAD_CURRENT_MAX) * (MOSFET_MAX_JUNCTION_TEMP - 25)
|
||||
) / (MOSFET_THERMAL_TIME_CONSTANT * CONTROL_FREQUENCY);
|
||||
|
||||
if (load->junction_temperature > MOSFET_MAX_JUNCTION_TEMP) {
|
||||
hw_load_switch(false);
|
||||
hw_usb_out(false);
|
||||
load->enabled = false;
|
||||
load->switch_state = LOAD_STATE_OFF_OVERCURRENT;
|
||||
load->overcurrent_timestamp = time(NULL);
|
||||
}
|
||||
|
||||
static int debounce_counter = 0;
|
||||
if (load->voltage > LOW_SIDE_VOLTAGE_MAX) {
|
||||
debounce_counter++;
|
||||
if (debounce_counter > CONTROL_FREQUENCY) { // waited 1s before setting the flag
|
||||
hw_load_switch(false);
|
||||
hw_usb_out(false);
|
||||
load->enabled = false;
|
||||
load->switch_state = LOAD_STATE_OFF_OVERVOLTAGE;
|
||||
load->overcurrent_timestamp = time(NULL);
|
||||
log_data.error_flags |= (1 << ERR_BAT_OVERVOLTAGE);
|
||||
}
|
||||
}
|
||||
debounce_counter = 0;
|
||||
}
|
||||
|
||||
|
||||
+13
-4
@@ -34,7 +34,8 @@ enum load_state_t {
|
||||
LOAD_STATE_DISABLED = 0, ///< Actively disabled
|
||||
LOAD_STATE_ON, ///< Normal state: On
|
||||
LOAD_STATE_OFF_LOW_SOC, ///< Off to protect battery (overrules target setting)
|
||||
LOAD_STATE_OFF_OVERCURRENT ///< Off to protect charge controller (overrules target setting)
|
||||
LOAD_STATE_OFF_OVERCURRENT, ///< Off to protect charge controller (overrules target setting)
|
||||
LOAD_STATE_OFF_OVERVOLTAGE ///< Off to protect loads (overrules target setting)
|
||||
};
|
||||
|
||||
/** Load output type
|
||||
@@ -44,9 +45,15 @@ enum load_state_t {
|
||||
typedef struct {
|
||||
uint16_t switch_state; ///< Current state of load output switch
|
||||
uint16_t usb_state; ///< Current state of USB output
|
||||
float current; ///< actual measurement
|
||||
|
||||
float voltage; ///< actual voltage measurement
|
||||
|
||||
float current; ///< actual current measurement
|
||||
float current_max; ///< maximum allowed current
|
||||
int overcurrent_timestamp; ///< time at which an overcurrent event occured
|
||||
|
||||
float junction_temperature; ///< calculated using thermal model based on current and ambient temperature measurement (unit: °C)
|
||||
|
||||
bool enabled; ///< actual status
|
||||
bool enabled_target; ///< target setting defined via communication port (overruled if battery is empty)
|
||||
bool usb_enabled_target; ///< same for USB output
|
||||
@@ -60,8 +67,10 @@ void load_init(load_output_t *load);
|
||||
*/
|
||||
void load_state_machine(load_output_t *load, bool source_enabled);
|
||||
|
||||
/** Overcurrent check function, should be called as often as possible
|
||||
/** Main load control function, should be called by control timer
|
||||
*
|
||||
* Performs time-critical checks like overcurrent and overvoltage
|
||||
*/
|
||||
void load_check_overcurrent(load_output_t *load);
|
||||
void load_control(load_output_t *load);
|
||||
|
||||
#endif /* LOAD_H */
|
||||
|
||||
@@ -26,6 +26,14 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/** Error Flags
|
||||
*/
|
||||
enum error_flag_t {
|
||||
ERR_HS_MOSFET_SHORT = 0, ///< Short-circuit in HS MOSFET
|
||||
ERR_BAT_OVERVOLTAGE,
|
||||
ERR_BAT_UNDERVOLTAGE,
|
||||
};
|
||||
|
||||
/** Log Data
|
||||
*
|
||||
* Stores error counters and some maximum ever measured values to EEPROM
|
||||
@@ -49,6 +57,7 @@ typedef struct {
|
||||
int int_temp_max; // °C
|
||||
int mosfet_temp_max;
|
||||
int day_counter;
|
||||
uint32_t error_flags; ///< Instantaneous errors
|
||||
} log_data_t;
|
||||
|
||||
#endif /* LOG_H */
|
||||
|
||||
+3
-4
@@ -55,8 +55,6 @@ extern ThingSet ts; // defined in data_objects.cpp
|
||||
|
||||
time_t timestamp; // current unix timestamp (independent of time(NULL), as it is user-configurable)
|
||||
|
||||
#define CONTROL_FREQUENCY 10 // Hz (higher frequency caused issues with MPPT control)
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// function prototypes
|
||||
|
||||
@@ -76,14 +74,15 @@ void system_control() // called by control timer (see hardware.cpp)
|
||||
|
||||
#ifdef CHARGER_TYPE_PWM
|
||||
pwm_switch_control(&pwm_switch, &hs_port, bat_port);
|
||||
leds_set_charging(pwm_switch_enabled());
|
||||
#else
|
||||
// control PWM of the DC/DC according to hs and ls port settings
|
||||
// (this function includes MPPT algorithm)
|
||||
dcdc_control(&dcdc, &hs_port, &ls_port);
|
||||
leds_set_charging(half_bridge_enabled());
|
||||
#endif
|
||||
|
||||
load_check_overcurrent(&load);
|
||||
update_dcdc_led(half_bridge_enabled());
|
||||
load_control(&load);
|
||||
|
||||
if (counter % CONTROL_FREQUENCY == 0) {
|
||||
// called once per second (this timer is much more accurate than time(NULL) based on LSI)
|
||||
|
||||
@@ -24,9 +24,45 @@
|
||||
*/
|
||||
|
||||
// generic settings (for all charge controller boards)
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Maximum voltage at battery port (V)
|
||||
*/
|
||||
#define LOW_SIDE_VOLTAGE_MAX 32
|
||||
|
||||
/** Maximum voltage at PV input port (V)
|
||||
*/
|
||||
#define HIGH_SIDE_VOLTAGE_MAX 55
|
||||
|
||||
/** Main control function frequency (Hz)
|
||||
*
|
||||
* Frequencies higher than 10 Hz caused issues with MPPT control during lab test with
|
||||
* PV simulator. Might be different with actual solar panel.
|
||||
*/
|
||||
#define CONTROL_FREQUENCY 10
|
||||
|
||||
/** Maximum Tj of MOSFETs (°C)
|
||||
*
|
||||
* This value is used for model-based control of overcurrent protection. It represents
|
||||
* the steady-state junction temperature for max. continuous current at ambient
|
||||
* temperature of 25°C.
|
||||
*/
|
||||
#define MOSFET_MAX_JUNCTION_TEMP 120
|
||||
|
||||
/** Thermal time constant junction to ambient (s)
|
||||
*
|
||||
* This value is used for model-based control of overcurrent protection. It does not reflect
|
||||
* the much lower MOSFET-internal time constant junction to case, but includes thermal inertia
|
||||
* of the board.
|
||||
*
|
||||
* Around 5s seems to be a good conservative estimation for 5x6 type SMD MOSFETs
|
||||
*/
|
||||
#define MOSFET_THERMAL_TIME_CONSTANT 5
|
||||
|
||||
|
||||
// specific board settings
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if defined(PCB_LS_005)
|
||||
#include "pcbs/pcb_ls_005.h"
|
||||
#elif defined(PCB_LS_010)
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ void power_port_init_bat(power_port_t *port, battery_conf_t *bat)
|
||||
port->current_input_max = -bat->charge_current_max; // TODO: discharge current
|
||||
port->droop_res_input = -(bat->internal_resistance + -bat->wire_resistance); // negative sign for compensation of actual resistance
|
||||
|
||||
port->voltage_output_target = bat->voltage_max;
|
||||
port->voltage_output_target = bat->voltage_topping;
|
||||
port->voltage_output_min = bat->voltage_absolute_min;
|
||||
port->current_output_max = bat->charge_current_max;
|
||||
port->droop_res_output = -bat->wire_resistance; // negative sign for compensation of actual resistance
|
||||
|
||||
Reference in New Issue
Block a user