thermferm/thermferm.c

changeset 401
0226d0f37bb7
parent 398
efdfef1677d1
child 402
6b9f0c3c7f63
equal deleted inserted replaced
400:d36f4fefd4e2 401:0226d0f37bb7
1225 if ((run_hours >= time_until_now) && (run_hours < (time_until_now + step->steptime + step->resttime))) { 1225 if ((run_hours >= time_until_now) && (run_hours < (time_until_now + step->steptime + step->resttime))) {
1226 /* 1226 /*
1227 * This is our current step 1227 * This is our current step
1228 */ 1228 */
1229 valid_step = TRUE; 1229 valid_step = TRUE;
1230 unit->prof_fridge_mode = step->fridge_mode; 1230 // unit->prof_fridge_mode = step->fridge_mode;
1231 if (debug) 1231 if (debug)
1232 fprintf(stdout, "step=%d step_pos=%d step=%d/%d target=%.1f..%.1f ", 1232 fprintf(stdout, "step=%d step_pos=%d step=%d/%d target=%.1f..%.1f ",
1233 current_step, run_hours - time_until_now, 1233 current_step, run_hours - time_until_now,
1234 step->steptime, step->resttime, step->target_lo, step->target_hi); 1234 step->steptime, step->resttime, step->target_lo, step->target_hi);
1235 if ((run_hours - time_until_now) < step->steptime) { 1235 if ((run_hours - time_until_now) < step->steptime) {
1236 unit->prof_target_lo = previous_target_lo + (((run_minutes - (time_until_now * 60.0)) / (step->steptime * 60.0)) * (step->target_lo - previous_target_lo)); 1236 unit->prof_target_lo = previous_target_lo + (((run_minutes - (time_until_now * 60.0)) / (step->steptime * 60.0)) * (step->target_lo - previous_target_lo));
1237 unit->prof_target_hi = previous_target_hi + (((run_minutes - (time_until_now * 60.0)) / (step->steptime * 60.0)) * (step->target_hi - previous_target_hi)); 1237 unit->prof_target_hi = previous_target_hi + (((run_minutes - (time_until_now * 60.0)) / (step->steptime * 60.0)) * (step->target_hi - previous_target_hi));
1238 // FIXME: shift fridge_mode 1238 if (step->fridge_mode > previous_fridge_mode) {
1239 unit->prof_fridge_mode = (((run_minutes - (time_until_now * 60)) * 100) / (step->steptime * 60));
1240 } else if (step->fridge_mode < previous_fridge_mode) {
1241 unit->prof_fridge_mode = 100 - (((run_minutes - (time_until_now * 60)) * 100) / (step->steptime * 60));
1242 } else {
1243 unit->prof_fridge_mode = step->fridge_mode;
1244 }
1245 if (debug)
1246 fprintf(stdout, "%d/%d/%d ", previous_fridge_mode, step->fridge_mode, unit->prof_fridge_mode);
1247
1239 if (debug) 1248 if (debug)
1240 fprintf(stdout, "tempshift=%.1f..%.1f minutes=%d duration=%d temp_move=%.3f..%.3f ", 1249 fprintf(stdout, "tempshift=%.1f..%.1f minutes=%d duration=%d temp_move=%.3f..%.3f ",
1241 step->target_lo - previous_target_lo, 1250 step->target_lo - previous_target_lo,
1242 step->target_hi - previous_target_hi, 1251 step->target_hi - previous_target_hi,
1243 run_minutes - (time_until_now * 60), 1252 run_minutes - (time_until_now * 60),
1388 /* 1397 /*
1389 * Set both PID's to their input values. 1398 * Set both PID's to their input values.
1390 */ 1399 */
1391 unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_NONE; 1400 unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_NONE;
1392 if (unit->mode == UNITMODE_FRIDGE) { 1401 if (unit->mode == UNITMODE_FRIDGE) {
1393 unit->PID_cool->SetP = unit->PID_heat->SetP = unit->fridge_set; 1402 unit->PID_cool->SetP = unit->fridge_set;
1403 unit->PID_heat->SetP = unit->fridge_set;
1394 unit->PID_cool->Input = unit->PID_heat->Input = unit->air_temperature / 1000.0; 1404 unit->PID_cool->Input = unit->PID_heat->Input = unit->air_temperature / 1000.0;
1395 unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_BOO; 1405 unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_BOO;
1396 } else if (unit->mode == UNITMODE_BEER) { 1406 } else if (unit->mode == UNITMODE_BEER) {
1397 unit->PID_cool->SetP = unit->PID_heat->SetP = unit->beer_set; 1407 unit->PID_cool->SetP = unit->beer_set;
1408 unit->PID_heat->SetP = unit->beer_set;
1398 unit->PID_cool->Input = unit->PID_heat->Input = unit->beer_temperature / 1000.0; 1409 unit->PID_cool->Input = unit->PID_heat->Input = unit->beer_temperature / 1000.0;
1399 unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_AUTO; 1410 unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_AUTO;
1400 } else if (unit->mode == UNITMODE_PROFILE) { 1411 } else if (unit->mode == UNITMODE_PROFILE) {
1412 double usetemp;
1401 unit->PID_cool->SetP = unit->prof_target_hi; 1413 unit->PID_cool->SetP = unit->prof_target_hi;
1402 unit->PID_heat->SetP = unit->prof_target_lo; 1414 unit->PID_heat->SetP = unit->prof_target_lo;
1403 if (unit->prof_fridge_mode) 1415 /*
1404 unit->PID_cool->Input = unit->PID_heat->Input = unit->air_temperature / 1000.0; 1416 * Get percentage to use from each thermometer. unit->prof_fridge_mode = 0..100
1405 else 1417 */
1406 unit->PID_cool->Input = unit->PID_heat->Input = unit->beer_temperature / 1000.0; 1418 usetemp = ((unit->prof_fridge_mode * (unit->air_temperature / 1000.0)) +
1419 ((100 - unit->prof_fridge_mode) * (unit->beer_temperature / 1000.0))) / 100.0;
1420 if (debug)
1421 fprintf(stdout, " fridge_mode=%d measured=%.3f %.3f => %.3f\n", unit->prof_fridge_mode,
1422 unit->air_temperature / 1000.0, unit->beer_temperature / 1000.0, usetemp);
1423 unit->PID_cool->Input = unit->PID_heat->Input = usetemp;
1407 unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_AUTO; 1424 unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_AUTO;
1408 } 1425 }
1409 1426
1410 /* 1427 /*
1411 * PID controller compute 1428 * PID controller compute

mercurial