My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

temperature.cpp 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. /*
  2. temperature.c - temperature control
  3. Part of Marlin
  4. Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. /*
  17. This firmware is a mashup between Sprinter and grbl.
  18. (https://github.com/kliment/Sprinter)
  19. (https://github.com/simen/grbl/tree)
  20. It has preliminary support for Matthew Roberts advance algorithm
  21. http://reprap.org/pipermail/reprap-dev/2011-May/003323.html
  22. This firmware is optimized for gen6 electronics.
  23. */
  24. #include <avr/pgmspace.h>
  25. #include "fastio.h"
  26. #include "Configuration.h"
  27. #include "pins.h"
  28. #include "Marlin.h"
  29. #include "ultralcd.h"
  30. #include "temperature.h"
  31. #include "watchdog.h"
  32. //===========================================================================
  33. //=============================public variables============================
  34. //===========================================================================
  35. int target_raw[3] = {0, 0, 0};
  36. int current_raw[3] = {0, 0, 0};
  37. int heatingtarget_raw[3]= {0, 0, 0};
  38. #ifdef PIDTEMP
  39. // probably used external
  40. float HeaterPower;
  41. float pid_setpoint = 0.0;
  42. float Kp=DEFAULT_Kp;
  43. float Ki=DEFAULT_Ki;
  44. float Kd=DEFAULT_Kd;
  45. #ifdef PID_ADD_EXTRUSION_RATE
  46. float Kc=DEFAULT_Kc;
  47. #endif
  48. #endif //PIDTEMP
  49. //===========================================================================
  50. //=============================private variables============================
  51. //===========================================================================
  52. static bool temp_meas_ready = false;
  53. static unsigned long previous_millis_bed_heater;
  54. //static unsigned long previous_millis_heater;
  55. #ifdef PIDTEMP
  56. //static cannot be external:
  57. static float temp_iState = 0;
  58. static float temp_dState = 0;
  59. static float pTerm;
  60. static float iTerm;
  61. static float dTerm;
  62. //int output;
  63. static float pid_error;
  64. static float temp_iState_min;
  65. static float temp_iState_max;
  66. // static float pid_input;
  67. // static float pid_output;
  68. static bool pid_reset;
  69. #endif //PIDTEMP
  70. #ifdef WATCHPERIOD
  71. static int watch_oldtemp[3] = {0,0,0};
  72. static unsigned long watchmillis = 0;
  73. #endif //WATCHPERIOD
  74. // Init min and max temp with extreme values to prevent false errors during startup
  75. static int minttemp_0 = 0;
  76. static int maxttemp_0 = 16383;
  77. //static int minttemp_1 = 0;
  78. //static int maxttemp_1 = 16383;
  79. static int bed_minttemp = 0;
  80. static int bed_maxttemp = 16383;
  81. //===========================================================================
  82. //=============================functions ============================
  83. //===========================================================================
  84. void updatePID()
  85. {
  86. #ifdef PIDTEMP
  87. temp_iState_max = PID_INTEGRAL_DRIVE_MAX / Ki;
  88. #endif
  89. }
  90. void manage_heater()
  91. {
  92. #ifdef USE_WATCHDOG
  93. wd_reset();
  94. #endif
  95. float pid_input;
  96. float pid_output;
  97. if(temp_meas_ready != true) //better readability
  98. return;
  99. CRITICAL_SECTION_START;
  100. temp_meas_ready = false;
  101. CRITICAL_SECTION_END;
  102. #ifdef PIDTEMP
  103. pid_input = analog2temp(current_raw[TEMPSENSOR_HOTEND_0]);
  104. #ifndef PID_OPENLOOP
  105. pid_error = pid_setpoint - pid_input;
  106. if(pid_error > 10){
  107. pid_output = PID_MAX;
  108. pid_reset = true;
  109. }
  110. else if(pid_error < -10) {
  111. pid_output = 0;
  112. pid_reset = true;
  113. }
  114. else {
  115. if(pid_reset == true) {
  116. temp_iState = 0.0;
  117. pid_reset = false;
  118. }
  119. pTerm = Kp * pid_error;
  120. temp_iState += pid_error;
  121. temp_iState = constrain(temp_iState, temp_iState_min, temp_iState_max);
  122. iTerm = Ki * temp_iState;
  123. //K1 defined in Configuration.h in the PID settings
  124. #define K2 (1.0-K1)
  125. dTerm = (Kd * (pid_input - temp_dState))*K2 + (K1 * dTerm);
  126. temp_dState = pid_input;
  127. // #ifdef PID_ADD_EXTRUSION_RATE
  128. // pTerm+=Kc*current_block->speed_e; //additional heating if extrusion speed is high
  129. // #endif
  130. pid_output = constrain(pTerm + iTerm - dTerm, 0, PID_MAX);
  131. }
  132. #endif //PID_OPENLOOP
  133. #ifdef PID_DEBUG
  134. //SERIAL_ECHOLN(" PIDDEBUG Input "<<pid_input<<" Output "<<pid_output" pTerm "<<pTerm<<" iTerm "<<iTerm<<" dTerm "<<dTerm);
  135. #endif //PID_DEBUG
  136. HeaterPower=pid_output;
  137. // Check if temperature is within the correct range
  138. if((current_raw[TEMPSENSOR_HOTEND_0] > minttemp_0) && (current_raw[TEMPSENSOR_HOTEND_0] < maxttemp_0)) {
  139. analogWrite(HEATER_0_PIN, pid_output);
  140. }
  141. else {
  142. analogWrite(HEATER_0_PIN, 0);
  143. }
  144. #endif //PIDTEMP
  145. #ifndef PIDTEMP
  146. // Check if temperature is within the correct range
  147. if((current_raw[TEMPSENSOR_HOTEND_0] > minttemp_0) && (current_raw[TEMPSENSOR_HOTEND_0] < maxttemp_0)) {
  148. if(current_raw[TEMPSENSOR_HOTEND_0] >= target_raw[TEMPSENSOR_HOTEND_0]) {
  149. WRITE(HEATER_0_PIN,LOW);
  150. }
  151. else {
  152. WRITE(HEATER_0_PIN,HIGH);
  153. }
  154. }
  155. else {
  156. WRITE(HEATER_0_PIN,LOW);
  157. }
  158. #endif
  159. #ifdef WATCHPERIOD
  160. if(watchmillis && millis() - watchmillis > WATCHPERIOD){
  161. if(watch_oldtemp[TEMPSENSOR_HOTEND_0] >= degHotend(active_extruder)){
  162. setTargetHotend(0,active_extruder);
  163. LCD_MESSAGEPGM("Heating failed");
  164. SERIAL_ECHO_START;
  165. SERIAL_ECHOLN("Heating failed");
  166. }else{
  167. watchmillis = 0;
  168. }
  169. }
  170. #endif
  171. if(millis() - previous_millis_bed_heater < BED_CHECK_INTERVAL)
  172. return;
  173. previous_millis_bed_heater = millis();
  174. #if TEMP_1_PIN > -1
  175. // Check if temperature is within the correct range
  176. if((current_raw[TEMPSENSOR_BED] > bed_minttemp) && (current_raw[TEMPSENSOR_BED] < bed_maxttemp)) {
  177. if(current_raw[TEMPSENSOR_BED] >= target_raw[TEMPSENSOR_BED])
  178. {
  179. WRITE(HEATER_1_PIN,LOW);
  180. }
  181. else
  182. {
  183. WRITE(HEATER_1_PIN,HIGH);
  184. }
  185. }
  186. else {
  187. WRITE(HEATER_1_PIN,LOW);
  188. }
  189. #endif
  190. }
  191. #define PGM_RD_W(x) (short)pgm_read_word(&x)
  192. // Takes hot end temperature value as input and returns corresponding raw value.
  193. // For a thermistor, it uses the RepRap thermistor temp table.
  194. // This is needed because PID in hydra firmware hovers around a given analog value, not a temp value.
  195. // This function is derived from inversing the logic from a portion of getTemperature() in FiveD RepRap firmware.
  196. int temp2analog(int celsius) {
  197. #ifdef HEATER_0_USES_THERMISTOR
  198. int raw = 0;
  199. byte i;
  200. for (i=1; i<NUMTEMPS_HEATER_0; i++)
  201. {
  202. if (PGM_RD_W(heater_0_temptable[i][1]) < celsius)
  203. {
  204. raw = PGM_RD_W(heater_0_temptable[i-1][0]) +
  205. (celsius - PGM_RD_W(heater_0_temptable[i-1][1])) *
  206. (PGM_RD_W(heater_0_temptable[i][0]) - PGM_RD_W(heater_0_temptable[i-1][0])) /
  207. (PGM_RD_W(heater_0_temptable[i][1]) - PGM_RD_W(heater_0_temptable[i-1][1]));
  208. break;
  209. }
  210. }
  211. // Overflow: Set to last value in the table
  212. if (i == NUMTEMPS_HEATER_0) raw = PGM_RD_W(heater_0_temptable[i-1][0]);
  213. return (1023 * OVERSAMPLENR) - raw;
  214. #elif defined HEATER_0_USES_AD595
  215. return celsius * (1024.0 / (5.0 * 100.0) ) * OVERSAMPLENR;
  216. #endif
  217. }
  218. // Takes bed temperature value as input and returns corresponding raw value.
  219. // For a thermistor, it uses the RepRap thermistor temp table.
  220. // This is needed because PID in hydra firmware hovers around a given analog value, not a temp value.
  221. // This function is derived from inversing the logic from a portion of getTemperature() in FiveD RepRap firmware.
  222. int temp2analogBed(int celsius) {
  223. #ifdef BED_USES_THERMISTOR
  224. int raw = 0;
  225. byte i;
  226. for (i=1; i<BNUMTEMPS; i++)
  227. {
  228. if (PGM_RD_W(bedtemptable[i][1]) < celsius)
  229. {
  230. raw = PGM_RD_W(bedtemptable[i-1][0]) +
  231. (celsius - PGM_RD_W(bedtemptable[i-1][1])) *
  232. (PGM_RD_W(bedtemptable[i][0]) - PGM_RD_W(bedtemptable[i-1][0])) /
  233. (PGM_RD_W(bedtemptable[i][1]) - PGM_RD_W(bedtemptable[i-1][1]));
  234. break;
  235. }
  236. }
  237. // Overflow: Set to last value in the table
  238. if (i == BNUMTEMPS) raw = PGM_RD_W(bedtemptable[i-1][0]);
  239. return (1023 * OVERSAMPLENR) - raw;
  240. #elif defined BED_USES_AD595
  241. return lround(celsius * (1024.0 * OVERSAMPLENR/ (5.0 * 100.0) ) );
  242. #else
  243. #warning No heater-type defined for the bed.
  244. #endif
  245. return 0;
  246. }
  247. // Derived from RepRap FiveD extruder::getTemperature()
  248. // For hot end temperature measurement.
  249. float analog2temp(int raw) {
  250. #ifdef HEATER_0_USES_THERMISTOR
  251. float celsius = 0;
  252. byte i;
  253. raw = (1023 * OVERSAMPLENR) - raw;
  254. for (i=1; i<NUMTEMPS_HEATER_0; i++)
  255. {
  256. if (PGM_RD_W(heater_0_temptable[i][0]) > raw)
  257. {
  258. celsius = PGM_RD_W(heater_0_temptable[i-1][1]) +
  259. (raw - PGM_RD_W(heater_0_temptable[i-1][0])) *
  260. (float)(PGM_RD_W(heater_0_temptable[i][1]) - PGM_RD_W(heater_0_temptable[i-1][1])) /
  261. (float)(PGM_RD_W(heater_0_temptable[i][0]) - PGM_RD_W(heater_0_temptable[i-1][0]));
  262. break;
  263. }
  264. }
  265. // Overflow: Set to last value in the table
  266. if (i == NUMTEMPS_HEATER_0) celsius = PGM_RD_W(heater_0_temptable[i-1][1]);
  267. return celsius;
  268. #elif defined HEATER_0_USES_AD595
  269. return raw * ((5.0 * 100.0) / 1024.0) / OVERSAMPLENR;
  270. #else
  271. #error PLEASE DEFINE HEATER TYPE
  272. #endif
  273. }
  274. // Derived from RepRap FiveD extruder::getTemperature()
  275. // For bed temperature measurement.
  276. float analog2tempBed(int raw) {
  277. #ifdef BED_USES_THERMISTOR
  278. int celsius = 0;
  279. byte i;
  280. raw = (1023 * OVERSAMPLENR) - raw;
  281. for (i=1; i<BNUMTEMPS; i++)
  282. {
  283. if (PGM_RD_W(bedtemptable[i][0]) > raw)
  284. {
  285. celsius = PGM_RD_W(bedtemptable[i-1][1]) +
  286. (raw - PGM_RD_W(bedtemptable[i-1][0])) *
  287. (PGM_RD_W(bedtemptable[i][1]) - PGM_RD_W(bedtemptable[i-1][1])) /
  288. (PGM_RD_W(bedtemptable[i][0]) - PGM_RD_W(bedtemptable[i-1][0]));
  289. break;
  290. }
  291. }
  292. // Overflow: Set to last value in the table
  293. if (i == BNUMTEMPS) celsius = PGM_RD_W(bedtemptable[i-1][1]);
  294. return celsius;
  295. #elif defined BED_USES_AD595
  296. return raw * ((5.0 * 100.0) / 1024.0) / OVERSAMPLENR;
  297. #else
  298. #warning No heater-type defined for the bed.
  299. #endif
  300. return 0;
  301. }
  302. void tp_init()
  303. {
  304. #if (HEATER_0_PIN > -1)
  305. SET_OUTPUT(HEATER_0_PIN);
  306. #endif
  307. #if (HEATER_1_PIN > -1)
  308. SET_OUTPUT(HEATER_1_PIN);
  309. #endif
  310. #if (HEATER_2_PIN > -1)
  311. SET_OUTPUT(HEATER_2_PIN);
  312. #endif
  313. #ifdef PIDTEMP
  314. temp_iState_min = 0.0;
  315. temp_iState_max = PID_INTEGRAL_DRIVE_MAX / Ki;
  316. #endif //PIDTEMP
  317. // Set analog inputs
  318. ADCSRA = 1<<ADEN | 1<<ADSC | 1<<ADIF | 0x07;
  319. DIDR0 = 0;
  320. #ifdef DIDR2
  321. DIDR2 = 0;
  322. #endif
  323. #if (TEMP_0_PIN > -1)
  324. #if TEMP_0_PIN < 8
  325. DIDR0 |= 1 << TEMP_0_PIN;
  326. #else
  327. DIDR2 |= 1<<(TEMP_0_PIN - 8);
  328. ADCSRB = 1<<MUX5;
  329. #endif
  330. #endif
  331. #if (TEMP_1_PIN > -1)
  332. #if TEMP_1_PIN < 8
  333. DIDR0 |= 1<<TEMP_1_PIN;
  334. #else
  335. DIDR2 |= 1<<(TEMP_1_PIN - 8);
  336. ADCSRB = 1<<MUX5;
  337. #endif
  338. #endif
  339. #if (TEMP_2_PIN > -1)
  340. #if TEMP_2_PIN < 8
  341. DIDR0 |= 1 << TEMP_2_PIN;
  342. #else
  343. DIDR2 = 1<<(TEMP_2_PIN - 8);
  344. ADCSRB = 1<<MUX5;
  345. #endif
  346. #endif
  347. // Use timer0 for temperature measurement
  348. // Interleave temperature interrupt with millies interrupt
  349. OCR0B = 128;
  350. TIMSK0 |= (1<<OCIE0B);
  351. // Wait for temperature measurement to settle
  352. delay(200);
  353. #ifdef HEATER_0_MINTEMP
  354. minttemp_0 = temp2analog(HEATER_0_MINTEMP);
  355. #endif //MINTEMP
  356. #ifdef HEATER_0_MAXTEMP
  357. maxttemp_0 = temp2analog(HEATER_0_MAXTEMP);
  358. #endif //MAXTEMP
  359. #ifdef HEATER_1_MINTEMP
  360. minttemp_1 = temp2analog(HEATER_1_MINTEMP);
  361. #endif //MINTEMP
  362. #ifdef HEATER_1_MAXTEMP
  363. maxttemp_1 = temp2analog(HEATER_1_MAXTEMP);
  364. #endif //MAXTEMP
  365. #ifdef BED_MINTEMP
  366. bed_minttemp = temp2analog(BED_MINTEMP);
  367. #endif //BED_MINTEMP
  368. #ifdef BED_MAXTEMP
  369. bed_maxttemp = temp2analog(BED_MAXTEMP);
  370. #endif //BED_MAXTEMP
  371. }
  372. void setWatch()
  373. {
  374. #ifdef WATCHPERIOD
  375. if(isHeatingHotend0())
  376. {
  377. watchmillis = max(1,millis());
  378. watch_oldtemp[TEMPSENSOR_HOTEND_0] = degHotend(0);
  379. }
  380. else
  381. {
  382. watchmillis = 0;
  383. }
  384. #endif
  385. }
  386. void disable_heater()
  387. {
  388. #if TEMP_0_PIN > -1
  389. target_raw[0]=0;
  390. #if HEATER_0_PIN > -1
  391. digitalWrite(HEATER_0_PIN,LOW);
  392. #endif
  393. #endif
  394. #if TEMP_1_PIN > -1
  395. target_raw[1]=0;
  396. #if HEATER_1_PIN > -1
  397. digitalWrite(HEATER_1_PIN,LOW);
  398. #endif
  399. #endif
  400. #if TEMP_2_PIN > -1
  401. target_raw[2]=0;
  402. #if HEATER_2_PIN > -1
  403. digitalWrite(HEATER_2_PIN,LOW);
  404. #endif
  405. #endif
  406. }
  407. // Timer 0 is shared with millies
  408. ISR(TIMER0_COMPB_vect)
  409. {
  410. //these variables are only accesible from the ISR, but static, so they don't loose their value
  411. static unsigned char temp_count = 0;
  412. static unsigned long raw_temp_0_value = 0;
  413. static unsigned long raw_temp_1_value = 0;
  414. static unsigned long raw_temp_2_value = 0;
  415. static unsigned char temp_state = 0;
  416. switch(temp_state) {
  417. case 0: // Prepare TEMP_0
  418. #if (TEMP_0_PIN > -1)
  419. #if TEMP_0_PIN > 7
  420. ADCSRB = 1<<MUX5;
  421. #else
  422. ADCSRB = 0;
  423. #endif
  424. ADMUX = ((1 << REFS0) | (TEMP_0_PIN & 0x07));
  425. ADCSRA |= 1<<ADSC; // Start conversion
  426. #endif
  427. #ifdef ULTIPANEL
  428. buttons_check();
  429. #endif
  430. temp_state = 1;
  431. break;
  432. case 1: // Measure TEMP_0
  433. #if (TEMP_0_PIN > -1)
  434. raw_temp_0_value += ADC;
  435. #endif
  436. temp_state = 2;
  437. break;
  438. case 2: // Prepare TEMP_1
  439. #if (TEMP_1_PIN > -1)
  440. #if TEMP_1_PIN > 7
  441. ADCSRB = 1<<MUX5;
  442. #else
  443. ADCSRB = 0;
  444. #endif
  445. ADMUX = ((1 << REFS0) | (TEMP_1_PIN & 0x07));
  446. ADCSRA |= 1<<ADSC; // Start conversion
  447. #endif
  448. #ifdef ULTIPANEL
  449. buttons_check();
  450. #endif
  451. temp_state = 3;
  452. break;
  453. case 3: // Measure TEMP_1
  454. #if (TEMP_1_PIN > -1)
  455. raw_temp_1_value += ADC;
  456. #endif
  457. temp_state = 4;
  458. break;
  459. case 4: // Prepare TEMP_2
  460. #if (TEMP_2_PIN > -1)
  461. #if TEMP_2_PIN > 7
  462. ADCSRB = 1<<MUX5;
  463. #else
  464. ADCSRB = 0;
  465. #endif
  466. ADMUX = ((1 << REFS0) | (TEMP_2_PIN & 0x07));
  467. ADCSRA |= 1<<ADSC; // Start conversion
  468. #endif
  469. #ifdef ULTIPANEL
  470. buttons_check();
  471. #endif
  472. temp_state = 5;
  473. break;
  474. case 5: // Measure TEMP_2
  475. #if (TEMP_2_PIN > -1)
  476. raw_temp_2_value += ADC;
  477. #endif
  478. temp_state = 0;
  479. temp_count++;
  480. break;
  481. default:
  482. SERIAL_ERROR_START;
  483. SERIAL_ERRORLNPGM("Temp measurement error!");
  484. break;
  485. }
  486. if(temp_count >= 16) // 6 ms * 16 = 96ms.
  487. {
  488. #ifdef HEATER_0_USES_AD595
  489. current_raw[0] = raw_temp_0_value;
  490. #else
  491. current_raw[0] = 16383 - raw_temp_0_value;
  492. #endif
  493. #ifdef HEATER_1_USES_AD595
  494. current_raw[2] = raw_temp_2_value;
  495. #else
  496. current_raw[2] = 16383 - raw_temp_2_value;
  497. #endif
  498. #ifdef BED_USES_AD595
  499. current_raw[1] = raw_temp_1_value;
  500. #else
  501. current_raw[1] = 16383 - raw_temp_1_value;
  502. #endif
  503. temp_meas_ready = true;
  504. temp_count = 0;
  505. raw_temp_0_value = 0;
  506. raw_temp_1_value = 0;
  507. raw_temp_2_value = 0;
  508. #ifdef HEATER_0_MAXTEMP
  509. #if (HEATER_0_PIN > -1)
  510. if(current_raw[TEMPSENSOR_HOTEND_0] >= maxttemp_0) {
  511. target_raw[TEMPSENSOR_HOTEND_0] = 0;
  512. digitalWrite(HEATER_0_PIN, 0);
  513. SERIAL_ERROR_START;
  514. SERIAL_ERRORLNPGM("Temperature extruder 0 switched off. MAXTEMP triggered !!");
  515. kill();
  516. }
  517. #endif
  518. #endif
  519. #ifdef HEATER_1_MAXTEMP
  520. #if (HEATER_1_PIN > -1)
  521. if(current_raw[TEMPSENSOR_HOTEND_1] >= maxttemp_1) {
  522. target_raw[TEMPSENSOR_HOTEND_1] = 0;
  523. digitalWrite(HEATER_2_PIN, 0);
  524. SERIAL_ERROR_START;
  525. SERIAL_ERRORLNPGM("Temperature extruder 1 switched off. MAXTEMP triggered !!");
  526. kill();
  527. }
  528. #endif
  529. #endif //MAXTEMP
  530. #ifdef HEATER_0_MINTEMP
  531. #if (HEATER_0_PIN > -1)
  532. if(current_raw[TEMPSENSOR_HOTEND_0] <= minttemp_0) {
  533. target_raw[TEMPSENSOR_HOTEND_0] = 0;
  534. digitalWrite(HEATER_0_PIN, 0);
  535. SERIAL_ERROR_START;
  536. SERIAL_ERRORLNPGM("Temperature extruder 0 switched off. MINTEMP triggered !!");
  537. kill();
  538. }
  539. #endif
  540. #endif
  541. #ifdef HEATER_1_MINTEMP
  542. #if (HEATER_2_PIN > -1)
  543. if(current_raw[TEMPSENSOR_HOTEND_1] <= minttemp_1) {
  544. target_raw[TEMPSENSOR_HOTEND_1] = 0;
  545. digitalWrite(HEATER_2_PIN, 0);
  546. SERIAL_ERROR_START;
  547. SERIAL_ERRORLNPGM("Temperature extruder 1 switched off. MINTEMP triggered !!");
  548. kill();
  549. }
  550. #endif
  551. #endif //MAXTEMP
  552. #ifdef BED_MINTEMP
  553. #if (HEATER_1_PIN > -1)
  554. if(current_raw[1] <= bed_minttemp) {
  555. target_raw[1] = 0;
  556. digitalWrite(HEATER_1_PIN, 0);
  557. SERIAL_ERROR_START;
  558. SERIAL_ERRORLNPGM("Temperatur heated bed switched off. MINTEMP triggered !!");
  559. kill();
  560. }
  561. #endif
  562. #endif
  563. #ifdef BED_MAXTEMP
  564. #if (HEATER_1_PIN > -1)
  565. if(current_raw[1] >= bed_maxttemp) {
  566. target_raw[1] = 0;
  567. digitalWrite(HEATER_1_PIN, 0);
  568. SERIAL_ERROR_START;
  569. SERIAL_ERRORLNPGM("Temperature heated bed switched off. MAXTEMP triggered !!");
  570. kill();
  571. }
  572. #endif
  573. #endif
  574. }
  575. }