diff options
-rw-r--r-- | Sprinter/Configuration.h | 8 | ||||
-rw-r--r-- | Sprinter/Sprinter.pde | 28 | ||||
-rw-r--r-- | Sprinter/pins.h | 2 |
3 files changed, 34 insertions, 4 deletions
diff --git a/Sprinter/Configuration.h b/Sprinter/Configuration.h index 53ab2e5..aa676bd 100644 --- a/Sprinter/Configuration.h +++ b/Sprinter/Configuration.h @@ -117,13 +117,15 @@ char uuid[] = "00000000-0000-0000-0000-000000000000"; // Uncomment the following line to enable PID support. This is untested and could be disastrous. Be careful. //#define PIDTEMP #ifdef PIDTEMP -#define PID_MAX 255 // limits current to nozzle #define PID_INTEGRAL_DRIVE_MAX 220 #define PID_PGAIN 180 //100 is 1.0 #define PID_IGAIN 2 //100 is 1.0 #define PID_DGAIN 100 //100 is 1.0 #endif +// Change this value (range 1-255) to limit the current to the nozzle +#define HEATER_CURRENT 255 + // How often should the heater check for new temp readings, in milliseconds #define HEATER_CHECK_INTERVAL 500 #define BED_CHECK_INTERVAL 5000 @@ -147,6 +149,10 @@ char uuid[] = "00000000-0000-0000-0000-000000000000"; // If the temperature has not increased at the end of that period, the target temperature is set to zero. It can be reset with another M104/M109 //#define WATCHPERIOD 5000 //5 seconds +// Actual temperature must be close to target for this long before M109 returns success +//#define TEMP_RESIDENCY_TIME 20 // (seconds) +//#define TEMP_HYSTERESIS 5 // (C°) range of +/- temperatures considered "close" to the target one + //// The minimal temperature defines the temperature below which the heater will not be enabled #define MINTEMP 5 diff --git a/Sprinter/Sprinter.pde b/Sprinter/Sprinter.pde index dde302c..76c221f 100644 --- a/Sprinter/Sprinter.pde +++ b/Sprinter/Sprinter.pde @@ -126,6 +126,9 @@ int tt = 0, bt = 0; int temp_iState_min = 100 * -PID_INTEGRAL_DRIVE_MAX / PID_IGAIN; int temp_iState_max = 100 * PID_INTEGRAL_DRIVE_MAX / PID_IGAIN; #endif +#ifndef HEATER_CURRENT + #define HEATER_CURRENT 255 +#endif #ifdef SMOOTHING uint32_t nma = 0; #endif @@ -769,7 +772,16 @@ inline void process_commands() } #endif codenum = millis(); - while(current_raw < target_raw) { + #ifdef TEMP_RESIDENCY_TIME + long residencyStart; + residencyStart = -1; + /* continue to loop until we have reached the target temp + _and_ until TEMP_RESIDENCY_TIME hasn't passed since we reached it */ + while( current_raw < target_raw + || (residencyStart > -1 && (millis() - residencyStart) < TEMP_RESIDENCY_TIME*1000) ) { + #else + while(current_raw < target_raw) { + #endif if( (millis() - codenum) > 1000 ) //Print Temp Reading every 1 second while heating up. { Serial.print("T:"); @@ -777,7 +789,16 @@ inline void process_commands() codenum = millis(); } manage_heater(); + #ifdef TEMP_RESIDENCY_TIME + /* start/restart the TEMP_RESIDENCY_TIME timer whenever we reach target temp for the first time + or when current temp falls outside the hysteresis after target temp was reached */ + if ( (residencyStart == -1 && current_raw >= target_raw) + || (residencyStart > -1 && labs(analog2temp(current_raw) - analog2temp(target_raw)) > TEMP_HYSTERESIS) ) { + residencyStart = millis(); + } + #endif } + break; case 190: // M190 - Wait bed for heater to reach target. #if TEMP_1_PIN > -1 @@ -1400,6 +1421,7 @@ void manage_heater() if(watch_raw + 1 >= current_raw){ target_raw = 0; WRITE(HEATER_0_PIN,LOW); + analogWrite(HEATER_0_PIN, 0); #if LED_PIN>-1 WRITE(LED_PIN,LOW); #endif @@ -1426,11 +1448,12 @@ void manage_heater() iTerm = (PID_IGAIN * temp_iState) / 100; dTerm = (PID_DGAIN * (current_raw - temp_dState)) / 100; temp_dState = current_raw; - analogWrite(HEATER_0_PIN, constrain(pTerm + iTerm - dTerm, 0, PID_MAX)); + analogWrite(HEATER_0_PIN, constrain(pTerm + iTerm - dTerm, 0, HEATER_CURRENT)); #else if(current_raw >= target_raw) { WRITE(HEATER_0_PIN,LOW); + analogWrite(HEATER_0_PIN, 0); #if LED_PIN>-1 WRITE(LED_PIN,LOW); #endif @@ -1438,6 +1461,7 @@ void manage_heater() else { WRITE(HEATER_0_PIN,HIGH); + analogWrite(HEATER_0_PIN, HEATER_CURRENT); #if LED_PIN > -1 WRITE(LED_PIN,HIGH); #endif diff --git a/Sprinter/pins.h b/Sprinter/pins.h index 0d861cc..93b69ae 100644 --- a/Sprinter/pins.h +++ b/Sprinter/pins.h @@ -384,7 +384,7 @@ #define HEATER_1_PIN 8 #define TEMP_0_PIN 13 // ANALOG NUMBERING #define TEMP_1_PIN 14 // ANALOG NUMBERING - +#define TEMP_2_PIN 15 // ANALOG NUMBERING #else // RAMPS_V_1_1 or RAMPS_V_1_2 as default |