diff --git a/src/eez/modules/psu/conf_advanced.h b/src/eez/modules/psu/conf_advanced.h index bd7da4ca1..d34b283c7 100644 --- a/src/eez/modules/psu/conf_advanced.h +++ b/src/eez/modules/psu/conf_advanced.h @@ -122,7 +122,7 @@ #define CONF_SKIP_PWRGOOD_TEST 0 /// Minimal temperature (in oC) for sensor to be declared as valid. -#define TEMP_SENSOR_MIN_VALID_TEMPERATURE -55 +#define TEMP_SENSOR_MIN_VALID_TEMPERATURE 1 #define TEMP_SENSOR_MAX_VALID_TEMPERATURE 125 /// Interval at which fan speed should be adjusted @@ -264,4 +264,4 @@ #define CONF_LIST_COUNDOWN_DISPLAY_THRESHOLD 5 // 5 seconds #define CONF_RAMP_COUNDOWN_DISPLAY_THRESHOLD 5 // 5 seconds -#define MAX_CALIBRATION_POINTS 20 \ No newline at end of file +#define MAX_CALIBRATION_POINTS 20 diff --git a/src/eez/modules/psu/temp_sensor.cpp b/src/eez/modules/psu/temp_sensor.cpp index 04a4ea019..9715283d4 100644 --- a/src/eez/modules/psu/temp_sensor.cpp +++ b/src/eez/modules/psu/temp_sensor.cpp @@ -26,6 +26,8 @@ #include #endif +#define CONF_DECLARE_TEMP_SENSOR_FAILED_THRESHOLD_MS 2000 + namespace eez { namespace psu { @@ -43,7 +45,7 @@ TempSensor sensors[NUM_TEMP_SENSORS] = { TEMP_SENSORS }; //////////////////////////////////////////////////////////////////////////////// TempSensor::TempSensor(Type type_, const char *name_, int ques_bit_, int scpi_error_) - : type(type_), name(name_), ques_bit(ques_bit_), scpi_error(scpi_error_) { + : type(type_), name(name_), ques_bit(ques_bit_), scpi_error(scpi_error_), m_timeOfFirstInvalidValue(0) { } bool TempSensor::isInstalled() { @@ -95,31 +97,49 @@ float TempSensor::doRead() { return NAN; } -bool TempSensor::test() { - if (isInstalled()) { - float temperature = doRead(); - g_testResult = - isNaN(temperature) || - temperature < TEMP_SENSOR_MIN_VALID_TEMPERATURE || - temperature > TEMP_SENSOR_MAX_VALID_TEMPERATURE ? TEST_FAILED : TEST_OK; - } else { - g_testResult = TEST_SKIPPED; - } - +void TempSensor::testTemperatureValidity(float value) { Channel *channel = getChannel(); - if (g_testResult == TEST_FAILED) { - if (channel) { - // set channel current max. limit to ERR_MAX_CURRENT if sensor is faulty - channel->limitMaxCurrent(MAX_CURRENT_LIMIT_CAUSE_TEMPERATURE); + bool isTemperatureValueInvalid = isNaN(value) || value < TEMP_SENSOR_MIN_VALID_TEMPERATURE || value > TEMP_SENSOR_MAX_VALID_TEMPERATURE; + if (isTemperatureValueInvalid) { + if (g_testResult == TEST_OK) { + if (m_timeOfFirstInvalidValue != 0) { + int32_t diff = millis() - m_timeOfFirstInvalidValue; + if (diff > CONF_DECLARE_TEMP_SENSOR_FAILED_THRESHOLD_MS) { + g_testResult = TEST_FAILED; + + if (channel) { + // set channel current max. limit to ERR_MAX_CURRENT if sensor is faulty + channel->limitMaxCurrent(MAX_CURRENT_LIMIT_CAUSE_TEMPERATURE); + } + + generateError(scpi_error); + } + } else { + m_timeOfFirstInvalidValue = millis(); + if (m_timeOfFirstInvalidValue == 0) { + m_timeOfFirstInvalidValue = 1; + } + } } - - generateError(scpi_error); } else { + g_testResult = TEST_OK; + m_timeOfFirstInvalidValue = 0; + if (channel) { channel->unlimitMaxCurrent(); } } +} + +bool TempSensor::test() { + if (isInstalled()) { + g_testResult = TEST_OK; + float temperature = doRead(); + testTemperatureValidity(temperature); + } else { + g_testResult = TEST_SKIPPED; + } return g_testResult != TEST_FAILED; } @@ -131,17 +151,7 @@ float TempSensor::read() { float value = doRead(); - if (isNaN(value) || value < TEMP_SENSOR_MIN_VALID_TEMPERATURE || value > TEMP_SENSOR_MAX_VALID_TEMPERATURE) { - g_testResult = TEST_FAILED; - - Channel *channel = getChannel(); - if (channel) { - // set channel current max. limit to ERR_MAX_CURRENT if sensor is faulty - channel->limitMaxCurrent(MAX_CURRENT_LIMIT_CAUSE_TEMPERATURE); - } - - generateError(scpi_error); - } + testTemperatureValidity(value); return value; } diff --git a/src/eez/modules/psu/temp_sensor.h b/src/eez/modules/psu/temp_sensor.h index 7959dcd56..5ffda1a32 100644 --- a/src/eez/modules/psu/temp_sensor.h +++ b/src/eez/modules/psu/temp_sensor.h @@ -68,6 +68,9 @@ class TempSensor { private: float doRead(); + + uint32_t m_timeOfFirstInvalidValue; + void testTemperatureValidity(float value); }; ////////////////////////////////////////////////////////////////////////////////