chiark / gitweb /
Limit PID autotune PWM to PID_MAX
authorErik van der Zalm <erik@vdzalm.eu>
Wed, 16 May 2012 17:32:23 +0000 (19:32 +0200)
committerErik van der Zalm <erik@vdzalm.eu>
Wed, 16 May 2012 17:32:23 +0000 (19:32 +0200)
Marlin/temperature.cpp

index e21bd2598da94e626228749c1c7b2aacf6bfb645..395061cc212475dab409c7ad93fb7a17aad89eb8 100644 (file)
@@ -134,8 +134,8 @@ void PID_autotune(float temp)
   long t_high;
   long t_low;
 
-  long bias=127;
-  long d = 127;
+  long bias=PID_MAX/2;
+  long d = PID_MAX/2;
   float Ku, Tu;
   float Kp, Ki, Kd;
   float max, min;
@@ -144,7 +144,7 @@ void PID_autotune(float temp)
   
   disable_heater(); // switch off all heaters.
   
-  soft_pwm[0] = 255>>1;
+  soft_pwm[0] = PID_MAX/2;
     
   for(;;) {
 
@@ -172,8 +172,8 @@ void PID_autotune(float temp)
           t_low=t2 - t1;
           if(cycles > 0) {
             bias += (d*(t_high - t_low))/(t_low + t_high);
-            bias = constrain(bias, 20 ,235);
-            if(bias > 127) d = 254 - bias;
+            bias = constrain(bias, 20 ,PID_MAX-20);
+            if(bias > PID_MAX/2) d = PID_MAX - 1 - bias;
             else d = bias;
 
             SERIAL_PROTOCOLPGM(" bias: "); SERIAL_PROTOCOL(bias);