Skip to content

Commit

Permalink
✨ PREHEAT_TIME_BED_MS (MarlinFirmware#25146)
Browse files Browse the repository at this point in the history
  • Loading branch information
Powerlated authored Jan 11, 2023
1 parent 250fd60 commit 64167df
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 43 deletions.
3 changes: 2 additions & 1 deletion Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 8 additions & 2 deletions Marlin/src/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
*/
Expand Down
56 changes: 32 additions & 24 deletions Marlin/src/module/temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand All @@ -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)
Expand Down
52 changes: 36 additions & 16 deletions Marlin/src/module/temperature.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 64167df

Please sign in to comment.