diff -r 31b14c9ac625 -r 750f2468dec5 thermferm/thermferm.c --- a/thermferm/thermferm.c Sat Mar 05 12:50:23 2016 +0100 +++ b/thermferm/thermferm.c Fri Mar 11 20:27:02 2016 +0100 @@ -1516,15 +1516,15 @@ */ unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_NONE; if (unit->mode == UNITMODE_FRIDGE) { - unit->PID_cool->SetP = unit->fridge_set; - unit->PID_heat->SetP = unit->fridge_set; + unit->PID_cool->SetP = unit->fridge_set + unit->PID_cool->idleRange; + unit->PID_heat->SetP = unit->fridge_set - unit->PID_heat->idleRange; unit->PID_cool->Input = unit->PID_heat->Input = unit->air_temperature / 1000.0; unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_BOO; } else if (unit->mode == UNITMODE_BEER) { unit->PID_cool->SetP = unit->beer_set; unit->PID_heat->SetP = unit->beer_set; unit->PID_cool->Input = unit->PID_heat->Input = unit->beer_temperature / 1000.0; - unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_BOO; + unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_AUTO; } else if (unit->mode == UNITMODE_PROFILE) { double usetemp; unit->PID_cool->SetP = unit->prof_target_hi; @@ -1538,7 +1538,7 @@ fprintf(stdout, " fridge_mode=%d measured=%.3f %.3f => %.3f\n", unit->prof_fridge_mode, unit->air_temperature / 1000.0, unit->beer_temperature / 1000.0, usetemp); unit->PID_cool->Input = unit->PID_heat->Input = usetemp; - unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_BOO; + unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_AUTO; } /* @@ -1551,19 +1551,31 @@ * Logging */ if (unit->heater_address) { + /* + * Prevent extreme heating + */ + if ((unit->mode == UNITMODE_BEER) && ((unit->air_temperature / 1000.0) > (unit->PID_heat->Input + 5.0))) { + unit->PID_heat->OutP = 0.0; + } if (debug) fprintf(stdout, "Heat: sp=%.2f Input=%.2f iState=%.2f Err=%.2f Out=%.2f\n", unit->PID_heat->SetP, unit->PID_heat->Input, unit->PID_heat->iState, unit->PID_heat->Err, unit->PID_heat->OutP); - if (/* ((unit->PID_heat->OutP >= 2) && unit->heater_address) || */ (seconds == 60) /* || unit->heater_state */) { + if (seconds == 60) { syslog(LOG_NOTICE, "Heat: sp=%.2f Input=%.2f iState=%.2f Err=%.2f Out=%.2f", unit->PID_heat->SetP, unit->PID_heat->Input, unit->PID_heat->iState, unit->PID_heat->Err, unit->PID_heat->OutP); } } if (unit->cooler_address) { + /* + * Prevent extreme cooling + */ + if ((unit->mode == UNITMODE_BEER) && ((unit->air_temperature / 1000.0) < (unit->PID_cool->Input - 5.0))) { + unit->PID_cool->OutP = 0.0; + } if (debug) fprintf(stdout, "Cool: sp=%.2f Input=%.2f iState=%.2f Err=%.2f Out=%.2f\n", unit->PID_cool->SetP, unit->PID_cool->Input, unit->PID_cool->iState, unit->PID_cool->Err, unit->PID_cool->OutP); - if (/* ((unit->PID_cool->OutP >= 2) && unit->cooler_address) || */ (seconds == 60) /* || unit->cooler_state*/ ) { + if (seconds == 60) { syslog(LOG_NOTICE, "Cool: sp=%.2f Input=%.2f iState=%.2f Err=%.2f Out=%.2f", unit->PID_cool->SetP, unit->PID_cool->Input, unit->PID_cool->iState, unit->PID_cool->Err, unit->PID_cool->OutP); } @@ -1574,11 +1586,15 @@ */ if (unit->PID_cool->OutP && unit->PID_heat->OutP) { syslog(LOG_NOTICE, "Heat and Cool lockdown"); - unit->PID_cool->OutP = unit->PID_heat->OutP = 0.0; + if (unit->PID_cool->OutP > unit->PID_heat->OutP) + unit->PID_heat->OutP = 0.0; + else + unit->PID_cool->OutP = 0.0; +// unit->PID_cool->OutP = unit->PID_heat->OutP = 0.0; } if (unit->heater_address && ! unit->cooler_state) { - if (unit->PID_heat->OutP >= 2) { + if (unit->PID_heat->OutP >= 50) { if (unit->heater_wait < unit->heater_delay) { unit->heater_wait++; } else { @@ -1605,7 +1621,7 @@ } if (unit->cooler_address && ! unit->heater_state) { - if (unit->PID_cool->OutP >= 2) { + if (unit->PID_cool->OutP >= 50) { if (unit->cooler_wait < unit->cooler_delay) { unit->cooler_wait++; } else { @@ -1630,6 +1646,9 @@ else device_out(unit->cooler_address, 0); } + if (debug) + fprintf(stdout, "Final: PIDheat=%.2f PWRheat=%d PIDcool=%.2f PWRcool=%d\n", + unit->PID_heat->OutP, unit->heater_state, unit->PID_cool->OutP, unit->cooler_state); if ((unit->heater_address || unit->cooler_address) && unit->fan_address) { /*