Skip to content

Commit 3be967b

Browse files
committed
🩹 PID / MPC heating followup
Followup to MarlinFirmware#25314
1 parent 57a7e28 commit 3be967b

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

Marlin/src/module/temperature.cpp

+10-7
Original file line numberDiff line numberDiff line change
@@ -907,11 +907,10 @@ volatile bool Temperature::raw_temps_ready = false;
907907
SERIAL_ECHOPGM(STR_MPC_AUTOTUNE);
908908
SERIAL_ECHOLNPGM(STR_MPC_AUTOTUNE_INTERRUPTED);
909909
TERN_(DWIN_LCD_PROUI, DWIN_MPCTuning(MPC_INTERRUPTED));
910-
return false;
910+
return true;
911911
}
912912

913-
wait_for_heatup = false;
914-
return true;
913+
return false;
915914
};
916915

917916
struct OnExit {
@@ -964,7 +963,7 @@ volatile bool Temperature::raw_temps_ready = false;
964963

965964
wait_for_heatup = true;
966965
for (;;) { // Can be interrupted with M108
967-
if (!housekeeping(ms, current_temp, next_report_ms)) return;
966+
if (housekeeping(ms, current_temp, next_report_ms)) return;
968967

969968
if (ELAPSED(ms, next_test_ms)) {
970969
if (current_temp >= ambient_temp) {
@@ -975,6 +974,7 @@ volatile bool Temperature::raw_temps_ready = false;
975974
next_test_ms += 10000UL;
976975
}
977976
}
977+
wait_for_heatup = false;
978978

979979
#if HAS_FAN
980980
set_fan_speed(EITHER(MPC_FAN_0_ALL_HOTENDS, MPC_FAN_0_ACTIVE_HOTEND) ? 0 : active_extruder, 0);
@@ -986,7 +986,7 @@ volatile bool Temperature::raw_temps_ready = false;
986986
SERIAL_ECHOLNPGM(STR_MPC_HEATING_PAST_200);
987987
TERN(DWIN_LCD_PROUI, LCD_ALERTMESSAGE(MSG_MPC_HEATING_PAST_200), LCD_MESSAGE(MSG_HEATING));
988988
hotend.target = 200.0f; // So M105 looks nice
989-
hotend.soft_pwm_amount = MPC_MAX >> 1;
989+
hotend.soft_pwm_amount = (MPC_MAX) >> 1;
990990
const millis_t heat_start_time = next_test_ms = ms;
991991
celsius_float_t temp_samples[16];
992992
uint8_t sample_count = 0;
@@ -995,7 +995,7 @@ volatile bool Temperature::raw_temps_ready = false;
995995

996996
wait_for_heatup = true;
997997
for (;;) { // Can be interrupted with M108
998-
if (!housekeeping(ms, current_temp, next_report_ms)) return;
998+
if (housekeeping(ms, current_temp, next_report_ms)) return;
999999

10001000
if (ELAPSED(ms, next_test_ms)) {
10011001
// Record samples between 100C and 200C
@@ -1017,6 +1017,8 @@ volatile bool Temperature::raw_temps_ready = false;
10171017
next_test_ms += 1000UL * sample_distance;
10181018
}
10191019
}
1020+
wait_for_heatup = false;
1021+
10201022
hotend.soft_pwm_amount = 0;
10211023

10221024
// Calculate physical constants from three equally-spaced samples
@@ -1052,7 +1054,7 @@ volatile bool Temperature::raw_temps_ready = false;
10521054

10531055
wait_for_heatup = true;
10541056
for (;;) { // Can be interrupted with M108
1055-
if (!housekeeping(ms, current_temp, next_report_ms)) return;
1057+
if (housekeeping(ms, current_temp, next_report_ms)) return;
10561058

10571059
if (ELAPSED(ms, next_test_ms)) {
10581060
hotend.soft_pwm_amount = (int)get_pid_output_hotend(active_extruder) >> 1;
@@ -1082,6 +1084,7 @@ volatile bool Temperature::raw_temps_ready = false;
10821084
break;
10831085
}
10841086
}
1087+
wait_for_heatup = false;
10851088

10861089
const float power_fan0 = total_energy_fan0 * 1000 / test_duration;
10871090
mpc.ambient_xfer_coeff_fan0 = power_fan0 / (hotend.target - ambient_temp);

Marlin/src/module/temperature.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -1162,6 +1162,12 @@ class Temperature {
11621162
static void auto_job_check_timer(const bool can_start, const bool can_stop);
11631163
#endif
11641164

1165+
#if ENABLED(TEMP_TUNING_MAINTAIN_FAN)
1166+
static bool adaptive_fan_slowing;
1167+
#elif ENABLED(ADAPTIVE_FAN_SLOWING)
1168+
static constexpr bool adaptive_fan_slowing = true;
1169+
#endif
1170+
11651171
/**
11661172
* Perform auto-tuning for hotend or bed in response to M303
11671173
*/
@@ -1173,12 +1179,6 @@ class Temperature {
11731179

11741180
static void PID_autotune(const celsius_t target, const heater_id_t heater_id, const int8_t ncycles, const bool set_result=false);
11751181

1176-
#if ENABLED(TEMP_TUNING_MAINTAIN_FAN)
1177-
static bool adaptive_fan_slowing;
1178-
#elif ENABLED(ADAPTIVE_FAN_SLOWING)
1179-
static constexpr bool adaptive_fan_slowing = true;
1180-
#endif
1181-
11821182
// Update the temp manager when PID values change
11831183
#if ENABLED(PIDTEMP)
11841184
static void updatePID() { HOTEND_LOOP() temp_hotend[e].pid.reset(); }

0 commit comments

Comments
 (0)