Skip to content

Commit 64167df

Browse files
authored
✨ PREHEAT_TIME_BED_MS (MarlinFirmware#25146)
1 parent 250fd60 commit 64167df

File tree

4 files changed

+78
-43
lines changed

4 files changed

+78
-43
lines changed

Marlin/Configuration_adv.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,8 @@
493493
* the minimum temperature your thermistor can read. The lower the better/safer.
494494
* This shouldn't need to be more than 30 seconds (30000)
495495
*/
496-
//#define MILLISECONDS_PREHEAT_TIME 0
496+
//#define PREHEAT_TIME_HOTEND_MS 0
497+
//#define PREHEAT_TIME_BED_MS 0
497498

498499
// @section extruder
499500

Marlin/src/inc/SanityCheck.h

+8-2
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,8 @@
664664
#error "SCARA_PRINTABLE_RADIUS is now PRINTABLE_RADIUS."
665665
#elif defined(SCARA_FEEDRATE_SCALING)
666666
#error "SCARA_FEEDRATE_SCALING is now FEEDRATE_SCALING."
667+
#elif defined(MILLISECONDS_PREHEAT_TIME)
668+
#error "MILLISECONDS_PREHEAT_TIME is now PREHEAT_TIME_HOTEND_MS."
667669
#endif
668670

669671
// 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
24002402
#endif
24012403
#if MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED < 5
24022404
#error "Thermistor 66 requires MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED ≥ 5."
2403-
#elif MILLISECONDS_PREHEAT_TIME < 15000
2404-
#error "Thermistor 66 requires MILLISECONDS_PREHEAT_TIME ≥ 15000, but 30000 or higher is recommended."
2405+
#elif PREHEAT_TIME_HOTEND_MS < 15000
2406+
#error "Thermistor 66 requires PREHEAT_TIME_HOTEND_MS ≥ 15000, but 30000 or higher is recommended."
24052407
#endif
24062408
#undef _BAD_MINTEMP
24072409
#endif
24082410

2411+
#if TEMP_SENSOR_BED == 66 && PREHEAT_TIME_BED_MS < 15000
2412+
#error "Thermistor 66 requires PREHEAT_TIME_BED_MS ≥ 15000, but 30000 or higher is recommended."
2413+
#endif
2414+
24092415
/**
24102416
* Required MAX31865 settings
24112417
*/

Marlin/src/module/temperature.cpp

+32-24
Original file line numberDiff line numberDiff line change
@@ -561,8 +561,11 @@ volatile bool Temperature::raw_temps_ready = false;
561561
uint8_t Temperature::consecutive_low_temperature_error[HOTENDS] = { 0 };
562562
#endif
563563

564-
#if MILLISECONDS_PREHEAT_TIME > 0
565-
millis_t Temperature::preheat_end_time[HOTENDS] = { 0 };
564+
#if PREHEAT_TIME_HOTEND_MS > 0
565+
millis_t Temperature::preheat_end_ms_hotend[HOTENDS] { 0 };
566+
#endif
567+
#if HAS_HEATED_BED && PREHEAT_TIME_BED_MS > 0
568+
millis_t Temperature::preheat_end_ms_bed = 0;
566569
#endif
567570

568571
#if HAS_FAN_LOGIC
@@ -1535,7 +1538,7 @@ void Temperature::mintemp_error(const heater_id_t heater_id) {
15351538
tr_state_machine[e].run(temp_hotend[e].celsius, temp_hotend[e].target, (heater_id_t)e, THERMAL_PROTECTION_PERIOD, THERMAL_PROTECTION_HYSTERESIS);
15361539
#endif
15371540

1538-
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;
1541+
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;
15391542

15401543
#if WATCH_HOTENDS
15411544
// Make sure temperature is increasing
@@ -1609,25 +1612,30 @@ void Temperature::mintemp_error(const heater_id_t heater_id) {
16091612
#endif
16101613

16111614
if (!bed_timed_out) {
1612-
#if ENABLED(PIDTEMPBED)
1613-
temp_bed.soft_pwm_amount = WITHIN(temp_bed.celsius, BED_MINTEMP, BED_MAXTEMP) ? (int)get_pid_output_bed() >> 1 : 0;
1614-
#else
1615-
// Check if temperature is within the correct band
1616-
if (WITHIN(temp_bed.celsius, BED_MINTEMP, BED_MAXTEMP)) {
1617-
#if ENABLED(BED_LIMIT_SWITCHING)
1618-
if (temp_bed.is_above_target((BED_HYSTERESIS) - 1))
1619-
temp_bed.soft_pwm_amount = 0;
1620-
else if (temp_bed.is_below_target((BED_HYSTERESIS) - 1))
1621-
temp_bed.soft_pwm_amount = MAX_BED_POWER >> 1;
1622-
#else // !PIDTEMPBED && !BED_LIMIT_SWITCHING
1623-
temp_bed.soft_pwm_amount = temp_bed.is_below_target() ? MAX_BED_POWER >> 1 : 0;
1624-
#endif
1625-
}
1626-
else {
1627-
temp_bed.soft_pwm_amount = 0;
1628-
WRITE_HEATER_BED(LOW);
1629-
}
1630-
#endif
1615+
if (is_bed_preheating()) {
1616+
temp_bed.soft_pwm_amount = MAX_BED_POWER >> 1;
1617+
}
1618+
else {
1619+
#if ENABLED(PIDTEMPBED)
1620+
temp_bed.soft_pwm_amount = WITHIN(temp_bed.celsius, BED_MINTEMP, BED_MAXTEMP) ? (int)get_pid_output_bed() >> 1 : 0;
1621+
#else
1622+
// Check if temperature is within the correct band
1623+
if (WITHIN(temp_bed.celsius, BED_MINTEMP, BED_MAXTEMP)) {
1624+
#if ENABLED(BED_LIMIT_SWITCHING)
1625+
if (temp_bed.is_above_target((BED_HYSTERESIS) - 1))
1626+
temp_bed.soft_pwm_amount = 0;
1627+
else if (temp_bed.is_below_target((BED_HYSTERESIS) - 1))
1628+
temp_bed.soft_pwm_amount = MAX_BED_POWER >> 1;
1629+
#else // !PIDTEMPBED && !BED_LIMIT_SWITCHING
1630+
temp_bed.soft_pwm_amount = temp_bed.is_below_target() ? MAX_BED_POWER >> 1 : 0;
1631+
#endif
1632+
}
1633+
else {
1634+
temp_bed.soft_pwm_amount = 0;
1635+
WRITE_HEATER_BED(LOW);
1636+
}
1637+
#endif
1638+
}
16311639
}
16321640

16331641
} while (false);
@@ -2394,7 +2402,7 @@ void Temperature::updateTemperaturesFromRawValues() {
23942402
//*/
23952403

23962404
const bool heater_on = temp_hotend[e].target > 0;
2397-
if (heater_on && !is_preheating(e) && ((neg && r > temp_range[e].raw_min) || (pos && r < temp_range[e].raw_min))) {
2405+
if (heater_on && !is_hotend_preheating(e) && ((neg && r > temp_range[e].raw_min) || (pos && r < temp_range[e].raw_min))) {
23982406
if (TERN1(MULTI_MAX_CONSECUTIVE_LOW_TEMP_ERR, ++consecutive_low_temperature_error[e] >= MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED))
23992407
mintemp_error((heater_id_t)e);
24002408
}
@@ -2408,7 +2416,7 @@ void Temperature::updateTemperaturesFromRawValues() {
24082416
#define TP_CMP(S,A,B) (TEMPDIR(S) < 0 ? ((A)<(B)) : ((A)>(B)))
24092417
#if ENABLED(THERMAL_PROTECTION_BED)
24102418
if (TP_CMP(BED, temp_bed.getraw(), maxtemp_raw_BED)) maxtemp_error(H_BED);
2411-
if (temp_bed.target > 0 && TP_CMP(BED, mintemp_raw_BED, temp_bed.getraw())) mintemp_error(H_BED);
2419+
if (temp_bed.target > 0 && !is_bed_preheating() && TP_CMP(BED, mintemp_raw_BED, temp_bed.getraw())) mintemp_error(H_BED);
24122420
#endif
24132421

24142422
#if BOTH(HAS_HEATED_CHAMBER, THERMAL_PROTECTION_CHAMBER)

Marlin/src/module/temperature.h

+36-16
Original file line numberDiff line numberDiff line change
@@ -748,10 +748,6 @@ class Temperature {
748748
static uint8_t consecutive_low_temperature_error[HOTENDS];
749749
#endif
750750

751-
#if MILLISECONDS_PREHEAT_TIME > 0
752-
static millis_t preheat_end_time[HOTENDS];
753-
#endif
754-
755751
#if HAS_FAN_LOGIC
756752
static millis_t fan_update_ms;
757753

@@ -907,20 +903,38 @@ class Temperature {
907903
static void task();
908904

909905
/**
910-
* Preheating hotends
906+
* Preheating hotends & bed
911907
*/
912-
#if MILLISECONDS_PREHEAT_TIME > 0
913-
static bool is_preheating(const uint8_t E_NAME) {
914-
return preheat_end_time[HOTEND_INDEX] && PENDING(millis(), preheat_end_time[HOTEND_INDEX]);
908+
#if PREHEAT_TIME_HOTEND_MS > 0
909+
static millis_t preheat_end_ms_hotend[HOTENDS];
910+
static bool is_hotend_preheating(const uint8_t E_NAME) {
911+
return preheat_end_ms_hotend[HOTEND_INDEX] && PENDING(millis(), preheat_end_ms_hotend[HOTEND_INDEX]);
915912
}
916-
static void start_preheat_time(const uint8_t E_NAME) {
917-
preheat_end_time[HOTEND_INDEX] = millis() + MILLISECONDS_PREHEAT_TIME;
913+
static void start_hotend_preheat_time(const uint8_t E_NAME) {
914+
preheat_end_ms_hotend[HOTEND_INDEX] = millis() + PREHEAT_TIME_HOTEND_MS;
918915
}
919-
static void reset_preheat_time(const uint8_t E_NAME) {
920-
preheat_end_time[HOTEND_INDEX] = 0;
916+
static void reset_hotend_preheat_time(const uint8_t E_NAME) {
917+
preheat_end_ms_hotend[HOTEND_INDEX] = 0;
921918
}
922919
#else
923-
#define is_preheating(n) (false)
920+
static bool is_hotend_preheating(const uint8_t) { return false; }
921+
#endif
922+
923+
#if HAS_HEATED_BED
924+
#if PREHEAT_TIME_BED_MS > 0
925+
static millis_t preheat_end_ms_bed;
926+
static bool is_bed_preheating() {
927+
return preheat_end_ms_bed && PENDING(millis(), preheat_end_ms_bed);
928+
}
929+
static void start_bed_preheat_time() {
930+
preheat_end_ms_bed = millis() + PREHEAT_TIME_BED_MS;
931+
}
932+
static void reset_bed_preheat_time() {
933+
preheat_end_ms_bed = 0;
934+
}
935+
#else
936+
static bool is_bed_preheating() { return false; }
937+
#endif
924938
#endif
925939

926940
//high level conversion routines, for use outside of temperature.cpp
@@ -949,11 +963,11 @@ class Temperature {
949963

950964
static void setTargetHotend(const celsius_t celsius, const uint8_t E_NAME) {
951965
const uint8_t ee = HOTEND_INDEX;
952-
#if MILLISECONDS_PREHEAT_TIME > 0
966+
#if PREHEAT_TIME_HOTEND_MS > 0
953967
if (celsius == 0)
954-
reset_preheat_time(ee);
968+
reset_hotend_preheat_time(ee);
955969
else if (temp_hotend[ee].target == 0)
956-
start_preheat_time(ee);
970+
start_hotend_preheat_time(ee);
957971
#endif
958972
TERN_(AUTO_POWER_CONTROL, if (celsius) powerManager.power_on());
959973
temp_hotend[ee].target = _MIN(celsius, hotend_max_target(ee));
@@ -1016,6 +1030,12 @@ class Temperature {
10161030
static void start_watching_bed() { TERN_(WATCH_BED, watch_bed.restart(degBed(), degTargetBed())); }
10171031

10181032
static void setTargetBed(const celsius_t celsius) {
1033+
#if PREHEAT_TIME_BED_MS > 0
1034+
if (celsius == 0)
1035+
reset_bed_preheat_time();
1036+
else if (temp_bed.target == 0)
1037+
start_bed_preheat_time();
1038+
#endif
10191039
TERN_(AUTO_POWER_CONTROL, if (celsius) powerManager.power_on());
10201040
temp_bed.target = _MIN(celsius, BED_MAX_TARGET);
10211041
start_watching_bed();

0 commit comments

Comments
 (0)