Heater for threaded program

Dependents:   LEX_Threaded_Programming_V3

Revision:
49:35fd40559960
Parent:
48:cd2a9b799e89
Child:
50:ad9a1eb063b3
--- a/Heater.cpp	Tue Dec 17 13:28:23 2019 +0000
+++ b/Heater.cpp	Mon Mar 09 15:26:53 2020 +0000
@@ -73,15 +73,19 @@
 
     //Integral term (if used)
     if (thermal.pid_integral_time_ms > 0) { // set integral time to zero to have no integral term
-        if (abs(error) > thermal.pid_wind_up_limit_ohm) error = error * thermal.pid_wind_up_limit_ohm / abs(error);    
+    //  if (abs(error) > thermal.pid_wind_up_limit_ohm) error = error * thermal.pid_wind_up_limit_ohm / abs(error);    // don't use pid_wind_up_limit
         error_integrated += error * (float) thermal.thermal_control_loop_interval_ms;
         duty_cycle += thermal.pid_kp_mho * error_integrated/thermal.pid_integral_time_ms;
     }
     
-    if (duty_cycle > thermal.pid_pwm_limit)
+    if (duty_cycle > thermal.pid_pwm_limit) {
         duty_cycle = thermal.pid_pwm_limit;  
-    else if (duty_cycle < 0)
+        error_integrated = 0;  // zero error_integrated if system is outside linear control range
+        }
+    else if (duty_cycle < 0) {
         duty_cycle = 0;
+        error_integrated = 0;  // zero error_integrated if system is outside linear control range
+        }
         
     drive->write(duty_cycle);
     guard->write(duty_cycle * thermal.guard_drive_ratio);