From 53be78c9496f3fa2df191fb7dc621affdb2e1dc1 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Tue, 26 Jul 2011 18:17:52 +0200 Subject: New implementation of TEMP_RESIDENCY_TIME. We now wait for the target temp to be esablished and maintained for residency time +/- a configurable hysteresis --- Sprinter/Sprinter.pde | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'Sprinter/Sprinter.pde') diff --git a/Sprinter/Sprinter.pde b/Sprinter/Sprinter.pde index 801f103..4b93c0e 100644 --- a/Sprinter/Sprinter.pde +++ b/Sprinter/Sprinter.pde @@ -769,7 +769,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,23 +786,15 @@ inline void process_commands() codenum = millis(); } manage_heater(); - } - // wait extra time before letting the print continue - #ifdef TEMP_RESIDENCY_TIME - { - long residencyStart = millis(); - codenum = millis(); - while(millis()-residencyStart<(TEMP_RESIDENCY_TIME*1000)) { - if( (millis() - codenum) > 1000 ) //Print Temp Reading every 1 second while heating up. - { - Serial.print("T:"); - Serial.println( analog2temp(current_raw) ); - codenum = millis(); + #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(); } - manage_heater(); - } + #endif } - #endif break; case 190: // M190 - Wait bed for heater to reach target. -- cgit v1.2.1