Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions Marlin/src/core/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,6 @@ void safe_delay(millis_t ms) {
thermalManager.manage_heater(); // This keeps us safe if too many small safe_delay() calls are made
}

#if ENABLED(MARLIN_DEV_MODE)
void early_safe_delay(millis_t ms) {
while (ms > 50) {
ms -= 50;
delay(50);
watchdog_refresh();
}
delay(ms);
watchdog_refresh();
}
#endif

// A delay to provide brittle hosts time to receive bytes
#if ENABLED(SERIAL_OVERRUN_PROTECTION)

Expand Down
5 changes: 0 additions & 5 deletions Marlin/src/core/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@
#include "../core/millis_t.h"

void safe_delay(millis_t ms); // Delay ensuring that temperatures are updated and the watchdog is kept alive.
#if ENABLED(MARLIN_DEV_MODE)
void early_safe_delay(millis_t ms); // Delay ensuring that the watchdog is kept alive. Can be used before the Temperature ISR starts.
#else
inline void early_safe_delay(millis_t ms) { safe_delay(ms); }
#endif

#if ENABLED(SERIAL_OVERRUN_PROTECTION)
void serial_delay(const millis_t ms);
Expand Down
5 changes: 0 additions & 5 deletions Marlin/src/inc/Conditionals_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -370,11 +370,6 @@
#endif
#endif

// If platform requires early initialization of watchdog to properly boot
#if ENABLED(USE_WATCHDOG) && defined(ARDUINO_ARCH_SAM)
#define EARLY_WATCHDOG 1
#endif

// Full Touch Screen needs 'tft/xpt2046'
#if EITHER(TOUCH_SCREEN, HAS_TFT_LVGL_UI)
#define HAS_TFT_XPT2046 1
Expand Down
8 changes: 4 additions & 4 deletions Marlin/src/lcd/dogm/marlinui_DOGM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,14 @@ bool MarlinUI::detected() { return true; }
#endif
u8g.firstPage();
do { draw_custom_bootscreen(f); } while (u8g.nextPage());
if (frame_time) early_safe_delay(frame_time);
if (frame_time) safe_delay(frame_time);
}

#ifndef CUSTOM_BOOTSCREEN_TIMEOUT
#define CUSTOM_BOOTSCREEN_TIMEOUT 2500
#endif
#if CUSTOM_BOOTSCREEN_TIMEOUT
early_safe_delay(CUSTOM_BOOTSCREEN_TIMEOUT);
safe_delay(CUSTOM_BOOTSCREEN_TIMEOUT);
#endif
}
#endif // SHOW_CUSTOM_BOOTSCREEN
Expand Down Expand Up @@ -226,7 +226,7 @@ bool MarlinUI::detected() { return true; }
constexpr millis_t frame_time = MARLIN_BOOTSCREEN_FRAME_TIME;
LOOP_L_N(f, COUNT(marlin_bootscreen_animation)) {
draw_bootscreen_bmp((uint8_t*)pgm_read_ptr(&marlin_bootscreen_animation[f]));
if (frame_time) early_safe_delay(frame_time);
if (frame_time) safe_delay(frame_time);
}
#endif
}
Expand All @@ -235,7 +235,7 @@ bool MarlinUI::detected() { return true; }
void MarlinUI::show_marlin_bootscreen() {
for (uint8_t q = bootscreen_pages; q--;) {
draw_marlin_bootscreen(q == 0);
if (q) early_safe_delay((BOOTSCREEN_TIMEOUT) / bootscreen_pages);
if (q) safe_delay((BOOTSCREEN_TIMEOUT) / bootscreen_pages);
}
}

