// Comment the following line to disable PID and enable bang-bang.
// Comment the following line to disable PID and enable bang-bang.
#define PIDTEMP
#define PIDTEMP
#define BANG_MAX 255 // limits current to nozzle while in bang-bang mode; 255=full current
#define PID_MAX BANG_MAX // limits current to nozzle while PID is active (see PID_FUNCTIONAL_RANGE below); 255=full current
#define BANG_MAX 255 // limits current to nozzle while in bang-bang mode; 255=full current
#define PID_MAX BANG_MAX // limits current to nozzle while PID is active (see PID_FUNCTIONAL_RANGE below); 255=full current
#ifdef PIDTEMP
//#define PID_DEBUG // Sends debug data to the serial port.
//#define PID_DEBUG // Sends debug data to the serial port.
//#define PID_OPENLOOP 1 // Puts PID in open loop. M104/M140 sets the output power from 0 to PID_MAX
//#define PID_OPENLOOP 1 // Puts PID in open loop. M104/M140 sets the output power from 0 to PID_MAX
//#define SLOW_PWM_HEATERS // PWM with very low frequency (roughly 0.125Hz=8s) and minimum state time of approximately 1s useful for heaters driven by a relay
//#define SLOW_PWM_HEATERS // PWM with very low frequency (roughly 0.125Hz=8s) and minimum state time of approximately 1s useful for heaters driven by a relay
// If the temperature difference between the target temperature and the actual temperature
// If the temperature difference between the target temperature and the actual temperature
// is more then PID_FUNCTIONAL_RANGE then the PID will be shut off and the heater will be set to min/max.
// is more then PID_FUNCTIONAL_RANGE then the PID will be shut off and the heater will be set to min/max.
#define PID_FUNCTIONAL_RANGE 10 // degC
#define PID_FUNCTIONAL_RANGE 10 // degC
#define PID_INTEGRAL_DRIVE_MAX PID_MAX // Limit for the integral term
#define PID_INTEGRAL_DRIVE_MAX PID_MAX // Limit for the integral term
#define K1 0.95 // Smoothing factor within the PID
#define K1 0.95 // Smoothing factor within the PID
@@ -555,6 +563,8 @@ your extruder heater takes 2 minutes to hit the target on heating.
...
@@ -555,6 +563,8 @@ your extruder heater takes 2 minutes to hit the target on heating.
//When using an LCD, uncomment the line below to display the Power consumption sensor data on the last line instead of status. Status will appear for 5 sec.
//When using an LCD, uncomment the line below to display the Power consumption sensor data on the last line instead of status. Status will appear for 5 sec.
intConfigSD_KeyIndex(char*key){//At the moment a binary search algorithm is used for simplicity, if it will be necessary (Eg. tons of key), an hash search algorithm will be implemented.
staticconstchar*cfgSD_KEY[]={//Keep this in lexicographical order for better search performance(O(Nlog2(N)) insted of O(N*N)) (if you don't keep this sorted, the algorithm for find the key index won't work, keep attention.)
#ifdef POWER_CONSUMPTION
"PWR",
#endif
"TME",
};
enumcfgSD_ENUM{//This need to be in the same order as cfgSD_KEY
//The M105 command return, besides traditional information, the ADC value read from temperature sensors.
//The M105 command return, besides traditional information, the ADC value read from temperature sensors.
//#define SHOW_TEMP_ADC_VALUES
//#define SHOW_TEMP_ADC_VALUES
// extruder idle oozing prevention
//extruder idle oozing prevention
//if the extruder motor is idle for more than SECONDS, and the temperature over MINTEMP, some filament is retracted. The filament retracted is re-added before the next extrusion
//if the extruder motor is idle for more than SECONDS, and the temperature over MINTEMP,
//or when the target temperature is less than EXTRUDE_MINTEMP and the actual temperature is greater than IDLE_OOZING_MINTEMP and less than IDLE_OOZING_FEEDRATE
//some filament is retracted. The filament retracted is re-added before the next extrusion
//or when the target temperature is less than EXTRUDE_MINTEMP and the actual temperature
//is greater than IDLE_OOZING_MINTEMP and less than IDLE_OOZING_FEEDRATE
externunsignedlongprinter_usage_seconds;//this can old about 136 year before go overflow. If you belive that you can live more than this please contact me.
ln_ignore=false;//We've reached a new line try to find a key again
continue;
}
if(ln_ignore)continue;
if(ln_char==' '){
ln_space=true;
continue;
}
if(ln_char=='='){
key[ln_buf]='\0';
len_k=ln_buf;
key_found=true;
break;//key finded and buffered
}
if(ln_char==';'||ln_buf+1>=len_k||ln_space&&ln_buf>0){//comments on key is not allowd. Also key len can't be longer than len_k or contain spaces. Stop buffering and try the next line
ln_ignore=true;
continue;
}
ln_space=false;
key[ln_buf]=ln_char;
ln_buf++;
}
if(!key_found){//definitly there isn't no more key that can be readed in the file
key[0]=value[0]='\0';
len_k=len_v=0;
return;
}
ln_buf=0;
ln_ignore=false;
while(!eof()){//READ VALUE
ln_char=(char)get();
if(ln_char=='\n'){
value[ln_buf]='\0';
len_v=ln_buf;
break;//new line reached, we can stop
}
if(ln_ignore||ln_char==' '&&ln_buf==0)continue;//ignore also initial spaces of the value
if(ln_char==';'||ln_buf+1>=len_v){//comments reached or value len longer than len_v. Stop buffering and go to the next line.
//this is to delay autostart and hence the initialisaiton of the sd card to some seconds after the normal init, so the device is available quick after a reset
//this is to delay autostart and hence the initialisaiton of the sd card to some seconds after the normal init, so the device is available quick after a reset
#define MSG_SD_MAX_DEPTH "trying to call sub-gcode files with too many levels. MAX level is:"
#define MSG_STEPPER_TOO_HIGH "Steprate too high: "
#define MSG_STEPPER_TOO_HIGH "Steprate too high: "
#define MSG_ENDSTOPS_HIT "endstops hit: "
#define MSG_ENDSTOPS_HIT "endstops hit: "
...
@@ -161,6 +166,17 @@
...
@@ -161,6 +166,17 @@
#define MSG_BABYSTEPPING_Y "Babystepping Y"
#define MSG_BABYSTEPPING_Y "Babystepping Y"
#define MSG_BABYSTEPPING_Z "Babystepping Z"
#define MSG_BABYSTEPPING_Z "Babystepping Z"
#define MSG_SERIAL_ERROR_MENU_STRUCTURE "Error in menu structure"
#define MSG_SERIAL_ERROR_MENU_STRUCTURE "Error in menu structure"
#define MSG_MICROSTEP_MS1_MS2 "MS1,MS2 Pins"
#define MSG_MICROSTEP_X "X:"
#define MSG_MICROSTEP_Y "Y:"
#define MSG_MICROSTEP_Z "Z:"
#define MSG_MICROSTEP_E0 "E0:"
#define MSG_MICROSTEP_E1 "E1:"
#define MSG_ENDSTOP_X " X:"
#define MSG_ENDSTOP_Y " Y:"
#define MSG_ENDSTOP_Z " Z:"
#define MSG_ENDSTOP_E " E:"
#define MSG_ENDSTOP_ZP " ZP:"
#define MSG_ERR_EEPROM_WRITE "Error writing to EEPROM!"
#define MSG_ERR_EEPROM_WRITE "Error writing to EEPROM!"
...
@@ -181,26 +197,43 @@
...
@@ -181,26 +197,43 @@
#define MSG_KP " Kp: "
#define MSG_KP " Kp: "
#define MSG_KI " Ki: "
#define MSG_KI " Ki: "
#define MSG_KD " Kd: "
#define MSG_KD " Kd: "
#define MSG_OK_B "ok B:"
#define MSG_B " B:"
#define MSG_OK_T "ok T:"
#define MSG_T " T:"
#define MSG_AT " @:"
#define MSG_AT " @:"
#define MSG_PID_AUTOTUNE_FINISHED MSG_PID_AUTOTUNE " finished! Put the last Kp, Ki and Kd constants from above into Configuration.h or send command M500 for save in EEPROM the new value!"
#define MSG_PID_AUTOTUNE_FINISHED MSG_PID_AUTOTUNE " finished! Put the last Kp, Ki and Kd constants from above into Configuration.h or send command M500 for save in EEPROM the new value!"
#define MSG_PID_DEBUG " PID_DEBUG "
#define MSG_PID_DEBUG_INPUT ": Input "
#define MSG_PID_DEBUG_OUTPUT " Output "
#define MSG_PID_DEBUG_PTERM " pTerm "
#define MSG_PID_DEBUG_ITERM " iTerm "
#define MSG_PID_DEBUG_DTERM " dTerm "
#define MSG_HEATING_FAILED "Heating failed"
#define MSG_HEATING_FAILED "Heating failed"
#define MSG_THERMAL_RUNAWAY_STOP "Thermal Runaway, system stopped! Heater_ID: "