Skip to content

Commit

Permalink
temperature failure check revisited
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Jul 22, 2020
1 parent 6ca8911 commit daadefb
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 31 deletions.
4 changes: 2 additions & 2 deletions src/eez/modules/psu/conf_advanced.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
#define MAX_CALIBRATION_POINTS 20
68 changes: 39 additions & 29 deletions src/eez/modules/psu/temp_sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include <eez/modules/aux_ps/fan.h>
#endif

#define CONF_DECLARE_TEMP_SENSOR_FAILED_THRESHOLD_MS 2000

namespace eez {
namespace psu {

Expand All @@ -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() {
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
3 changes: 3 additions & 0 deletions src/eez/modules/psu/temp_sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ class TempSensor {

private:
float doRead();

uint32_t m_timeOfFirstInvalidValue;
void testTemperatureValidity(float value);
};

////////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit daadefb

Please sign in to comment.