Expand Down
18 changes: 10 additions & 8 deletions Marlin/src/lcd/tft/touch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,16 @@ void Touch::touch(touch_control_t *control) {
int8_t heater;
heater = control->data;
ui.clear_lcd();
if (heater >= 0) { // HotEnd
#if HOTENDS == 1
MenuItem_int3::action((const char *)GET_TEXT_F(MSG_NOZZLE), &thermalManager.temp_hotend[0].target, 0, thermalManager.hotend_max_target(0), []{ thermalManager.start_watching_hotend(0); });
#else
MenuItemBase::itemIndex = heater;
MenuItem_int3::action((const char *)GET_TEXT_F(MSG_NOZZLE_N), &thermalManager.temp_hotend[heater].target, 0, thermalManager.hotend_max_target(heater), []{ thermalManager.start_watching_hotend(MenuItemBase::itemIndex); });
#endif
}
#if HAS_HOTEND
if (heater >= 0) { // HotEnd
#if HOTENDS == 1
MenuItem_int3::action((const char *)GET_TEXT_F(MSG_NOZZLE), &thermalManager.temp_hotend[0].target, 0, thermalManager.hotend_max_target(0), []{ thermalManager.start_watching_hotend(0); });
#else
MenuItemBase::itemIndex = heater;
MenuItem_int3::action((const char *)GET_TEXT_F(MSG_NOZZLE_N), &thermalManager.temp_hotend[heater].target, 0, thermalManager.hotend_max_target(heater), []{ thermalManager.start_watching_hotend(MenuItemBase::itemIndex); });
#endif
}
#endif
#if HAS_HEATED_BED
else if (heater == H_BED) {
MenuItem_int3::action((const char *)GET_TEXT_F(MSG_BED), &thermalManager.temp_bed.target, 0, BED_MAX_TARGET, thermalManager.start_watching_bed);
Expand Down
113 changes: 34 additions & 79 deletions Marlin/src/module/temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,10 +420,6 @@ const char str_t_thermal_runaway[] PROGMEM = STR_T_THERMAL_RUNAWAY,

// private:

#if EARLY_WATCHDOG
bool Temperature::inited = false;
#endif

volatile bool Temperature::raw_temps_ready = false;

#if ENABLED(PID_EXTRUSION_SCALING)
Expand All @@ -447,11 +443,11 @@ volatile bool Temperature::raw_temps_ready = false;
temp_range_t Temperature::temp_range[HOTENDS] = ARRAY_BY_HOTENDS(sensor_heater_0, sensor_heater_1, sensor_heater_2, sensor_heater_3, sensor_heater_4, sensor_heater_5, sensor_heater_6, sensor_heater_7);
#endif

#ifdef MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED
#if MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED > 1
uint8_t Temperature::consecutive_low_temperature_error[HOTENDS] = { 0 };
#endif

#ifdef MILLISECONDS_PREHEAT_TIME
#if MILLISECONDS_PREHEAT_TIME > 0
millis_t Temperature::preheat_end_time[HOTENDS] = { 0 };
#endif

Expand All @@ -472,7 +468,7 @@ volatile bool Temperature::raw_temps_ready = false;
#endif

#if ENABLED(PROBING_HEATERS_OFF)
bool Temperature::paused;
bool Temperature::paused_for_probing;
#endif

// public:
Expand Down Expand Up @@ -1203,11 +1199,7 @@ void Temperature::min_temp_error(const heater_id_t heater_id) {
* - Update the heated bed PID output value
*/
void Temperature::manage_heater() {

#if EARLY_WATCHDOG
// If thermal manager is still not running, make sure to at least reset the watchdog!
if (!inited) return watchdog_refresh();
#endif
if (marlin_state == MF_INITIALIZING) return watchdog_refresh(); // If Marlin isn't started, at least reset the watchdog!

#if ENABLED(EMERGENCY_PARSER)
if (emergency_parser.killed_by_M112) kill(M112_KILL_STR, nullptr, true);
Expand Down Expand Up @@ -1318,10 +1310,10 @@ void Temperature::manage_heater() {

#if DISABLED(PIDTEMPBED)
if (PENDING(ms, next_bed_check_ms)
&& TERN1(PAUSE_CHANGE_REQD, paused == last_pause_state)
&& TERN1(PAUSE_CHANGE_REQD, paused_for_probing == last_pause_state)
) break;
next_bed_check_ms = ms + BED_CHECK_INTERVAL;
TERN_(PAUSE_CHANGE_REQD, last_pause_state = paused);
TERN_(PAUSE_CHANGE_REQD, last_pause_state = paused_for_probing);
#endif

TERN_(HEATER_IDLE_HANDLER, heater_idle[IDLE_INDEX_BED].update(ms));
Expand Down Expand Up @@ -1956,9 +1948,30 @@ void Temperature::updateTemperaturesFromRawValues() {

/**
* Initialize the temperature manager
*
* The manager is implemented by periodic calls to manage_heater()
*
* - Init (and disable) SPI thermocouples like MAX6675 and MAX31865
* - Disable RUMBA JTAG to accommodate a thermocouple extension
* - Read-enable thermistors with a read-enable pin
* - Init HEATER and COOLER pins for OUTPUT in OFF state
* - Init the FAN pins as PWM or OUTPUT
* - Init the SPI interface for SPI thermocouples
* - Init ADC according to the HAL
* - Set thermistor pins to analog inputs according to the HAL
* - Start the Temperature ISR timer
* - Init the AUTO FAN pins as PWM or OUTPUT
* - Wait 250ms for temperatures to settle
* - Init temp_range[], used for catching min/maxtemp
*/
void Temperature::init() {

TERN_(PROBING_HEATERS_OFF, paused_for_probing = false);

#if BOTH(PIDTEMP, PID_EXTRUSION_SCALING)
last_e_position = 0;
#endif

// Init (and disable) SPI thermocouples
#if TEMP_SENSOR_0_IS_MAX6675 && PIN_EXISTS(MAX6675_CS)
OUT_WRITE(MAX6675_CS_PIN, HIGH);
Expand Down Expand Up @@ -1992,12 +2005,6 @@ void Temperature::init() {
TERN_(TEMP_SENSOR_1_IS_MAX6675, max6675_1.begin());
#endif

#if EARLY_WATCHDOG
// Flag that the thermalManager should be running
if (inited) return;
inited = true;
#endif

#if MB(RUMBA)
// Disable RUMBA JTAG in case the thermocouple extension is plugged on top of JTAG connector
#define _AD(N) (TEMP_SENSOR_##N##_IS_AD595 || TEMP_SENSOR_##N##_IS_AD8495)
Expand All @@ -2015,10 +2022,6 @@ void Temperature::init() {
OUT_WRITE(TEMP_1_TR_ENABLE_PIN, ENABLED(TEMP_SENSOR_1_IS_MAX_TC));
#endif

#if BOTH(PIDTEMP, PID_EXTRUSION_SCALING)
last_e_position = 0;
#endif

#if HAS_HEATER_0
#ifdef BOARD_OPENDRAIN_MOSFETS
OUT_WRITE_OD(HEATER_0_PIN, HEATER_0_INVERTING);
Expand Down Expand Up @@ -2190,7 +2193,7 @@ void Temperature::init() {
#endif

// Wait for temperature measurement to settle
delay(250);
//delay(250);

#if HAS_HOTEND

Expand Down Expand Up @@ -2274,55 +2277,8 @@ void Temperature::init() {
while (analog_to_celsius_cooler(mintemp_raw_COOLER) > COOLER_MINTEMP) mintemp_raw_COOLER += TEMPDIR(COOLER) * (OVERSAMPLENR);
while (analog_to_celsius_cooler(maxtemp_raw_COOLER) < COOLER_MAXTEMP) maxtemp_raw_COOLER -= TEMPDIR(COOLER) * (OVERSAMPLENR);
#endif

TERN_(PROBING_HEATERS_OFF, paused = false);
}

#if WATCH_HOTENDS
/**
* Start Heating Sanity Check for hotends that are below
* their target temperature by a configurable margin.
* This is called when the temperature is set. (M104, M109)
*/
void Temperature::start_watching_hotend(const uint8_t E_NAME) {
const uint8_t ee = HOTEND_INDEX;
watch_hotend[ee].restart(degHotend(ee), degTargetHotend(ee));
}
#endif

#if WATCH_BED
/**
* Start Heating Sanity Check for hotends that are below
* their target temperature by a configurable margin.
* This is called when the temperature is set. (M140, M190)
*/
void Temperature::start_watching_bed() {
watch_bed.restart(degBed(), degTargetBed());
}
#endif

#if WATCH_CHAMBER
/**
* Start Heating Sanity Check for chamber that is below
* its target temperature by a configurable margin.
* This is called when the temperature is set. (M141, M191)
*/
void Temperature::start_watching_chamber() {
watch_chamber.restart(degChamber(), degTargetChamber());
}
#endif

#if WATCH_COOLER
/**
* Start Cooling Sanity Check for cooler that is above
* its target temperature by a configurable margin.
* This is called when the temperature is set. (M143, M193)
*/
void Temperature::start_watching_cooler() {
watch_cooler.restart(degCooler(), degTargetCooler());
}
#endif

#if HAS_THERMAL_PROTECTION

Temperature::tr_state_machine_t Temperature::tr_state_machine[NR_HEATER_RUNAWAY]; // = { { TRInactive, 0 } };
Expand Down Expand Up @@ -2485,8 +2441,8 @@ void Temperature::disable_all_heaters() {
#if ENABLED(PROBING_HEATERS_OFF)

void Temperature::pause(const bool p) {
if (p != paused) {
paused = p;
if (p != paused_for_probing) {
paused_for_probing = p;
if (p) {
HOTEND_LOOP() heater_idle[e].expire(); // Timeout immediately
TERN_(HAS_HEATED_BED, heater_idle[IDLE_INDEX_BED].expire()); // Timeout immediately
Expand Down Expand Up @@ -2771,17 +2727,16 @@ void Temperature::readings_ready() {
const int8_t tdir = temp_dir[e];
if (tdir) {
const int16_t rawtemp = temp_hotend[e].raw * tdir; // normal direction, +rawtemp, else -rawtemp
const bool heater_on = (temp_hotend[e].target > 0
|| TERN0(PIDTEMP, temp_hotend[e].soft_pwm_amount) > 0
);
if (rawtemp > temp_range[e].raw_max * tdir) max_temp_error((heater_id_t)e);

const bool heater_on = (temp_hotend[e].target > 0 || TERN0(PIDTEMP, temp_hotend[e].soft_pwm_amount > 0));
if (heater_on && rawtemp < temp_range[e].raw_min * tdir && !is_preheating(e)) {
#ifdef MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED
#if MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED > 1
if (++consecutive_low_temperature_error[e] >= MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED)
#endif
min_temp_error((heater_id_t)e);
}
#ifdef MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED
#if MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED > 1
else
consecutive_low_temperature_error[e] = 0;
#endif
Expand Down
Loading