2016-03-25 07:19:46 +01:00
|
|
|
/**
|
2016-03-24 19:01:20 +01:00
|
|
|
* Marlin 3D Printer Firmware
|
2020-02-03 15:00:57 +01:00
|
|
|
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2016-03-24 19:01:20 +01:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
2019-06-28 06:57:50 +02:00
|
|
|
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
2016-03-24 19:01:20 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
2018-11-04 09:25:55 +01:00
|
|
|
#pragma once
|
2016-03-24 19:01:20 +01:00
|
|
|
|
2016-03-25 07:19:46 +01:00
|
|
|
/**
|
2016-04-29 03:18:13 +02:00
|
|
|
* temperature.h - temperature controller
|
|
|
|
*/
|
2012-03-08 21:43:21 +01:00
|
|
|
|
2017-09-06 13:28:32 +02:00
|
|
|
#include "thermistor/thermistors.h"
|
2019-05-07 01:51:06 +02:00
|
|
|
|
2018-02-06 07:22:30 +01:00
|
|
|
#include "../inc/MarlinConfig.h"
|
2016-04-29 03:18:13 +02:00
|
|
|
|
2018-02-06 07:22:30 +01:00
|
|
|
#if ENABLED(AUTO_POWER_CONTROL)
|
2018-02-10 22:41:18 +01:00
|
|
|
#include "../feature/power.h"
|
2018-02-06 07:22:30 +01:00
|
|
|
#endif
|
|
|
|
|
2016-04-29 03:18:13 +02:00
|
|
|
#ifndef SOFT_PWM_SCALE
|
|
|
|
#define SOFT_PWM_SCALE 0
|
|
|
|
#endif
|
2012-03-08 21:43:21 +01:00
|
|
|
|
2019-03-07 09:09:39 +01:00
|
|
|
#if HOTENDS <= 1
|
2018-05-28 00:56:21 +02:00
|
|
|
#define HOTEND_INDEX 0
|
2019-10-01 04:44:07 +02:00
|
|
|
#define E_NAME
|
2018-05-28 00:56:21 +02:00
|
|
|
#else
|
|
|
|
#define HOTEND_INDEX e
|
2019-10-01 04:44:07 +02:00
|
|
|
#define E_NAME e
|
2018-05-28 00:56:21 +02:00
|
|
|
#endif
|
|
|
|
|
2019-07-02 15:39:55 +02:00
|
|
|
// Identifiers for other heaters
|
|
|
|
typedef enum : int8_t {
|
2020-01-18 00:16:45 +01:00
|
|
|
INDEX_NONE = -5,
|
|
|
|
H_PROBE, H_REDUNDANT, H_CHAMBER, H_BED,
|
2020-01-26 10:20:11 +01:00
|
|
|
H_E0, H_E1, H_E2, H_E3, H_E4, H_E5, H_E6, H_E7
|
2019-07-02 15:39:55 +02:00
|
|
|
} heater_ind_t;
|
|
|
|
|
2018-10-10 16:45:20 +02:00
|
|
|
// PID storage
|
|
|
|
typedef struct { float Kp, Ki, Kd; } PID_t;
|
|
|
|
typedef struct { float Kp, Ki, Kd, Kc; } PIDC_t;
|
2019-11-26 10:34:43 +01:00
|
|
|
typedef struct { float Kp, Ki, Kd, Kf; } PIDF_t;
|
|
|
|
typedef struct { float Kp, Ki, Kd, Kc, Kf; } PIDCF_t;
|
|
|
|
|
|
|
|
typedef
|
|
|
|
#if BOTH(PID_EXTRUSION_SCALING, PID_FAN_SCALING)
|
|
|
|
PIDCF_t
|
|
|
|
#elif ENABLED(PID_EXTRUSION_SCALING)
|
|
|
|
PIDC_t
|
|
|
|
#elif ENABLED(PID_FAN_SCALING)
|
|
|
|
PIDF_t
|
2019-03-07 09:09:39 +01:00
|
|
|
#else
|
2019-11-26 10:34:43 +01:00
|
|
|
PID_t
|
2019-03-07 09:09:39 +01:00
|
|
|
#endif
|
2019-11-26 10:34:43 +01:00
|
|
|
hotend_pid_t;
|
|
|
|
|
|
|
|
#if ENABLED(PID_EXTRUSION_SCALING)
|
|
|
|
typedef IF<(LPQ_MAX_LEN > 255), uint16_t, uint8_t>::type lpq_ptr_t;
|
2018-10-10 16:45:20 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define DUMMY_PID_VALUE 3000.0f
|
|
|
|
|
|
|
|
#if ENABLED(PIDTEMP)
|
2019-03-07 09:09:39 +01:00
|
|
|
#define _PID_Kp(H) Temperature::temp_hotend[H].pid.Kp
|
|
|
|
#define _PID_Ki(H) Temperature::temp_hotend[H].pid.Ki
|
|
|
|
#define _PID_Kd(H) Temperature::temp_hotend[H].pid.Kd
|
2018-10-10 16:45:20 +02:00
|
|
|
#if ENABLED(PID_EXTRUSION_SCALING)
|
2019-03-07 09:09:39 +01:00
|
|
|
#define _PID_Kc(H) Temperature::temp_hotend[H].pid.Kc
|
2018-10-10 16:45:20 +02:00
|
|
|
#else
|
|
|
|
#define _PID_Kc(H) 1
|
|
|
|
#endif
|
2019-11-26 10:34:43 +01:00
|
|
|
|
|
|
|
#if ENABLED(PID_FAN_SCALING)
|
|
|
|
#define _PID_Kf(H) Temperature::temp_hotend[H].pid.Kf
|
|
|
|
#else
|
|
|
|
#define _PID_Kf(H) 0
|
|
|
|
#endif
|
2018-10-10 16:45:20 +02:00
|
|
|
#else
|
|
|
|
#define _PID_Kp(H) DUMMY_PID_VALUE
|
|
|
|
#define _PID_Ki(H) DUMMY_PID_VALUE
|
|
|
|
#define _PID_Kd(H) DUMMY_PID_VALUE
|
|
|
|
#define _PID_Kc(H) 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define PID_PARAM(F,H) _PID_##F(H)
|
|
|
|
|
2017-04-07 01:42:57 +02:00
|
|
|
/**
|
|
|
|
* States for ADC reading in the ISR
|
|
|
|
*/
|
2018-03-07 05:35:22 +01:00
|
|
|
enum ADCSensorState : char {
|
2018-07-26 10:59:19 +02:00
|
|
|
StartSampling,
|
2018-05-02 02:33:41 +02:00
|
|
|
#if HAS_TEMP_ADC_0
|
2019-09-08 07:55:34 +02:00
|
|
|
PrepareTemp_0, MeasureTemp_0,
|
2017-04-07 01:42:57 +02:00
|
|
|
#endif
|
2019-03-07 09:09:39 +01:00
|
|
|
#if HAS_HEATED_BED
|
2019-09-08 07:55:34 +02:00
|
|
|
PrepareTemp_BED, MeasureTemp_BED,
|
2019-03-07 09:09:39 +01:00
|
|
|
#endif
|
|
|
|
#if HAS_TEMP_CHAMBER
|
2019-09-08 07:55:34 +02:00
|
|
|
PrepareTemp_CHAMBER, MeasureTemp_CHAMBER,
|
2019-03-07 09:09:39 +01:00
|
|
|
#endif
|
2020-01-18 00:16:45 +01:00
|
|
|
#if HAS_TEMP_PROBE
|
|
|
|
PrepareTemp_PROBE, MeasureTemp_PROBE,
|
|
|
|
#endif
|
2018-05-02 02:33:41 +02:00
|
|
|
#if HAS_TEMP_ADC_1
|
2019-09-08 07:55:34 +02:00
|
|
|
PrepareTemp_1, MeasureTemp_1,
|
2017-04-07 01:42:57 +02:00
|
|
|
#endif
|
2018-05-02 02:33:41 +02:00
|
|
|
#if HAS_TEMP_ADC_2
|
2019-09-08 07:55:34 +02:00
|
|
|
PrepareTemp_2, MeasureTemp_2,
|
2017-04-07 01:42:57 +02:00
|
|
|
#endif
|
2018-05-02 02:33:41 +02:00
|
|
|
#if HAS_TEMP_ADC_3
|
2019-09-08 07:55:34 +02:00
|
|
|
PrepareTemp_3, MeasureTemp_3,
|
2017-04-07 01:42:57 +02:00
|
|
|
#endif
|
2018-05-02 02:33:41 +02:00
|
|
|
#if HAS_TEMP_ADC_4
|
2019-09-08 07:55:34 +02:00
|
|
|
PrepareTemp_4, MeasureTemp_4,
|
2017-04-07 01:42:57 +02:00
|
|
|
#endif
|
2019-03-07 09:09:39 +01:00
|
|
|
#if HAS_TEMP_ADC_5
|
2019-09-08 07:55:34 +02:00
|
|
|
PrepareTemp_5, MeasureTemp_5,
|
|
|
|
#endif
|
2020-01-25 09:13:39 +01:00
|
|
|
#if HAS_TEMP_ADC_6
|
|
|
|
PrepareTemp_6, MeasureTemp_6,
|
|
|
|
#endif
|
|
|
|
#if HAS_TEMP_ADC_7
|
|
|
|
PrepareTemp_7, MeasureTemp_7,
|
|
|
|
#endif
|
2019-09-08 07:55:34 +02:00
|
|
|
#if HAS_JOY_ADC_X
|
|
|
|
PrepareJoy_X, MeasureJoy_X,
|
|
|
|
#endif
|
|
|
|
#if HAS_JOY_ADC_Y
|
|
|
|
PrepareJoy_Y, MeasureJoy_Y,
|
|
|
|
#endif
|
|
|
|
#if HAS_JOY_ADC_Z
|
|
|
|
PrepareJoy_Z, MeasureJoy_Z,
|
2018-02-24 07:38:58 +01:00
|
|
|
#endif
|
2017-04-07 01:42:57 +02:00
|
|
|
#if ENABLED(FILAMENT_WIDTH_SENSOR)
|
2019-09-08 07:55:34 +02:00
|
|
|
Prepare_FILWIDTH, Measure_FILWIDTH,
|
2017-04-07 01:42:57 +02:00
|
|
|
#endif
|
2018-11-19 03:39:49 +01:00
|
|
|
#if HAS_ADC_BUTTONS
|
2019-09-08 07:55:34 +02:00
|
|
|
Prepare_ADC_KEY, Measure_ADC_KEY,
|
2017-06-10 07:12:18 +02:00
|
|
|
#endif
|
2017-04-07 01:42:57 +02:00
|
|
|
SensorsReady, // Temperatures ready. Delay the next round of readings to let ADC pins settle.
|
|
|
|
StartupDelay // Startup, delay initial temp reading a tiny bit so the hardware can settle
|
|
|
|
};
|
|
|
|
|
|
|
|
// Minimum number of Temperature::ISR loops between sensor readings.
|
|
|
|
// Multiplied by 16 (OVERSAMPLENR) to obtain the total time to
|
|
|
|
// get all oversampled sensor readings
|
|
|
|
#define MIN_ADC_ISR_LOOPS 10
|
|
|
|
|
2019-07-06 01:01:21 +02:00
|
|
|
#define ACTUAL_ADC_SAMPLES _MAX(int(MIN_ADC_ISR_LOOPS), int(SensorsReady))
|
2017-04-07 01:42:57 +02:00
|
|
|
|
2017-12-01 16:08:30 +01:00
|
|
|
#if HAS_PID_HEATING
|
2018-07-01 22:20:28 +02:00
|
|
|
#define PID_K2 (1-float(PID_K1))
|
2018-01-07 23:15:20 +01:00
|
|
|
#define PID_dT ((OVERSAMPLENR * float(ACTUAL_ADC_SAMPLES)) / TEMP_TIMER_FREQUENCY)
|
2017-12-01 16:08:30 +01:00
|
|
|
|
|
|
|
// Apply the scale factors to the PID values
|
2018-07-01 22:20:28 +02:00
|
|
|
#define scalePID_i(i) ( float(i) * PID_dT )
|
|
|
|
#define unscalePID_i(i) ( float(i) / PID_dT )
|
|
|
|
#define scalePID_d(d) ( float(d) / PID_dT )
|
|
|
|
#define unscalePID_d(d) ( float(d) * PID_dT )
|
2017-12-01 16:08:30 +01:00
|
|
|
#endif
|
|
|
|
|
2018-11-11 01:07:38 +01:00
|
|
|
#define G26_CLICK_CAN_CANCEL (HAS_LCD_MENU && ENABLED(G26_MESH_VALIDATION))
|
|
|
|
|
2019-03-07 09:09:39 +01:00
|
|
|
// A temperature sensor
|
|
|
|
typedef struct TempInfo {
|
|
|
|
uint16_t acc;
|
|
|
|
int16_t raw;
|
2019-09-09 09:56:23 +02:00
|
|
|
float celsius;
|
2019-09-06 02:44:55 +02:00
|
|
|
inline void reset() { acc = 0; }
|
|
|
|
inline void sample(const uint16_t s) { acc += s; }
|
|
|
|
inline void update() { raw = acc; }
|
2019-03-07 09:09:39 +01:00
|
|
|
} temp_info_t;
|
|
|
|
|
|
|
|
// A PWM heater with temperature sensor
|
|
|
|
typedef struct HeaterInfo : public TempInfo {
|
|
|
|
int16_t target;
|
|
|
|
uint8_t soft_pwm_amount;
|
|
|
|
} heater_info_t;
|
|
|
|
|
|
|
|
// A heater with PID stabilization
|
|
|
|
template<typename T>
|
|
|
|
struct PIDHeaterInfo : public HeaterInfo {
|
|
|
|
T pid; // Initialized by settings.load()
|
|
|
|
};
|
|
|
|
|
|
|
|
#if ENABLED(PIDTEMP)
|
|
|
|
typedef struct PIDHeaterInfo<hotend_pid_t> hotend_info_t;
|
|
|
|
#else
|
|
|
|
typedef heater_info_t hotend_info_t;
|
|
|
|
#endif
|
|
|
|
#if HAS_HEATED_BED
|
|
|
|
#if ENABLED(PIDTEMPBED)
|
|
|
|
typedef struct PIDHeaterInfo<PID_t> bed_info_t;
|
|
|
|
#else
|
|
|
|
typedef heater_info_t bed_info_t;
|
|
|
|
#endif
|
|
|
|
#endif
|
2020-01-18 00:16:45 +01:00
|
|
|
#if HAS_TEMP_PROBE
|
|
|
|
typedef temp_info_t probe_info_t;
|
|
|
|
#endif
|
2019-04-12 22:38:10 +02:00
|
|
|
#if HAS_HEATED_CHAMBER
|
|
|
|
typedef heater_info_t chamber_info_t;
|
|
|
|
#elif HAS_TEMP_CHAMBER
|
|
|
|
typedef temp_info_t chamber_info_t;
|
2019-03-07 09:09:39 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Heater idle handling
|
|
|
|
typedef struct {
|
|
|
|
millis_t timeout_ms;
|
|
|
|
bool timed_out;
|
|
|
|
inline void update(const millis_t &ms) { if (!timed_out && timeout_ms && ELAPSED(ms, timeout_ms)) timed_out = true; }
|
|
|
|
inline void start(const millis_t &ms) { timeout_ms = millis() + ms; timed_out = false; }
|
|
|
|
inline void reset() { timeout_ms = 0; timed_out = false; }
|
|
|
|
inline void expire() { start(0); }
|
2020-01-30 10:24:43 +01:00
|
|
|
} hotend_idle_t;
|
2019-03-07 09:09:39 +01:00
|
|
|
|
|
|
|
// Heater watch handling
|
2020-01-30 10:24:43 +01:00
|
|
|
template <int INCREASE, int HYSTERESIS, millis_t PERIOD>
|
|
|
|
struct HeaterWatch {
|
2019-03-07 09:09:39 +01:00
|
|
|
uint16_t target;
|
|
|
|
millis_t next_ms;
|
|
|
|
inline bool elapsed(const millis_t &ms) { return next_ms && ELAPSED(ms, next_ms); }
|
|
|
|
inline bool elapsed() { return elapsed(millis()); }
|
2020-01-30 10:24:43 +01:00
|
|
|
|
|
|
|
inline void restart(const int16_t curr, const int16_t tgt) {
|
|
|
|
if (tgt) {
|
|
|
|
const int16_t newtarget = curr + INCREASE;
|
|
|
|
if (newtarget < tgt - HYSTERESIS - 1) {
|
|
|
|
target = newtarget;
|
|
|
|
next_ms = millis() + PERIOD * 1000UL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
next_ms = 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#if WATCH_HOTENDS
|
|
|
|
typedef struct HeaterWatch<WATCH_TEMP_INCREASE, TEMP_HYSTERESIS, WATCH_TEMP_PERIOD> hotend_watch_t;
|
|
|
|
#endif
|
|
|
|
#if WATCH_BED
|
|
|
|
typedef struct HeaterWatch<WATCH_BED_TEMP_INCREASE, TEMP_BED_HYSTERESIS, WATCH_BED_TEMP_PERIOD> bed_watch_t;
|
|
|
|
#endif
|
|
|
|
#if WATCH_CHAMBER
|
|
|
|
typedef struct HeaterWatch<WATCH_CHAMBER_TEMP_INCREASE, TEMP_CHAMBER_HYSTERESIS, WATCH_CHAMBER_TEMP_PERIOD> chamber_watch_t;
|
|
|
|
#endif
|
2019-03-07 09:09:39 +01:00
|
|
|
|
|
|
|
// Temperature sensor read value ranges
|
|
|
|
typedef struct { int16_t raw_min, raw_max; } raw_range_t;
|
|
|
|
typedef struct { int16_t mintemp, maxtemp; } celsius_range_t;
|
|
|
|
typedef struct { int16_t raw_min, raw_max, mintemp, maxtemp; } temp_range_t;
|
|
|
|
|
2019-11-13 02:23:02 +01:00
|
|
|
#define THERMISTOR_ABS_ZERO_C -273.15f // bbbbrrrrr cold !
|
|
|
|
#define THERMISTOR_RESISTANCE_NOMINAL_C 25.0f // mmmmm comfortable
|
2019-05-07 01:51:06 +02:00
|
|
|
|
|
|
|
#if HAS_USER_THERMISTORS
|
|
|
|
|
|
|
|
enum CustomThermistorIndex : uint8_t {
|
|
|
|
#if ENABLED(HEATER_0_USER_THERMISTOR)
|
|
|
|
CTI_HOTEND_0,
|
|
|
|
#endif
|
|
|
|
#if ENABLED(HEATER_1_USER_THERMISTOR)
|
|
|
|
CTI_HOTEND_1,
|
|
|
|
#endif
|
|
|
|
#if ENABLED(HEATER_2_USER_THERMISTOR)
|
|
|
|
CTI_HOTEND_2,
|
|
|
|
#endif
|
|
|
|
#if ENABLED(HEATER_3_USER_THERMISTOR)
|
|
|
|
CTI_HOTEND_3,
|
|
|
|
#endif
|
|
|
|
#if ENABLED(HEATER_4_USER_THERMISTOR)
|
|
|
|
CTI_HOTEND_4,
|
|
|
|
#endif
|
|
|
|
#if ENABLED(HEATER_5_USER_THERMISTOR)
|
|
|
|
CTI_HOTEND_5,
|
|
|
|
#endif
|
2019-05-29 00:43:31 +02:00
|
|
|
#if ENABLED(HEATER_BED_USER_THERMISTOR)
|
2019-05-07 01:51:06 +02:00
|
|
|
CTI_BED,
|
|
|
|
#endif
|
2020-01-18 00:16:45 +01:00
|
|
|
#if ENABLED(HEATER_PROBE_USER_THERMISTOR)
|
|
|
|
CTI_PROBE,
|
|
|
|
#endif
|
2019-05-29 00:43:31 +02:00
|
|
|
#if ENABLED(HEATER_CHAMBER_USER_THERMISTOR)
|
2019-05-07 01:51:06 +02:00
|
|
|
CTI_CHAMBER,
|
|
|
|
#endif
|
|
|
|
USER_THERMISTORS
|
|
|
|
};
|
|
|
|
|
|
|
|
// User-defined thermistor
|
|
|
|
typedef struct {
|
|
|
|
bool pre_calc; // true if pre-calculations update needed
|
|
|
|
float sh_c_coeff, // Steinhart-Hart C coefficient .. defaults to '0.0'
|
|
|
|
sh_alpha,
|
|
|
|
series_res,
|
|
|
|
res_25, res_25_recip,
|
|
|
|
res_25_log,
|
|
|
|
beta, beta_recip;
|
|
|
|
} user_thermistor_t;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2016-04-29 03:18:13 +02:00
|
|
|
class Temperature {
|
2015-10-03 08:08:58 +02:00
|
|
|
|
2016-04-29 03:18:13 +02:00
|
|
|
public:
|
2014-08-07 02:30:57 +02:00
|
|
|
|
2019-09-10 09:20:49 +02:00
|
|
|
#if HOTENDS
|
2019-08-07 06:25:47 +02:00
|
|
|
#if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
|
2019-09-10 09:20:49 +02:00
|
|
|
#define HOTEND_TEMPS (HOTENDS + 1)
|
|
|
|
#else
|
|
|
|
#define HOTEND_TEMPS HOTENDS
|
2019-08-07 06:25:47 +02:00
|
|
|
#endif
|
2019-09-10 09:20:49 +02:00
|
|
|
static hotend_info_t temp_hotend[HOTEND_TEMPS];
|
|
|
|
#endif
|
2019-03-07 09:09:39 +01:00
|
|
|
#if HAS_HEATED_BED
|
|
|
|
static bed_info_t temp_bed;
|
|
|
|
#endif
|
2020-01-18 00:16:45 +01:00
|
|
|
#if HAS_TEMP_PROBE
|
|
|
|
static probe_info_t temp_probe;
|
|
|
|
#endif
|
2019-03-07 09:09:39 +01:00
|
|
|
#if HAS_TEMP_CHAMBER
|
|
|
|
static chamber_info_t temp_chamber;
|
|
|
|
#endif
|
2017-05-28 18:11:17 +02:00
|
|
|
|
2018-02-06 07:22:30 +01:00
|
|
|
#if ENABLED(AUTO_POWER_E_FANS)
|
2018-10-07 22:34:41 +02:00
|
|
|
static uint8_t autofan_speed[HOTENDS];
|
2018-02-06 07:22:30 +01:00
|
|
|
#endif
|
2019-05-05 05:51:47 +02:00
|
|
|
#if ENABLED(AUTO_POWER_CHAMBER_FAN)
|
|
|
|
static uint8_t chamberfan_speed;
|
|
|
|
#endif
|
|
|
|
|
2016-04-29 03:18:13 +02:00
|
|
|
#if ENABLED(FAN_SOFT_PWM)
|
2017-04-20 21:04:26 +02:00
|
|
|
static uint8_t soft_pwm_amount_fan[FAN_COUNT],
|
|
|
|
soft_pwm_count_fan[FAN_COUNT];
|
2016-04-17 04:19:40 +02:00
|
|
|
#endif
|
2016-04-29 03:18:13 +02:00
|
|
|
|
2016-08-21 06:34:24 +02:00
|
|
|
#if ENABLED(PREVENT_COLD_EXTRUSION)
|
2016-07-06 17:28:09 +02:00
|
|
|
static bool allow_cold_extrude;
|
2017-06-11 01:29:17 +02:00
|
|
|
static int16_t extrude_min_temp;
|
2018-01-02 01:24:54 +01:00
|
|
|
FORCE_INLINE static bool tooCold(const int16_t temp) { return allow_cold_extrude ? false : temp < extrude_min_temp; }
|
2019-10-01 04:44:07 +02:00
|
|
|
FORCE_INLINE static bool tooColdToExtrude(const uint8_t E_NAME) {
|
2018-01-02 01:24:54 +01:00
|
|
|
return tooCold(degHotend(HOTEND_INDEX));
|
|
|
|
}
|
2019-10-01 04:44:07 +02:00
|
|
|
FORCE_INLINE static bool targetTooColdToExtrude(const uint8_t E_NAME) {
|
2018-01-02 01:24:54 +01:00
|
|
|
return tooCold(degTargetHotend(HOTEND_INDEX));
|
2016-07-10 04:47:11 +02:00
|
|
|
}
|
2016-04-29 03:18:13 +02:00
|
|
|
#else
|
2019-10-01 04:44:07 +02:00
|
|
|
FORCE_INLINE static bool tooColdToExtrude(const uint8_t) { return false; }
|
|
|
|
FORCE_INLINE static bool targetTooColdToExtrude(const uint8_t) { return false; }
|
2016-04-29 03:18:13 +02:00
|
|
|
#endif
|
|
|
|
|
2018-01-22 11:29:29 +01:00
|
|
|
FORCE_INLINE static bool hotEnoughToExtrude(const uint8_t e) { return !tooColdToExtrude(e); }
|
|
|
|
FORCE_INLINE static bool targetHotEnoughToExtrude(const uint8_t e) { return !targetTooColdToExtrude(e); }
|
|
|
|
|
2019-03-07 09:09:39 +01:00
|
|
|
#if HEATER_IDLE_HANDLER
|
2020-01-30 10:24:43 +01:00
|
|
|
static hotend_idle_t hotend_idle[HOTENDS];
|
2019-03-07 09:09:39 +01:00
|
|
|
#if HAS_HEATED_BED
|
2020-01-30 10:24:43 +01:00
|
|
|
static hotend_idle_t bed_idle;
|
2019-03-07 09:09:39 +01:00
|
|
|
#endif
|
|
|
|
#if HAS_HEATED_CHAMBER
|
2020-01-30 10:24:43 +01:00
|
|
|
static hotend_idle_t chamber_idle;
|
2019-03-07 09:09:39 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2016-04-29 03:18:13 +02:00
|
|
|
private:
|
|
|
|
|
2018-03-22 01:04:45 +01:00
|
|
|
#if EARLY_WATCHDOG
|
2018-04-24 00:13:01 +02:00
|
|
|
static bool inited; // If temperature controller is running
|
|
|
|
#endif
|
|
|
|
|
2020-01-27 00:39:45 +01:00
|
|
|
static volatile bool raw_temps_ready;
|
2018-04-24 00:13:01 +02:00
|
|
|
|
|
|
|
#if WATCH_HOTENDS
|
2020-01-30 10:24:43 +01:00
|
|
|
static hotend_watch_t watch_hotend[HOTENDS];
|
2018-03-22 01:04:45 +01:00
|
|
|
#endif
|
|
|
|
|
2016-04-29 03:18:13 +02:00
|
|
|
#if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
|
2017-05-21 11:48:53 +02:00
|
|
|
static uint16_t redundant_temperature_raw;
|
2016-05-26 20:58:38 +02:00
|
|
|
static float redundant_temperature;
|
2016-04-29 03:18:13 +02:00
|
|
|
#endif
|
|
|
|
|
2019-02-27 11:38:56 +01:00
|
|
|
#if ENABLED(PID_EXTRUSION_SCALING)
|
2019-03-07 09:09:39 +01:00
|
|
|
static int32_t last_e_position, lpq[LPQ_MAX_LEN];
|
|
|
|
static lpq_ptr_t lpq_ptr;
|
2016-04-29 03:18:13 +02:00
|
|
|
#endif
|
|
|
|
|
2019-09-10 09:20:49 +02:00
|
|
|
#if HOTENDS
|
|
|
|
static temp_range_t temp_range[HOTENDS];
|
|
|
|
#endif
|
2016-04-29 03:18:13 +02:00
|
|
|
|
2018-04-24 00:13:01 +02:00
|
|
|
#if HAS_HEATED_BED
|
2019-03-07 09:09:39 +01:00
|
|
|
#if WATCH_BED
|
2020-01-30 10:24:43 +01:00
|
|
|
static bed_watch_t watch_bed;
|
2018-04-24 00:13:01 +02:00
|
|
|
#endif
|
2018-10-10 16:45:20 +02:00
|
|
|
#if DISABLED(PIDTEMPBED)
|
2018-04-24 00:13:01 +02:00
|
|
|
static millis_t next_bed_check_ms;
|
|
|
|
#endif
|
|
|
|
#ifdef BED_MINTEMP
|
2019-03-07 09:09:39 +01:00
|
|
|
static int16_t mintemp_raw_BED;
|
2018-04-24 00:13:01 +02:00
|
|
|
#endif
|
|
|
|
#ifdef BED_MAXTEMP
|
2019-03-07 09:09:39 +01:00
|
|
|
static int16_t maxtemp_raw_BED;
|
2018-04-24 00:13:01 +02:00
|
|
|
#endif
|
2016-07-09 04:28:37 +02:00
|
|
|
#endif
|
|
|
|
|
2019-03-07 09:09:39 +01:00
|
|
|
#if HAS_HEATED_CHAMBER
|
|
|
|
#if WATCH_CHAMBER
|
2020-01-30 10:24:43 +01:00
|
|
|
static chamber_watch_t watch_chamber;
|
2019-03-07 09:09:39 +01:00
|
|
|
#endif
|
2019-04-12 22:38:10 +02:00
|
|
|
static millis_t next_chamber_check_ms;
|
2019-03-07 09:09:39 +01:00
|
|
|
#ifdef CHAMBER_MINTEMP
|
|
|
|
static int16_t mintemp_raw_CHAMBER;
|
|
|
|
#endif
|
|
|
|
#ifdef CHAMBER_MAXTEMP
|
|
|
|
static int16_t maxtemp_raw_CHAMBER;
|
|
|
|
#endif
|
2016-07-09 04:28:37 +02:00
|
|
|
#endif
|
|
|
|
|
2018-04-24 00:13:01 +02:00
|
|
|
#ifdef MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED
|
|
|
|
static uint8_t consecutive_low_temperature_error[HOTENDS];
|
2016-04-29 03:18:13 +02:00
|
|
|
#endif
|
|
|
|
|
2018-04-24 00:13:01 +02:00
|
|
|
#ifdef MILLISECONDS_PREHEAT_TIME
|
|
|
|
static millis_t preheat_end_time[HOTENDS];
|
2016-04-29 03:18:13 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAS_AUTO_FAN
|
2016-05-26 20:58:38 +02:00
|
|
|
static millis_t next_auto_fan_check_ms;
|
2016-04-29 03:18:13 +02:00
|
|
|
#endif
|
|
|
|
|
2017-05-07 13:06:06 +02:00
|
|
|
#if ENABLED(PROBING_HEATERS_OFF)
|
|
|
|
static bool paused;
|
2017-05-26 20:01:02 +02:00
|
|
|
#endif
|
2017-05-07 13:06:06 +02:00
|
|
|
|
2016-04-29 03:18:13 +02:00
|
|
|
public:
|
2018-11-19 03:39:49 +01:00
|
|
|
#if HAS_ADC_BUTTONS
|
2017-06-10 07:12:18 +02:00
|
|
|
static uint32_t current_ADCKey_raw;
|
|
|
|
static uint8_t ADCKey_count;
|
|
|
|
#endif
|
2016-04-29 03:18:13 +02:00
|
|
|
|
2018-05-12 09:13:40 +02:00
|
|
|
#if ENABLED(PID_EXTRUSION_SCALING)
|
|
|
|
static int16_t lpq_len;
|
|
|
|
#endif
|
|
|
|
|
2016-04-29 03:18:13 +02:00
|
|
|
/**
|
|
|
|
* Instance Methods
|
|
|
|
*/
|
|
|
|
|
|
|
|
void init();
|
|
|
|
|
2016-05-26 20:58:38 +02:00
|
|
|
/**
|
|
|
|
* Static (class) methods
|
|
|
|
*/
|
2019-05-07 01:51:06 +02:00
|
|
|
|
|
|
|
#if HAS_USER_THERMISTORS
|
|
|
|
static user_thermistor_t user_thermistor[USER_THERMISTORS];
|
|
|
|
static void log_user_thermistor(const uint8_t t_index, const bool eprom=false);
|
|
|
|
static void reset_user_thermistors();
|
|
|
|
static float user_thermistor_to_deg_c(const uint8_t t_index, const int raw);
|
|
|
|
static bool set_pull_up_res(int8_t t_index, float value) {
|
|
|
|
//if (!WITHIN(t_index, 0, USER_THERMISTORS - 1)) return false;
|
|
|
|
if (!WITHIN(value, 1, 1000000)) return false;
|
|
|
|
user_thermistor[t_index].series_res = value;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
static bool set_res25(int8_t t_index, float value) {
|
|
|
|
if (!WITHIN(value, 1, 10000000)) return false;
|
|
|
|
user_thermistor[t_index].res_25 = value;
|
|
|
|
user_thermistor[t_index].pre_calc = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
static bool set_beta(int8_t t_index, float value) {
|
|
|
|
if (!WITHIN(value, 1, 1000000)) return false;
|
|
|
|
user_thermistor[t_index].beta = value;
|
|
|
|
user_thermistor[t_index].pre_calc = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
static bool set_sh_coeff(int8_t t_index, float value) {
|
|
|
|
if (!WITHIN(value, -0.01f, 0.01f)) return false;
|
|
|
|
user_thermistor[t_index].sh_c_coeff = value;
|
|
|
|
user_thermistor[t_index].pre_calc = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-09-10 09:20:49 +02:00
|
|
|
#if HOTENDS
|
|
|
|
static float analog_to_celsius_hotend(const int raw, const uint8_t e);
|
|
|
|
#endif
|
2018-01-02 01:24:54 +01:00
|
|
|
|
2018-04-24 00:13:01 +02:00
|
|
|
#if HAS_HEATED_BED
|
2018-11-14 20:13:51 +01:00
|
|
|
static float analog_to_celsius_bed(const int raw);
|
2018-01-02 01:24:54 +01:00
|
|
|
#endif
|
2020-01-18 00:16:45 +01:00
|
|
|
#if HAS_TEMP_PROBE
|
|
|
|
static float analog_to_celsius_probe(const int raw);
|
|
|
|
#endif
|
2018-02-24 07:38:58 +01:00
|
|
|
#if HAS_TEMP_CHAMBER
|
2019-03-07 09:09:39 +01:00
|
|
|
static float analog_to_celsius_chamber(const int raw);
|
2018-02-24 07:38:58 +01:00
|
|
|
#endif
|
2016-05-26 20:58:38 +02:00
|
|
|
|
2019-01-12 07:41:48 +01:00
|
|
|
#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);
|
|
|
|
|
2019-05-07 21:14:12 +02:00
|
|
|
#if EITHER(PROBING_FANS_OFF, ADVANCED_PAUSE_FANS_PAUSE)
|
2019-01-12 07:41:48 +01:00
|
|
|
static bool fans_paused;
|
2019-05-07 21:14:12 +02:00
|
|
|
static uint8_t saved_fan_speed[FAN_COUNT];
|
2019-01-12 07:41:48 +01:00
|
|
|
#endif
|
|
|
|
|
2019-03-29 20:07:43 +01:00
|
|
|
static constexpr inline uint8_t fanPercent(const uint8_t speed) { return ui8_to_percent(speed); }
|
2019-01-12 07:41:48 +01:00
|
|
|
|
|
|
|
#if ENABLED(ADAPTIVE_FAN_SLOWING)
|
|
|
|
static uint8_t fan_speed_scaler[FAN_COUNT];
|
|
|
|
#endif
|
|
|
|
|
2019-06-29 04:24:31 +02:00
|
|
|
static inline uint8_t scaledFanSpeed(const uint8_t target, const uint8_t fs) {
|
2019-11-11 01:49:41 +01:00
|
|
|
UNUSED(target); // Potentially unused!
|
2019-10-10 02:44:49 +02:00
|
|
|
return (fs * uint16_t(
|
|
|
|
#if ENABLED(ADAPTIVE_FAN_SLOWING)
|
|
|
|
fan_speed_scaler[target]
|
|
|
|
#else
|
|
|
|
128
|
|
|
|
#endif
|
|
|
|
)) >> 7;
|
2019-06-28 20:58:40 +02:00
|
|
|
}
|
|
|
|
|
2019-06-29 04:24:31 +02:00
|
|
|
static inline uint8_t scaledFanSpeed(const uint8_t target) {
|
2019-06-28 20:58:40 +02:00
|
|
|
return scaledFanSpeed(target, fan_speed[target]);
|
2019-01-12 07:41:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#if ENABLED(EXTRA_FAN_SPEED)
|
|
|
|
static uint8_t old_fan_speed[FAN_COUNT], new_fan_speed[FAN_COUNT];
|
2019-01-20 01:47:29 +01:00
|
|
|
static void set_temp_fan_speed(const uint8_t fan, const uint16_t tmp_temp);
|
2019-01-12 07:41:48 +01:00
|
|
|
#endif
|
|
|
|
|
2019-05-04 22:50:44 +02:00
|
|
|
#if EITHER(PROBING_FANS_OFF, ADVANCED_PAUSE_FANS_PAUSE)
|
2019-01-12 07:41:48 +01:00
|
|
|
void set_fans_paused(const bool p);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif // FAN_COUNT > 0
|
|
|
|
|
|
|
|
static inline void zero_fan_speeds() {
|
|
|
|
#if FAN_COUNT > 0
|
2019-02-23 04:00:36 +01:00
|
|
|
FANS_LOOP(i) set_fan_speed(i, 0);
|
2019-01-12 07:41:48 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-04-29 03:18:13 +02:00
|
|
|
/**
|
|
|
|
* Called from the Temperature ISR
|
|
|
|
*/
|
2018-07-26 10:59:19 +02:00
|
|
|
static void readings_ready();
|
2019-11-13 02:23:02 +01:00
|
|
|
static void tick();
|
2016-04-29 03:18:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Call periodically to manage heaters
|
|
|
|
*/
|
2017-05-22 20:47:43 +02:00
|
|
|
static void manage_heater() _O2; // Added _O2 to work around a compiler error
|
2016-04-29 03:18:13 +02:00
|
|
|
|
2016-07-09 04:28:37 +02:00
|
|
|
/**
|
|
|
|
* Preheating hotends
|
|
|
|
*/
|
|
|
|
#ifdef MILLISECONDS_PREHEAT_TIME
|
2019-10-01 04:44:07 +02:00
|
|
|
static bool is_preheating(const uint8_t E_NAME) {
|
2016-07-12 07:08:47 +02:00
|
|
|
return preheat_end_time[HOTEND_INDEX] && PENDING(millis(), preheat_end_time[HOTEND_INDEX]);
|
|
|
|
}
|
2019-10-01 04:44:07 +02:00
|
|
|
static void start_preheat_time(const uint8_t E_NAME) {
|
2016-07-12 07:08:47 +02:00
|
|
|
preheat_end_time[HOTEND_INDEX] = millis() + MILLISECONDS_PREHEAT_TIME;
|
|
|
|
}
|
2019-10-01 04:44:07 +02:00
|
|
|
static void reset_preheat_time(const uint8_t E_NAME) {
|
2016-07-12 07:08:47 +02:00
|
|
|
preheat_end_time[HOTEND_INDEX] = 0;
|
2016-07-09 04:28:37 +02:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define is_preheating(n) (false)
|
|
|
|
#endif
|
|
|
|
|
2016-04-29 03:18:13 +02:00
|
|
|
//high level conversion routines, for use outside of temperature.cpp
|
|
|
|
//inline so that there is no performance decrease.
|
|
|
|
//deg=degreeCelsius
|
|
|
|
|
2019-10-01 04:44:07 +02:00
|
|
|
FORCE_INLINE static float degHotend(const uint8_t E_NAME) {
|
|
|
|
return (0
|
|
|
|
#if HOTENDS
|
|
|
|
+ temp_hotend[HOTEND_INDEX].celsius
|
|
|
|
#endif
|
|
|
|
);
|
2016-05-27 02:43:20 +02:00
|
|
|
}
|
2016-04-29 03:18:13 +02:00
|
|
|
|
|
|
|
#if ENABLED(SHOW_TEMP_ADC_VALUES)
|
2019-10-01 04:44:07 +02:00
|
|
|
FORCE_INLINE static int16_t rawHotendTemp(const uint8_t E_NAME) {
|
|
|
|
return (0
|
|
|
|
#if HOTENDS
|
|
|
|
+ temp_hotend[HOTEND_INDEX].raw
|
|
|
|
#endif
|
|
|
|
);
|
2017-05-04 00:12:14 +02:00
|
|
|
}
|
2016-04-29 03:18:13 +02:00
|
|
|
#endif
|
|
|
|
|
2019-10-01 04:44:07 +02:00
|
|
|
FORCE_INLINE static int16_t degTargetHotend(const uint8_t E_NAME) {
|
|
|
|
return (0
|
|
|
|
#if HOTENDS
|
|
|
|
+ temp_hotend[HOTEND_INDEX].target
|
|
|
|
#endif
|
|
|
|
);
|
2016-05-27 02:43:20 +02:00
|
|
|
}
|
2017-05-04 23:09:45 +02:00
|
|
|
|
2017-04-02 18:48:10 +02:00
|
|
|
#if WATCH_HOTENDS
|
2019-07-02 15:39:55 +02:00
|
|
|
static void start_watching_hotend(const uint8_t e=0);
|
2019-03-07 09:09:39 +01:00
|
|
|
#else
|
2019-10-01 04:44:07 +02:00
|
|
|
static inline void start_watching_hotend(const uint8_t=0) {}
|
2019-03-07 09:09:39 +01:00
|
|
|
#endif
|
|
|
|
|
2019-09-10 09:20:49 +02:00
|
|
|
#if HOTENDS
|
2016-04-29 03:18:13 +02:00
|
|
|
|
2019-10-01 04:44:07 +02:00
|
|
|
static void setTargetHotend(const int16_t celsius, const uint8_t E_NAME) {
|
2019-09-10 09:20:49 +02:00
|
|
|
const uint8_t ee = HOTEND_INDEX;
|
|
|
|
#ifdef MILLISECONDS_PREHEAT_TIME
|
|
|
|
if (celsius == 0)
|
|
|
|
reset_preheat_time(ee);
|
|
|
|
else if (temp_hotend[ee].target == 0)
|
|
|
|
start_preheat_time(ee);
|
|
|
|
#endif
|
|
|
|
#if ENABLED(AUTO_POWER_CONTROL)
|
|
|
|
powerManager.power_on();
|
|
|
|
#endif
|
|
|
|
temp_hotend[ee].target = _MIN(celsius, temp_range[ee].maxtemp - 15);
|
|
|
|
start_watching_hotend(ee);
|
|
|
|
}
|
2018-04-24 00:13:01 +02:00
|
|
|
|
2019-10-01 04:44:07 +02:00
|
|
|
FORCE_INLINE static bool isHeatingHotend(const uint8_t E_NAME) {
|
2019-09-10 09:20:49 +02:00
|
|
|
return temp_hotend[HOTEND_INDEX].target > temp_hotend[HOTEND_INDEX].celsius;
|
|
|
|
}
|
2018-04-24 00:13:01 +02:00
|
|
|
|
2019-10-01 04:44:07 +02:00
|
|
|
FORCE_INLINE static bool isCoolingHotend(const uint8_t E_NAME) {
|
2019-09-10 09:20:49 +02:00
|
|
|
return temp_hotend[HOTEND_INDEX].target < temp_hotend[HOTEND_INDEX].celsius;
|
|
|
|
}
|
2018-09-29 08:44:47 +02:00
|
|
|
|
2019-09-10 09:20:49 +02:00
|
|
|
#if HAS_TEMP_HOTEND
|
|
|
|
static bool wait_for_hotend(const uint8_t target_extruder, const bool no_wait_for_cooling=true
|
|
|
|
#if G26_CLICK_CAN_CANCEL
|
|
|
|
, const bool click_to_cancel=false
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
FORCE_INLINE static bool still_heating(const uint8_t e) {
|
|
|
|
return degTargetHotend(e) > TEMP_HYSTERESIS && ABS(degHotend(e) - degTargetHotend(e)) > TEMP_HYSTERESIS;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // HOTENDS
|
2019-09-08 09:20:18 +02:00
|
|
|
|
2018-04-24 00:13:01 +02:00
|
|
|
#if HAS_HEATED_BED
|
2018-09-29 08:44:47 +02:00
|
|
|
|
2018-04-24 00:13:01 +02:00
|
|
|
#if ENABLED(SHOW_TEMP_ADC_VALUES)
|
2019-03-07 09:09:39 +01:00
|
|
|
FORCE_INLINE static int16_t rawBedTemp() { return temp_bed.raw; }
|
|
|
|
#endif
|
2019-09-09 09:56:23 +02:00
|
|
|
FORCE_INLINE static float degBed() { return temp_bed.celsius; }
|
2019-03-07 09:09:39 +01:00
|
|
|
FORCE_INLINE static int16_t degTargetBed() { return temp_bed.target; }
|
2019-09-09 09:56:23 +02:00
|
|
|
FORCE_INLINE static bool isHeatingBed() { return temp_bed.target > temp_bed.celsius; }
|
|
|
|
FORCE_INLINE static bool isCoolingBed() { return temp_bed.target < temp_bed.celsius; }
|
2019-03-07 09:09:39 +01:00
|
|
|
|
|
|
|
#if WATCH_BED
|
|
|
|
static void start_watching_bed();
|
|
|
|
#else
|
|
|
|
static inline void start_watching_bed() {}
|
2018-04-24 00:13:01 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static void setTargetBed(const int16_t celsius) {
|
2018-02-06 07:22:30 +01:00
|
|
|
#if ENABLED(AUTO_POWER_CONTROL)
|
|
|
|
powerManager.power_on();
|
|
|
|
#endif
|
2019-03-07 09:09:39 +01:00
|
|
|
temp_bed.target =
|
2017-05-28 18:11:17 +02:00
|
|
|
#ifdef BED_MAXTEMP
|
2019-07-06 01:01:21 +02:00
|
|
|
_MIN(celsius, BED_MAXTEMP - 10)
|
2017-05-28 18:11:17 +02:00
|
|
|
#else
|
|
|
|
celsius
|
|
|
|
#endif
|
|
|
|
;
|
2019-03-07 09:09:39 +01:00
|
|
|
start_watching_bed();
|
2018-04-24 00:13:01 +02:00
|
|
|
}
|
2016-04-29 03:18:13 +02:00
|
|
|
|
2018-11-26 01:05:18 +01:00
|
|
|
static bool wait_for_bed(const bool no_wait_for_cooling=true
|
2018-11-11 01:07:38 +01:00
|
|
|
#if G26_CLICK_CAN_CANCEL
|
|
|
|
, const bool click_to_cancel=false
|
|
|
|
#endif
|
|
|
|
);
|
2018-09-29 08:44:47 +02:00
|
|
|
|
|
|
|
#endif // HAS_HEATED_BED
|
2016-04-29 03:18:13 +02:00
|
|
|
|
2020-01-18 00:16:45 +01:00
|
|
|
#if HAS_TEMP_PROBE
|
|
|
|
#if ENABLED(SHOW_TEMP_ADC_VALUES)
|
|
|
|
FORCE_INLINE static int16_t rawProbeTemp() { return temp_probe.raw; }
|
|
|
|
#endif
|
|
|
|
FORCE_INLINE static float degProbe() { return temp_probe.celsius; }
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if WATCH_PROBE
|
|
|
|
static void start_watching_probe();
|
|
|
|
#else
|
|
|
|
static inline void start_watching_probe() {}
|
|
|
|
#endif
|
|
|
|
|
2018-04-24 00:13:01 +02:00
|
|
|
#if HAS_TEMP_CHAMBER
|
|
|
|
#if ENABLED(SHOW_TEMP_ADC_VALUES)
|
2019-05-05 05:51:47 +02:00
|
|
|
FORCE_INLINE static int16_t rawChamberTemp() { return temp_chamber.raw; }
|
2016-05-27 02:43:20 +02:00
|
|
|
#endif
|
2019-09-09 09:56:23 +02:00
|
|
|
FORCE_INLINE static float degChamber() { return temp_chamber.celsius; }
|
2019-03-07 09:09:39 +01:00
|
|
|
#if HAS_HEATED_CHAMBER
|
2019-05-05 05:51:47 +02:00
|
|
|
FORCE_INLINE static int16_t degTargetChamber() { return temp_chamber.target; }
|
2019-09-09 09:56:23 +02:00
|
|
|
FORCE_INLINE static bool isHeatingChamber() { return temp_chamber.target > temp_chamber.celsius; }
|
|
|
|
FORCE_INLINE static bool isCoolingChamber() { return temp_chamber.target < temp_chamber.celsius; }
|
2019-05-05 05:51:47 +02:00
|
|
|
|
|
|
|
static bool wait_for_chamber(const bool no_wait_for_cooling=true);
|
2019-03-07 09:09:39 +01:00
|
|
|
#endif
|
|
|
|
#endif // HAS_TEMP_CHAMBER
|
2018-01-02 01:24:54 +01:00
|
|
|
|
2019-09-08 09:20:18 +02:00
|
|
|
#if WATCH_CHAMBER
|
|
|
|
static void start_watching_chamber();
|
|
|
|
#else
|
|
|
|
static inline void start_watching_chamber() {}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAS_HEATED_CHAMBER
|
|
|
|
static void setTargetChamber(const int16_t celsius) {
|
|
|
|
temp_chamber.target =
|
|
|
|
#ifdef CHAMBER_MAXTEMP
|
2020-01-20 07:44:51 +01:00
|
|
|
_MIN(celsius, CHAMBER_MAXTEMP - 10)
|
2019-09-08 09:20:18 +02:00
|
|
|
#else
|
|
|
|
celsius
|
|
|
|
#endif
|
|
|
|
;
|
|
|
|
start_watching_chamber();
|
|
|
|
}
|
|
|
|
#endif // HAS_HEATED_CHAMBER
|
2016-04-29 03:18:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The software PWM power for a heater
|
|
|
|
*/
|
2019-07-02 15:39:55 +02:00
|
|
|
static int16_t getHeaterPower(const heater_ind_t heater);
|
2016-04-29 03:18:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Switch off all heaters, set all target temperatures to 0
|
|
|
|
*/
|
2016-05-26 20:58:38 +02:00
|
|
|
static void disable_all_heaters();
|
2016-04-29 03:18:13 +02:00
|
|
|
|
2020-01-30 10:24:43 +01:00
|
|
|
#if ENABLED(PRINTJOB_TIMER_AUTOSTART)
|
|
|
|
/**
|
|
|
|
* Methods to check if heaters are enabled, indicating an active job
|
|
|
|
*/
|
|
|
|
static bool over_autostart_threshold();
|
|
|
|
static void check_timer_autostart(const bool can_start, const bool can_stop);
|
|
|
|
#endif
|
|
|
|
|
2016-04-29 03:18:13 +02:00
|
|
|
/**
|
|
|
|
* Perform auto-tuning for hotend or bed in response to M303
|
|
|
|
*/
|
|
|
|
#if HAS_PID_HEATING
|
2019-07-02 15:39:55 +02:00
|
|
|
static void PID_autotune(const float &target, const heater_ind_t hotend, const int8_t ncycles, const bool set_result=false);
|
2016-04-29 03:18:13 +02:00
|
|
|
|
2019-02-04 07:12:41 +01:00
|
|
|
#if ENABLED(NO_FAN_SLOWING_IN_PID_TUNING)
|
|
|
|
static bool adaptive_fan_slowing;
|
|
|
|
#elif ENABLED(ADAPTIVE_FAN_SLOWING)
|
2019-04-04 10:06:19 +02:00
|
|
|
static constexpr bool adaptive_fan_slowing = true;
|
2019-02-04 07:12:41 +01:00
|
|
|
#endif
|
|
|
|
|
2017-12-01 16:08:30 +01:00
|
|
|
/**
|
|
|
|
* Update the temp manager when PID values change
|
|
|
|
*/
|
2017-11-10 07:48:00 +01:00
|
|
|
#if ENABLED(PIDTEMP)
|
|
|
|
FORCE_INLINE static void updatePID() {
|
|
|
|
#if ENABLED(PID_EXTRUSION_SCALING)
|
|
|
|
last_e_position = 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
2016-04-29 03:18:13 +02:00
|
|
|
|
2017-05-07 13:06:06 +02:00
|
|
|
#if ENABLED(PROBING_HEATERS_OFF)
|
2017-05-08 21:09:37 +02:00
|
|
|
static void pause(const bool p);
|
2018-01-02 01:24:54 +01:00
|
|
|
FORCE_INLINE static bool is_paused() { return paused; }
|
2017-05-26 20:01:02 +02:00
|
|
|
#endif
|
|
|
|
|
2017-06-12 07:22:31 +02:00
|
|
|
#if HEATER_IDLE_HANDLER
|
2018-01-02 01:24:54 +01:00
|
|
|
|
2020-01-30 10:24:43 +01:00
|
|
|
static void reset_hotend_idle_timer(const uint8_t E_NAME) {
|
2019-03-07 09:09:39 +01:00
|
|
|
hotend_idle[HOTEND_INDEX].reset();
|
2019-07-02 15:39:55 +02:00
|
|
|
start_watching_hotend(HOTEND_INDEX);
|
2017-05-26 20:01:02 +02:00
|
|
|
}
|
|
|
|
|
2018-04-24 00:13:01 +02:00
|
|
|
#if HAS_HEATED_BED
|
2017-05-26 20:01:02 +02:00
|
|
|
static void reset_bed_idle_timer() {
|
2019-03-07 09:09:39 +01:00
|
|
|
bed_idle.reset();
|
|
|
|
start_watching_bed();
|
2017-05-26 20:01:02 +02:00
|
|
|
}
|
|
|
|
#endif
|
2018-01-02 01:24:54 +01:00
|
|
|
|
|
|
|
#endif // HEATER_IDLE_HANDLER
|
2017-05-07 13:06:06 +02:00
|
|
|
|
2018-03-07 08:53:50 +01:00
|
|
|
#if HAS_TEMP_SENSOR
|
2019-06-28 04:29:53 +02:00
|
|
|
static void print_heater_states(const uint8_t target_extruder
|
|
|
|
#if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
|
|
|
|
, const bool include_r=false
|
|
|
|
#endif
|
|
|
|
);
|
2017-09-16 20:05:01 +02:00
|
|
|
#if ENABLED(AUTO_REPORT_TEMPERATURES)
|
|
|
|
static uint8_t auto_report_temp_interval;
|
|
|
|
static millis_t next_temp_report_ms;
|
2019-09-17 03:31:08 +02:00
|
|
|
static void auto_report_temperatures();
|
2019-03-02 02:29:48 +01:00
|
|
|
static inline void set_auto_report_interval(uint8_t v) {
|
2017-09-16 20:05:01 +02:00
|
|
|
NOMORE(v, 60);
|
|
|
|
auto_report_temp_interval = v;
|
|
|
|
next_temp_report_ms = millis() + 1000UL * v;
|
|
|
|
}
|
|
|
|
#endif
|
2017-09-16 11:44:37 +02:00
|
|
|
#endif
|
|
|
|
|
2019-07-17 10:12:39 +02:00
|
|
|
#if HAS_DISPLAY
|
2018-10-08 00:06:14 +02:00
|
|
|
static void set_heating_message(const uint8_t e);
|
|
|
|
#endif
|
|
|
|
|
2016-04-29 03:18:13 +02:00
|
|
|
private:
|
2020-01-27 00:39:45 +01:00
|
|
|
static void update_raw_temperatures();
|
2016-05-26 20:58:38 +02:00
|
|
|
static void updateTemperaturesFromRawValues();
|
2016-04-29 03:18:13 +02:00
|
|
|
|
2019-03-17 05:43:06 +01:00
|
|
|
#define HAS_MAX6675 EITHER(HEATER_0_USES_MAX6675, HEATER_1_USES_MAX6675)
|
2018-11-17 01:20:33 +01:00
|
|
|
#if HAS_MAX6675
|
2019-03-17 05:43:06 +01:00
|
|
|
#if BOTH(HEATER_0_USES_MAX6675, HEATER_1_USES_MAX6675)
|
2018-11-17 01:20:33 +01:00
|
|
|
#define COUNT_6675 2
|
|
|
|
#else
|
|
|
|
#define COUNT_6675 1
|
|
|
|
#endif
|
|
|
|
#if COUNT_6675 > 1
|
|
|
|
#define READ_MAX6675(N) read_max6675(N)
|
|
|
|
#else
|
|
|
|
#define READ_MAX6675(N) read_max6675()
|
|
|
|
#endif
|
|
|
|
static int read_max6675(
|
|
|
|
#if COUNT_6675 > 1
|
|
|
|
const uint8_t hindex=0
|
|
|
|
#endif
|
|
|
|
);
|
2016-04-29 03:18:13 +02:00
|
|
|
#endif
|
|
|
|
|
2016-05-26 20:58:38 +02:00
|
|
|
static void checkExtruderAutoFans();
|
2016-04-29 03:18:13 +02:00
|
|
|
|
2019-07-02 15:39:55 +02:00
|
|
|
static float get_pid_output_hotend(const uint8_t e);
|
2016-04-29 03:18:13 +02:00
|
|
|
|
|
|
|
#if ENABLED(PIDTEMPBED)
|
2016-05-26 20:58:38 +02:00
|
|
|
static float get_pid_output_bed();
|
2016-04-29 03:18:13 +02:00
|
|
|
#endif
|
|
|
|
|
2019-03-07 09:09:39 +01:00
|
|
|
#if HAS_HEATED_CHAMBER
|
|
|
|
static float get_pid_output_chamber();
|
|
|
|
#endif
|
|
|
|
|
2019-07-02 15:39:55 +02:00
|
|
|
static void _temp_error(const heater_ind_t e, PGM_P const serial_msg, PGM_P const lcd_msg);
|
|
|
|
static void min_temp_error(const heater_ind_t e);
|
|
|
|
static void max_temp_error(const heater_ind_t e);
|
2016-04-29 03:18:13 +02:00
|
|
|
|
2019-07-14 15:56:29 +02:00
|
|
|
#define HAS_THERMAL_PROTECTION (EITHER(THERMAL_PROTECTION_HOTENDS, THERMAL_PROTECTION_CHAMBER) || HAS_THERMALLY_PROTECTED_BED)
|
|
|
|
|
|
|
|
#if HAS_THERMAL_PROTECTION
|
2016-04-29 03:18:13 +02:00
|
|
|
|
2018-04-24 00:13:01 +02:00
|
|
|
enum TRState : char { TRInactive, TRFirstHeating, TRStable, TRRunaway };
|
2016-04-29 03:18:13 +02:00
|
|
|
|
2019-03-07 09:09:39 +01:00
|
|
|
typedef struct {
|
|
|
|
millis_t timer = 0;
|
|
|
|
TRState state = TRInactive;
|
|
|
|
} tr_state_machine_t;
|
2016-04-29 03:18:13 +02:00
|
|
|
|
|
|
|
#if ENABLED(THERMAL_PROTECTION_HOTENDS)
|
2019-03-07 09:09:39 +01:00
|
|
|
static tr_state_machine_t tr_state_machine[HOTENDS];
|
2016-04-29 03:18:13 +02:00
|
|
|
#endif
|
|
|
|
#if HAS_THERMALLY_PROTECTED_BED
|
2019-03-07 09:09:39 +01:00
|
|
|
static tr_state_machine_t tr_state_machine_bed;
|
|
|
|
#endif
|
|
|
|
#if ENABLED(THERMAL_PROTECTION_CHAMBER)
|
|
|
|
static tr_state_machine_t tr_state_machine_chamber;
|
2016-04-29 03:18:13 +02:00
|
|
|
#endif
|
|
|
|
|
2019-07-02 15:39:55 +02:00
|
|
|
static void thermal_runaway_protection(tr_state_machine_t &state, const float ¤t, const float &target, const heater_ind_t heater_id, const uint16_t period_seconds, const uint16_t hysteresis_degc);
|
2019-03-07 09:09:39 +01:00
|
|
|
|
2019-07-14 15:56:29 +02:00
|
|
|
#endif // HAS_THERMAL_PROTECTION
|
2016-04-29 03:18:13 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
extern Temperature thermalManager;
|