diff --git a/boil_kettle/src/thermoControl/thermoControl.cpp b/boil_kettle/src/thermoControl/thermoControl.cpp index 2656d04..655b985 100644 --- a/boil_kettle/src/thermoControl/thermoControl.cpp +++ b/boil_kettle/src/thermoControl/thermoControl.cpp @@ -14,24 +14,27 @@ thermoControl::thermoControl(double* current_temp, double* setpoint, double* pow actual_temp = current_temp; hysteresis = 1.0; max_pwr_threshold = 5.0; + isheating=false; Serial.println("Controller Started"); } bool thermoControl::Compute() { unsigned long now = millis(); unsigned long timeChange = (now - lastTime); - + if(timeChange >= SampleInterval && OpMode == AUTOMATIC) { double error = *control_temp - *actual_temp; if (error >= max_pwr_threshold) { *output_pwm = outMax; - } else if (error > hysteresis) { + isheating=true; + } else if (error > hysteresis || (error <= hysteresis && error > 0 && isheating)) { *output_pwm = 100 * error / max_pwr_threshold; if (*output_pwm > 100) *output_pwm = 100; - if (*output_pwm < 0) *output_pwm = 0; + isheating=true; } else { *output_pwm = 0; + isheating=false; } lastTime = now; diff --git a/boil_kettle/src/thermoControl/thermoControl.h b/boil_kettle/src/thermoControl/thermoControl.h index 3562e57..ee212d3 100644 --- a/boil_kettle/src/thermoControl/thermoControl.h +++ b/boil_kettle/src/thermoControl/thermoControl.h @@ -17,6 +17,7 @@ class thermoControl { int outMin; int SampleInterval; unsigned long lastTime; + bool isheating; modes OpMode; public: