Commit cf380d0d authored by MagoKimbra's avatar MagoKimbra

Merge remote-tracking branch 'origin/master' into Development

parents a985527c e9d95297
......@@ -280,44 +280,37 @@
//===========================================================================
//============================= Thermal Runaway Protection ==================
//======================== Thermal Runaway Protection =======================
//===========================================================================
/*
This is a feature to protect your printer from burn up in flames if it has
a thermistor coming off place (this happened to a friend of mine recently and
motivated me writing this feature).
The issue: If a thermistor come off, it will read a lower temperature than actual.
The system will turn the heater on forever, burning up the filament and anything
else around.
After the temperature reaches the target for the first time, this feature will
start measuring for how long the current temperature stays below the target
minus _HYSTERESIS (set_temperature - THERMAL_RUNAWAY_PROTECTION_HYSTERESIS).
If it stays longer than _PERIOD, it means the thermistor temperature
cannot catch up with the target, so something *may be* wrong. Then, to be on the
safe side, the system will he halt.
Bear in mind the count down will just start AFTER the first time the
thermistor temperature is over the target, so you will have no problem if
your extruder heater takes 2 minutes to hit the target on heating.
*/
// If you want to enable this feature for all your extruder heaters,
// uncomment the 2 defines below:
/**
* Thermal Runaway Protection protects your printer from damage and fire if a
* thermistor falls out or temperature sensors fail in any way.
*
* The issue: If a thermistor falls out or a temperature sensor fails,
* Marlin can no longer sense the actual temperature. Since a disconnected
* thermistor reads as a low temperature, the firmware will keep the heater on.
*
* The solution: Once the temperature reaches the target, start observing.
* If the temperature stays too far below the target (hysteresis) for too long,
* the firmware will halt as a safety precaution.
*
* Note that because the countdown starts only AFTER the temperature reaches
* the target, this will not catch a thermistor that is already disconnected
* when the print starts!
*
* To enable for all extruder heaters, uncomment the two defines below:
*/
// Parameters for all extruder heaters
//#define THERMAL_RUNAWAY_PROTECTION_PERIOD 40 //in seconds
//#define THERMAL_RUNAWAY_PROTECTION_HYSTERESIS 4 // in degree Celsius
#define THERMAL_RUNAWAY_PROTECTION_PERIOD 40 // in seconds
#define THERMAL_RUNAWAY_PROTECTION_HYSTERESIS 4 // in degree Celsius
// If you want to enable this feature for your bed heater,
// uncomment the 2 defines below:
// To enable for the bed heater, uncomment the two defines below:
// Parameters for the bed heater
//#define THERMAL_RUNAWAY_PROTECTION_BED_PERIOD 20 //in seconds
//#define THERMAL_RUNAWAY_PROTECTION_BED_HYSTERESIS 2 // in degree Celsius
#define THERMAL_RUNAWAY_PROTECTION_BED_PERIOD 20 // in seconds
#define THERMAL_RUNAWAY_PROTECTION_BED_HYSTERESIS 2 // in degree Celsius
//===========================================================================
......
......@@ -4134,11 +4134,11 @@ inline void gcode_M105() {
#if HAS_TEMP_0 || HAS_TEMP_BED || defined(HEATER_0_USES_MAX6675)
ECHO_S(OK);
#if HAS_TEMP_0
ECHO_MV(" T:", degHotend(target_extruder), 1);
ECHO_MV(MSG_T, degHotend(target_extruder), 1);
ECHO_MV(" /", degTargetHotend(target_extruder), 1);
#endif
#if HAS_TEMP_BED
ECHO_MV(" B:", degBed(), 1);
ECHO_MV(MSG_B, degBed(), 1);
ECHO_MV(" /", degTargetBed(), 1);
#endif
for (int8_t e = 0; e < EXTRUDERS; ++e) {
......@@ -6266,8 +6266,7 @@ void ClearToSend() {
#ifdef SDSUPPORT
if (fromsd[cmd_queue_index_r]) return;
#endif
ECHO_S(OK);
ECHO_E;
ECHO_L(OK);
#ifdef ADVANCED_OK
ECHO_MV(" N", gcode_LastN);
ECHO_EMV(" S", commands_in_queue);
......
......@@ -67,18 +67,19 @@ FORCE_INLINE void PS_PGM(const char *str) {
#define ECHO_V SERIAL_PRINT
#define ECHO_C SERIAL_WRITE
#define ECHO_S(srt) ECHO_PGM(srt)
#define ECHO_E ECHO_ENDL
#define ECHO_SM(srt, msg) ECHO_S(srt),ECHO_M(msg)
#define ECHO_SV(srt, val, args...) ECHO_S(srt),ECHO_V(val, ##args)
#define ECHO_SMV(srt, msg, val, args...) ECHO_S(srt),ECHO_MV(msg, val, ##args)
#define ECHO_SVM(srt, val, msg, args...) ECHO_S(srt),ECHO_VM(val, msg, ##args)
#define ECHO_E ECHO_ENDL
#define ECHO_EM(msg) ECHO_M(msg),ECHO_E
#define ECHO_EV(val, args...) ECHO_V(val, ##args),ECHO_E
#define ECHO_EMV(msg, val, args...) ECHO_MV(msg, val, ##args),ECHO_E
#define ECHO_EVM(val, msg, args...) ECHO_VM(val, msg, ##args),ECHO_E
#define ECHO_L(srt) ECHO_S(srt),ECHO_E
#define ECHO_LM(srt, msg) ECHO_S(srt),ECHO_M(msg),ECHO_E
#define ECHO_LV(srt, val) ECHO_S(srt),ECHO_V(val),ECHO_E
#define ECHO_LMV(srt, msg, val, args...) ECHO_S(srt),ECHO_MV(msg, val, ##args),ECHO_E
......
......@@ -539,7 +539,7 @@ ISR(TIMER1_COMPA_vect) {
{ // -direction
#ifdef DUAL_X_CARRIAGE
// with 2 x-carriages, endstops are only checked in the homing direction for the active extruder
if ((current_block->active_extruder == 0 && X_HOME_DIR == -1) || (current_block->active_extruder != 0 && X2_HOME_DIR == -1))
if ((current_block->active_driver == 0 && X_HOME_DIR == -1) || (current_block->active_driver != 0 && X2_HOME_DIR == -1))
#endif
{
#if HAS_X_MIN
......@@ -723,63 +723,34 @@ ISR(TIMER1_COMPA_vect) {
#endif //ADVANCE
#define _COUNTER(axis) counter_## axis
#define _WRITE_STEP(AXIS, HIGHLOW) AXIS ##_STEP_WRITE(HIGHLOW)
#define _APPLY_STEP(AXIS) AXIS ##_APPLY_STEP
#define _INVERT_STEP_PIN(AXIS) INVERT_## AXIS ##_STEP_PIN
#if defined(CONFIG_STEPPERS_TOSHIBA) || MB(ALLIGATOR)
/**
* The Toshiba stepper controller require much longer pulses.
* So we 'stage' decompose the pulses between high and low
* instead of doing each in turn. The extra tests add enough
* lag to allow it work with without needing NOPs
*/
#define STEP_ADD(axis, AXIS) \
#define STEP_START(axis, AXIS) \
_COUNTER(axis) += current_block->steps[_AXIS(AXIS)]; \
if (_COUNTER(axis) > 0) { _WRITE_STEP(AXIS, HIGH); }
STEP_ADD(x,X);
STEP_ADD(y,Y);
STEP_ADD(z,Z);
#ifndef ADVANCE
STEP_ADD(e,E);
#endif
_delay_us(1U); // Add delay us
#define STEP_IF_COUNTER(axis, AXIS) \
if (_COUNTER(axis) > 0) { \
_APPLY_STEP(AXIS)(!_INVERT_STEP_PIN(AXIS),0); \
_COUNTER(axis) -= current_block->step_event_count; \
count_position[_AXIS(AXIS)] += count_direction[_AXIS(AXIS)]; \
_WRITE_STEP(AXIS, LOW); \
}
count_position[_AXIS(AXIS)] += count_direction[_AXIS(AXIS)]; }
STEP_IF_COUNTER(x, X);
STEP_IF_COUNTER(y, Y);
STEP_IF_COUNTER(z, Z);
STEP_START(x,X);
STEP_START(y,Y);
STEP_START(z,Z);
#ifndef ADVANCE
STEP_IF_COUNTER(e, E);
STEP_START(e,E);
#endif
#else // !CONFIG_STEPPERS_TOSHIBA || MB(ALLIGATOR)
delayMicroseconds(1);
#define APPLY_MOVEMENT(axis, AXIS) \
_COUNTER(axis) += current_block->steps[_AXIS(AXIS)]; \
if (_COUNTER(axis) > 0) { \
_APPLY_STEP(AXIS)(!_INVERT_STEP_PIN(AXIS),0); \
_COUNTER(axis) -= current_block->step_event_count; \
count_position[_AXIS(AXIS)] += count_direction[_AXIS(AXIS)]; \
_APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS),0); \
}
#define STEP_END(axis, AXIS) _APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS),0)
APPLY_MOVEMENT(x, X);
APPLY_MOVEMENT(y, Y);
APPLY_MOVEMENT(z, Z);
STEP_END(x, X);
STEP_END(y, Y);
STEP_END(z, Z);
#ifndef ADVANCE
APPLY_MOVEMENT(e, E);
STEP_END(e, E);
#endif
#endif // CONFIG_STEPPERS_TOSHIBA
step_events_completed++;
if (step_events_completed >= current_block->step_event_count) break;
}
......@@ -1096,6 +1067,7 @@ void st_init() {
#endif
#define _STEP_INIT(AXIS) AXIS ##_STEP_INIT
#define _WRITE_STEP(AXIS, HIGHLOW) AXIS ##_STEP_WRITE(HIGHLOW)
#define _DISABLE(axis) disable_## axis()
#define AXIS_INIT(axis, AXIS, PIN) \
......
......@@ -208,7 +208,15 @@ void PID_autotune(float temp, int hotend, int ncycles)
return;
}
ECHO_LM(OK, MSG_PID_AUTOTUNE_START);
ECHO_LM(DB, MSG_PID_AUTOTUNE_START);
if (hotend < 0) {
ECHO_SM(DB, "BED");
}
else {
ECHO_SMV(DB, "Hotend: ", hotend);
}
ECHO_MV(" Temp: ", temp);
ECHO_EMV(" Cycles: ", ncycles);
disable_all_heaters(); // switch off all heaters.
......@@ -260,7 +268,7 @@ void PID_autotune(float temp, int hotend, int ncycles)
bias = constrain(bias, 20, max_pow - 20);
d = (bias > max_pow / 2) ? max_pow - 1 - bias : bias;
ECHO_SMV(OK, MSG_BIAS, bias);
ECHO_MV(MSG_BIAS, bias);
ECHO_MV(MSG_D, d);
ECHO_MV(MSG_T_MIN, min);
ECHO_MV(MSG_T_MAX, max);
......@@ -268,32 +276,15 @@ void PID_autotune(float temp, int hotend, int ncycles)
Ku = (4.0 * d) / (3.14159265 * (max - min) / 2.0);
Tu = ((float)(t_low + t_high) / 1000.0);
ECHO_MV(MSG_KU, Ku);
ECHO_MV(MSG_TU, Tu);
ECHO_EMV(MSG_TU, Tu);
Kp_temp = 0.6 * Ku;
Ki_temp = 2 * Kp_temp / Tu;
Kd_temp = Kp_temp * Tu / 8;
ECHO_M(MSG_CLASSIC_PID);
ECHO_EM(MSG_CLASSIC_PID);
ECHO_MV(MSG_KP, Kp_temp);
ECHO_MV(MSG_KI, Ki_temp);
ECHO_EMV(MSG_KD, Kd_temp);
/*
Kp = 0.33*Ku;
Ki = Kp_temp / Tu;
Kd = Kp_temp * Tu / 3;
ECHO_SMV(DB," Some overshoot ");
ECHO_MV(" Kp: ", Kp_temp);
ECHO_MV(" Ki: ", Ki_temp);
ECHO_MV(" Kd: ", Kd_temp);
Kp = 0.2 * Ku;
Ki = 2 * Kp_temp / Tu;
Kd = Kp_temp * Tu / 3;
ECHO_M(" No overshoot ");
ECHO_MV(" Kp: ", Kp_temp);
ECHO_MV(" Ki: ", Ki_temp);
ECHO_EMV(" Kd: ", Kd_temp);
*/
}
else {
ECHO_E;
......@@ -312,6 +303,7 @@ void PID_autotune(float temp, int hotend, int ncycles)
ECHO_LM(ER, MSG_PID_TEMP_TOO_HIGH);
return;
}
// Every 2 seconds...
if (ms > temp_ms + 2000) {
int p;
......@@ -328,20 +320,29 @@ void PID_autotune(float temp, int hotend, int ncycles)
temp_ms = ms;
} // every 2 seconds
// Over 2 minutes?
if (((ms - t1) + (ms - t2)) > (10L*60L*1000L*2L)) {
ECHO_LM(ER, MSG_PID_TIMEOUT);
return;
}
if (cycles > ncycles) {
ECHO_LM(OK, MSG_PID_AUTOTUNE_FINISHED);
#ifdef PIDTEMP
ECHO_LM(DB, MSG_PID_AUTOTUNE_FINISHED);
if (hotend >= 0) {
PID_PARAM(Kp, hotend) = Kp_temp;
PID_PARAM(Ki, hotend) = scalePID_i(Ki_temp);
PID_PARAM(Kd, hotend) = scalePID_d(Kd_temp);
updatePID();
ECHO_SMV(DB, MSG_KP, PID_PARAM(Kp, hotend));
ECHO_MV(MSG_KI, unscalePID_i(PID_PARAM(Ki, hotend)));
ECHO_EMV(MSG_KD, unscalePID_d(PID_PARAM(Kd, hotend)));
}
else {
ECHO_LMV(DB, "#define DEFAULT_bedKp ", Kp_temp);
ECHO_LMV(DB, "#define DEFAULT_bedKi ", unscalePID_i(Ki_temp));
ECHO_LMV(DB, "#define DEFAULT_bedKd ", unscalePID_d(Kd_temp));
}
#endif
return;
}
lcd_update();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment