Skip to content

Commit

Permalink
compare (running_temp - current)
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Mar 18, 2023
1 parent c948d9e commit 8de80d7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
16 changes: 9 additions & 7 deletions Marlin/src/module/temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2885,7 +2885,7 @@ void Temperature::init() {
*
* TODO: Embed the last 3 parameters during init, if not less optimal
*/
void Temperature::tr_state_machine_t::run(const_celsius_float_t current, const_celsius_float_t target, const heater_id_t heater_id, const uint16_t period_seconds, const celsius_t hysteresis_degc) {
void Temperature::tr_state_machine_t::run(const_celsius_float_t current, const_celsius_float_t target, const heater_id_t heater_id, const uint16_t period_seconds, const celsius_float_t hysteresis_degc) {

#if HEATER_IDLE_HANDLER
// Convert the given heater_id_t to an idle array index
Expand Down Expand Up @@ -2947,17 +2947,19 @@ void Temperature::init() {
// While the temperature is stable watch for a bad temperature
case TRStable: {

const celsius_float_t rdiff = running_temp - current;

#if ENABLED(ADAPTIVE_FAN_SLOWING)
if (adaptive_fan_slowing && heater_id >= 0) {
const int fan_index = _MIN(heater_id, FAN_COUNT - 1);
const int_fast8_t fan_index = _MIN(heater_id, FAN_COUNT - 1);
uint8_t scale;
if (fan_speed[fan_index] == 0 || current >= running_temp - (hysteresis_degc * 0.25f))
if (fan_speed[fan_index] == 0 || rdiff <= hysteresis_degc * 0.25f)
scale = 128;
else if (current >= running_temp - (hysteresis_degc * 0.3335f))
else if (rdiff <= hysteresis_degc * 0.3335f)
scale = 96;
else if (current >= running_temp - (hysteresis_degc * 0.5f))
else if (rdiff <= hysteresis_degc * 0.5f)
scale = 64;
else if (current >= running_temp - (hysteresis_degc * 0.8f))
else if (rdiff <= hysteresis_degc * 0.8f)
scale = 32;
else
scale = 0;
Expand Down Expand Up @@ -2994,7 +2996,7 @@ void Temperature::init() {
}
#endif

if (current >= running_temp - hysteresis_degc) {
if (rdiff <= hysteresis_degc) {
timer = now + SEC_TO_MS(period_seconds);
break;
}
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/module/temperature.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
#define E_NAME TERN_(HAS_MULTI_HOTEND, e)

// Element identifiers. Positive values are hotends. Negative values are other heaters or coolers.
typedef enum : int8_t {
typedef enum : int_fast8_t {
H_REDUNDANT = HID_REDUNDANT,
H_COOLER = HID_COOLER,
H_PROBE = HID_PROBE,
Expand Down Expand Up @@ -1317,12 +1317,12 @@ class Temperature {
typedef struct {
millis_t timer = 0;
TRState state = TRInactive;
float running_temp;
celsius_float_t running_temp;
#if ENABLED(THERMAL_PROTECTION_VARIANCE_MONITOR)
millis_t variance_timer = 0;
celsius_float_t last_temp = 0.0, variance = 0.0;
#endif
void run(const_celsius_float_t current, const_celsius_float_t target, const heater_id_t heater_id, const uint16_t period_seconds, const celsius_t hysteresis_degc);
void run(const_celsius_float_t current, const_celsius_float_t target, const heater_id_t heater_id, const uint16_t period_seconds, const celsius_float_t hysteresis_degc);
} tr_state_machine_t;

static tr_state_machine_t tr_state_machine[NR_HEATER_RUNAWAY];
Expand Down

0 comments on commit 8de80d7

Please sign in to comment.