Skip to content

Commit

Permalink
Added erporting (via serial echo) of adaptive fan slowing
Browse files Browse the repository at this point in the history
  • Loading branch information
StevilKnevil committed Mar 17, 2023
1 parent 89e8257 commit cde941b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,9 @@
#define THERMAL_PROTECTION_HYSTERESIS 4 // Degrees Celsius

//#define ADAPTIVE_FAN_SLOWING // Slow part cooling fan if temperature drops
#if ENABLED(ADAPTIVE_FAN_SLOWING)
#define REPORT_ADAPTIVE_FAN_SLOWING // Report changes to fan slowing to the console
#endif
#if ENABLED(ADAPTIVE_FAN_SLOWING) && EITHER(MPCTEMP, PIDTEMP)
//#define TEMP_TUNING_MAINTAIN_FAN // Don't slow fan speed during M303 or M306 T
#endif
Expand Down
21 changes: 16 additions & 5 deletions Marlin/src/module/temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2875,6 +2875,17 @@ void Temperature::init() {

Temperature::tr_state_machine_t Temperature::tr_state_machine[NR_HEATER_RUNAWAY]; // = { { TRInactive, 0 } };

void set_fan_scale(uint8_t &speed_scaler, uint8_t scale) {
#if ENABLED(REPORT_ADAPTIVE_FAN_SLOWING)
const float scale_as_percentage = 100.0f * (float(scale)/128);
if (speed_scaler >= scale)
SERIAL_ECHOLNPGM("Thermal divergence. Fan speed scale: ", scale_as_percentage, "%");
else
SERIAL_ECHOLNPGM("Thermal convergence. Fan speed scale: ", scale_as_percentage, "%");
#endif
speed_scaler = scale;
}

/**
* @brief Thermal Runaway state machine for a single heater
* @param current current measured temperature
Expand Down Expand Up @@ -2951,15 +2962,15 @@ void Temperature::init() {
if (adaptive_fan_slowing && heater_id >= 0) {
const int fan_index = _MIN(heater_id, FAN_COUNT - 1);
if (fan_speed[fan_index] == 0 || current >= running_temp - (hysteresis_degc * 0.25f))
fan_speed_scaler[fan_index] = 128;
set_fan_scale(fan_speed_scaler[fan_index], 128);
else if (current >= running_temp - (hysteresis_degc * 0.3335f))
fan_speed_scaler[fan_index] = 96;
set_fan_scale(fan_speed_scaler[fan_index], 96);
else if (current >= running_temp - (hysteresis_degc * 0.5f))
fan_speed_scaler[fan_index] = 64;
set_fan_scale(fan_speed_scaler[fan_index], 64);
else if (current >= running_temp - (hysteresis_degc * 0.8f))
fan_speed_scaler[fan_index] = 32;
set_fan_scale(fan_speed_scaler[fan_index], 32);
else
fan_speed_scaler[fan_index] = 0;
set_fan_scale(fan_speed_scaler[fan_index], 0);
}
#endif

Expand Down

0 comments on commit cde941b

Please sign in to comment.