Skip to content

Commit

Permalink
fan/temp_sensor fixed when there is no power channel
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed May 4, 2020
1 parent 3c12a44 commit e39369d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
50 changes: 27 additions & 23 deletions src/eez/modules/aux_ps/fan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,32 +475,36 @@ int updateFanSpeed() {
}
}
} else {
// adjust fan speed depending on max. channel temperature
float maxChannelTemperature = psu::temperature::getMaxChannelTemperature();

float iMonMax, iMax;
getIMonMax(iMonMax, iMax);
float Ki = roundPrec(remap(iMonMax * iMonMax, 0, FAN_PID_KI_MIN, iMax * iMax, FAN_PID_KI_MAX), 0.05f);
if (Ki != g_Ki) {
g_Ki = Ki;
g_fanPID.SetTunings(g_Kp, g_Ki, g_Kd, g_POn);
g_pidTarget = FAN_MIN_TEMP - 2.0 * iMonMax;
}
if (psu::CH_NUM > 0) {
// adjust fan speed depending on max. channel temperature
float maxChannelTemperature = psu::temperature::getMaxChannelTemperature();

float iMonMax, iMax;
getIMonMax(iMonMax, iMax);
float Ki = roundPrec(remap(iMonMax * iMonMax, 0, FAN_PID_KI_MIN, iMax * iMax, FAN_PID_KI_MAX), 0.05f);
if (Ki != g_Ki) {
g_Ki = Ki;
g_fanPID.SetTunings(g_Kp, g_Ki, g_Kd, g_POn);
g_pidTarget = FAN_MIN_TEMP - 2.0 * iMonMax;
}

g_pidTemp = maxChannelTemperature;
if (g_fanPID.Compute()) {
newFanSpeedPWM = (int)round(g_pidDuty);
g_pidTemp = maxChannelTemperature;
if (g_fanPID.Compute()) {
newFanSpeedPWM = (int)round(g_pidDuty);

if (newFanSpeedPWM <= 0) {
newFanSpeedPWM = 0;
} else {
newFanSpeedPWM += FAN_MIN_PWM;
}
if (newFanSpeedPWM <= 0) {
newFanSpeedPWM = 0;
} else {
newFanSpeedPWM += FAN_MIN_PWM;
}

if (newFanSpeedPWM > FAN_MAX_PWM) {
newFanSpeedPWM = FAN_MAX_PWM;
}
}
if (newFanSpeedPWM > FAN_MAX_PWM) {
newFanSpeedPWM = FAN_MAX_PWM;
}
}
} else {
newFanSpeedPWM = 0;
}
}

return newFanSpeedPWM;
Expand Down
4 changes: 2 additions & 2 deletions src/eez/modules/psu/temp_sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ bool TempSensor::isInstalled() {
}

Channel *TempSensor::getChannel() {
if (type >= CH1 && type <= CH6) {
if (type >= CH1 && type < CH1 + CH_NUM) {
return &Channel::get(type - CH1);
}
return NULL;
return nullptr;
}

void TempSensor::init() {
Expand Down

0 comments on commit e39369d

Please sign in to comment.