diff options
Diffstat (limited to 'Sprinter/Sprinter.pde')
-rw-r--r-- | Sprinter/Sprinter.pde | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/Sprinter/Sprinter.pde b/Sprinter/Sprinter.pde index 026daba..1173c79 100644 --- a/Sprinter/Sprinter.pde +++ b/Sprinter/Sprinter.pde @@ -127,6 +127,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 @@ -795,7 +798,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:"); @@ -803,7 +815,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 @@ -1426,6 +1447,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 @@ -1452,11 +1474,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 @@ -1464,6 +1487,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 |