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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  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. for(int i=0;i<EXTRUDERS;i++)
  389. setTargetHotend(0,i);
  390. setTargetBed(0);
  391. #if TEMP_0_PIN > -1
  392. target_raw[0]=0;
  393. #if HEATER_0_PIN > -1
  394. digitalWrite(HEATER_0_PIN,LOW);
  395. #endif
  396. #endif
  397. #if TEMP_1_PIN > -1
  398. target_raw[1]=0;
  399. #if HEATER_1_PIN > -1
  400. digitalWrite(HEATER_1_PIN,LOW);
  401. #endif
  402. #endif
  403. #if TEMP_2_PIN > -1
  404. target_raw[2]=0;
  405. #if HEATER_2_PIN > -1
  406. digitalWrite(HEATER_2_PIN,LOW);
  407. #endif
  408. #endif
  409. }
  410. // Timer 0 is shared with millies
  411. ISR(TIMER0_COMPB_vect)
  412. {
  413. //these variables are only accesible from the ISR, but static, so they don't loose their value
  414. static unsigned char temp_count = 0;
  415. static unsigned long raw_temp_0_value = 0;
  416. static unsigned long raw_temp_1_value = 0;
  417. static unsigned long raw_temp_2_value = 0;
  418. static unsigned char temp_state = 0;
  419. switch(temp_state) {
  420. case 0: // Prepare TEMP_0
  421. #if (TEMP_0_PIN > -1)
  422. #if TEMP_0_PIN > 7
  423. ADCSRB = 1<<MUX5;
  424. #else
  425. ADCSRB = 0;
  426. #endif
  427. ADMUX = ((1 << REFS0) | (TEMP_0_PIN & 0x07));
  428. ADCSRA |= 1<<ADSC; // Start conversion
  429. #endif
  430. #ifdef ULTIPANEL
  431. buttons_check();
  432. #endif
  433. temp_state = 1;
  434. break;
  435. case 1: // Measure TEMP_0
  436. #if (TEMP_0_PIN > -1)
  437. raw_temp_0_value += ADC;
  438. #endif
  439. temp_state = 2;
  440. break;
  441. case 2: // Prepare TEMP_1
  442. #if (TEMP_1_PIN > -1)
  443. #if TEMP_1_PIN > 7
  444. ADCSRB = 1<<MUX5;
  445. #else
  446. ADCSRB = 0;
  447. #endif
  448. ADMUX = ((1 << REFS0) | (TEMP_1_PIN & 0x07));
  449. ADCSRA |= 1<<ADSC; // Start conversion
  450. #endif
  451. #ifdef ULTIPANEL
  452. buttons_check();
  453. #endif
  454. temp_state = 3;
  455. break;
  456. case 3: // Measure TEMP_1
  457. #if (TEMP_1_PIN > -1)
  458. raw_temp_1_value += ADC;
  459. #endif
  460. temp_state = 4;
  461. break;
  462. case 4: // Prepare TEMP_2
  463. #if (TEMP_2_PIN > -1)
  464. #if TEMP_2_PIN > 7
  465. ADCSRB = 1<<MUX5;
  466. #else
  467. ADCSRB = 0;
  468. #endif
  469. ADMUX = ((1 << REFS0) | (TEMP_2_PIN & 0x07));
  470. ADCSRA |= 1<<ADSC; // Start conversion
  471. #endif
  472. #ifdef ULTIPANEL
  473. buttons_check();
  474. #endif
  475. temp_state = 5;
  476. break;
  477. case 5: // Measure TEMP_2
  478. #if (TEMP_2_PIN > -1)
  479. raw_temp_2_value += ADC;
  480. #endif
  481. temp_state = 0;
  482. temp_count++;
  483. break;
  484. default:
  485. SERIAL_ERROR_START;
  486. SERIAL_ERRORLNPGM("Temp measurement error!");
  487. break;
  488. }
  489. if(temp_count >= 16) // 6 ms * 16 = 96ms.
  490. {
  491. #ifdef HEATER_0_USES_AD595
  492. current_raw[0] = raw_temp_0_value;
  493. #else
  494. current_raw[0] = 16383 - raw_temp_0_value;
  495. #endif
  496. #ifdef HEATER_1_USES_AD595
  497. current_raw[2] = raw_temp_2_value;
  498. #else
  499. current_raw[2] = 16383 - raw_temp_2_value;
  500. #endif
  501. #ifdef BED_USES_AD595
  502. current_raw[1] = raw_temp_1_value;
  503. #else
  504. current_raw[1] = 16383 - raw_temp_1_value;
  505. #endif
  506. temp_meas_ready = true;
  507. temp_count = 0;
  508. raw_temp_0_value = 0;
  509. raw_temp_1_value = 0;
  510. raw_temp_2_value = 0;
  511. #ifdef HEATER_0_MAXTEMP
  512. #if (HEATER_0_PIN > -1)
  513. if(current_raw[TEMPSENSOR_HOTEND_0] >= maxttemp_0) {
  514. target_raw[TEMPSENSOR_HOTEND_0] = 0;
  515. digitalWrite(HEATER_0_PIN, 0);
  516. SERIAL_ERROR_START;
  517. SERIAL_ERRORLNPGM("Temperature extruder 0 switched off. MAXTEMP triggered !!");
  518. kill();
  519. }
  520. #endif
  521. #endif
  522. #ifdef HEATER_1_MAXTEMP
  523. #if (HEATER_1_PIN > -1)
  524. if(current_raw[TEMPSENSOR_HOTEND_1] >= maxttemp_1) {
  525. target_raw[TEMPSENSOR_HOTEND_1] = 0;
  526. digitalWrite(HEATER_2_PIN, 0);
  527. SERIAL_ERROR_START;
  528. SERIAL_ERRORLNPGM("Temperature extruder 1 switched off. MAXTEMP triggered !!");
  529. kill();
  530. }
  531. #endif
  532. #endif //MAXTEMP
  533. #ifdef HEATER_0_MINTEMP
  534. #if (HEATER_0_PIN > -1)
  535. if(current_raw[TEMPSENSOR_HOTEND_0] <= minttemp_0) {
  536. target_raw[TEMPSENSOR_HOTEND_0] = 0;
  537. digitalWrite(HEATER_0_PIN, 0);
  538. SERIAL_ERROR_START;
  539. SERIAL_ERRORLNPGM("Temperature extruder 0 switched off. MINTEMP triggered !!");
  540. kill();
  541. }
  542. #endif
  543. #endif
  544. #ifdef HEATER_1_MINTEMP
  545. #if (HEATER_2_PIN > -1)
  546. if(current_raw[TEMPSENSOR_HOTEND_1] <= minttemp_1) {
  547. target_raw[TEMPSENSOR_HOTEND_1] = 0;
  548. digitalWrite(HEATER_2_PIN, 0);
  549. SERIAL_ERROR_START;
  550. SERIAL_ERRORLNPGM("Temperature extruder 1 switched off. MINTEMP triggered !!");
  551. kill();
  552. }
  553. #endif
  554. #endif //MAXTEMP
  555. #ifdef BED_MINTEMP
  556. #if (HEATER_1_PIN > -1)
  557. if(current_raw[1] <= bed_minttemp) {
  558. target_raw[1] = 0;
  559. digitalWrite(HEATER_1_PIN, 0);
  560. SERIAL_ERROR_START;
  561. SERIAL_ERRORLNPGM("Temperatur heated bed switched off. MINTEMP triggered !!");
  562. kill();
  563. }
  564. #endif
  565. #endif
  566. #ifdef BED_MAXTEMP
  567. #if (HEATER_1_PIN > -1)
  568. if(current_raw[1] >= bed_maxttemp) {
  569. target_raw[1] = 0;
  570. digitalWrite(HEATER_1_PIN, 0);
  571. SERIAL_ERROR_START;
  572. SERIAL_ERRORLNPGM("Temperature heated bed switched off. MAXTEMP triggered !!");
  573. kill();
  574. }
  575. #endif
  576. #endif
  577. }
  578. }