2016-03-25 07:19:46 +01:00
|
|
|
/**
|
2016-03-24 19:01:20 +01:00
|
|
|
* Marlin 3D Printer Firmware
|
|
|
|
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
|
|
|
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
2015-04-02 14:10:14 +02:00
|
|
|
#ifndef TEMPERATURE_H
|
2015-10-03 08:08:58 +02:00
|
|
|
#define TEMPERATURE_H
|
2012-03-08 21:43:21 +01:00
|
|
|
|
2017-09-06 13:28:32 +02:00
|
|
|
#include "thermistor/thermistors.h"
|
2018-02-06 07:22:30 +01:00
|
|
|
#include "../inc/MarlinConfig.h"
|
2016-04-29 03:18:13 +02:00
|
|
|
|
2017-09-06 13:28:32 +02:00
|
|
|
#if ENABLED(BABYSTEPPING)
|
2018-06-12 04:29:31 +02:00
|
|
|
extern uint8_t axis_known_position;
|
2017-09-06 13:28:32 +02:00
|
|
|
#endif
|
2016-08-03 04:36:58 +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
|
|
|
|
2018-05-28 00:56:21 +02:00
|
|
|
#if HOTENDS == 1
|
|
|
|
#define HOTEND_INDEX 0
|
|
|
|
#else
|
|
|
|
#define HOTEND_INDEX e
|
|
|
|
#endif
|
|
|
|
|
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;
|
|
|
|
#if ENABLED(PID_EXTRUSION_SCALING)
|
|
|
|
typedef PIDC_t hotend_pid_t;
|
|
|
|
#else
|
|
|
|
typedef PID_t hotend_pid_t;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define DUMMY_PID_VALUE 3000.0f
|
|
|
|
|
|
|
|
#if ENABLED(PIDTEMP)
|
|
|
|
#define _PID_Kp(H) Temperature::pid[H].Kp
|
|
|
|
#define _PID_Ki(H) Temperature::pid[H].Ki
|
|
|
|
#define _PID_Kd(H) Temperature::pid[H].Kd
|
|
|
|
#if ENABLED(PID_EXTRUSION_SCALING)
|
|
|
|
#define _PID_Kc(H) Temperature::pid[H].Kc
|
|
|
|
#else
|
|
|
|
#define _PID_Kc(H) 1
|
|
|
|
#endif
|
|
|
|
#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
|
2017-04-07 01:42:57 +02:00
|
|
|
PrepareTemp_0,
|
|
|
|
MeasureTemp_0,
|
|
|
|
#endif
|
2018-05-02 02:33:41 +02:00
|
|
|
#if HAS_TEMP_ADC_1
|
2017-04-07 01:42:57 +02:00
|
|
|
PrepareTemp_1,
|
|
|
|
MeasureTemp_1,
|
|
|
|
#endif
|
2018-05-02 02:33:41 +02:00
|
|
|
#if HAS_TEMP_ADC_2
|
2017-04-07 01:42:57 +02:00
|
|
|
PrepareTemp_2,
|
|
|
|
MeasureTemp_2,
|
|
|
|
#endif
|
2018-05-02 02:33:41 +02:00
|
|
|
#if HAS_TEMP_ADC_3
|
2017-04-07 01:42:57 +02:00
|
|
|
PrepareTemp_3,
|
|
|
|
MeasureTemp_3,
|
|
|
|
#endif
|
2018-05-02 02:33:41 +02:00
|
|
|
#if HAS_TEMP_ADC_4
|
2017-04-07 01:42:57 +02:00
|
|
|
PrepareTemp_4,
|
|
|
|
MeasureTemp_4,
|
|
|
|
#endif
|
2018-04-24 00:13:01 +02:00
|
|
|
#if HAS_HEATED_BED
|
2017-04-07 01:42:57 +02:00
|
|
|
PrepareTemp_BED,
|
|
|
|
MeasureTemp_BED,
|
|
|
|
#endif
|
2018-02-24 07:38:58 +01:00
|
|
|
#if HAS_TEMP_CHAMBER
|
|
|
|
PrepareTemp_CHAMBER,
|
|
|
|
MeasureTemp_CHAMBER,
|
|
|
|
#endif
|
2017-04-07 01:42:57 +02:00
|
|
|
#if ENABLED(FILAMENT_WIDTH_SENSOR)
|
|
|
|
Prepare_FILWIDTH,
|
|
|
|
Measure_FILWIDTH,
|
|
|
|
#endif
|
2017-06-10 07:12:18 +02:00
|
|
|
#if ENABLED(ADC_KEYPAD)
|
|
|
|
Prepare_ADC_KEY,
|
|
|
|
Measure_ADC_KEY,
|
|
|
|
#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
|
|
|
|
|
2018-05-13 08:10:34 +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
|
|
|
|
|
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
|
|
|
|
2018-04-24 00:13:01 +02:00
|
|
|
static volatile bool in_temp_isr;
|
|
|
|
|
|
|
|
static float current_temperature[HOTENDS];
|
2017-05-04 00:12:14 +02:00
|
|
|
static int16_t current_temperature_raw[HOTENDS],
|
2018-04-24 00:13:01 +02:00
|
|
|
target_temperature[HOTENDS];
|
|
|
|
static uint8_t soft_pwm_amount[HOTENDS];
|
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
|
|
|
|
|
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
|
|
|
|
|
|
|
#if ENABLED(PIDTEMP)
|
2018-10-10 16:45:20 +02:00
|
|
|
static hotend_pid_t pid[HOTENDS];
|
2016-04-29 03:18:13 +02:00
|
|
|
#endif
|
2015-05-21 21:07:37 +02:00
|
|
|
|
2018-04-24 00:13:01 +02:00
|
|
|
#if HAS_HEATED_BED
|
|
|
|
static float current_temperature_bed;
|
|
|
|
static int16_t current_temperature_bed_raw, target_temperature_bed;
|
|
|
|
static uint8_t soft_pwm_amount_bed;
|
|
|
|
#if ENABLED(PIDTEMPBED)
|
2018-10-10 16:45:20 +02:00
|
|
|
static PID_t bed_pid;
|
2018-04-24 00:13:01 +02:00
|
|
|
#endif
|
2016-04-29 03:18:13 +02:00
|
|
|
#endif
|
2012-03-08 21:43:21 +01:00
|
|
|
|
2018-04-24 00:13:01 +02:00
|
|
|
#if ENABLED(BABYSTEPPING)
|
2018-09-13 08:35:55 +02:00
|
|
|
static volatile int16_t babystepsTodo[3];
|
2016-04-29 03:18:13 +02:00
|
|
|
#endif
|
|
|
|
|
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; }
|
|
|
|
FORCE_INLINE static bool tooColdToExtrude(const uint8_t e) {
|
2016-07-10 04:47:11 +02:00
|
|
|
#if HOTENDS == 1
|
|
|
|
UNUSED(e);
|
|
|
|
#endif
|
2018-01-02 01:24:54 +01:00
|
|
|
return tooCold(degHotend(HOTEND_INDEX));
|
|
|
|
}
|
|
|
|
FORCE_INLINE static bool targetTooColdToExtrude(const uint8_t e) {
|
|
|
|
#if HOTENDS == 1
|
|
|
|
UNUSED(e);
|
|
|
|
#endif
|
|
|
|
return tooCold(degTargetHotend(HOTEND_INDEX));
|
2016-07-10 04:47:11 +02:00
|
|
|
}
|
2016-04-29 03:18:13 +02:00
|
|
|
#else
|
2018-01-02 01:24:54 +01:00
|
|
|
FORCE_INLINE static bool tooColdToExtrude(const uint8_t e) { UNUSED(e); return false; }
|
|
|
|
FORCE_INLINE static bool targetTooColdToExtrude(const uint8_t e) { UNUSED(e); 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); }
|
|
|
|
|
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
|
|
|
|
|
|
|
|
static volatile bool temp_meas_ready;
|
|
|
|
static uint16_t raw_temp_value[MAX_EXTRUDERS];
|
|
|
|
|
|
|
|
#if WATCH_HOTENDS
|
|
|
|
static uint16_t watch_target_temp[HOTENDS];
|
|
|
|
static millis_t watch_heater_next_ms[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
|
|
|
|
|
|
|
|
#if ENABLED(PIDTEMP)
|
2016-08-01 02:49:34 +02:00
|
|
|
#if ENABLED(PID_EXTRUSION_SCALING)
|
2016-07-12 07:06:44 +02:00
|
|
|
static long last_e_position;
|
2016-05-26 20:58:38 +02:00
|
|
|
static long lpq[LPQ_MAX_LEN];
|
|
|
|
static int lpq_ptr;
|
2016-04-29 03:18:13 +02:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Init min and max temp with extreme values to prevent false errors during startup
|
2017-05-04 00:12:14 +02:00
|
|
|
static int16_t minttemp_raw[HOTENDS],
|
|
|
|
maxttemp_raw[HOTENDS],
|
|
|
|
minttemp[HOTENDS],
|
|
|
|
maxttemp[HOTENDS];
|
2016-04-29 03:18:13 +02:00
|
|
|
|
2018-04-24 00:13:01 +02:00
|
|
|
#if HAS_HEATED_BED
|
|
|
|
static uint16_t raw_temp_bed_value;
|
|
|
|
#if WATCH_THE_BED
|
|
|
|
static uint16_t watch_target_bed_temp;
|
|
|
|
static millis_t watch_bed_next_ms;
|
|
|
|
#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
|
|
|
|
#if HEATER_IDLE_HANDLER
|
|
|
|
static millis_t bed_idle_timeout_ms;
|
|
|
|
static bool bed_idle_timeout_exceeded;
|
|
|
|
#endif
|
|
|
|
#ifdef BED_MINTEMP
|
|
|
|
static int16_t bed_minttemp_raw;
|
|
|
|
#endif
|
|
|
|
#ifdef BED_MAXTEMP
|
|
|
|
static int16_t bed_maxttemp_raw;
|
|
|
|
#endif
|
2016-07-09 04:28:37 +02:00
|
|
|
#endif
|
|
|
|
|
2018-04-24 00:13:01 +02:00
|
|
|
#if HAS_TEMP_CHAMBER
|
|
|
|
static uint16_t raw_temp_chamber_value;
|
2018-04-24 14:55:58 +02:00
|
|
|
static float current_temperature_chamber;
|
|
|
|
static int16_t current_temperature_chamber_raw;
|
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 ENABLED(FILAMENT_WIDTH_SENSOR)
|
2017-06-23 21:48:02 +02:00
|
|
|
static int8_t meas_shift_index; // Index of a delayed sample in buffer
|
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
|
|
|
|
|
|
|
|
#if ENABLED(FILAMENT_WIDTH_SENSOR)
|
2017-06-23 21:48:02 +02:00
|
|
|
static uint16_t current_raw_filwidth; // Measured filament diameter - one extruder only
|
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
|
|
|
|
2017-06-12 07:22:31 +02:00
|
|
|
#if HEATER_IDLE_HANDLER
|
2017-05-26 20:01:02 +02:00
|
|
|
static millis_t heater_idle_timeout_ms[HOTENDS];
|
|
|
|
static bool heater_idle_timeout_exceeded[HOTENDS];
|
2017-05-07 13:06:06 +02:00
|
|
|
#endif
|
|
|
|
|
2016-04-29 03:18:13 +02:00
|
|
|
public:
|
2017-06-10 07:12:18 +02:00
|
|
|
#if ENABLED(ADC_KEYPAD)
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
|
|
|
|
Temperature();
|
|
|
|
|
|
|
|
void init();
|
|
|
|
|
2016-05-26 20:58:38 +02:00
|
|
|
/**
|
|
|
|
* Static (class) methods
|
|
|
|
*/
|
2018-01-02 01:24:54 +01:00
|
|
|
static float analog2temp(const int raw, const uint8_t e);
|
|
|
|
|
2018-04-24 00:13:01 +02:00
|
|
|
#if HAS_HEATED_BED
|
2018-01-02 01:24:54 +01:00
|
|
|
static float analog2tempBed(const int raw);
|
|
|
|
#endif
|
2018-02-24 07:38:58 +01:00
|
|
|
#if HAS_TEMP_CHAMBER
|
|
|
|
static float analog2tempChamber(const int raw);
|
|
|
|
#endif
|
2016-05-26 20:58:38 +02:00
|
|
|
|
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();
|
2016-05-26 20:58:38 +02:00
|
|
|
static void isr();
|
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
|
2018-01-02 01:24:54 +01:00
|
|
|
static bool is_preheating(const uint8_t e) {
|
2016-07-12 07:08:47 +02:00
|
|
|
#if HOTENDS == 1
|
|
|
|
UNUSED(e);
|
|
|
|
#endif
|
|
|
|
return preheat_end_time[HOTEND_INDEX] && PENDING(millis(), preheat_end_time[HOTEND_INDEX]);
|
|
|
|
}
|
2018-01-02 01:24:54 +01:00
|
|
|
static void start_preheat_time(const uint8_t e) {
|
2016-07-12 07:08:47 +02:00
|
|
|
#if HOTENDS == 1
|
|
|
|
UNUSED(e);
|
|
|
|
#endif
|
|
|
|
preheat_end_time[HOTEND_INDEX] = millis() + MILLISECONDS_PREHEAT_TIME;
|
|
|
|
}
|
2018-01-02 01:24:54 +01:00
|
|
|
static void reset_preheat_time(const uint8_t e) {
|
2016-07-12 07:08:47 +02:00
|
|
|
#if HOTENDS == 1
|
|
|
|
UNUSED(e);
|
|
|
|
#endif
|
|
|
|
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
|
|
|
#if ENABLED(FILAMENT_WIDTH_SENSOR)
|
2017-12-13 09:32:34 +01:00
|
|
|
static float analog2widthFil(); // Convert raw Filament Width to millimeters
|
|
|
|
static int8_t widthFil_to_size_ratio(); // Convert Filament Width (mm) to an extrusion ratio
|
2016-04-29 03:18:13 +02:00
|
|
|
#endif
|
|
|
|
|
2018-01-02 01:24:54 +01:00
|
|
|
|
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
|
|
|
|
|
2018-01-02 01:24:54 +01:00
|
|
|
FORCE_INLINE static float degHotend(const uint8_t e) {
|
2016-05-27 02:43:20 +02:00
|
|
|
#if HOTENDS == 1
|
2016-07-10 06:11:17 +02:00
|
|
|
UNUSED(e);
|
2016-05-27 02:43:20 +02:00
|
|
|
#endif
|
2016-07-10 06:11:17 +02:00
|
|
|
return current_temperature[HOTEND_INDEX];
|
2016-05-27 02:43:20 +02:00
|
|
|
}
|
2016-04-29 03:18:13 +02:00
|
|
|
|
|
|
|
#if ENABLED(SHOW_TEMP_ADC_VALUES)
|
2018-01-02 01:24:54 +01:00
|
|
|
FORCE_INLINE static int16_t rawHotendTemp(const uint8_t e) {
|
2017-05-04 00:12:14 +02:00
|
|
|
#if HOTENDS == 1
|
|
|
|
UNUSED(e);
|
|
|
|
#endif
|
|
|
|
return current_temperature_raw[HOTEND_INDEX];
|
|
|
|
}
|
2016-04-29 03:18:13 +02:00
|
|
|
#endif
|
|
|
|
|
2018-01-02 01:24:54 +01:00
|
|
|
FORCE_INLINE static int16_t degTargetHotend(const uint8_t e) {
|
2016-05-27 02:43:20 +02:00
|
|
|
#if HOTENDS == 1
|
2016-07-10 06:11:17 +02:00
|
|
|
UNUSED(e);
|
2016-05-27 02:43:20 +02:00
|
|
|
#endif
|
2016-07-10 06:11:17 +02:00
|
|
|
return target_temperature[HOTEND_INDEX];
|
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
|
2017-11-16 02:01:52 +01:00
|
|
|
static void start_watching_heater(const uint8_t e = 0);
|
2016-04-29 03:18:13 +02:00
|
|
|
#endif
|
|
|
|
|
2017-11-16 02:01:52 +01:00
|
|
|
static void setTargetHotend(const int16_t celsius, const uint8_t e) {
|
2016-05-27 02:43:20 +02:00
|
|
|
#if HOTENDS == 1
|
2016-07-10 06:11:17 +02:00
|
|
|
UNUSED(e);
|
2016-05-27 02:43:20 +02:00
|
|
|
#endif
|
2016-07-09 04:28:37 +02:00
|
|
|
#ifdef MILLISECONDS_PREHEAT_TIME
|
2017-05-04 00:12:14 +02:00
|
|
|
if (celsius == 0)
|
2016-07-12 07:07:43 +02:00
|
|
|
reset_preheat_time(HOTEND_INDEX);
|
2017-05-04 00:12:14 +02:00
|
|
|
else if (target_temperature[HOTEND_INDEX] == 0)
|
2016-07-12 07:07:43 +02:00
|
|
|
start_preheat_time(HOTEND_INDEX);
|
2016-07-09 04:28:37 +02:00
|
|
|
#endif
|
2018-02-06 07:22:30 +01:00
|
|
|
#if ENABLED(AUTO_POWER_CONTROL)
|
|
|
|
powerManager.power_on();
|
|
|
|
#endif
|
2016-07-10 06:11:17 +02:00
|
|
|
target_temperature[HOTEND_INDEX] = celsius;
|
2017-04-02 18:48:10 +02:00
|
|
|
#if WATCH_HOTENDS
|
2016-07-10 06:11:17 +02:00
|
|
|
start_watching_heater(HOTEND_INDEX);
|
2016-04-29 03:18:13 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-04-24 00:13:01 +02:00
|
|
|
FORCE_INLINE static bool isHeatingHotend(const uint8_t e) {
|
|
|
|
#if HOTENDS == 1
|
|
|
|
UNUSED(e);
|
|
|
|
#endif
|
|
|
|
return target_temperature[HOTEND_INDEX] > current_temperature[HOTEND_INDEX];
|
|
|
|
}
|
|
|
|
|
|
|
|
FORCE_INLINE static bool isCoolingHotend(const uint8_t e) {
|
|
|
|
#if HOTENDS == 1
|
|
|
|
UNUSED(e);
|
|
|
|
#endif
|
|
|
|
return target_temperature[HOTEND_INDEX] < current_temperature[HOTEND_INDEX];
|
|
|
|
}
|
|
|
|
|
2018-09-29 08:44:47 +02:00
|
|
|
#if HAS_TEMP_HOTEND
|
|
|
|
static bool wait_for_hotend(const uint8_t target_extruder, const bool no_wait_for_cooling=true);
|
|
|
|
#endif
|
|
|
|
|
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)
|
|
|
|
FORCE_INLINE static int16_t rawBedTemp() { return current_temperature_bed_raw; }
|
|
|
|
#endif
|
|
|
|
FORCE_INLINE static float degBed() { return current_temperature_bed; }
|
|
|
|
FORCE_INLINE static int16_t degTargetBed() { return target_temperature_bed; }
|
|
|
|
FORCE_INLINE static bool isHeatingBed() { return target_temperature_bed > current_temperature_bed; }
|
|
|
|
FORCE_INLINE static bool isCoolingBed() { return target_temperature_bed < current_temperature_bed; }
|
|
|
|
|
|
|
|
static void setTargetBed(const int16_t celsius) {
|
2018-02-06 07:22:30 +01:00
|
|
|
#if ENABLED(AUTO_POWER_CONTROL)
|
|
|
|
powerManager.power_on();
|
|
|
|
#endif
|
2017-05-28 18:11:17 +02:00
|
|
|
target_temperature_bed =
|
|
|
|
#ifdef BED_MAXTEMP
|
2018-05-13 08:10:34 +02:00
|
|
|
MIN(celsius, BED_MAXTEMP)
|
2017-05-28 18:11:17 +02:00
|
|
|
#else
|
|
|
|
celsius
|
|
|
|
#endif
|
|
|
|
;
|
|
|
|
#if WATCH_THE_BED
|
|
|
|
start_watching_bed();
|
|
|
|
#endif
|
2018-04-24 00:13:01 +02:00
|
|
|
}
|
2016-04-29 03:18:13 +02:00
|
|
|
|
2018-04-24 00:13:01 +02:00
|
|
|
#if WATCH_THE_BED
|
|
|
|
static void start_watching_bed();
|
2016-05-27 02:43:20 +02:00
|
|
|
#endif
|
2018-09-29 08:44:47 +02:00
|
|
|
|
|
|
|
static void wait_for_bed(const bool no_wait_for_cooling);
|
|
|
|
|
|
|
|
#endif // HAS_HEATED_BED
|
2016-04-29 03:18:13 +02:00
|
|
|
|
2018-04-24 00:13:01 +02:00
|
|
|
#if HAS_TEMP_CHAMBER
|
|
|
|
#if ENABLED(SHOW_TEMP_ADC_VALUES)
|
|
|
|
FORCE_INLINE static int16_t rawChamberTemp() { return current_temperature_chamber_raw; }
|
2016-05-27 02:43:20 +02:00
|
|
|
#endif
|
2018-04-24 00:13:01 +02:00
|
|
|
FORCE_INLINE static float degChamber() { return current_temperature_chamber; }
|
|
|
|
#endif
|
2018-01-02 01:24:54 +01:00
|
|
|
|
2018-09-29 08:44:47 +02:00
|
|
|
FORCE_INLINE static bool still_heating(const uint8_t e) {
|
2018-05-13 08:10:34 +02:00
|
|
|
return degTargetHotend(e) > TEMP_HYSTERESIS && ABS(degHotend(e) - degTargetHotend(e)) > TEMP_HYSTERESIS;
|
2018-01-02 01:24:54 +01:00
|
|
|
}
|
2016-04-29 03:18:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The software PWM power for a heater
|
|
|
|
*/
|
2018-04-24 00:13:01 +02:00
|
|
|
static int getHeaterPower(const int 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
|
|
|
|
|
|
|
/**
|
|
|
|
* Perform auto-tuning for hotend or bed in response to M303
|
|
|
|
*/
|
|
|
|
#if HAS_PID_HEATING
|
2018-01-04 04:30:45 +01:00
|
|
|
static void PID_autotune(const float &target, const int8_t hotend, const int8_t ncycles, const bool set_result=false);
|
2016-04-29 03:18:13 +02:00
|
|
|
|
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
|
|
|
|
2016-05-05 23:57:24 +02:00
|
|
|
#if ENABLED(BABYSTEPPING)
|
|
|
|
|
2017-10-16 23:29:37 +02:00
|
|
|
static void babystep_axis(const AxisEnum axis, const int16_t distance) {
|
2018-06-12 04:29:31 +02:00
|
|
|
if (TEST(axis_known_position, axis)) {
|
2017-04-16 06:15:13 +02:00
|
|
|
#if IS_CORE
|
|
|
|
#if ENABLED(BABYSTEP_XY)
|
|
|
|
switch (axis) {
|
|
|
|
case CORE_AXIS_1: // X on CoreXY and CoreXZ, Y on CoreYZ
|
|
|
|
babystepsTodo[CORE_AXIS_1] += distance * 2;
|
|
|
|
babystepsTodo[CORE_AXIS_2] += distance * 2;
|
|
|
|
break;
|
|
|
|
case CORE_AXIS_2: // Y on CoreXY, Z on CoreXZ and CoreYZ
|
|
|
|
babystepsTodo[CORE_AXIS_1] += CORESIGN(distance * 2);
|
|
|
|
babystepsTodo[CORE_AXIS_2] -= CORESIGN(distance * 2);
|
|
|
|
break;
|
|
|
|
case NORMAL_AXIS: // Z on CoreXY, Y on CoreXZ, X on CoreYZ
|
2018-10-07 02:29:22 +02:00
|
|
|
default:
|
2017-04-16 06:15:13 +02:00
|
|
|
babystepsTodo[NORMAL_AXIS] += distance;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#elif CORE_IS_XZ || CORE_IS_YZ
|
|
|
|
// Only Z stepping needs to be handled here
|
|
|
|
babystepsTodo[CORE_AXIS_1] += CORESIGN(distance * 2);
|
|
|
|
babystepsTodo[CORE_AXIS_2] -= CORESIGN(distance * 2);
|
|
|
|
#else
|
|
|
|
babystepsTodo[Z_AXIS] += distance;
|
|
|
|
#endif
|
2016-05-05 23:57:24 +02:00
|
|
|
#else
|
2017-04-16 06:15:13 +02:00
|
|
|
babystepsTodo[axis] += distance;
|
2016-05-05 23:57:24 +02:00
|
|
|
#endif
|
2017-04-16 06:15:13 +02:00
|
|
|
}
|
2016-05-05 23:57:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // BABYSTEPPING
|
|
|
|
|
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
|
|
|
|
|
|
|
static void start_heater_idle_timer(const uint8_t e, const millis_t timeout_ms) {
|
2017-05-26 20:01:02 +02:00
|
|
|
#if HOTENDS == 1
|
|
|
|
UNUSED(e);
|
|
|
|
#endif
|
|
|
|
heater_idle_timeout_ms[HOTEND_INDEX] = millis() + timeout_ms;
|
|
|
|
heater_idle_timeout_exceeded[HOTEND_INDEX] = false;
|
|
|
|
}
|
|
|
|
|
2018-01-02 01:24:54 +01:00
|
|
|
static void reset_heater_idle_timer(const uint8_t e) {
|
2017-05-26 20:01:02 +02:00
|
|
|
#if HOTENDS == 1
|
|
|
|
UNUSED(e);
|
|
|
|
#endif
|
|
|
|
heater_idle_timeout_ms[HOTEND_INDEX] = 0;
|
|
|
|
heater_idle_timeout_exceeded[HOTEND_INDEX] = false;
|
|
|
|
#if WATCH_HOTENDS
|
|
|
|
start_watching_heater(HOTEND_INDEX);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-01-02 01:24:54 +01:00
|
|
|
FORCE_INLINE static bool is_heater_idle(const uint8_t e) {
|
2017-05-26 20:01:02 +02:00
|
|
|
#if HOTENDS == 1
|
|
|
|
UNUSED(e);
|
|
|
|
#endif
|
|
|
|
return heater_idle_timeout_exceeded[HOTEND_INDEX];
|
|
|
|
}
|
|
|
|
|
2018-04-24 00:13:01 +02:00
|
|
|
#if HAS_HEATED_BED
|
2018-01-02 01:24:54 +01:00
|
|
|
static void start_bed_idle_timer(const millis_t timeout_ms) {
|
2017-05-26 20:01:02 +02:00
|
|
|
bed_idle_timeout_ms = millis() + timeout_ms;
|
|
|
|
bed_idle_timeout_exceeded = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void reset_bed_idle_timer() {
|
|
|
|
bed_idle_timeout_ms = 0;
|
|
|
|
bed_idle_timeout_exceeded = false;
|
|
|
|
#if WATCH_THE_BED
|
|
|
|
start_watching_bed();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-01-02 01:24:54 +01:00
|
|
|
FORCE_INLINE static bool is_bed_idle() { return bed_idle_timeout_exceeded; }
|
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
|
2017-11-05 15:49:38 +01:00
|
|
|
static void print_heaterstates(
|
|
|
|
#if NUM_SERIAL > 1
|
|
|
|
const int8_t port = -1
|
|
|
|
#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;
|
|
|
|
static void auto_report_temperatures(void);
|
|
|
|
FORCE_INLINE void set_auto_report_interval(uint8_t v) {
|
|
|
|
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
|
|
|
|
|
2018-10-08 00:06:14 +02:00
|
|
|
#if ENABLED(ULTRA_LCD)
|
|
|
|
static void set_heating_message(const uint8_t e);
|
|
|
|
#endif
|
|
|
|
|
2016-04-29 03:18:13 +02:00
|
|
|
private:
|
|
|
|
|
2017-09-06 13:28:32 +02:00
|
|
|
#if ENABLED(FAST_PWM_FAN)
|
2017-11-20 10:49:21 +01:00
|
|
|
static void setPwmFrequency(const pin_t pin, int val);
|
2017-09-06 13:28:32 +02:00
|
|
|
#endif
|
|
|
|
|
2016-05-26 20:58:38 +02:00
|
|
|
static void set_current_temp_raw();
|
2016-04-29 03:18:13 +02:00
|
|
|
|
2016-05-26 20:58:38 +02:00
|
|
|
static void updateTemperaturesFromRawValues();
|
2016-04-29 03:18:13 +02:00
|
|
|
|
|
|
|
#if ENABLED(HEATER_0_USES_MAX6675)
|
2016-05-26 20:58:38 +02:00
|
|
|
static int read_max6675();
|
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
|
|
|
|
2017-06-15 22:14:08 +02:00
|
|
|
static float get_pid_output(const int8_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
|
|
|
|
|
2018-10-01 06:44:33 +02:00
|
|
|
static void _temp_error(const int8_t e, PGM_P const serial_msg, PGM_P const lcd_msg);
|
2017-06-15 22:14:08 +02:00
|
|
|
static void min_temp_error(const int8_t e);
|
|
|
|
static void max_temp_error(const int8_t e);
|
2016-04-29 03:18:13 +02:00
|
|
|
|
|
|
|
#if ENABLED(THERMAL_PROTECTION_HOTENDS) || HAS_THERMALLY_PROTECTED_BED
|
|
|
|
|
2018-04-24 00:13:01 +02:00
|
|
|
enum TRState : char { TRInactive, TRFirstHeating, TRStable, TRRunaway };
|
2016-04-29 03:18:13 +02:00
|
|
|
|
2018-01-02 01:24:54 +01:00
|
|
|
static void thermal_runaway_protection(TRState * const state, millis_t * const timer, const float ¤t, const float &target, const int8_t heater_id, const uint16_t period_seconds, const uint16_t hysteresis_degc);
|
2016-04-29 03:18:13 +02:00
|
|
|
|
|
|
|
#if ENABLED(THERMAL_PROTECTION_HOTENDS)
|
2016-05-27 02:43:20 +02:00
|
|
|
static TRState thermal_runaway_state_machine[HOTENDS];
|
|
|
|
static millis_t thermal_runaway_timer[HOTENDS];
|
2016-04-29 03:18:13 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAS_THERMALLY_PROTECTED_BED
|
2016-05-26 20:58:38 +02:00
|
|
|
static TRState thermal_runaway_bed_state_machine;
|
|
|
|
static millis_t thermal_runaway_bed_timer;
|
2016-04-29 03:18:13 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif // THERMAL_PROTECTION
|
|
|
|
};
|
|
|
|
|
|
|
|
extern Temperature thermalManager;
|
2012-03-08 21:43:21 +01:00
|
|
|
|
2015-04-02 14:10:14 +02:00
|
|
|
#endif // TEMPERATURE_H
|