From fd5b7e0cec6f03a744876ebd48b0845072fc3564 Mon Sep 17 00:00:00 2001
From: whosawhatsis <whosawhatsis@gmail.com>
Date: Fri, 22 Mar 2013 18:16:26 -0700
Subject: [PATCH] Separate PID_MAX from BANG_MAX

This allows PID_FUNCTIONAL_RANGE to use a maximum duty cycle higher
than PID_MAX. This is useful for powerful heaters to heat quickly in
bang-bang mode, but use a lower duty cycle that is easier to stabilize
in PID mode.
---
 Marlin/Configuration.h | 3 ++-
 Marlin/temperature.cpp | 4 ++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h
index 8031272db6..6019200884 100644
--- a/Marlin/Configuration.h
+++ b/Marlin/Configuration.h
@@ -117,7 +117,8 @@
 // PID settings:
 // Comment the following line to disable PID and enable bang-bang.
 #define PIDTEMP
-#define PID_MAX 256 // limits current to nozzle; 256=full current
+#define BANG_MAX 256 // limits current to nozzle while in bang-bang mode; 256=full current
+#define PID_MAX 256 // limits current to nozzle while PID is active (see PID_FUNCTIONAL_RANGE below); 256=full current
 #ifdef PIDTEMP
   //#define PID_DEBUG // Sends debug data to the serial port. 
   //#define PID_OPENLOOP 1 // Puts PID in open loop. M104/M140 sets the output power from 0 to PID_MAX
diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp
index 6093c99346..58c7b60e6f 100644
--- a/Marlin/temperature.cpp
+++ b/Marlin/temperature.cpp
@@ -325,10 +325,10 @@ void manage_heater()
     #ifndef PID_OPENLOOP
         pid_error[e] = target_temperature[e] - pid_input;
         if(pid_error[e] > PID_FUNCTIONAL_RANGE) {
-          pid_output = PID_MAX;
+          pid_output = BANG_MAX;
           pid_reset[e] = true;
         }
-        else if(pid_error[e] < -PID_FUNCTIONAL_RANGE) {
+        else if(pid_error[e] < -PID_FUNCTIONAL_RANGE || target_temperature[e] == 0) {
           pid_output = 0;
           pid_reset[e] = true;
         }