ADAPTIVE_FAN_SLOWING extension to hotend thermal protection (#12853)

This commit is contained in:
InsanityAutomation
2019-01-12 01:41:48 -05:00
committed by Scott Lahteine
parent 459f4fef60
commit 082f6a27de
88 changed files with 405 additions and 161 deletions

View File

@ -1178,10 +1178,9 @@ void Planner::check_axes_activity() {
#endif
if (has_blocks_queued()) {
#if FAN_COUNT > 0
FANS_LOOP(i)
tail_fan_speed[i] = block_buffer[block_buffer_tail].fan_speed[i];
tail_fan_speed[i] = (block_buffer[block_buffer_tail].fan_speed[i] * uint16_t(thermalManager.fan_speed_scaler[i])) >> 7;
#endif
block_t* block;
@ -1203,7 +1202,8 @@ void Planner::check_axes_activity() {
}
else {
#if FAN_COUNT > 0
FANS_LOOP(i) tail_fan_speed[i] = fan_speed[i];
FANS_LOOP(i)
tail_fan_speed[i] = (thermalManager.fan_speed[i] * uint16_t(thermalManager.fan_speed_scaler[i])) >> 7;
#endif
#if ENABLED(BARICUDA)
@ -1903,7 +1903,7 @@ bool Planner::_populate_block(block_t * const block, bool split_move,
#endif
#if FAN_COUNT > 0
FANS_LOOP(i) block->fan_speed[i] = fan_speed[i];
FANS_LOOP(i) block->fan_speed[i] = thermalManager.fan_speed[i];
#endif
#if ENABLED(BARICUDA)

View File

@ -268,31 +268,13 @@ float zprobe_zoffset; // Initialized by settings.load()
#endif // Z_PROBE_ALLEN_KEY
#if ENABLED(PROBING_FANS_OFF)
void fans_pause(const bool p) {
if (p != fans_paused) {
fans_paused = p;
if (p)
for (uint8_t x = 0; x < FAN_COUNT; x++) {
paused_fan_speed[x] = fan_speed[x];
fan_speed[x] = 0;
}
else
for (uint8_t x = 0; x < FAN_COUNT; x++)
fan_speed[x] = paused_fan_speed[x];
}
}
#endif // PROBING_FANS_OFF
#if QUIET_PROBING
void probing_pause(const bool p) {
#if ENABLED(PROBING_HEATERS_OFF)
thermalManager.pause(p);
#endif
#if ENABLED(PROBING_FANS_OFF)
fans_pause(p);
thermalManager.set_fans_paused(p);
#endif
#if ENABLED(PROBING_STEPPERS_OFF)
disable_e_steppers();

View File

@ -58,10 +58,6 @@
void probing_pause(const bool p);
#endif
#if ENABLED(PROBING_FANS_OFF)
void fans_pause(const bool p);
#endif
#if ENABLED(BLTOUCH)
void bltouch_command(int angle);
bool set_bltouch_deployed(const bool deploy);

View File

@ -55,6 +55,10 @@
#include "../feature/leds/printer_event_leds.h"
#endif
#if ENABLED(SINGLENOZZLE)
#include "tool_change.h"
#endif
#if HOTEND_USES_THERMISTOR
#if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
static void* heater_ttbl_map[2] = { (void*)HEATER_0_TEMPTABLE, (void*)HEATER_1_TEMPTABLE };
@ -92,14 +96,99 @@ Temperature thermalManager;
// public:
float Temperature::current_temperature[HOTENDS] = { 0.0 };
int16_t Temperature::current_temperature_raw[HOTENDS] = { 0 },
Temperature::target_temperature[HOTENDS] = { 0 };
float Temperature::current_temperature[HOTENDS]; // = { 0.0 };
int16_t Temperature::current_temperature_raw[HOTENDS], // = { 0 }
Temperature::target_temperature[HOTENDS]; // = { 0 }
#if ENABLED(AUTO_POWER_E_FANS)
uint8_t Temperature::autofan_speed[HOTENDS] = { 0 };
uint8_t Temperature::autofan_speed[HOTENDS]; // = { 0 }
#endif
#if FAN_COUNT > 0
uint8_t Temperature::fan_speed[FAN_COUNT]; // = { 0 }
#if ENABLED(EXTRA_FAN_SPEED)
uint8_t Temperature::old_fan_speed[FAN_COUNT], Temperature::new_fan_speed[FAN_COUNT];
void Temperature::set_temp_fan_speed(const uint8_t fan, const int16_t tmp_temp) {
switch (tmp_temp) {
case 1:
set_fan_speed(fan, old_fan_speed[fan]);
break;
case 2:
old_fan_speed[fan] = fan_speed[fan];
set_fan_speed(fan, new_fan_speed[fan]);
break;
default:
new_fan_speed[fan] = MIN(tmp_temp, 255U);
break;
}
}
#endif
#if ENABLED(PROBING_FANS_OFF)
bool Temperature::fans_paused; // = false;
uint8_t Temperature::paused_fan_speed[FAN_COUNT]; // = { 0 }
#endif
#if ENABLED(ADAPTIVE_FAN_SLOWING)
uint8_t Temperature::fan_speed_scaler[FAN_COUNT] = ARRAY_N(FAN_COUNT, 128, 128, 128, 128, 128, 128);
#endif
#if HAS_LCD_MENU
uint8_t Temperature::lcd_tmpfan_speed[
#if ENABLED(SINGLENOZZLE)
MAX(EXTRUDERS, FAN_COUNT)
#else
FAN_COUNT
#endif
]; // = { 0 }
#endif
void Temperature::set_fan_speed(uint8_t target, uint16_t speed) {
NOMORE(speed, 255U);
#if ENABLED(SINGLENOZZLE)
if (target != active_extruder) {
if (target < EXTRUDERS) singlenozzle_fan_speed[target] = speed;
return;
}
target = 0; // Always use fan index 0 with SINGLENOZZLE
#endif
if (target >= FAN_COUNT) return;
fan_speed[target] = speed;
#if ENABLED(ULTRA_LCD)
lcd_tmpfan_speed[target] = speed;
#endif
}
#if ENABLED(PROBING_FANS_OFF)
void Temperature::set_fans_paused(const bool p) {
if (p != fans_paused) {
fans_paused = p;
if (p)
for (uint8_t x = 0; x < FAN_COUNT; x++) {
paused_fan_speed[x] = fan_speed[x];
fan_speed[x] = 0;
}
else
for (uint8_t x = 0; x < FAN_COUNT; x++)
fan_speed[x] = paused_fan_speed[x];
}
}
#endif // PROBING_FANS_OFF
#endif // FAN_COUNT > 0
#if HAS_HEATED_BED
float Temperature::current_temperature_bed = 0.0;
int16_t Temperature::current_temperature_bed_raw = 0,
@ -1529,18 +1618,38 @@ void Temperature::init() {
switch (*state) {
// Inactive state waits for a target temperature to be set
case TRInactive: break;
// When first heating, wait for the temperature to be reached then go to Stable state
case TRFirstHeating:
if (current < tr_target_temperature[heater_index]) break;
*state = TRStable;
// While the temperature is stable watch for a bad temperature
case TRStable:
#if ENABLED(ADAPTIVE_FAN_SLOWING) && FAN_COUNT > 0
if (heater_id >= 0) {
const int fan_index = MIN(heater_id, FAN_COUNT - 1);
if (fan_speed[fan_index] == 0 || current >= tr_target_temperature[heater_id] - (hysteresis_degc * 0.25f))
fan_speed_scaler[fan_index] = 128;
else if (current >= tr_target_temperature[heater_id] - (hysteresis_degc * 0.3335f))
fan_speed_scaler[fan_index] = 96;
else if (current >= tr_target_temperature[heater_id] - (hysteresis_degc * 0.5f))
fan_speed_scaler[fan_index] = 64;
else if (current >= tr_target_temperature[heater_id] - (hysteresis_degc * 0.8f))
fan_speed_scaler[fan_index] = 32;
else
fan_speed_scaler[fan_index] = 0;
}
#endif
if (current >= tr_target_temperature[heater_index] - hysteresis_degc) {
*timer = millis() + period_seconds * 1000UL;
break;
}
else if (PENDING(millis(), *timer)) break;
*state = TRRunaway;
case TRRunaway:
_temp_error(heater_id, PSTR(MSG_T_THERMAL_RUNAWAY), TEMP_ERR_PSTR(MSG_THERMAL_RUNAWAY, heater_id));
}

View File

@ -320,6 +320,71 @@ class Temperature {
static float analog_to_celsiusChamber(const int raw);
#endif
#if FAN_COUNT > 0
static uint8_t fan_speed[FAN_COUNT];
#define FANS_LOOP(I) LOOP_L_N(I, FAN_COUNT)
static void set_fan_speed(const uint8_t target, const uint16_t speed);
#if ENABLED(PROBING_FANS_OFF)
static bool fans_paused;
static uint8_t paused_fan_speed[FAN_COUNT];
#endif
static constexpr inline uint8_t fanPercent(const uint8_t speed) { return (int(speed) * 100 + 127) / 255; }
#if ENABLED(ADAPTIVE_FAN_SLOWING)
static uint8_t fan_speed_scaler[FAN_COUNT];
#else
static constexpr uint8_t fan_speed_scaler[FAN_COUNT] = ARRAY_N(FAN_COUNT, 128, 128, 128, 128, 128, 128);
#endif
static inline uint8_t lcd_fanSpeedActual(const uint8_t target) {
return (fan_speed[target] * uint16_t(fan_speed_scaler[target])) >> 7;
}
#if ENABLED(EXTRA_FAN_SPEED)
static uint8_t old_fan_speed[FAN_COUNT], new_fan_speed[FAN_COUNT];
static void set_temp_fan_speed(const uint8_t fan, const int16_t tmp_temp);
#endif
#if HAS_LCD_MENU
static uint8_t lcd_tmpfan_speed[
#if ENABLED(SINGLENOZZLE)
MAX(EXTRUDERS, FAN_COUNT)
#else
FAN_COUNT
#endif
];
static inline void lcd_setFanSpeed(const uint8_t target) { set_fan_speed(target, lcd_tmpfan_speed[target]); }
#if HAS_FAN0
FORCE_INLINE static void lcd_setFanSpeed0() { lcd_setFanSpeed(0); }
#endif
#if HAS_FAN1 || (ENABLED(SINGLENOZZLE) && EXTRUDERS > 1)
FORCE_INLINE static void lcd_setFanSpeed1() { lcd_setFanSpeed(1); }
#endif
#if HAS_FAN2 || (ENABLED(SINGLENOZZLE) && EXTRUDERS > 2)
FORCE_INLINE static void lcd_setFanSpeed2() { lcd_setFanSpeed(2); }
#endif
#endif // HAS_LCD_MENU
#if ENABLED(PROBING_FANS_OFF)
void set_fans_paused(const bool p);
#endif
#endif // FAN_COUNT > 0
static inline void zero_fan_speeds() {
#if FAN_COUNT > 0
FANS_LOOP(i) fan_speed[i] = 0;
#endif
}
/**
* Called from the Temperature ISR
*/

View File

@ -674,8 +674,8 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
#if ENABLED(SINGLENOZZLE)
#if FAN_COUNT > 0
singlenozzle_fan_speed[active_extruder] = fan_speed[0];
fan_speed[0] = singlenozzle_fan_speed[tmp_extruder];
singlenozzle_fan_speed[active_extruder] = thermalManager.fan_speed[0];
thermalManager.fan_speed[0] = singlenozzle_fan_speed[tmp_extruder];
#endif
singlenozzle_temp[active_extruder] = thermalManager.target_temperature[0];