Skip to content

Commit

Permalink
max temp condition check updated
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Apr 16, 2020
1 parent 3ba0a1b commit b30738a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 44 deletions.
4 changes: 0 additions & 4 deletions src/eez/modules/psu/conf_advanced.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,6 @@
/// Number of seconds after which main power will be turned off.
#define FAN_MAX_TEMP_DELAY 30

/// Temperature drop (in oC) below FAN_MAX_TEMP to turn again main power on. Premature attempt to
/// turn power on will report error -200.
#define FAN_MAX_TEMP_DROP 15

/// Interval (in minutes) at which "on time" will be written to EEPROM
#define WRITE_ONTIME_INTERVAL 10

Expand Down
32 changes: 17 additions & 15 deletions src/eez/modules/psu/temp_sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,24 @@ float TempSensor::doRead() {
return aux_ps::fan::readTemperature();
}
#endif

if (type >= CH1 && type <= CH6) {
int channelIndex = type - CH1;
int slotIndex = Channel::get(channelIndex).slotIndex;
auto &slot = g_slots[slotIndex];

if ((slot.moduleInfo->moduleType == MODULE_TYPE_DCP405 && slot.moduleRevision >= MODULE_REVISION_DCP405_R1B1) || slot.moduleInfo->moduleType == MODULE_TYPE_DCP405B) {
return drivers::tc77::readTemperature(slotIndex);
}

if (slot.moduleInfo->moduleType == MODULE_TYPE_DCP405 || slot.moduleInfo->moduleType == MODULE_TYPE_DCP505) {
return drivers::tmp1075::readTemperature(slotIndex);
}

if (slot.moduleInfo->moduleType == MODULE_TYPE_DCM220) {
return dcm220::readTemperature(channelIndex);
if (isPowerUp()) {
if (type >= CH1 && type <= CH6) {
int channelIndex = type - CH1;
int slotIndex = Channel::get(channelIndex).slotIndex;
auto &slot = g_slots[slotIndex];

if ((slot.moduleInfo->moduleType == MODULE_TYPE_DCP405 && slot.moduleRevision >= MODULE_REVISION_DCP405_R1B1) || slot.moduleInfo->moduleType == MODULE_TYPE_DCP405B) {
return drivers::tc77::readTemperature(slotIndex);
}

if (slot.moduleInfo->moduleType == MODULE_TYPE_DCP405 || slot.moduleInfo->moduleType == MODULE_TYPE_DCP505) {
return drivers::tmp1075::readTemperature(slotIndex);
}

if (slot.moduleInfo->moduleType == MODULE_TYPE_DCM220) {
return dcm220::readTemperature(channelIndex);
}
}
}
#endif
Expand Down
43 changes: 19 additions & 24 deletions src/eez/modules/psu/temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ TempSensorTemperature sensors[temp_sensor::NUM_TEMP_SENSORS] = { TEMP_SENSORS };

////////////////////////////////////////////////////////////////////////////////

static uint32_t last_measured_tick;
static float last_max_channel_temperature;
static uint32_t max_temp_start_tick;
static bool force_power_down = false;
static uint32_t g_lastMeasuredTick;
static uint32_t g_maxTempCheckStartTick;
static float g_lastMaxChannelTemperature;

void init() {
for (int i = 0; i < temp_sensor::NUM_TEMP_SENSORS; ++i) {
Expand All @@ -65,45 +64,45 @@ bool test() {
return success;
}

void tick(uint32_t tick_usec) {
if (tick_usec - last_measured_tick >= TEMP_SENSOR_READ_EVERY_MS * 1000L) {
last_measured_tick = tick_usec;
void tick(uint32_t tickCount) {
if (tickCount - g_lastMeasuredTick >= TEMP_SENSOR_READ_EVERY_MS * 1000L) {
g_lastMeasuredTick = tickCount;

for (int i = 0; i < temp_sensor::NUM_TEMP_SENSORS; ++i) {
sensors[i].tick(tick_usec);
sensors[i].tick(tickCount);
}

// find max. channel temperature
float max_channel_temperature = FLT_MIN;
float maxChannelTemperature = FLT_MIN;

for (int i = 0; i < temp_sensor::NUM_TEMP_SENSORS; ++i) {
temp_sensor::TempSensor &sensor = temp_sensor::sensors[i];
if (sensor.getChannel()) {
if (sensor.g_testResult == TEST_OK) {
temperature::TempSensorTemperature &sensorTemperature = temperature::sensors[i];
if (sensorTemperature.temperature > max_channel_temperature) {
max_channel_temperature = sensorTemperature.temperature;
if (sensorTemperature.temperature > maxChannelTemperature) {
maxChannelTemperature = sensorTemperature.temperature;
}
}
}
}

// check if max_channel_temperature is too high
if (max_channel_temperature > FAN_MAX_TEMP) {
if (last_max_channel_temperature <= FAN_MAX_TEMP) {
max_temp_start_tick = tick_usec;
if (isPowerUp() && maxChannelTemperature > FAN_MAX_TEMP) {
if (g_lastMaxChannelTemperature <= FAN_MAX_TEMP) {
g_maxTempCheckStartTick = tickCount;
}

if (tick_usec - max_temp_start_tick > FAN_MAX_TEMP_DELAY * 1000000L) {
if (tickCount - g_maxTempCheckStartTick > FAN_MAX_TEMP_DELAY * 1000000L) {
// turn off power
force_power_down = true;
event_queue::pushEvent(event_queue::EVENT_ERROR_HIGH_TEMPERATURE);
changePowerState(false);
}
} else if (max_channel_temperature <= FAN_MAX_TEMP - FAN_MAX_TEMP_DROP) {
force_power_down = false;
} else {
g_maxTempCheckStartTick = tickCount;
}

last_max_channel_temperature = max_channel_temperature;
g_lastMaxChannelTemperature = maxChannelTemperature;
}
}

Expand Down Expand Up @@ -150,11 +149,7 @@ void disableChannelProtection(Channel *channel) {
}

float getMaxChannelTemperature() {
return last_max_channel_temperature;
}

bool isAllowedToPowerUp() {
return !force_power_down;
return g_lastMaxChannelTemperature;
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
1 change: 0 additions & 1 deletion src/eez/modules/psu/temperature.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ void clearChannelProtection(Channel *channel);
void disableChannelProtection(Channel *channel);

float getMaxChannelTemperature();
bool isAllowedToPowerUp();

class TempSensorTemperature {
public:
Expand Down

0 comments on commit b30738a

Please sign in to comment.