From 6c4046fa4f54f45e2b5fff2f5c889d93630a4d3f Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 3 Jan 2023 18:57:33 -0600 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=8E=A8=20Rename=20*=5Ftemp=5Ferror=20?= =?UTF-8?q?to=20*temp=5Ferror?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/Configuration_adv.h | 6 ++-- Marlin/src/module/temperature.cpp | 50 +++++++++++++++---------------- Marlin/src/module/temperature.h | 4 +-- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 090fa0f93a68..cc15c4f20bd8 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -472,10 +472,10 @@ * Thermistors able to support high temperature tend to have a hard time getting * good readings at room and lower temperatures. This means TEMP_SENSOR_X_RAW_LO_TEMP * will probably be caught when the heating element first turns on during the - * preheating process, which will trigger a min_temp_error as a safety measure + * preheating process, which will trigger a mintemp_error as a safety measure * and force stop everything. * To circumvent this limitation, we allow for a preheat time (during which, - * min_temp_error won't be triggered) and add a min_temp buffer to handle + * mintemp_error won't be triggered) and add a min_temp buffer to handle * aberrant readings. * * If you want to enable this feature for your hotend thermistor(s) @@ -483,7 +483,7 @@ */ // The number of consecutive low temperature errors that can occur -// before a min_temp_error is triggered. (Shouldn't be more than 10.) +// before a mintemp_error is triggered. (Shouldn't be more than 10.) //#define MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED 0 /** diff --git a/Marlin/src/module/temperature.cpp b/Marlin/src/module/temperature.cpp index d7c31ebbeb65..ead7e97a8106 100644 --- a/Marlin/src/module/temperature.cpp +++ b/Marlin/src/module/temperature.cpp @@ -1314,14 +1314,14 @@ void Temperature::_temp_error(const heater_id_t heater_id, FSTR_P const serial_m #endif } -void Temperature::max_temp_error(const heater_id_t heater_id) { +void Temperature::maxtemp_error(const heater_id_t heater_id) { #if HAS_DWIN_E3V2_BASIC && (HAS_HOTEND || HAS_HEATED_BED) DWIN_Popup_Temperature(1); #endif _temp_error(heater_id, F(STR_T_MAXTEMP), GET_TEXT_F(MSG_ERR_MAXTEMP)); } -void Temperature::min_temp_error(const heater_id_t heater_id) { +void Temperature::mintemp_error(const heater_id_t heater_id) { #if HAS_DWIN_E3V2_BASIC && (HAS_HOTEND || HAS_HEATED_BED) DWIN_Popup_Temperature(0); #endif @@ -1525,7 +1525,7 @@ void Temperature::min_temp_error(const heater_id_t heater_id) { void Temperature::manage_hotends(const millis_t &ms) { HOTEND_LOOP() { #if ENABLED(THERMAL_PROTECTION_HOTENDS) - if (degHotend(e) > temp_range[e].maxtemp) max_temp_error((heater_id_t)e); + if (degHotend(e) > temp_range[e].maxtemp) maxtemp_error((heater_id_t)e); #endif TERN_(HEATER_IDLE_HANDLER, heater_idle[e].update(ms)); @@ -1559,7 +1559,7 @@ void Temperature::min_temp_error(const heater_id_t heater_id) { void Temperature::manage_heated_bed(const millis_t &ms) { #if ENABLED(THERMAL_PROTECTION_BED) - if (degBed() > BED_MAXTEMP) max_temp_error(H_BED); + if (degBed() > BED_MAXTEMP) maxtemp_error(H_BED); #endif #if WATCH_BED @@ -1641,7 +1641,7 @@ void Temperature::min_temp_error(const heater_id_t heater_id) { #endif #if ENABLED(THERMAL_PROTECTION_CHAMBER) - if (degChamber() > CHAMBER_MAXTEMP) max_temp_error(H_CHAMBER); + if (degChamber() > CHAMBER_MAXTEMP) maxtemp_error(H_CHAMBER); #endif #if WATCH_CHAMBER @@ -1768,7 +1768,7 @@ void Temperature::min_temp_error(const heater_id_t heater_id) { #endif #if ENABLED(THERMAL_PROTECTION_COOLER) - if (degCooler() > COOLER_MAXTEMP) max_temp_error(H_COOLER); + if (degCooler() > COOLER_MAXTEMP) maxtemp_error(H_COOLER); #endif #if WATCH_COOLER @@ -1860,20 +1860,20 @@ void Temperature::task() { #if DISABLED(IGNORE_THERMOCOUPLE_ERRORS) #if TEMP_SENSOR_IS_MAX_TC(0) - if (degHotend(0) > _MIN(HEATER_0_MAXTEMP, TEMP_SENSOR_0_MAX_TC_TMAX - 1.0)) max_temp_error(H_E0); - if (degHotend(0) < _MAX(HEATER_0_MINTEMP, TEMP_SENSOR_0_MAX_TC_TMIN + .01)) min_temp_error(H_E0); + if (degHotend(0) > _MIN(HEATER_0_MAXTEMP, TEMP_SENSOR_0_MAX_TC_TMAX - 1.0)) maxtemp_error(H_E0); + if (degHotend(0) < _MAX(HEATER_0_MINTEMP, TEMP_SENSOR_0_MAX_TC_TMIN + .01)) mintemp_error(H_E0); #endif #if TEMP_SENSOR_IS_MAX_TC(1) - if (degHotend(1) > _MIN(HEATER_1_MAXTEMP, TEMP_SENSOR_1_MAX_TC_TMAX - 1.0)) max_temp_error(H_E1); - if (degHotend(1) < _MAX(HEATER_1_MINTEMP, TEMP_SENSOR_1_MAX_TC_TMIN + .01)) min_temp_error(H_E1); + if (degHotend(1) > _MIN(HEATER_1_MAXTEMP, TEMP_SENSOR_1_MAX_TC_TMAX - 1.0)) maxtemp_error(H_E1); + if (degHotend(1) < _MAX(HEATER_1_MINTEMP, TEMP_SENSOR_1_MAX_TC_TMIN + .01)) mintemp_error(H_E1); #endif #if TEMP_SENSOR_IS_MAX_TC(2) - if (degHotend(2) > _MIN(HEATER_2_MAXTEMP, TEMP_SENSOR_2_MAX_TC_TMAX - 1.0)) max_temp_error(H_E2); - if (degHotend(2) < _MAX(HEATER_2_MINTEMP, TEMP_SENSOR_2_MAX_TC_TMIN + .01)) min_temp_error(H_E2); + if (degHotend(2) > _MIN(HEATER_2_MAXTEMP, TEMP_SENSOR_2_MAX_TC_TMAX - 1.0)) maxtemp_error(H_E2); + if (degHotend(2) < _MAX(HEATER_2_MINTEMP, TEMP_SENSOR_2_MAX_TC_TMIN + .01)) mintemp_error(H_E2); #endif #if TEMP_SENSOR_IS_MAX_TC(REDUNDANT) - if (degRedundant() > TEMP_SENSOR_REDUNDANT_MAX_TC_TMAX - 1.0) max_temp_error(H_REDUNDANT); - if (degRedundant() < TEMP_SENSOR_REDUNDANT_MAX_TC_TMIN + .01) min_temp_error(H_REDUNDANT); + if (degRedundant() > TEMP_SENSOR_REDUNDANT_MAX_TC_TMAX - 1.0) maxtemp_error(H_REDUNDANT); + if (degRedundant() < TEMP_SENSOR_REDUNDANT_MAX_TC_TMIN + .01) mintemp_error(H_REDUNDANT); #endif #else #warning "Safety Alert! Disable IGNORE_THERMOCOUPLE_ERRORS for the final build!" @@ -2384,7 +2384,7 @@ void Temperature::updateTemperaturesFromRawValues() { const raw_adc_t r = temp_hotend[e].getraw(); const bool neg = temp_dir[e] < 0, pos = temp_dir[e] > 0; if ((neg && r < temp_range[e].raw_max) || (pos && r > temp_range[e].raw_max)) - max_temp_error((heater_id_t)e); + maxtemp_error((heater_id_t)e); /** // DEBUG PREHEATING TIME @@ -2396,7 +2396,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 (TERN1(MULTI_MAX_CONSECUTIVE_LOW_TEMP_ERR, ++consecutive_low_temperature_error[e] >= MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED)) - min_temp_error((heater_id_t)e); + mintemp_error((heater_id_t)e); } else { TERN_(MULTI_MAX_CONSECUTIVE_LOW_TEMP_ERR, consecutive_low_temperature_error[e] = 0); @@ -2407,23 +2407,23 @@ 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)) max_temp_error(H_BED); - if (temp_bed.target > 0 && TP_CMP(BED, mintemp_raw_BED, temp_bed.getraw())) min_temp_error(H_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); #endif #if BOTH(HAS_HEATED_CHAMBER, THERMAL_PROTECTION_CHAMBER) - if (TP_CMP(CHAMBER, temp_chamber.getraw(), maxtemp_raw_CHAMBER)) max_temp_error(H_CHAMBER); - if (temp_chamber.target > 0 && TP_CMP(CHAMBER, mintemp_raw_CHAMBER, temp_chamber.getraw())) min_temp_error(H_CHAMBER); + if (TP_CMP(CHAMBER, temp_chamber.getraw(), maxtemp_raw_CHAMBER)) maxtemp_error(H_CHAMBER); + if (temp_chamber.target > 0 && TP_CMP(CHAMBER, mintemp_raw_CHAMBER, temp_chamber.getraw())) mintemp_error(H_CHAMBER); #endif #if BOTH(HAS_COOLER, THERMAL_PROTECTION_COOLER) - if (cutter.unitPower > 0 && TP_CMP(COOLER, temp_cooler.getraw(), maxtemp_raw_COOLER)) max_temp_error(H_COOLER); - if (TP_CMP(COOLER, mintemp_raw_COOLER, temp_cooler.getraw())) min_temp_error(H_COOLER); + if (cutter.unitPower > 0 && TP_CMP(COOLER, temp_cooler.getraw(), maxtemp_raw_COOLER)) maxtemp_error(H_COOLER); + if (TP_CMP(COOLER, mintemp_raw_COOLER, temp_cooler.getraw())) mintemp_error(H_COOLER); #endif #if BOTH(HAS_TEMP_BOARD, THERMAL_PROTECTION_BOARD) - if (TP_CMP(BOARD, temp_board.getraw(), maxtemp_raw_BOARD)) max_temp_error(H_BOARD); - if (TP_CMP(BOARD, mintemp_raw_BOARD, temp_board.getraw())) min_temp_error(H_BOARD); + if (TP_CMP(BOARD, temp_board.getraw(), maxtemp_raw_BOARD)) maxtemp_error(H_BOARD); + if (TP_CMP(BOARD, mintemp_raw_BOARD, temp_board.getraw())) mintemp_error(H_BOARD); #endif #undef TP_CMP @@ -3138,7 +3138,7 @@ void Temperature::disable_all_heaters() { #endif // Handle an error. If there have been more than THERMOCOUPLE_MAX_ERRORS, send an error over serial. - // Either way, return the TMAX for the thermocouple to trigger a max_temp_error() + // Either way, return the TMAX for the thermocouple to trigger a maxtemp_error() if (max_tc_temp & MAX_TC_ERROR_MASK) { max_tc_errors[hindex]++; diff --git a/Marlin/src/module/temperature.h b/Marlin/src/module/temperature.h index c40a418428bc..11b2530d38d5 100644 --- a/Marlin/src/module/temperature.h +++ b/Marlin/src/module/temperature.h @@ -1252,8 +1252,8 @@ class Temperature { #endif static void _temp_error(const heater_id_t e, FSTR_P const serial_msg, FSTR_P const lcd_msg); - static void min_temp_error(const heater_id_t e); - static void max_temp_error(const heater_id_t e); + static void mintemp_error(const heater_id_t e); + static void maxtemp_error(const heater_id_t e); #define HAS_THERMAL_PROTECTION ANY(THERMAL_PROTECTION_HOTENDS, THERMAL_PROTECTION_CHAMBER, THERMAL_PROTECTION_BED, THERMAL_PROTECTION_COOLER) From 48f533ed0d0fcf192f2acd275a19c3b65f1e781f Mon Sep 17 00:00:00 2001 From: thinkyhead Date: Wed, 4 Jan 2023 06:06:14 +0000 Subject: [PATCH 2/4] [cron] Bump distribution date (2023-01-04) --- Marlin/Version.h | 2 +- Marlin/src/inc/Version.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Marlin/Version.h b/Marlin/Version.h index f3b118aaaf0b..9be97bc2544f 100644 --- a/Marlin/Version.h +++ b/Marlin/Version.h @@ -41,7 +41,7 @@ * here we define this default string as the date where the latest release * version was tagged. */ -//#define STRING_DISTRIBUTION_DATE "2023-01-03" +//#define STRING_DISTRIBUTION_DATE "2023-01-04" /** * Defines a generic printer name to be output to the LCD after booting Marlin. diff --git a/Marlin/src/inc/Version.h b/Marlin/src/inc/Version.h index d0740bef0003..b05d3fe58d0b 100644 --- a/Marlin/src/inc/Version.h +++ b/Marlin/src/inc/Version.h @@ -42,7 +42,7 @@ * version was tagged. */ #ifndef STRING_DISTRIBUTION_DATE - #define STRING_DISTRIBUTION_DATE "2023-01-03" + #define STRING_DISTRIBUTION_DATE "2023-01-04" #endif /** From f8283a40a2f1ff558d65b646bb758ff6529a56aa Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 3 Jan 2023 19:40:23 -0600 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20Add=20T?= =?UTF-8?q?emperature::is=5Fabove=5Ftarget?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/src/lcd/e3v2/jyersui/dwin.cpp | 12 ++++---- Marlin/src/module/temperature.cpp | 42 ++++++++++++++-------------- Marlin/src/module/temperature.h | 3 +- 3 files changed, 29 insertions(+), 28 deletions(-) diff --git a/Marlin/src/lcd/e3v2/jyersui/dwin.cpp b/Marlin/src/lcd/e3v2/jyersui/dwin.cpp index cf0d6dc8fccc..0f78e58ef5d7 100644 --- a/Marlin/src/lcd/e3v2/jyersui/dwin.cpp +++ b/Marlin/src/lcd/e3v2/jyersui/dwin.cpp @@ -1213,7 +1213,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ if (thermalManager.temp_hotend[0].target < thermalManager.extrude_min_temp) Popup_Handler(ETemp); else { - if (thermalManager.temp_hotend[0].is_below_target(-2)) { + if (thermalManager.temp_hotend[0].is_below_target(2)) { Popup_Handler(Heating); thermalManager.wait_for_hotend(0); } @@ -1356,7 +1356,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ Popup_Handler(ETemp); } else { - if (thermalManager.temp_hotend[0].is_below_target(-2)) { + if (thermalManager.temp_hotend[0].is_below_target(2)) { Popup_Handler(Heating); thermalManager.wait_for_hotend(0); Redraw_Menu(); @@ -1743,7 +1743,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ if (thermalManager.temp_hotend[0].target < thermalManager.extrude_min_temp) Popup_Handler(ETemp); else { - if (thermalManager.temp_hotend[0].is_below_target(-2)) { + if (thermalManager.temp_hotend[0].is_below_target(2)) { Popup_Handler(Heating); thermalManager.wait_for_hotend(0); } @@ -1762,7 +1762,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ Popup_Handler(ETemp); } else { - if (thermalManager.temp_hotend[0].is_below_target(-2)) { + if (thermalManager.temp_hotend[0].is_below_target(2)) { Popup_Handler(Heating); thermalManager.wait_for_hotend(0); } @@ -1780,7 +1780,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ if (thermalManager.temp_hotend[0].target < thermalManager.extrude_min_temp) Popup_Handler(ETemp); else { - if (thermalManager.temp_hotend[0].is_below_target(-2)) { + if (thermalManager.temp_hotend[0].is_below_target(2)) { Popup_Handler(Heating); thermalManager.wait_for_hotend(0); } @@ -4505,7 +4505,7 @@ void CrealityDWINClass::Popup_Control() { if (thermalManager.temp_hotend[0].target < thermalManager.extrude_min_temp) Popup_Handler(ETemp); else { - if (thermalManager.temp_hotend[0].is_below_target(-2)) { + if (thermalManager.temp_hotend[0].is_below_target(2)) { Popup_Handler(Heating); thermalManager.wait_for_hotend(0); } diff --git a/Marlin/src/module/temperature.cpp b/Marlin/src/module/temperature.cpp index ead7e97a8106..cd76dac326cf 100644 --- a/Marlin/src/module/temperature.cpp +++ b/Marlin/src/module/temperature.cpp @@ -1599,22 +1599,25 @@ void Temperature::mintemp_error(const heater_id_t heater_id) { #endif #if HEATER_IDLE_HANDLER - if (heater_idle[IDLE_INDEX_BED].timed_out) { + const bool bed_timed_out = heater_idle[IDLE_INDEX_BED].timed_out; + if (bed_timed_out) { temp_bed.soft_pwm_amount = 0; if (DISABLED(PIDTEMPBED)) WRITE_HEATER_BED(LOW); } - else + #else + constexpr bool bed_timed_out = false; #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.celsius >= temp_bed.target + BED_HYSTERESIS) + 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)) + 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; @@ -1641,7 +1644,7 @@ void Temperature::mintemp_error(const heater_id_t heater_id) { #endif #if ENABLED(THERMAL_PROTECTION_CHAMBER) - if (degChamber() > CHAMBER_MAXTEMP) maxtemp_error(H_CHAMBER); + if (degChamber() > (CHAMBER_MAXTEMP)) maxtemp_error(H_CHAMBER); #endif #if WATCH_CHAMBER @@ -1669,13 +1672,12 @@ void Temperature::mintemp_error(const heater_id_t heater_id) { #if CHAMBER_FAN_MODE == 0 fan_chamber_pwm = CHAMBER_FAN_BASE; #elif CHAMBER_FAN_MODE == 1 - fan_chamber_pwm = (temp_chamber.celsius > temp_chamber.target) ? (CHAMBER_FAN_BASE) + (CHAMBER_FAN_FACTOR) * (temp_chamber.celsius - temp_chamber.target) : 0; + fan_chamber_pwm = temp_chamber.is_above_target() ? (CHAMBER_FAN_BASE) + (CHAMBER_FAN_FACTOR) * (temp_chamber.celsius - temp_chamber.target) : 0; #elif CHAMBER_FAN_MODE == 2 fan_chamber_pwm = (CHAMBER_FAN_BASE) + (CHAMBER_FAN_FACTOR) * ABS(temp_chamber.celsius - temp_chamber.target); - if (temp_chamber.soft_pwm_amount) - fan_chamber_pwm += (CHAMBER_FAN_FACTOR) * 2; + if (temp_chamber.soft_pwm_amount) fan_chamber_pwm += (CHAMBER_FAN_FACTOR) * 2; #elif CHAMBER_FAN_MODE == 3 - fan_chamber_pwm = CHAMBER_FAN_BASE + _MAX((CHAMBER_FAN_FACTOR) * (temp_chamber.celsius - temp_chamber.target), 0); + fan_chamber_pwm = (CHAMBER_FAN_BASE) + _MAX((CHAMBER_FAN_FACTOR) * (temp_chamber.celsius - temp_chamber.target), 0); #endif NOMORE(fan_chamber_pwm, 255); set_fan_speed(CHAMBER_FAN_INDEX, fan_chamber_pwm); @@ -1688,7 +1690,7 @@ void Temperature::mintemp_error(const heater_id_t heater_id) { #ifndef MIN_COOLING_SLOPE_DEG_CHAMBER_VENT #define MIN_COOLING_SLOPE_DEG_CHAMBER_VENT 1.5 #endif - if (!flag_chamber_excess_heat && temp_chamber.celsius - temp_chamber.target >= HIGH_EXCESS_HEAT_LIMIT) { + if (!flag_chamber_excess_heat && temp_chamber.is_above_target((HIGH_EXCESS_HEAT_LIMIT) - 1)) { // Open vent after MIN_COOLING_SLOPE_TIME_CHAMBER_VENT seconds if the // temperature didn't drop at least MIN_COOLING_SLOPE_DEG_CHAMBER_VENT if (next_cool_check_ms_2 == 0 || ELAPSED(ms, next_cool_check_ms_2)) { @@ -1702,7 +1704,7 @@ void Temperature::mintemp_error(const heater_id_t heater_id) { next_cool_check_ms_2 = 0; old_temp = 9999; } - if (flag_chamber_excess_heat && (temp_chamber.target - temp_chamber.celsius >= LOW_EXCESS_HEAT_LIMIT)) + if (flag_chamber_excess_heat && temp_chamber.is_above_target((LOW_EXCESS_HEAT_LIMIT) - 1)) flag_chamber_excess_heat = false; #endif } @@ -1734,9 +1736,9 @@ void Temperature::mintemp_error(const heater_id_t heater_id) { } else { #if ENABLED(CHAMBER_LIMIT_SWITCHING) - if (temp_chamber.celsius >= temp_chamber.target + TEMP_CHAMBER_HYSTERESIS) + if (temp_chamber.is_above_target((TEMP_CHAMBER_HYSTERESIS) - 1)) temp_chamber.soft_pwm_amount = 0; - else if (temp_chamber.is_below_target(-(TEMP_CHAMBER_HYSTERESIS) + 1)) + else if (temp_chamber.is_below_target((TEMP_CHAMBER_HYSTERESIS) - 1)) temp_chamber.soft_pwm_amount = (MAX_CHAMBER_POWER) >> 1; #else temp_chamber.soft_pwm_amount = temp_chamber.is_below_target() ? (MAX_CHAMBER_POWER) >> 1 : 0; @@ -1788,20 +1790,18 @@ void Temperature::mintemp_error(const heater_id_t heater_id) { if (temp_cooler.target == 0) temp_cooler.target = COOLER_MIN_TARGET; if (ELAPSED(ms, next_cooler_check_ms)) { next_cooler_check_ms = ms + COOLER_CHECK_INTERVAL; - if (temp_cooler.celsius > temp_cooler.target) { - temp_cooler.soft_pwm_amount = temp_cooler.celsius > temp_cooler.target ? MAX_COOLER_POWER : 0; - flag_cooler_state = temp_cooler.soft_pwm_amount > 0 ? true : false; // used to allow M106 fan control when cooler is disabled + if (temp_cooler.is_above_target()) { // too warm? + temp_cooler.soft_pwm_amount = MAX_COOLER_POWER; #if ENABLED(COOLER_FAN) - int16_t fan_cooler_pwm = (COOLER_FAN_BASE) + (COOLER_FAN_FACTOR) * ABS(temp_cooler.celsius - temp_cooler.target); - NOMORE(fan_cooler_pwm, 255); - set_fan_speed(COOLER_FAN_INDEX, fan_cooler_pwm); // Set cooler fan pwm + const int16_t fan_cooler_pwm = (COOLER_FAN_BASE) + (COOLER_FAN_FACTOR) * ABS(temp_cooler.celsius - temp_cooler.target); + set_fan_speed(COOLER_FAN_INDEX, _MIN(fan_cooler_pwm, 255)); // Set cooler fan pwm cooler_fan_flush_ms = ms + 5000; #endif } else { temp_cooler.soft_pwm_amount = 0; #if ENABLED(COOLER_FAN) - set_fan_speed(COOLER_FAN_INDEX, temp_cooler.celsius > temp_cooler.target - 2 ? COOLER_FAN_BASE : 0); + set_fan_speed(COOLER_FAN_INDEX, temp_cooler.is_above_target(-2) ? COOLER_FAN_BASE : 0); #endif WRITE_HEATER_COOLER(LOW); } diff --git a/Marlin/src/module/temperature.h b/Marlin/src/module/temperature.h index 11b2530d38d5..091f218eb837 100644 --- a/Marlin/src/module/temperature.h +++ b/Marlin/src/module/temperature.h @@ -421,7 +421,8 @@ typedef struct TempInfo { typedef struct HeaterInfo : public TempInfo { celsius_t target; uint8_t soft_pwm_amount; - bool is_below_target(const celsius_t offs=0) const { return (celsius < (target + offs)); } + bool is_below_target(const celsius_t offs=0) const { return (target - celsius > offs); } // celsius < target - offs + bool is_above_target(const celsius_t offs=0) const { return (celsius - target > offs); } // celsius > target + offs } heater_info_t; // A heater with PID stabilization From eb34063956b8e47d1217a610c06e93f29482c1c3 Mon Sep 17 00:00:00 2001 From: Bob-the-Kuhn Date: Thu, 26 Jan 2023 06:56:36 -0600 Subject: [PATCH 4/4] spindle_laser.h bug fix Change line 284 to eliminate compile error when LASER_FEATURE is enabled and SPINDLE_LASER_USE_PWM is disabled --- Marlin/src/feature/spindle_laser.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/src/feature/spindle_laser.h b/Marlin/src/feature/spindle_laser.h index a49e5611a4a9..9750d4807fc1 100644 --- a/Marlin/src/feature/spindle_laser.h +++ b/Marlin/src/feature/spindle_laser.h @@ -281,7 +281,7 @@ class SpindleLaser { set_enabled(state); if (state) { if (!menuPower) menuPower = cpwr_to_upwr(SPEED_POWER_STARTUP); - power = upower_to_ocr(menuPower); + power = TERN(SPINDLE_LASER_USE_PWM, upower_to_ocr(menuPower), 255); apply_power(power); } else apply_power(0);