Merge pull request #61 from alexrj/temp-residency

New implementation of TEMP_RESIDENCY_TIME
This commit is contained in:
kliment 2011-07-26 11:04:54 -07:00
commit 15c76d51bb
2 changed files with 20 additions and 18 deletions

View file

@ -143,8 +143,9 @@ 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
// Wait this long after achieving target temperature on M109 before continuing with print (seconds)
//#define TEMP_RESIDENCY_TIME 20
// 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

View file

@ -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.