Add HAL-based thermal protection grace period for all heaters (#13778)

This commit is contained in:
Kajetan Rzepecki 2019-04-22 03:50:32 +02:00 committed by Scott Lahteine
parent 81ca5a4cd4
commit 875e673a8c
2 changed files with 42 additions and 19 deletions

View file

@ -147,6 +147,9 @@ using FilteredADC = LPC176x::ADC<ADC_LOWPASS_K_VALUE, ADC_MEDIAN_FILTER_SIZE>;
#define HAL_READ_ADC() FilteredADC::get_result()
#define HAL_ADC_READY() FilteredADC::finished_conversion()
// A grace period for the ADC readings to stabilize before they start causing thermal protection errors.
#define THERMAL_PROTECTION_GRACE_PERIOD 500
// Parse a G-code word into a pin index
int16_t PARSED_PIN_INDEX(const char code, const int16_t dval);
// P0.6 thru P0.9 are for the onboard SD card

View file

@ -944,13 +944,29 @@ void Temperature::manage_heater() {
if (temp_hotend[1].current < MAX(HEATER_1_MINTEMP, HEATER_1_MAX6675_TMIN + .01)) min_temp_error(1);
#endif
#if WATCH_HOTENDS || WATCH_BED || DISABLED(PIDTEMPBED) || HAS_AUTO_FAN || HEATER_IDLE_HANDLER || WATCH_CHAMBER
#define HAS_THERMAL_PROTECTION (ENABLED(THERMAL_PROTECTION_HOTENDS) || HAS_THERMALLY_PROTECTED_BED || ENABLED(THERMAL_PROTECTION_CHAMBER))
#if HAS_THERMAL_PROTECTION || DISABLED(PIDTEMPBED) || HAS_AUTO_FAN || HEATER_IDLE_HANDLER
millis_t ms = millis();
#endif
#if HAS_THERMAL_PROTECTION
#ifndef THERMAL_PROTECTION_GRACE_PERIOD
#define THERMAL_PROTECTION_GRACE_PERIOD 0 // No grace period needed on well-behaved boards
#endif
#if THERMAL_PROTECTION_GRACE_PERIOD > 0
static millis_t grace_period = ms + THERMAL_PROTECTION_GRACE_PERIOD;
if (ELAPSED(ms, grace_period)) grace_period = 0UL;
#else
static constexpr millis_t grace_period = 0UL;
#endif
#endif
HOTEND_LOOP() {
if (degHotend(e) > temp_range[e].maxtemp)
_temp_error(e, PSTR(MSG_T_THERMAL_RUNAWAY), TEMP_ERR_PSTR(MSG_THERMAL_RUNAWAY, e));
#if ENABLED(THERMAL_PROTECTION_HOTENDS)
if (!grace_period && degHotend(e) > temp_range[e].maxtemp)
_temp_error(e, PSTR(MSG_T_THERMAL_RUNAWAY), TEMP_ERR_PSTR(MSG_THERMAL_RUNAWAY, e));
#endif
#if HEATER_IDLE_HANDLER
hotend_idle[e].update(ms);
@ -1003,8 +1019,10 @@ void Temperature::manage_heater() {
#if HAS_HEATED_BED
if (degBed() > BED_MAXTEMP)
_temp_error(-1, PSTR(MSG_T_THERMAL_RUNAWAY), TEMP_ERR_PSTR(MSG_THERMAL_RUNAWAY, -1));
#if ENABLED(THERMAL_PROTECTION_BED)
if (!grace_period && degBed() > BED_MAXTEMP)
_temp_error(-1, PSTR(MSG_T_THERMAL_RUNAWAY), TEMP_ERR_PSTR(MSG_THERMAL_RUNAWAY, -1));
#endif
#if WATCH_BED
// Make sure temperature is increasing
@ -1076,8 +1094,10 @@ void Temperature::manage_heater() {
#if HAS_HEATED_CHAMBER
if (degChamber() > CHAMBER_MAXTEMP)
_temp_error(-2, PSTR(MSG_T_THERMAL_RUNAWAY), TEMP_ERR_PSTR(MSG_THERMAL_RUNAWAY, -2));
#if ENABLED(THERMAL_PROTECTION_CHAMBER)
if (!grace_period && degChamber() > CHAMBER_MAXTEMP)
_temp_error(-2, PSTR(MSG_T_THERMAL_RUNAWAY), TEMP_ERR_PSTR(MSG_THERMAL_RUNAWAY, -2));
#endif
#if WATCH_CHAMBER
// Make sure temperature is increasing
@ -1610,7 +1630,7 @@ void Temperature::init() {
}
#endif
#if ENABLED(THERMAL_PROTECTION_HOTENDS) || HAS_THERMALLY_PROTECTED_BED || ENABLED(THERMAL_PROTECTION_CHAMBER)
#if HAS_THERMAL_PROTECTION
#if ENABLED(THERMAL_PROTECTION_HOTENDS)
Temperature::tr_state_machine_t Temperature::tr_state_machine[HOTENDS]; // = { { TRInactive, 0 } };
@ -1627,17 +1647,17 @@ void Temperature::init() {
static float tr_target_temperature[HOTENDS + 1] = { 0.0 };
/**
SERIAL_ECHO_START();
SERIAL_ECHOPGM("Thermal Thermal Runaway Running. Heater ID: ");
if (heater_id == -2) SERIAL_ECHOPGM("chamber");
if (heater_id < 0) SERIAL_ECHOPGM("bed"); else SERIAL_ECHO(heater_id);
SERIAL_ECHOPAIR(" ; State:", sm.state, " ; Timer:", sm.timer, " ; Temperature:", current, " ; Target Temp:", target);
if (heater_id >= 0)
SERIAL_ECHOPAIR(" ; Idle Timeout:", hotend_idle[heater_id].timed_out);
else
SERIAL_ECHOPAIR(" ; Idle Timeout:", bed_idle.timed_out);
SERIAL_EOL();
*/
SERIAL_ECHO_START();
SERIAL_ECHOPGM("Thermal Thermal Runaway Running. Heater ID: ");
if (heater_id == -2) SERIAL_ECHOPGM("chamber");
if (heater_id < 0) SERIAL_ECHOPGM("bed"); else SERIAL_ECHO(heater_id);
SERIAL_ECHOPAIR(" ; State:", sm.state, " ; Timer:", sm.timer, " ; Temperature:", current, " ; Target Temp:", target);
if (heater_id >= 0)
SERIAL_ECHOPAIR(" ; Idle Timeout:", hotend_idle[heater_id].timed_out);
else
SERIAL_ECHOPAIR(" ; Idle Timeout:", bed_idle.timed_out);
SERIAL_EOL();
//*/
const int heater_index = heater_id >= 0 ? heater_id : HOTENDS;