From d3eeb5b332d9fb8b23b5cee562901c3323d721d2 Mon Sep 17 00:00:00 2001 From: tombrazier <68918209+tombrazier@users.noreply.github.com> Date: Wed, 1 Feb 2023 07:25:13 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A9=B9=20Fix=20PID=20/=20MPC=20heating=20?= =?UTF-8?q?flags=20(#25314)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Scott Lahteine --- Marlin/Configuration_adv.h | 4 ++-- Marlin/src/inc/Conditionals_post.h | 2 +- Marlin/src/inc/SanityCheck.h | 2 ++ Marlin/src/module/temperature.cpp | 34 +++++++++++++++++++++--------- Marlin/src/module/temperature.h | 12 +++++------ buildroot/tests/LPC1768 | 2 +- buildroot/tests/LPC1769 | 2 +- 7 files changed, 37 insertions(+), 21 deletions(-) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 71f46bfe8a79..16f8bdee1adf 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -304,8 +304,8 @@ #define THERMAL_PROTECTION_HYSTERESIS 4 // Degrees Celsius //#define ADAPTIVE_FAN_SLOWING // Slow part cooling fan if temperature drops - #if BOTH(ADAPTIVE_FAN_SLOWING, PIDTEMP) - //#define NO_FAN_SLOWING_IN_PID_TUNING // Don't slow fan speed during M303 + #if ENABLED(ADAPTIVE_FAN_SLOWING) && EITHER(MPCTEMP, PIDTEMP) + //#define TEMP_TUNING_MAINTAIN_FAN // Don't slow fan speed during M303 or M306 T #endif /** diff --git a/Marlin/src/inc/Conditionals_post.h b/Marlin/src/inc/Conditionals_post.h index 5ec428edf29d..cf6c560b5cc7 100644 --- a/Marlin/src/inc/Conditionals_post.h +++ b/Marlin/src/inc/Conditionals_post.h @@ -3054,7 +3054,7 @@ */ #if !HAS_FAN #undef ADAPTIVE_FAN_SLOWING - #undef NO_FAN_SLOWING_IN_PID_TUNING + #undef TEMP_TUNING_MAINTAIN_FAN #endif #if !BOTH(HAS_BED_PROBE, HAS_FAN) #undef PROBING_FANS_OFF diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index b5a37307ab32..c501c328c769 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -97,6 +97,8 @@ #error "Thermal Runaway Protection for hotends is now enabled with THERMAL_PROTECTION_HOTENDS." #elif DISABLED(THERMAL_PROTECTION_BED) && defined(THERMAL_PROTECTION_BED_PERIOD) #error "Thermal Runaway Protection for the bed is now enabled with THERMAL_PROTECTION_BED." +#elif defined(NO_FAN_SLOWING_IN_PID_TUNING) + #error "NO_FAN_SLOWING_IN_PID_TUNING is now TEMP_TUNING_MAINTAIN_FAN." #elif (CORE_IS_XZ || CORE_IS_YZ) && ENABLED(Z_LATE_ENABLE) #error "Z_LATE_ENABLE can't be used with COREXZ, COREZX, COREYZ, or COREZY." #elif defined(X_HOME_RETRACT_MM) diff --git a/Marlin/src/module/temperature.cpp b/Marlin/src/module/temperature.cpp index 5d4ccc0a5189..4b0ee355d4cf 100644 --- a/Marlin/src/module/temperature.cpp +++ b/Marlin/src/module/temperature.cpp @@ -311,7 +311,7 @@ PGMSTR(str_t_heating_failed, STR_T_HEATING_FAILED); * public: */ -#if ENABLED(NO_FAN_SLOWING_IN_PID_TUNING) +#if ENABLED(TEMP_TUNING_MAINTAIN_FAN) bool Temperature::adaptive_fan_slowing = true; #endif @@ -688,7 +688,7 @@ volatile bool Temperature::raw_temps_ready = false; LEDColor color = ONHEATINGSTART(); #endif - TERN_(NO_FAN_SLOWING_IN_PID_TUNING, adaptive_fan_slowing = false); + TERN_(TEMP_TUNING_MAINTAIN_FAN, adaptive_fan_slowing = false); LCD_MESSAGE(MSG_HEATING); @@ -876,7 +876,7 @@ volatile bool Temperature::raw_temps_ready = false; TERN_(DWIN_PID_TUNE, DWIN_PidTuning(PID_DONE)); EXIT_M303: - TERN_(NO_FAN_SLOWING_IN_PID_TUNING, adaptive_fan_slowing = true); + TERN_(TEMP_TUNING_MAINTAIN_FAN, adaptive_fan_slowing = true); return; } @@ -907,10 +907,10 @@ volatile bool Temperature::raw_temps_ready = false; SERIAL_ECHOPGM(STR_MPC_AUTOTUNE); SERIAL_ECHOLNPGM(STR_MPC_AUTOTUNE_INTERRUPTED); TERN_(DWIN_LCD_PROUI, DWIN_MPCTuning(MPC_INTERRUPTED)); - return false; + return true; } - return true; + return false; }; struct OnExit { @@ -927,6 +927,8 @@ volatile bool Temperature::raw_temps_ready = false; #endif do_z_clearance(MPC_TUNING_END_Z); + + TERN_(TEMP_TUNING_MAINTAIN_FAN, adaptive_fan_slowing = true); } } on_exit; @@ -935,6 +937,8 @@ volatile bool Temperature::raw_temps_ready = false; MPCHeaterInfo &hotend = temp_hotend[active_extruder]; MPC_t &mpc = hotend.mpc; + TERN_(TEMP_TUNING_MAINTAIN_FAN, adaptive_fan_slowing = false); + // Move to center of bed, just above bed height and cool with max fan gcode.home_all_axes(true); disable_all_heaters(); @@ -959,7 +963,7 @@ volatile bool Temperature::raw_temps_ready = false; wait_for_heatup = true; for (;;) { // Can be interrupted with M108 - if (!housekeeping(ms, current_temp, next_report_ms)) return; + if (housekeeping(ms, current_temp, next_report_ms)) return; if (ELAPSED(ms, next_test_ms)) { if (current_temp >= ambient_temp) { @@ -982,15 +986,16 @@ volatile bool Temperature::raw_temps_ready = false; SERIAL_ECHOLNPGM(STR_MPC_HEATING_PAST_200); TERN(DWIN_LCD_PROUI, LCD_ALERTMESSAGE(MSG_MPC_HEATING_PAST_200), LCD_MESSAGE(MSG_HEATING)); hotend.target = 200.0f; // So M105 looks nice - hotend.soft_pwm_amount = MPC_MAX >> 1; + hotend.soft_pwm_amount = (MPC_MAX) >> 1; const millis_t heat_start_time = next_test_ms = ms; celsius_float_t temp_samples[16]; uint8_t sample_count = 0; uint16_t sample_distance = 1; float t1_time = 0; + wait_for_heatup = true; for (;;) { // Can be interrupted with M108 - if (!housekeeping(ms, current_temp, next_report_ms)) return; + if (housekeeping(ms, current_temp, next_report_ms)) return; if (ELAPSED(ms, next_test_ms)) { // Record samples between 100C and 200C @@ -1012,6 +1017,8 @@ volatile bool Temperature::raw_temps_ready = false; next_test_ms += 1000UL * sample_distance; } } + wait_for_heatup = false; + hotend.soft_pwm_amount = 0; // Calculate physical constants from three equally-spaced samples @@ -1045,8 +1052,9 @@ volatile bool Temperature::raw_temps_ready = false; #endif float last_temp = current_temp; + wait_for_heatup = true; for (;;) { // Can be interrupted with M108 - if (!housekeeping(ms, current_temp, next_report_ms)) return; + if (housekeeping(ms, current_temp, next_report_ms)) return; if (ELAPSED(ms, next_test_ms)) { hotend.soft_pwm_amount = (int)get_pid_output_hotend(active_extruder) >> 1; @@ -1076,6 +1084,7 @@ volatile bool Temperature::raw_temps_ready = false; break; } } + wait_for_heatup = false; const float power_fan0 = total_energy_fan0 * 1000 / test_duration; mpc.ambient_xfer_coeff_fan0 = power_fan0 / (hotend.target - ambient_temp); @@ -4124,6 +4133,7 @@ void Temperature::isr() { } while (wait_for_heatup && TEMP_CONDITIONS); + // If wait_for_heatup is set, temperature was reached, no cancel if (wait_for_heatup) { wait_for_heatup = false; #if HAS_DWIN_E3V2_BASIC @@ -4262,6 +4272,7 @@ void Temperature::isr() { } while (wait_for_heatup && TEMP_BED_CONDITIONS); + // If wait_for_heatup is set, temperature was reached, no cancel if (wait_for_heatup) { wait_for_heatup = false; ui.reset_status(); @@ -4340,6 +4351,7 @@ void Temperature::isr() { } } + // If wait_for_heatup is set, temperature was reached, no cancel if (wait_for_heatup) { wait_for_heatup = false; ui.reset_status(); @@ -4439,6 +4451,7 @@ void Temperature::isr() { } } while (wait_for_heatup && TEMP_CHAMBER_CONDITIONS); + // If wait_for_heatup is set, temperature was reached, no cancel if (wait_for_heatup) { wait_for_heatup = false; ui.reset_status(); @@ -4525,6 +4538,7 @@ void Temperature::isr() { first_loop = false; #endif // TEMP_COOLER_RESIDENCY_TIME > 0 + // Prevent a wait-forever situation if R is misused i.e. M191 R0 if (wants_to_cool) { // Break after MIN_COOLING_SLOPE_TIME_CHAMBER seconds // if the temperature did not drop at least MIN_COOLING_SLOPE_DEG_CHAMBER @@ -4537,7 +4551,7 @@ void Temperature::isr() { } while (wait_for_heatup && TEMP_COOLER_CONDITIONS); - // Prevent a wait-forever situation if R is misused i.e. M191 R0 + // If wait_for_heatup is set, temperature was reached, no cancel if (wait_for_heatup) { wait_for_heatup = false; ui.reset_status(); diff --git a/Marlin/src/module/temperature.h b/Marlin/src/module/temperature.h index 9ac5db44edfa..afbf656a7ab6 100644 --- a/Marlin/src/module/temperature.h +++ b/Marlin/src/module/temperature.h @@ -1162,6 +1162,12 @@ class Temperature { static void auto_job_check_timer(const bool can_start, const bool can_stop); #endif + #if ENABLED(TEMP_TUNING_MAINTAIN_FAN) + static bool adaptive_fan_slowing; + #elif ENABLED(ADAPTIVE_FAN_SLOWING) + static constexpr bool adaptive_fan_slowing = true; + #endif + /** * Perform auto-tuning for hotend or bed in response to M303 */ @@ -1173,12 +1179,6 @@ class Temperature { static void PID_autotune(const celsius_t target, const heater_id_t heater_id, const int8_t ncycles, const bool set_result=false); - #if ENABLED(NO_FAN_SLOWING_IN_PID_TUNING) - static bool adaptive_fan_slowing; - #elif ENABLED(ADAPTIVE_FAN_SLOWING) - static constexpr bool adaptive_fan_slowing = true; - #endif - // Update the temp manager when PID values change #if ENABLED(PIDTEMP) static void updatePID() { HOTEND_LOOP() temp_hotend[e].pid.reset(); } diff --git a/buildroot/tests/LPC1768 b/buildroot/tests/LPC1768 index 535e776a3892..2e680b60d797 100755 --- a/buildroot/tests/LPC1768 +++ b/buildroot/tests/LPC1768 @@ -40,7 +40,7 @@ opt_set MOTHERBOARD BOARD_RAMPS_14_RE_ARM_EEB \ NOZZLE_CLEAN_MIN_TEMP 170 \ NOZZLE_CLEAN_START_POINT "{ { 10, 10, 3 }, { 10, 10, 3 } }" \ NOZZLE_CLEAN_END_POINT "{ { 10, 20, 3 }, { 10, 20, 3 } }" -opt_enable REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER ADAPTIVE_FAN_SLOWING NO_FAN_SLOWING_IN_PID_TUNING \ +opt_enable REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER ADAPTIVE_FAN_SLOWING TEMP_TUNING_MAINTAIN_FAN \ FILAMENT_WIDTH_SENSOR FILAMENT_LCD_DISPLAY PID_EXTRUSION_SCALING SOUND_MENU_ITEM \ NOZZLE_AS_PROBE AUTO_BED_LEVELING_BILINEAR PREHEAT_BEFORE_LEVELING G29_RETRY_AND_RECOVER Z_MIN_PROBE_REPEATABILITY_TEST DEBUG_LEVELING_FEATURE \ ASSISTED_TRAMMING ASSISTED_TRAMMING_WIZARD REPORT_TRAMMING_MM ASSISTED_TRAMMING_WAIT_POSITION \ diff --git a/buildroot/tests/LPC1769 b/buildroot/tests/LPC1769 index 086dffffc92c..ec5c824450c6 100755 --- a/buildroot/tests/LPC1769 +++ b/buildroot/tests/LPC1769 @@ -18,7 +18,7 @@ opt_set MOTHERBOARD BOARD_SMOOTHIEBOARD \ GRID_MAX_POINTS_X 16 \ NOZZLE_CLEAN_START_POINT "{ { 10, 10, 3 }, { 10, 10, 3 } }" \ NOZZLE_CLEAN_END_POINT "{ { 10, 20, 3 }, { 10, 20, 3 } }" -opt_enable TFTGLCD_PANEL_SPI SDSUPPORT ADAPTIVE_FAN_SLOWING NO_FAN_SLOWING_IN_PID_TUNING \ +opt_enable TFTGLCD_PANEL_SPI SDSUPPORT ADAPTIVE_FAN_SLOWING TEMP_TUNING_MAINTAIN_FAN \ MAX31865_SENSOR_OHMS_0 MAX31865_CALIBRATION_OHMS_0 \ FIX_MOUNTED_PROBE AUTO_BED_LEVELING_BILINEAR G29_RETRY_AND_RECOVER Z_MIN_PROBE_REPEATABILITY_TEST DEBUG_LEVELING_FEATURE \ BABYSTEPPING BABYSTEP_XY BABYSTEP_ZPROBE_OFFSET BED_TRAMMING_USE_PROBE BED_TRAMMING_VERIFY_RAISED \