|
|
@ -40,6 +40,7 @@
|
|
|
|
#include "Simplelcd.h"
|
|
|
|
#include "Simplelcd.h"
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Heater htr;
|
|
|
|
char version_string[] = "1.0.0 Alpha 1";
|
|
|
|
char version_string[] = "1.0.0 Alpha 1";
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef SDSUPPORT
|
|
|
|
#ifdef SDSUPPORT
|
|
|
@ -263,7 +264,7 @@ void setup()
|
|
|
|
#endif //SDSUPPORT
|
|
|
|
#endif //SDSUPPORT
|
|
|
|
plan_init(); // Initialize planner;
|
|
|
|
plan_init(); // Initialize planner;
|
|
|
|
st_init(); // Initialize stepper;
|
|
|
|
st_init(); // Initialize stepper;
|
|
|
|
tp_init(); // Initialize temperature loop
|
|
|
|
//tp_init(); // Initialize temperature loop is now done by the constructor of the Heater class
|
|
|
|
//checkautostart();
|
|
|
|
//checkautostart();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -367,7 +368,7 @@ void loop()
|
|
|
|
bufindr = (bufindr + 1)%BUFSIZE;
|
|
|
|
bufindr = (bufindr + 1)%BUFSIZE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//check heater every n milliseconds
|
|
|
|
//check heater every n milliseconds
|
|
|
|
manage_heater();
|
|
|
|
Heater::manage_heater();
|
|
|
|
manage_inactivity(1);
|
|
|
|
manage_inactivity(1);
|
|
|
|
LCD_STATUS;
|
|
|
|
LCD_STATUS;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -547,7 +548,7 @@ inline void process_commands()
|
|
|
|
if(code_seen('S')) codenum = code_value() * 1000; // seconds to wait
|
|
|
|
if(code_seen('S')) codenum = code_value() * 1000; // seconds to wait
|
|
|
|
codenum += millis(); // keep track of when we started waiting
|
|
|
|
codenum += millis(); // keep track of when we started waiting
|
|
|
|
while(millis() < codenum ){
|
|
|
|
while(millis() < codenum ){
|
|
|
|
manage_heater();
|
|
|
|
Heater::manage_heater();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 28: //G28 Home all Axis one at a time
|
|
|
|
case 28: //G28 Home all Axis one at a time
|
|
|
@ -801,12 +802,9 @@ inline void process_commands()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 104: // M104
|
|
|
|
case 104: // M104
|
|
|
|
if (code_seen('S')) target_raw[TEMPSENSOR_HOTEND] = temp2analog(code_value());
|
|
|
|
if (code_seen('S')) Heater::setCelsius(TEMPSENSOR_HOTEND,code_value());
|
|
|
|
#ifdef PIDTEMP
|
|
|
|
|
|
|
|
pid_setpoint = code_value();
|
|
|
|
|
|
|
|
#endif //PIDTEM
|
|
|
|
|
|
|
|
#ifdef WATCHPERIOD
|
|
|
|
#ifdef WATCHPERIOD
|
|
|
|
if(target_raw[TEMPSENSOR_HOTEND] > current_raw[TEMPSENSOR_HOTEND]){
|
|
|
|
if(Heater::isHeating(TEMPSENSOR_HOTEND)){
|
|
|
|
watchmillis = max(1,millis());
|
|
|
|
watchmillis = max(1,millis());
|
|
|
|
watch_raw[TEMPSENSOR_HOTEND] = current_raw[TEMPSENSOR_HOTEND];
|
|
|
|
watch_raw[TEMPSENSOR_HOTEND] = current_raw[TEMPSENSOR_HOTEND];
|
|
|
|
}else{
|
|
|
|
}else{
|
|
|
@ -815,14 +813,14 @@ inline void process_commands()
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 140: // M140 set bed temp
|
|
|
|
case 140: // M140 set bed temp
|
|
|
|
if (code_seen('S')) target_raw[TEMPSENSOR_BED] = temp2analogBed(code_value());
|
|
|
|
if (code_seen('S')) Heater::setCelsius(TEMPSENSOR_BED,code_value());
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 105: // M105
|
|
|
|
case 105: // M105
|
|
|
|
#if (TEMP_0_PIN > -1) || defined (HEATER_USES_AD595)
|
|
|
|
#if (TEMP_0_PIN > -1) || defined (HEATER_USES_AD595)
|
|
|
|
tt = analog2temp(current_raw[TEMPSENSOR_HOTEND]);
|
|
|
|
tt = Heater::celsius(TEMPSENSOR_HOTEND);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#if TEMP_1_PIN > -1
|
|
|
|
#if TEMP_1_PIN > -1
|
|
|
|
bt = analog2tempBed(current_raw[TEMPSENSOR_BED]);
|
|
|
|
bt = Heater::celsius(TEMPSENSOR_BED);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#if (TEMP_0_PIN > -1) || defined (HEATER_USES_AD595)
|
|
|
|
#if (TEMP_0_PIN > -1) || defined (HEATER_USES_AD595)
|
|
|
|
Serial.print("ok T:");
|
|
|
|
Serial.print("ok T:");
|
|
|
@ -835,12 +833,12 @@ inline void process_commands()
|
|
|
|
#if TEMP_1_PIN > -1
|
|
|
|
#if TEMP_1_PIN > -1
|
|
|
|
Serial.println(bt);
|
|
|
|
Serial.println(bt);
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
Serial.println(HeaterPower);
|
|
|
|
Serial.println(Heater::HeaterPower);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
Serial.println();
|
|
|
|
Serial.println();
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#else<
|
|
|
|
Serial.println();
|
|
|
|
Serial.println();
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#else
|
|
|
@ -850,14 +848,12 @@ inline void process_commands()
|
|
|
|
//break;
|
|
|
|
//break;
|
|
|
|
case 109: {// M109 - Wait for extruder heater to reach target.
|
|
|
|
case 109: {// M109 - Wait for extruder heater to reach target.
|
|
|
|
LCD_MESSAGE("Heating...");
|
|
|
|
LCD_MESSAGE("Heating...");
|
|
|
|
if (code_seen('S')) target_raw[TEMPSENSOR_HOTEND] = temp2analog(code_value());
|
|
|
|
if (code_seen('S')) Heater::setCelsius(TEMPSENSOR_HOTEND,code_value());
|
|
|
|
#ifdef PIDTEMP
|
|
|
|
|
|
|
|
pid_setpoint = code_value();
|
|
|
|
|
|
|
|
#endif //PIDTEM
|
|
|
|
|
|
|
|
#ifdef WATCHPERIOD
|
|
|
|
#ifdef WATCHPERIOD
|
|
|
|
if(target_raw[TEMPSENSOR_HOTEND]>current_raw[TEMPSENSOR_HOTEND]){
|
|
|
|
if(Heater::isHeating(TEMPSENSOR_HOTEND)){
|
|
|
|
watchmillis = max(1,millis());
|
|
|
|
watchmillis = max(1,millis());
|
|
|
|
watch_raw[TEMPSENSOR_HOTEND] = current_raw[TEMPSENSOR_HOTEND];
|
|
|
|
watch_raw[TEMPSENSOR_HOTEND] = Heater::current_raw[TEMPSENSOR_HOTEND];
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
watchmillis = 0;
|
|
|
|
watchmillis = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -865,31 +861,31 @@ inline void process_commands()
|
|
|
|
codenum = millis();
|
|
|
|
codenum = millis();
|
|
|
|
|
|
|
|
|
|
|
|
/* See if we are heating up or cooling down */
|
|
|
|
/* See if we are heating up or cooling down */
|
|
|
|
bool target_direction = (current_raw[0] < target_raw[0]); // true if heating, false if cooling
|
|
|
|
bool target_direction = Heater::isHeating(TEMPSENSOR_HOTEND); // true if heating, false if cooling
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef TEMP_RESIDENCY_TIME
|
|
|
|
#ifdef TEMP_RESIDENCY_TIME
|
|
|
|
long residencyStart;
|
|
|
|
long residencyStart;
|
|
|
|
residencyStart = -1;
|
|
|
|
residencyStart = -1;
|
|
|
|
/* continue to loop until we have reached the target temp
|
|
|
|
/* continue to loop until we have reached the target temp
|
|
|
|
_and_ until TEMP_RESIDENCY_TIME hasn't passed since we reached it */
|
|
|
|
_and_ until TEMP_RESIDENCY_TIME hasn't passed since we reached it */
|
|
|
|
while((target_direction ? (current_raw[0] < target_raw[0]) : (current_raw[0] > target_raw[0])) ||
|
|
|
|
while((target_direction ? Heater::isHeating(TEMPSENSOR_HOTEND) : Heater::isCooling(TEMPSENSOR_HOTEND)) ||
|
|
|
|
(residencyStart > -1 && (millis() - residencyStart) < TEMP_RESIDENCY_TIME*1000) ) {
|
|
|
|
(residencyStart > -1 && (millis() - residencyStart) < TEMP_RESIDENCY_TIME*1000) ) {
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
while ( target_direction ? (current_raw[0] < target_raw[0]) : (current_raw[0] > target_raw[0]) ) {
|
|
|
|
while ( target_direction ? Heater::isHeating(TEMPSENSOR_HOTEND) : Heater::isCooling(TEMPSENSOR_HOTEND) ) {
|
|
|
|
#endif //TEMP_RESIDENCY_TIME
|
|
|
|
#endif //TEMP_RESIDENCY_TIME
|
|
|
|
if( (millis() - codenum) > 1000 ) { //Print Temp Reading every 1 second while heating up/cooling down
|
|
|
|
if( (millis() - codenum) > 1000 ) { //Print Temp Reading every 1 second while heating up/cooling down
|
|
|
|
Serial.print("T:");
|
|
|
|
Serial.print("T:");
|
|
|
|
Serial.println( analog2temp(current_raw[TEMPSENSOR_HOTEND]) );
|
|
|
|
Serial.println( Heater::celsius(TEMPSENSOR_HOTEND) );
|
|
|
|
codenum = millis();
|
|
|
|
codenum = millis();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
manage_heater();
|
|
|
|
Heater::manage_heater();
|
|
|
|
LCD_STATUS;
|
|
|
|
LCD_STATUS;
|
|
|
|
#ifdef TEMP_RESIDENCY_TIME
|
|
|
|
#ifdef TEMP_RESIDENCY_TIME
|
|
|
|
/* start/restart the TEMP_RESIDENCY_TIME timer whenever we reach target temp for the first 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 */
|
|
|
|
or when current temp falls outside the hysteresis after target temp was reached */
|
|
|
|
if ((residencyStart == -1 && target_direction && current_raw[0] >= target_raw[0]) ||
|
|
|
|
if ((residencyStart == -1 && target_direction && !Heater::isHeating(TEMPSENSOR_HOTEND)) ||
|
|
|
|
(residencyStart == -1 && !target_direction && current_raw[0] <= target_raw[0]) ||
|
|
|
|
(residencyStart == -1 && !target_direction && !Heater::isCooling(TEMPSENSOR_HOTEND)) ||
|
|
|
|
(residencyStart > -1 && labs(analog2temp(current_raw[0]) - analog2temp(target_raw[0])) > TEMP_HYSTERESIS) ) {
|
|
|
|
(residencyStart > -1 && labs(Heater::celsius(TEMPSENSOR_HOTEND) - Heater::celsiusTarget(TEMPSENSOR_HOTEND)) > TEMP_HYSTERESIS) ) {
|
|
|
|
residencyStart = millis();
|
|
|
|
residencyStart = millis();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif //TEMP_RESIDENCY_TIME
|
|
|
|
#endif //TEMP_RESIDENCY_TIME
|
|
|
@ -899,22 +895,22 @@ inline void process_commands()
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 190: // M190 - Wait bed for heater to reach target.
|
|
|
|
case 190: // M190 - Wait bed for heater to reach target.
|
|
|
|
#if TEMP_1_PIN > -1
|
|
|
|
#if TEMP_1_PIN > -1
|
|
|
|
if (code_seen('S')) target_raw[TEMPSENSOR_BED] = temp2analog(code_value());
|
|
|
|
if (code_seen('S')) Heater::setCelsius(TEMPSENSOR_BED,code_value());
|
|
|
|
codenum = millis();
|
|
|
|
codenum = millis();
|
|
|
|
while(current_raw[TEMPSENSOR_BED] < target_raw[TEMPSENSOR_BED])
|
|
|
|
while(Heater::isHeating(TEMPSENSOR_BED))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if( (millis()-codenum) > 1000 ) //Print Temp Reading every 1 second while heating up.
|
|
|
|
if( (millis()-codenum) > 1000 ) //Print Temp Reading every 1 second while heating up.
|
|
|
|
{
|
|
|
|
{
|
|
|
|
float tt=analog2temp(current_raw[TEMPSENSOR_HOTEND]);
|
|
|
|
float tt=Heater::celsius(TEMPSENSOR_HOTEND);
|
|
|
|
Serial.print("T:");
|
|
|
|
Serial.print("T:");
|
|
|
|
Serial.println( tt );
|
|
|
|
Serial.println( tt );
|
|
|
|
Serial.print("ok T:");
|
|
|
|
Serial.print("ok T:");
|
|
|
|
Serial.print( tt );
|
|
|
|
Serial.print( tt );
|
|
|
|
Serial.print(" B:");
|
|
|
|
Serial.print(" B:");
|
|
|
|
Serial.println( analog2temp(current_raw[TEMPSENSOR_BED]) );
|
|
|
|
Serial.println( Heater::celsius(TEMPSENSOR_BED) );
|
|
|
|
codenum = millis();
|
|
|
|
codenum = millis();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
manage_heater();
|
|
|
|
Heater::manage_heater();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
break;
|
|
|
@ -1066,9 +1062,13 @@ inline void process_commands()
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
#ifdef PIDTEMP
|
|
|
|
#ifdef PIDTEMP
|
|
|
|
case 301: // M301
|
|
|
|
case 301: // M301
|
|
|
|
if(code_seen('P')) Kp = code_value();
|
|
|
|
if(code_seen('P')) Heater::Kp = code_value();
|
|
|
|
if(code_seen('I')) Ki = code_value()*PID_dT;
|
|
|
|
if(code_seen('I')) Heater::Ki = code_value()*PID_dT;
|
|
|
|
if(code_seen('D')) Kd = code_value()/PID_dT;
|
|
|
|
if(code_seen('D')) Heater::Kd = code_value()/PID_dT;
|
|
|
|
|
|
|
|
#ifdef PID_ADD_EXTRUSION_RATE
|
|
|
|
|
|
|
|
if(code_seen('C')) Heater::Kc = code_value();
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// ECHOLN("Kp "<<_FLOAT(Kp,2));
|
|
|
|
// ECHOLN("Kp "<<_FLOAT(Kp,2));
|
|
|
|
// ECHOLN("Ki "<<_FLOAT(Ki/PID_dT,2));
|
|
|
|
// ECHOLN("Ki "<<_FLOAT(Ki/PID_dT,2));
|
|
|
|
// ECHOLN("Kd "<<_FLOAT(Kd*PID_dT,2));
|
|
|
|
// ECHOLN("Kd "<<_FLOAT(Kd*PID_dT,2));
|
|
|
@ -1194,19 +1194,19 @@ void wd_reset() {
|
|
|
|
inline void kill()
|
|
|
|
inline void kill()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
#if TEMP_0_PIN > -1
|
|
|
|
#if TEMP_0_PIN > -1
|
|
|
|
target_raw[0]=0;
|
|
|
|
Heater::setCelsius(TEMPSENSOR_HOTEND,0);
|
|
|
|
#if HEATER_0_PIN > -1
|
|
|
|
#if HEATER_0_PIN > -1
|
|
|
|
WRITE(HEATER_0_PIN,LOW);
|
|
|
|
WRITE(HEATER_0_PIN,LOW);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#if TEMP_1_PIN > -1
|
|
|
|
#if TEMP_1_PIN > -1
|
|
|
|
target_raw[1]=0;
|
|
|
|
Heater::setCelsius(TEMPSENSOR_BED,0);
|
|
|
|
#if HEATER_1_PIN > -1
|
|
|
|
#if HEATER_1_PIN > -1
|
|
|
|
WRITE(HEATER_1_PIN,LOW);
|
|
|
|
WRITE(HEATER_1_PIN,LOW);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#if TEMP_2_PIN > -1
|
|
|
|
#if TEMP_2_PIN > -1
|
|
|
|
target_raw[2]=0;
|
|
|
|
Heater::setCelsius(TEMPSENSOR_AUX,0);
|
|
|
|
#if HEATER_2_PIN > -1
|
|
|
|
#if HEATER_2_PIN > -1
|
|
|
|
WRITE(HEATER_2_PIN,LOW);
|
|
|
|
WRITE(HEATER_2_PIN,LOW);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|