Browse Source

heater.c: Limit PID I term with conditional integration.

David Forrest 11 years ago
parent
commit
c9b8435749
1 changed files with 8 additions and 1 deletions
  1. 8
    1
      Marlin/temperature.cpp

+ 8
- 1
Marlin/temperature.cpp View File

@@ -455,7 +455,14 @@ void manage_heater()
455 455
           //K1 defined in Configuration.h in the PID settings
456 456
           #define K2 (1.0-K1)
457 457
           dTerm[e] = (Kd * (pid_input - temp_dState[e]))*K2 + (K1 * dTerm[e]);
458
-          pid_output = constrain(pTerm[e] + iTerm[e] - dTerm[e], 0, PID_MAX);
458
+          pid_output = pTerm[e] + iTerm[e] - dTerm[e];
459
+          if (pid_output > PID_MAX) {
460
+            if (pid_error[e] > 0 )  temp_iState[e] -= pid_error[e]; // conditional un-integration
461
+            pid_output=PID_MAX;
462
+          } else if (pid_output < 0){
463
+            if (pid_error[e] < 0 )  temp_iState[e] -= pid_error[e]; // conditional un-integration
464
+            pid_output=0;
465
+          }
459 466
         }
460 467
         temp_dState[e] = pid_input;
461 468
     #else 

Loading…
Cancel
Save