temperature.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * temperature.h - temperature controller
  24. */
  25. #ifndef TEMPERATURE_H
  26. #define TEMPERATURE_H
  27. #include "thermistortables.h"
  28. #include "MarlinConfig.h"
  29. #if ENABLED(AUTO_POWER_CONTROL)
  30. #include "power.h"
  31. #endif
  32. #if ENABLED(PID_EXTRUSION_SCALING)
  33. #include "stepper.h"
  34. #endif
  35. #ifndef SOFT_PWM_SCALE
  36. #define SOFT_PWM_SCALE 0
  37. #endif
  38. #define ENABLE_TEMPERATURE_INTERRUPT() SBI(TIMSK0, OCIE0B)
  39. #define DISABLE_TEMPERATURE_INTERRUPT() CBI(TIMSK0, OCIE0B)
  40. #define TEMPERATURE_ISR_ENABLED() TEST(TIMSK0, OCIE0B)
  41. #define HOTEND_LOOP() for (int8_t e = 0; e < HOTENDS; e++)
  42. #if HOTENDS == 1
  43. #define HOTEND_INDEX 0
  44. #else
  45. #define HOTEND_INDEX e
  46. #endif
  47. /**
  48. * States for ADC reading in the ISR
  49. */
  50. enum ADCSensorState : char {
  51. StartSampling,
  52. #if HAS_TEMP_ADC_0
  53. PrepareTemp_0,
  54. MeasureTemp_0,
  55. #endif
  56. #if HAS_TEMP_ADC_1
  57. PrepareTemp_1,
  58. MeasureTemp_1,
  59. #endif
  60. #if HAS_TEMP_ADC_2
  61. PrepareTemp_2,
  62. MeasureTemp_2,
  63. #endif
  64. #if HAS_TEMP_ADC_3
  65. PrepareTemp_3,
  66. MeasureTemp_3,
  67. #endif
  68. #if HAS_TEMP_ADC_4
  69. PrepareTemp_4,
  70. MeasureTemp_4,
  71. #endif
  72. #if HAS_HEATED_BED
  73. PrepareTemp_BED,
  74. MeasureTemp_BED,
  75. #endif
  76. #if HAS_TEMP_CHAMBER
  77. PrepareTemp_CHAMBER,
  78. MeasureTemp_CHAMBER,
  79. #endif
  80. #if ENABLED(FILAMENT_WIDTH_SENSOR)
  81. Prepare_FILWIDTH,
  82. Measure_FILWIDTH,
  83. #endif
  84. #if ENABLED(ADC_KEYPAD)
  85. Prepare_ADC_KEY,
  86. Measure_ADC_KEY,
  87. #endif
  88. SensorsReady, // Temperatures ready. Delay the next round of readings to let ADC pins settle.
  89. StartupDelay // Startup, delay initial temp reading a tiny bit so the hardware can settle
  90. };
  91. // Minimum number of Temperature::ISR loops between sensor readings.
  92. // Multiplied by 16 (OVERSAMPLENR) to obtain the total time to
  93. // get all oversampled sensor readings
  94. #define MIN_ADC_ISR_LOOPS 10
  95. #define ACTUAL_ADC_SAMPLES MAX(int(MIN_ADC_ISR_LOOPS), int(SensorsReady))
  96. #if HAS_PID_HEATING
  97. #define PID_K2 (1.0f-PID_K1)
  98. #define PID_dT ((OVERSAMPLENR * float(ACTUAL_ADC_SAMPLES)) / (F_CPU / 64.0f / 256.0f))
  99. // Apply the scale factors to the PID values
  100. #define scalePID_i(i) ( (i) * float(PID_dT) )
  101. #define unscalePID_i(i) ( (i) / float(PID_dT) )
  102. #define scalePID_d(d) ( (d) / float(PID_dT) )
  103. #define unscalePID_d(d) ( (d) * float(PID_dT) )
  104. #endif
  105. class Temperature {
  106. public:
  107. static float current_temperature[HOTENDS];
  108. static int16_t current_temperature_raw[HOTENDS],
  109. target_temperature[HOTENDS];
  110. static uint8_t soft_pwm_amount[HOTENDS];
  111. #if ENABLED(AUTO_POWER_E_FANS)
  112. static int16_t autofan_speed[HOTENDS];
  113. #endif
  114. #if ENABLED(FAN_SOFT_PWM)
  115. static uint8_t soft_pwm_amount_fan[FAN_COUNT],
  116. soft_pwm_count_fan[FAN_COUNT];
  117. #endif
  118. #if ENABLED(PIDTEMP)
  119. #if ENABLED(PID_PARAMS_PER_HOTEND) && HOTENDS > 1
  120. static float Kp[HOTENDS], Ki[HOTENDS], Kd[HOTENDS];
  121. #if ENABLED(PID_EXTRUSION_SCALING)
  122. static float Kc[HOTENDS];
  123. #endif
  124. #define PID_PARAM(param, h) Temperature::param[h]
  125. #else
  126. static float Kp, Ki, Kd;
  127. #if ENABLED(PID_EXTRUSION_SCALING)
  128. static float Kc;
  129. #endif
  130. #define PID_PARAM(param, h) Temperature::param
  131. #endif // PID_PARAMS_PER_HOTEND
  132. #endif
  133. #if HAS_HEATED_BED
  134. static float current_temperature_bed;
  135. static int16_t current_temperature_bed_raw, target_temperature_bed;
  136. static uint8_t soft_pwm_amount_bed;
  137. #if ENABLED(PIDTEMPBED)
  138. static float bedKp, bedKi, bedKd;
  139. #endif
  140. #endif
  141. #if ENABLED(BABYSTEPPING)
  142. static volatile int babystepsTodo[3];
  143. #endif
  144. #if ENABLED(PREVENT_COLD_EXTRUSION)
  145. static bool allow_cold_extrude;
  146. static int16_t extrude_min_temp;
  147. FORCE_INLINE static bool tooCold(const int16_t temp) { return allow_cold_extrude ? false : temp < extrude_min_temp; }
  148. FORCE_INLINE static bool tooColdToExtrude(const uint8_t e) {
  149. #if HOTENDS == 1
  150. UNUSED(e);
  151. #endif
  152. return tooCold(degHotend(HOTEND_INDEX));
  153. }
  154. FORCE_INLINE static bool targetTooColdToExtrude(const uint8_t e) {
  155. #if HOTENDS == 1
  156. UNUSED(e);
  157. #endif
  158. return tooCold(degTargetHotend(HOTEND_INDEX));
  159. }
  160. #else
  161. FORCE_INLINE static bool tooColdToExtrude(const uint8_t e) { UNUSED(e); return false; }
  162. FORCE_INLINE static bool targetTooColdToExtrude(const uint8_t e) { UNUSED(e); return false; }
  163. #endif
  164. FORCE_INLINE static bool hotEnoughToExtrude(const uint8_t e) { return !tooColdToExtrude(e); }
  165. FORCE_INLINE static bool targetHotEnoughToExtrude(const uint8_t e) { return !targetTooColdToExtrude(e); }
  166. private:
  167. static volatile bool temp_meas_ready;
  168. static uint16_t raw_temp_value[MAX_EXTRUDERS];
  169. #if WATCH_HOTENDS
  170. static uint16_t watch_target_temp[HOTENDS];
  171. static millis_t watch_heater_next_ms[HOTENDS];
  172. #endif
  173. #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
  174. static uint16_t redundant_temperature_raw;
  175. static float redundant_temperature;
  176. #endif
  177. #if ENABLED(PIDTEMP)
  178. static float temp_iState[HOTENDS],
  179. temp_dState[HOTENDS],
  180. pTerm[HOTENDS],
  181. iTerm[HOTENDS],
  182. dTerm[HOTENDS];
  183. #if ENABLED(PID_EXTRUSION_SCALING)
  184. static float cTerm[HOTENDS];
  185. static long last_e_position;
  186. static long lpq[LPQ_MAX_LEN];
  187. static int lpq_ptr;
  188. #endif
  189. static float pid_error[HOTENDS];
  190. static bool pid_reset[HOTENDS];
  191. #endif
  192. // Init min and max temp with extreme values to prevent false errors during startup
  193. static int16_t minttemp_raw[HOTENDS],
  194. maxttemp_raw[HOTENDS],
  195. minttemp[HOTENDS],
  196. maxttemp[HOTENDS];
  197. #if HAS_HEATED_BED
  198. static uint16_t raw_temp_bed_value;
  199. #if WATCH_THE_BED
  200. static uint16_t watch_target_bed_temp;
  201. static millis_t watch_bed_next_ms;
  202. #endif
  203. #if ENABLED(PIDTEMPBED)
  204. static float temp_iState_bed,
  205. temp_dState_bed,
  206. pTerm_bed,
  207. iTerm_bed,
  208. dTerm_bed,
  209. pid_error_bed;
  210. #else
  211. static millis_t next_bed_check_ms;
  212. #endif
  213. #if HEATER_IDLE_HANDLER
  214. static millis_t bed_idle_timeout_ms;
  215. static bool bed_idle_timeout_exceeded;
  216. #endif
  217. #ifdef BED_MINTEMP
  218. static int16_t bed_minttemp_raw;
  219. #endif
  220. #ifdef BED_MAXTEMP
  221. static int16_t bed_maxttemp_raw;
  222. #endif
  223. #endif
  224. #if HAS_TEMP_CHAMBER
  225. static uint16_t raw_temp_chamber_value;
  226. static float current_temperature_chamber;
  227. static int16_t current_temperature_chamber_raw;
  228. #endif
  229. #ifdef MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED
  230. static uint8_t consecutive_low_temperature_error[HOTENDS];
  231. #endif
  232. #ifdef MILLISECONDS_PREHEAT_TIME
  233. static millis_t preheat_end_time[HOTENDS];
  234. #endif
  235. #if ENABLED(FILAMENT_WIDTH_SENSOR)
  236. static int8_t meas_shift_index; // Index of a delayed sample in buffer
  237. #endif
  238. #if HAS_AUTO_FAN
  239. static millis_t next_auto_fan_check_ms;
  240. #endif
  241. #if ENABLED(FILAMENT_WIDTH_SENSOR)
  242. static uint16_t current_raw_filwidth; // Measured filament diameter - one extruder only
  243. #endif
  244. #if ENABLED(PROBING_HEATERS_OFF)
  245. static bool paused;
  246. #endif
  247. #if HEATER_IDLE_HANDLER
  248. static millis_t heater_idle_timeout_ms[HOTENDS];
  249. static bool heater_idle_timeout_exceeded[HOTENDS];
  250. #endif
  251. public:
  252. #if ENABLED(ADC_KEYPAD)
  253. static uint32_t current_ADCKey_raw;
  254. static uint8_t ADCKey_count;
  255. #endif
  256. #if ENABLED(PID_EXTRUSION_SCALING)
  257. static int16_t lpq_len;
  258. #endif
  259. /**
  260. * Instance Methods
  261. */
  262. Temperature();
  263. void init();
  264. /**
  265. * Static (class) methods
  266. */
  267. static float analog_to_celsius_hotend(const int raw, const uint8_t e);
  268. #if HAS_HEATED_BED
  269. static float analog_to_celsius_bed(const int raw);
  270. #endif
  271. #if HAS_TEMP_CHAMBER
  272. static float analog_to_celsius_chamber(const int raw);
  273. #endif
  274. /**
  275. * Called from the Temperature ISR
  276. */
  277. static void readings_ready();
  278. static void isr();
  279. /**
  280. * Call periodically to manage heaters
  281. */
  282. static void manage_heater() _O2; // Added _O2 to work around a compiler error
  283. /**
  284. * Preheating hotends
  285. */
  286. #ifdef MILLISECONDS_PREHEAT_TIME
  287. static bool is_preheating(const uint8_t e) {
  288. #if HOTENDS == 1
  289. UNUSED(e);
  290. #endif
  291. return preheat_end_time[HOTEND_INDEX] && PENDING(millis(), preheat_end_time[HOTEND_INDEX]);
  292. }
  293. static void start_preheat_time(const uint8_t e) {
  294. #if HOTENDS == 1
  295. UNUSED(e);
  296. #endif
  297. preheat_end_time[HOTEND_INDEX] = millis() + MILLISECONDS_PREHEAT_TIME;
  298. }
  299. static void reset_preheat_time(const uint8_t e) {
  300. #if HOTENDS == 1
  301. UNUSED(e);
  302. #endif
  303. preheat_end_time[HOTEND_INDEX] = 0;
  304. }
  305. #else
  306. #define is_preheating(n) (false)
  307. #endif
  308. #if ENABLED(FILAMENT_WIDTH_SENSOR)
  309. static float analog_to_mm_fil_width(); // Convert raw Filament Width to millimeters
  310. static int8_t widthFil_to_size_ratio(); // Convert Filament Width (mm) to an extrusion ratio
  311. #endif
  312. //high level conversion routines, for use outside of temperature.cpp
  313. //inline so that there is no performance decrease.
  314. //deg=degreeCelsius
  315. FORCE_INLINE static float degHotend(const uint8_t e) {
  316. #if HOTENDS == 1
  317. UNUSED(e);
  318. #endif
  319. return current_temperature[HOTEND_INDEX];
  320. }
  321. #if ENABLED(SHOW_TEMP_ADC_VALUES)
  322. FORCE_INLINE static int16_t rawHotendTemp(const uint8_t e) {
  323. #if HOTENDS == 1
  324. UNUSED(e);
  325. #endif
  326. return current_temperature_raw[HOTEND_INDEX];
  327. }
  328. #endif
  329. FORCE_INLINE static int16_t degTargetHotend(const uint8_t e) {
  330. #if HOTENDS == 1
  331. UNUSED(e);
  332. #endif
  333. return target_temperature[HOTEND_INDEX];
  334. }
  335. #if WATCH_HOTENDS
  336. static void start_watching_heater(const uint8_t e = 0);
  337. #endif
  338. static void setTargetHotend(const int16_t celsius, const uint8_t e) {
  339. #if HOTENDS == 1
  340. UNUSED(e);
  341. #endif
  342. #ifdef MILLISECONDS_PREHEAT_TIME
  343. if (celsius == 0)
  344. reset_preheat_time(HOTEND_INDEX);
  345. else if (target_temperature[HOTEND_INDEX] == 0)
  346. start_preheat_time(HOTEND_INDEX);
  347. #endif
  348. #if ENABLED(AUTO_POWER_CONTROL)
  349. powerManager.power_on();
  350. #endif
  351. target_temperature[HOTEND_INDEX] = MIN(celsius, maxttemp[HOTEND_INDEX] - 15);
  352. #if WATCH_HOTENDS
  353. start_watching_heater(HOTEND_INDEX);
  354. #endif
  355. }
  356. FORCE_INLINE static bool isHeatingHotend(const uint8_t e) {
  357. #if HOTENDS == 1
  358. UNUSED(e);
  359. #endif
  360. return target_temperature[HOTEND_INDEX] > current_temperature[HOTEND_INDEX];
  361. }
  362. FORCE_INLINE static bool isCoolingHotend(const uint8_t e) {
  363. #if HOTENDS == 1
  364. UNUSED(e);
  365. #endif
  366. return target_temperature[HOTEND_INDEX] < current_temperature[HOTEND_INDEX];
  367. }
  368. #if HAS_HEATED_BED
  369. #if ENABLED(SHOW_TEMP_ADC_VALUES)
  370. FORCE_INLINE static int16_t rawBedTemp() { return current_temperature_bed_raw; }
  371. #endif
  372. FORCE_INLINE static float degBed() { return current_temperature_bed; }
  373. FORCE_INLINE static int16_t degTargetBed() { return target_temperature_bed; }
  374. FORCE_INLINE static bool isHeatingBed() { return target_temperature_bed > current_temperature_bed; }
  375. FORCE_INLINE static bool isCoolingBed() { return target_temperature_bed < current_temperature_bed; }
  376. static void setTargetBed(const int16_t celsius) {
  377. #if ENABLED(AUTO_POWER_CONTROL)
  378. powerManager.power_on();
  379. #endif
  380. target_temperature_bed =
  381. #ifdef BED_MAXTEMP
  382. MIN(celsius, BED_MAXTEMP - 15)
  383. #else
  384. celsius
  385. #endif
  386. ;
  387. #if WATCH_THE_BED
  388. start_watching_bed();
  389. #endif
  390. }
  391. #if WATCH_THE_BED
  392. static void start_watching_bed();
  393. #endif
  394. #endif
  395. #if HAS_TEMP_CHAMBER
  396. #if ENABLED(SHOW_TEMP_ADC_VALUES)
  397. FORCE_INLINE static int16_t rawChamberTemp() { return current_temperature_chamber_raw; }
  398. #endif
  399. FORCE_INLINE static float degChamber() { return current_temperature_chamber; }
  400. #endif
  401. FORCE_INLINE static bool wait_for_heating(const uint8_t e) {
  402. return degTargetHotend(e) > TEMP_HYSTERESIS && ABS(degHotend(e) - degTargetHotend(e)) > TEMP_HYSTERESIS;
  403. }
  404. /**
  405. * The software PWM power for a heater
  406. */
  407. static int getHeaterPower(const int heater);
  408. /**
  409. * Switch off all heaters, set all target temperatures to 0
  410. */
  411. static void disable_all_heaters();
  412. /**
  413. * Perform auto-tuning for hotend or bed in response to M303
  414. */
  415. #if HAS_PID_HEATING
  416. static void pid_autotune(const float &target, const int8_t hotend, const int8_t ncycles, const bool set_result=false);
  417. /**
  418. * Update the temp manager when PID values change
  419. */
  420. #if ENABLED(PIDTEMP)
  421. FORCE_INLINE static void update_pid() {
  422. #if ENABLED(PID_EXTRUSION_SCALING)
  423. last_e_position = 0;
  424. #endif
  425. }
  426. #endif
  427. #endif
  428. #if ENABLED(BABYSTEPPING)
  429. static void babystep_axis(const AxisEnum axis, const int16_t distance) {
  430. if (TEST(axis_known_position, axis)) {
  431. #if IS_CORE
  432. #if ENABLED(BABYSTEP_XY)
  433. switch (axis) {
  434. case CORE_AXIS_1: // X on CoreXY and CoreXZ, Y on CoreYZ
  435. babystepsTodo[CORE_AXIS_1] += distance * 2;
  436. babystepsTodo[CORE_AXIS_2] += distance * 2;
  437. break;
  438. case CORE_AXIS_2: // Y on CoreXY, Z on CoreXZ and CoreYZ
  439. babystepsTodo[CORE_AXIS_1] += CORESIGN(distance * 2);
  440. babystepsTodo[CORE_AXIS_2] -= CORESIGN(distance * 2);
  441. break;
  442. case NORMAL_AXIS: // Z on CoreXY, Y on CoreXZ, X on CoreYZ
  443. babystepsTodo[NORMAL_AXIS] += distance;
  444. break;
  445. }
  446. #elif CORE_IS_XZ || CORE_IS_YZ
  447. // Only Z stepping needs to be handled here
  448. babystepsTodo[CORE_AXIS_1] += CORESIGN(distance * 2);
  449. babystepsTodo[CORE_AXIS_2] -= CORESIGN(distance * 2);
  450. #else
  451. babystepsTodo[Z_AXIS] += distance;
  452. #endif
  453. #else
  454. babystepsTodo[axis] += distance;
  455. #endif
  456. }
  457. }
  458. #endif // BABYSTEPPING
  459. #if ENABLED(PROBING_HEATERS_OFF)
  460. static void pause(const bool p);
  461. FORCE_INLINE static bool is_paused() { return paused; }
  462. #endif
  463. #if HEATER_IDLE_HANDLER
  464. static void start_heater_idle_timer(const uint8_t e, const millis_t timeout_ms) {
  465. #if HOTENDS == 1
  466. UNUSED(e);
  467. #endif
  468. heater_idle_timeout_ms[HOTEND_INDEX] = millis() + timeout_ms;
  469. heater_idle_timeout_exceeded[HOTEND_INDEX] = false;
  470. }
  471. static void reset_heater_idle_timer(const uint8_t e) {
  472. #if HOTENDS == 1
  473. UNUSED(e);
  474. #endif
  475. heater_idle_timeout_ms[HOTEND_INDEX] = 0;
  476. heater_idle_timeout_exceeded[HOTEND_INDEX] = false;
  477. #if WATCH_HOTENDS
  478. start_watching_heater(HOTEND_INDEX);
  479. #endif
  480. }
  481. FORCE_INLINE static bool is_heater_idle(const uint8_t e) {
  482. #if HOTENDS == 1
  483. UNUSED(e);
  484. #endif
  485. return heater_idle_timeout_exceeded[HOTEND_INDEX];
  486. }
  487. #if HAS_HEATED_BED
  488. static void start_bed_idle_timer(const millis_t timeout_ms) {
  489. bed_idle_timeout_ms = millis() + timeout_ms;
  490. bed_idle_timeout_exceeded = false;
  491. }
  492. static void reset_bed_idle_timer() {
  493. bed_idle_timeout_ms = 0;
  494. bed_idle_timeout_exceeded = false;
  495. #if WATCH_THE_BED
  496. start_watching_bed();
  497. #endif
  498. }
  499. FORCE_INLINE static bool is_bed_idle() { return bed_idle_timeout_exceeded; }
  500. #endif
  501. #endif // HEATER_IDLE_HANDLER
  502. #if HAS_TEMP_SENSOR
  503. static void print_heaterstates();
  504. #if ENABLED(AUTO_REPORT_TEMPERATURES)
  505. static uint8_t auto_report_temp_interval;
  506. static millis_t next_temp_report_ms;
  507. static void auto_report_temperatures(void);
  508. FORCE_INLINE void set_auto_report_interval(uint8_t v) {
  509. NOMORE(v, 60);
  510. auto_report_temp_interval = v;
  511. next_temp_report_ms = millis() + 1000UL * v;
  512. }
  513. #endif
  514. #endif
  515. private:
  516. #if ENABLED(FAST_PWM_FAN)
  517. static void setPwmFrequency(const pin_t pin, int val);
  518. #endif
  519. static void set_current_temp_raw();
  520. static void calculate_celsius_temperatures();
  521. #if ENABLED(HEATER_0_USES_MAX6675)
  522. static int read_max6675();
  523. #endif
  524. static void check_extruder_auto_fans();
  525. static float get_pid_output(const int8_t e);
  526. #if ENABLED(PIDTEMPBED)
  527. static float get_pid_output_bed();
  528. #endif
  529. static void _temp_error(const int8_t e, const char * const serial_msg, const char * const lcd_msg);
  530. static void min_temp_error(const int8_t e);
  531. static void max_temp_error(const int8_t e);
  532. #if ENABLED(THERMAL_PROTECTION_HOTENDS) || HAS_THERMALLY_PROTECTED_BED
  533. enum TRState : char { TRInactive, TRFirstHeating, TRStable, TRRunaway };
  534. static void thermal_runaway_protection(TRState * const state, millis_t * const timer, const float &current, const float &target, const int8_t heater_id, const uint16_t period_seconds, const uint16_t hysteresis_degc);
  535. #if ENABLED(THERMAL_PROTECTION_HOTENDS)
  536. static TRState thermal_runaway_state_machine[HOTENDS];
  537. static millis_t thermal_runaway_timer[HOTENDS];
  538. #endif
  539. #if HAS_THERMALLY_PROTECTED_BED
  540. static TRState thermal_runaway_bed_state_machine;
  541. static millis_t thermal_runaway_bed_timer;
  542. #endif
  543. #endif // THERMAL_PROTECTION
  544. };
  545. extern Temperature thermalManager;
  546. #endif // TEMPERATURE_H