From 64167dfe79df4ef5f69b2632e3c0cc162fb22914 Mon Sep 17 00:00:00 2001 From: Powerlated Date: Wed, 11 Jan 2023 00:40:15 -0500 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20PREHEAT=5FTIME=5FBED=5FMS=20(#25146?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/Configuration_adv.h | 3 +- Marlin/src/inc/SanityCheck.h | 10 ++++-- Marlin/src/module/temperature.cpp | 56 ++++++++++++++++++------------- Marlin/src/module/temperature.h | 52 +++++++++++++++++++--------- 4 files changed, 78 insertions(+), 43 deletions(-) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index c41cb04803dc..bf4b439d8531 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -493,7 +493,8 @@ * the minimum temperature your thermistor can read. The lower the better/safer. * This shouldn't need to be more than 30 seconds (30000) */ -//#define MILLISECONDS_PREHEAT_TIME 0 +//#define PREHEAT_TIME_HOTEND_MS 0 +//#define PREHEAT_TIME_BED_MS 0 // @section extruder diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index 5eb057e6646d..485eb9011d2c 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -664,6 +664,8 @@ #error "SCARA_PRINTABLE_RADIUS is now PRINTABLE_RADIUS." #elif defined(SCARA_FEEDRATE_SCALING) #error "SCARA_FEEDRATE_SCALING is now FEEDRATE_SCALING." +#elif defined(MILLISECONDS_PREHEAT_TIME) + #error "MILLISECONDS_PREHEAT_TIME is now PREHEAT_TIME_HOTEND_MS." #endif // L64xx stepper drivers have been removed @@ -2400,12 +2402,16 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS #endif #if MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED < 5 #error "Thermistor 66 requires MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED ≥ 5." - #elif MILLISECONDS_PREHEAT_TIME < 15000 - #error "Thermistor 66 requires MILLISECONDS_PREHEAT_TIME ≥ 15000, but 30000 or higher is recommended." + #elif PREHEAT_TIME_HOTEND_MS < 15000 + #error "Thermistor 66 requires PREHEAT_TIME_HOTEND_MS ≥ 15000, but 30000 or higher is recommended." #endif #undef _BAD_MINTEMP #endif +#if TEMP_SENSOR_BED == 66 && PREHEAT_TIME_BED_MS < 15000 + #error "Thermistor 66 requires PREHEAT_TIME_BED_MS ≥ 15000, but 30000 or higher is recommended." +#endif + /** * Required MAX31865 settings */ diff --git a/Marlin/src/module/temperature.cpp b/Marlin/src/module/temperature.cpp index d01b4bc14237..c53fa5df14ef 100644 --- a/Marlin/src/module/temperature.cpp +++ b/Marlin/src/module/temperature.cpp @@ -561,8 +561,11 @@ volatile bool Temperature::raw_temps_ready = false; uint8_t Temperature::consecutive_low_temperature_error[HOTENDS] = { 0 }; #endif -#if MILLISECONDS_PREHEAT_TIME > 0 - millis_t Temperature::preheat_end_time[HOTENDS] = { 0 }; +#if PREHEAT_TIME_HOTEND_MS > 0 + millis_t Temperature::preheat_end_ms_hotend[HOTENDS] { 0 }; +#endif +#if HAS_HEATED_BED && PREHEAT_TIME_BED_MS > 0 + millis_t Temperature::preheat_end_ms_bed = 0; #endif #if HAS_FAN_LOGIC @@ -1535,7 +1538,7 @@ void Temperature::mintemp_error(const heater_id_t heater_id) { tr_state_machine[e].run(temp_hotend[e].celsius, temp_hotend[e].target, (heater_id_t)e, THERMAL_PROTECTION_PERIOD, THERMAL_PROTECTION_HYSTERESIS); #endif - temp_hotend[e].soft_pwm_amount = (temp_hotend[e].celsius > temp_range[e].mintemp || is_preheating(e)) && temp_hotend[e].celsius < temp_range[e].maxtemp ? (int)get_pid_output_hotend(e) >> 1 : 0; + temp_hotend[e].soft_pwm_amount = (temp_hotend[e].celsius > temp_range[e].mintemp || is_hotend_preheating(e)) && temp_hotend[e].celsius < temp_range[e].maxtemp ? (int)get_pid_output_hotend(e) >> 1 : 0; #if WATCH_HOTENDS // Make sure temperature is increasing @@ -1609,25 +1612,30 @@ void Temperature::mintemp_error(const heater_id_t heater_id) { #endif if (!bed_timed_out) { - #if ENABLED(PIDTEMPBED) - temp_bed.soft_pwm_amount = WITHIN(temp_bed.celsius, BED_MINTEMP, BED_MAXTEMP) ? (int)get_pid_output_bed() >> 1 : 0; - #else - // Check if temperature is within the correct band - if (WITHIN(temp_bed.celsius, BED_MINTEMP, BED_MAXTEMP)) { - #if ENABLED(BED_LIMIT_SWITCHING) - if (temp_bed.is_above_target((BED_HYSTERESIS) - 1)) - temp_bed.soft_pwm_amount = 0; - else if (temp_bed.is_below_target((BED_HYSTERESIS) - 1)) - temp_bed.soft_pwm_amount = MAX_BED_POWER >> 1; - #else // !PIDTEMPBED && !BED_LIMIT_SWITCHING - temp_bed.soft_pwm_amount = temp_bed.is_below_target() ? MAX_BED_POWER >> 1 : 0; - #endif - } - else { - temp_bed.soft_pwm_amount = 0; - WRITE_HEATER_BED(LOW); - } - #endif + if (is_bed_preheating()) { + temp_bed.soft_pwm_amount = MAX_BED_POWER >> 1; + } + else { + #if ENABLED(PIDTEMPBED) + temp_bed.soft_pwm_amount = WITHIN(temp_bed.celsius, BED_MINTEMP, BED_MAXTEMP) ? (int)get_pid_output_bed() >> 1 : 0; + #else + // Check if temperature is within the correct band + if (WITHIN(temp_bed.celsius, BED_MINTEMP, BED_MAXTEMP)) { + #if ENABLED(BED_LIMIT_SWITCHING) + if (temp_bed.is_above_target((BED_HYSTERESIS) - 1)) + temp_bed.soft_pwm_amount = 0; + else if (temp_bed.is_below_target((BED_HYSTERESIS) - 1)) + temp_bed.soft_pwm_amount = MAX_BED_POWER >> 1; + #else // !PIDTEMPBED && !BED_LIMIT_SWITCHING + temp_bed.soft_pwm_amount = temp_bed.is_below_target() ? MAX_BED_POWER >> 1 : 0; + #endif + } + else { + temp_bed.soft_pwm_amount = 0; + WRITE_HEATER_BED(LOW); + } + #endif + } } } while (false); @@ -2394,7 +2402,7 @@ void Temperature::updateTemperaturesFromRawValues() { //*/ const bool heater_on = temp_hotend[e].target > 0; - if (heater_on && !is_preheating(e) && ((neg && r > temp_range[e].raw_min) || (pos && r < temp_range[e].raw_min))) { + if (heater_on && !is_hotend_preheating(e) && ((neg && r > temp_range[e].raw_min) || (pos && r < temp_range[e].raw_min))) { if (TERN1(MULTI_MAX_CONSECUTIVE_LOW_TEMP_ERR, ++consecutive_low_temperature_error[e] >= MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED)) mintemp_error((heater_id_t)e); } @@ -2408,7 +2416,7 @@ void Temperature::updateTemperaturesFromRawValues() { #define TP_CMP(S,A,B) (TEMPDIR(S) < 0 ? ((A)<(B)) : ((A)>(B))) #if ENABLED(THERMAL_PROTECTION_BED) if (TP_CMP(BED, temp_bed.getraw(), maxtemp_raw_BED)) maxtemp_error(H_BED); - if (temp_bed.target > 0 && TP_CMP(BED, mintemp_raw_BED, temp_bed.getraw())) mintemp_error(H_BED); + if (temp_bed.target > 0 && !is_bed_preheating() && TP_CMP(BED, mintemp_raw_BED, temp_bed.getraw())) mintemp_error(H_BED); #endif #if BOTH(HAS_HEATED_CHAMBER, THERMAL_PROTECTION_CHAMBER) diff --git a/Marlin/src/module/temperature.h b/Marlin/src/module/temperature.h index 091f218eb837..d099c3d73b36 100644 --- a/Marlin/src/module/temperature.h +++ b/Marlin/src/module/temperature.h @@ -748,10 +748,6 @@ class Temperature { static uint8_t consecutive_low_temperature_error[HOTENDS]; #endif - #if MILLISECONDS_PREHEAT_TIME > 0 - static millis_t preheat_end_time[HOTENDS]; - #endif - #if HAS_FAN_LOGIC static millis_t fan_update_ms; @@ -907,20 +903,38 @@ class Temperature { static void task(); /** - * Preheating hotends + * Preheating hotends & bed */ - #if MILLISECONDS_PREHEAT_TIME > 0 - static bool is_preheating(const uint8_t E_NAME) { - return preheat_end_time[HOTEND_INDEX] && PENDING(millis(), preheat_end_time[HOTEND_INDEX]); + #if PREHEAT_TIME_HOTEND_MS > 0 + static millis_t preheat_end_ms_hotend[HOTENDS]; + static bool is_hotend_preheating(const uint8_t E_NAME) { + return preheat_end_ms_hotend[HOTEND_INDEX] && PENDING(millis(), preheat_end_ms_hotend[HOTEND_INDEX]); } - static void start_preheat_time(const uint8_t E_NAME) { - preheat_end_time[HOTEND_INDEX] = millis() + MILLISECONDS_PREHEAT_TIME; + static void start_hotend_preheat_time(const uint8_t E_NAME) { + preheat_end_ms_hotend[HOTEND_INDEX] = millis() + PREHEAT_TIME_HOTEND_MS; } - static void reset_preheat_time(const uint8_t E_NAME) { - preheat_end_time[HOTEND_INDEX] = 0; + static void reset_hotend_preheat_time(const uint8_t E_NAME) { + preheat_end_ms_hotend[HOTEND_INDEX] = 0; } #else - #define is_preheating(n) (false) + static bool is_hotend_preheating(const uint8_t) { return false; } + #endif + + #if HAS_HEATED_BED + #if PREHEAT_TIME_BED_MS > 0 + static millis_t preheat_end_ms_bed; + static bool is_bed_preheating() { + return preheat_end_ms_bed && PENDING(millis(), preheat_end_ms_bed); + } + static void start_bed_preheat_time() { + preheat_end_ms_bed = millis() + PREHEAT_TIME_BED_MS; + } + static void reset_bed_preheat_time() { + preheat_end_ms_bed = 0; + } + #else + static bool is_bed_preheating() { return false; } + #endif #endif //high level conversion routines, for use outside of temperature.cpp @@ -949,11 +963,11 @@ class Temperature { static void setTargetHotend(const celsius_t celsius, const uint8_t E_NAME) { const uint8_t ee = HOTEND_INDEX; - #if MILLISECONDS_PREHEAT_TIME > 0 + #if PREHEAT_TIME_HOTEND_MS > 0 if (celsius == 0) - reset_preheat_time(ee); + reset_hotend_preheat_time(ee); else if (temp_hotend[ee].target == 0) - start_preheat_time(ee); + start_hotend_preheat_time(ee); #endif TERN_(AUTO_POWER_CONTROL, if (celsius) powerManager.power_on()); temp_hotend[ee].target = _MIN(celsius, hotend_max_target(ee)); @@ -1016,6 +1030,12 @@ class Temperature { static void start_watching_bed() { TERN_(WATCH_BED, watch_bed.restart(degBed(), degTargetBed())); } static void setTargetBed(const celsius_t celsius) { + #if PREHEAT_TIME_BED_MS > 0 + if (celsius == 0) + reset_bed_preheat_time(); + else if (temp_bed.target == 0) + start_bed_preheat_time(); + #endif TERN_(AUTO_POWER_CONTROL, if (celsius) powerManager.power_on()); temp_bed.target = _MIN(celsius, BED_MAX_TARGET); start_watching_bed();