Load off for internal overtemp implemented
This commit is contained in:
@@ -175,6 +175,15 @@ void update_measurements()
|
||||
uint16_t adcval = (adc_filtered[ADC_POS_TEMP_MCU] >> (4 + ADC_FILTER_CONST)) * vcc / VREFINT_VALUE;
|
||||
internal_temp = (TSENSE_CAL2_VALUE - TSENSE_CAL1_VALUE) /
|
||||
(TSENSE_CAL2 - TSENSE_CAL1) * (adcval - TSENSE_CAL1) + TSENSE_CAL1_VALUE;
|
||||
|
||||
if (internal_temp > 80) {
|
||||
log_data.error_flags |= 1U << ERR_INT_OVERTEMP;
|
||||
}
|
||||
else if (internal_temp < 70 && (log_data.error_flags & (1U << ERR_INT_OVERTEMP))) {
|
||||
// remove error flag with hysteresis of 10°C
|
||||
log_data.error_flags &= ~(1U << ERR_INT_OVERTEMP);
|
||||
}
|
||||
// else: keep previous setting
|
||||
}
|
||||
|
||||
#ifndef UNIT_TEST
|
||||
|
||||
+21
-2
@@ -275,7 +275,7 @@ void LoadOutput::state_machine()
|
||||
}
|
||||
else {
|
||||
// must be battery over/under temperature then
|
||||
state = LOAD_STATE_OFF_BAT_TEMP;
|
||||
state = LOAD_STATE_OFF_TEMPERATURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -294,7 +294,7 @@ void LoadOutput::state_machine()
|
||||
}
|
||||
else {
|
||||
// must be battery over/under temperature then
|
||||
state = LOAD_STATE_OFF_BAT_TEMP;
|
||||
state = LOAD_STATE_OFF_TEMPERATURE;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -328,6 +328,13 @@ void LoadOutput::state_machine()
|
||||
state = LOAD_STATE_DISABLED; // switch to normal mode again
|
||||
}
|
||||
break;
|
||||
case LOAD_STATE_OFF_TEMPERATURE:
|
||||
if (!(log_data.error_flags & (1U << ERR_INT_OVERTEMP)) &&
|
||||
port->pos_current_limit > 0)
|
||||
{
|
||||
state = LOAD_STATE_DISABLED;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
usb_state_machine();
|
||||
@@ -363,6 +370,16 @@ void LoadOutput::control()
|
||||
log_data.error_flags |= (1 << ERR_LOAD_OVERCURRENT);
|
||||
print_error("Load overcurrent detected\n");
|
||||
overcurrent_timestamp = time(NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
// internal overtemperature
|
||||
if (log_data.error_flags & (1U << ERR_INT_OVERTEMP)) {
|
||||
switch_set(false);
|
||||
usb_set(false);
|
||||
state = LOAD_STATE_OFF_TEMPERATURE;
|
||||
print_error("Device overtemperature detected\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// overcurrent detected because of voltage dip by 25%
|
||||
@@ -374,6 +391,7 @@ void LoadOutput::control()
|
||||
log_data.error_flags |= (1 << ERR_LOAD_VOLTAGE_DIP);
|
||||
print_error("Load voltage dip detected\n");
|
||||
overcurrent_timestamp = time(NULL);
|
||||
return;
|
||||
}
|
||||
voltage_prev = port->voltage;
|
||||
|
||||
@@ -389,6 +407,7 @@ void LoadOutput::control()
|
||||
state = LOAD_STATE_OFF_OVERVOLTAGE;
|
||||
overcurrent_timestamp = time(NULL);
|
||||
log_data.error_flags |= (1 << ERR_LOAD_OVERVOLTAGE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
+1
-1
@@ -40,7 +40,7 @@ enum LoadState {
|
||||
LOAD_STATE_OFF_OVERCURRENT, ///< Off to protect charge controller (overrules target setting)
|
||||
LOAD_STATE_OFF_OVERVOLTAGE, ///< Off to protect loads (overrules target setting)
|
||||
LOAD_STATE_OFF_SHORT_CIRCUIT, ///< Off to protect charge controller (overrules target setting)
|
||||
LOAD_STATE_OFF_BAT_TEMP ///< Off because of battery over/under-temperature
|
||||
LOAD_STATE_OFF_TEMPERATURE ///< Off because of battery or charge controller temperature
|
||||
};
|
||||
|
||||
/** Load output type
|
||||
|
||||
@@ -43,8 +43,9 @@ enum ErrorFlag {
|
||||
ERR_LOAD_OVERVOLTAGE, ///< To high voltage for load so that it was switched off
|
||||
ERR_LOAD_SHORT_CIRCUIT, ///< Short circuit detected by load port
|
||||
ERR_LOAD_OVERCURRENT, ///< Long-term overcurrent of charge controller
|
||||
ERR_LOAD_VOLTAGE_DIP ///< Overcurrent identified via voltage dip (may be because of
|
||||
ERR_LOAD_VOLTAGE_DIP, ///< Overcurrent identified via voltage dip (may be because of
|
||||
///< too small battery)
|
||||
ERR_INT_OVERTEMP ///< Charge controller internal temperature too high
|
||||
};
|
||||
|
||||
/** Log Data
|
||||
|
||||
+22
-4
@@ -40,13 +40,13 @@ void disabled_to_off_bat_temp_if_error_flag_set()
|
||||
// overtemp
|
||||
log_data.error_flags = 1 << ERR_BAT_CHG_OVERTEMP;
|
||||
load.state_machine();
|
||||
TEST_ASSERT_EQUAL(LOAD_STATE_OFF_BAT_TEMP, load.state);
|
||||
TEST_ASSERT_EQUAL(LOAD_STATE_OFF_TEMPERATURE, load.state);
|
||||
|
||||
// undertemp
|
||||
load.state = LOAD_STATE_DISABLED;
|
||||
log_data.error_flags = 1 << ERR_BAT_CHG_UNDERTEMP;
|
||||
load.state_machine();
|
||||
TEST_ASSERT_EQUAL(LOAD_STATE_OFF_BAT_TEMP, load.state);
|
||||
TEST_ASSERT_EQUAL(LOAD_STATE_OFF_TEMPERATURE, load.state);
|
||||
}
|
||||
|
||||
void off_low_soc_to_on_after_delay()
|
||||
@@ -146,12 +146,12 @@ void on_to_off_bat_temp_if_error_flag_set()
|
||||
load.state = LOAD_STATE_ON;
|
||||
log_data.error_flags = 1 << ERR_BAT_DIS_OVERTEMP;
|
||||
load.state_machine();
|
||||
TEST_ASSERT_EQUAL(LOAD_STATE_OFF_BAT_TEMP, load.state);
|
||||
TEST_ASSERT_EQUAL(LOAD_STATE_OFF_TEMPERATURE, load.state);
|
||||
|
||||
load.state = LOAD_STATE_ON;
|
||||
log_data.error_flags = 1 << ERR_BAT_DIS_UNDERTEMP;
|
||||
load.state_machine();
|
||||
TEST_ASSERT_EQUAL(LOAD_STATE_OFF_BAT_TEMP, load.state);
|
||||
TEST_ASSERT_EQUAL(LOAD_STATE_OFF_TEMPERATURE, load.state);
|
||||
}
|
||||
|
||||
void on_to_disabled_if_enable_false()
|
||||
@@ -225,6 +225,7 @@ void control_off_voltage_dip()
|
||||
PowerPort port;
|
||||
LoadOutput load(&port);
|
||||
port.init_load(14.6);
|
||||
port.current = 0;
|
||||
load.voltage_prev = port.voltage;
|
||||
load.state = LOAD_STATE_ON;
|
||||
internal_temp = 25;
|
||||
@@ -241,6 +242,22 @@ void control_off_voltage_dip()
|
||||
TEST_ASSERT_EQUAL(1 << ERR_LOAD_VOLTAGE_DIP, log_data.error_flags);
|
||||
}
|
||||
|
||||
void control_off_temperature()
|
||||
{
|
||||
PowerPort port;
|
||||
LoadOutput load(&port);
|
||||
port.init_load(14.6);
|
||||
port.current = 0;
|
||||
load.voltage_prev = port.voltage;
|
||||
load.state = LOAD_STATE_ON;
|
||||
internal_temp = 25;
|
||||
load.junction_temperature = 25;
|
||||
log_data.error_flags = 1U << ERR_INT_OVERTEMP;
|
||||
|
||||
load.control();
|
||||
TEST_ASSERT_EQUAL(LOAD_STATE_OFF_TEMPERATURE, load.state);
|
||||
}
|
||||
|
||||
void load_tests()
|
||||
{
|
||||
UNITY_BEGIN();
|
||||
@@ -261,6 +278,7 @@ void load_tests()
|
||||
RUN_TEST(control_off_overvoltage);
|
||||
RUN_TEST(control_off_overcurrent);
|
||||
RUN_TEST(control_off_voltage_dip);
|
||||
RUN_TEST(control_off_temperature);
|
||||
|
||||
// ToDo: What to do if port current is above the limit, but the hardware can still handle it?
|
||||
|
||||
|
||||
Reference in New Issue
Block a user