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 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  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_raw[3] = {-1000,-1000,-1000};
  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. if(millis() - previous_millis_bed_heater < BED_CHECK_INTERVAL)
  160. return;
  161. previous_millis_bed_heater = millis();
  162. #if TEMP_1_PIN > -1
  163. // Check if temperature is within the correct range
  164. if((current_raw[TEMPSENSOR_BED] > bed_minttemp) && (current_raw[TEMPSENSOR_BED] < bed_maxttemp)) {
  165. if(current_raw[TEMPSENSOR_BED] >= target_raw[TEMPSENSOR_BED])
  166. {
  167. WRITE(HEATER_1_PIN,LOW);
  168. }
  169. else
  170. {
  171. WRITE(HEATER_1_PIN,HIGH);
  172. }
  173. }
  174. else {
  175. WRITE(HEATER_1_PIN,LOW);
  176. }
  177. #endif
  178. }
  179. #define PGM_RD_W(x) (short)pgm_read_word(&x)
  180. // Takes hot end temperature value as input and returns corresponding raw value.
  181. // For a thermistor, it uses the RepRap thermistor temp table.
  182. // This is needed because PID in hydra firmware hovers around a given analog value, not a temp value.
  183. // This function is derived from inversing the logic from a portion of getTemperature() in FiveD RepRap firmware.
  184. int temp2analog(int celsius) {
  185. #ifdef HEATER_0_USES_THERMISTOR
  186. int raw = 0;
  187. byte i;
  188. for (i=1; i<NUMTEMPS_HEATER_0; i++)
  189. {
  190. if (PGM_RD_W(heater_0_temptable[i][1]) < celsius)
  191. {
  192. raw = PGM_RD_W(heater_0_temptable[i-1][0]) +
  193. (celsius - PGM_RD_W(heater_0_temptable[i-1][1])) *
  194. (PGM_RD_W(heater_0_temptable[i][0]) - PGM_RD_W(heater_0_temptable[i-1][0])) /
  195. (PGM_RD_W(heater_0_temptable[i][1]) - PGM_RD_W(heater_0_temptable[i-1][1]));
  196. break;
  197. }
  198. }
  199. // Overflow: Set to last value in the table
  200. if (i == NUMTEMPS_HEATER_0) raw = PGM_RD_W(heater_0_temptable[i-1][0]);
  201. return (1023 * OVERSAMPLENR) - raw;
  202. #elif defined HEATER_0_USES_AD595
  203. return celsius * (1024.0 / (5.0 * 100.0) ) * OVERSAMPLENR;
  204. #endif
  205. }
  206. // Takes bed temperature value as input and returns corresponding raw value.
  207. // For a thermistor, it uses the RepRap thermistor temp table.
  208. // This is needed because PID in hydra firmware hovers around a given analog value, not a temp value.
  209. // This function is derived from inversing the logic from a portion of getTemperature() in FiveD RepRap firmware.
  210. int temp2analogBed(int celsius) {
  211. #ifdef BED_USES_THERMISTOR
  212. int raw = 0;
  213. byte i;
  214. for (i=1; i<BNUMTEMPS; i++)
  215. {
  216. if (PGM_RD_W(bedtemptable[i][1]) < celsius)
  217. {
  218. raw = PGM_RD_W(bedtemptable[i-1][0]) +
  219. (celsius - PGM_RD_W(bedtemptable[i-1][1])) *
  220. (PGM_RD_W(bedtemptable[i][0]) - PGM_RD_W(bedtemptable[i-1][0])) /
  221. (PGM_RD_W(bedtemptable[i][1]) - PGM_RD_W(bedtemptable[i-1][1]));
  222. break;
  223. }
  224. }
  225. // Overflow: Set to last value in the table
  226. if (i == BNUMTEMPS) raw = PGM_RD_W(bedtemptable[i-1][0]);
  227. return (1023 * OVERSAMPLENR) - raw;
  228. #elif defined BED_USES_AD595
  229. return lround(celsius * (1024.0 * OVERSAMPLENR/ (5.0 * 100.0) ) );
  230. #else
  231. #warning No heater-type defined for the bed.
  232. #endif
  233. return 0;
  234. }
  235. // Derived from RepRap FiveD extruder::getTemperature()
  236. // For hot end temperature measurement.
  237. float analog2temp(int raw) {
  238. #ifdef HEATER_0_USES_THERMISTOR
  239. float celsius = 0;
  240. byte i;
  241. raw = (1023 * OVERSAMPLENR) - raw;
  242. for (i=1; i<NUMTEMPS_HEATER_0; i++)
  243. {
  244. if (PGM_RD_W(heater_0_temptable[i][0]) > raw)
  245. {
  246. celsius = PGM_RD_W(heater_0_temptable[i-1][1]) +
  247. (raw - PGM_RD_W(heater_0_temptable[i-1][0])) *
  248. (float)(PGM_RD_W(heater_0_temptable[i][1]) - PGM_RD_W(heater_0_temptable[i-1][1])) /
  249. (float)(PGM_RD_W(heater_0_temptable[i][0]) - PGM_RD_W(heater_0_temptable[i-1][0]));
  250. break;
  251. }
  252. }
  253. // Overflow: Set to last value in the table
  254. if (i == NUMTEMPS_HEATER_0) celsius = PGM_RD_W(heater_0_temptable[i-1][1]);
  255. return celsius;
  256. #elif defined HEATER_0_USES_AD595
  257. return raw * ((5.0 * 100.0) / 1024.0) / OVERSAMPLENR;
  258. #else
  259. #error PLEASE DEFINE HEATER TYPE
  260. #endif
  261. }
  262. // Derived from RepRap FiveD extruder::getTemperature()
  263. // For bed temperature measurement.
  264. float analog2tempBed(int raw) {
  265. #ifdef BED_USES_THERMISTOR
  266. int celsius = 0;
  267. byte i;
  268. raw = (1023 * OVERSAMPLENR) - raw;
  269. for (i=1; i<BNUMTEMPS; i++)
  270. {
  271. if (PGM_RD_W(bedtemptable[i][0]) > raw)
  272. {
  273. celsius = PGM_RD_W(bedtemptable[i-1][1]) +
  274. (raw - PGM_RD_W(bedtemptable[i-1][0])) *
  275. (PGM_RD_W(bedtemptable[i][1]) - PGM_RD_W(bedtemptable[i-1][1])) /
  276. (PGM_RD_W(bedtemptable[i][0]) - PGM_RD_W(bedtemptable[i-1][0]));
  277. break;
  278. }
  279. }
  280. // Overflow: Set to last value in the table
  281. if (i == BNUMTEMPS) celsius = PGM_RD_W(bedtemptable[i-1][1]);
  282. return celsius;
  283. #elif defined BED_USES_AD595
  284. return raw * ((5.0 * 100.0) / 1024.0) / OVERSAMPLENR;
  285. #else
  286. #warning No heater-type defined for the bed.
  287. #endif
  288. return 0;
  289. }
  290. void tp_init()
  291. {
  292. #if (HEATER_0_PIN > -1)
  293. SET_OUTPUT(HEATER_0_PIN);
  294. #endif
  295. #if (HEATER_1_PIN > -1)
  296. SET_OUTPUT(HEATER_1_PIN);
  297. #endif
  298. #if (HEATER_2_PIN > -1)
  299. SET_OUTPUT(HEATER_2_PIN);
  300. #endif
  301. #ifdef PIDTEMP
  302. temp_iState_min = 0.0;
  303. temp_iState_max = PID_INTEGRAL_DRIVE_MAX / Ki;
  304. #endif //PIDTEMP
  305. // Set analog inputs
  306. ADCSRA = 1<<ADEN | 1<<ADSC | 1<<ADIF | 0x07;
  307. DIDR0 = 0;
  308. #ifdef DIDR2
  309. DIDR2 = 0;
  310. #endif
  311. #if (TEMP_0_PIN > -1)
  312. #if TEMP_0_PIN < 8
  313. DIDR0 |= 1 << TEMP_0_PIN;
  314. #else
  315. DIDR2 |= 1<<(TEMP_0_PIN - 8);
  316. ADCSRB = 1<<MUX5;
  317. #endif
  318. #endif
  319. #if (TEMP_1_PIN > -1)
  320. #if TEMP_1_PIN < 8
  321. DIDR0 |= 1<<TEMP_1_PIN;
  322. #else
  323. DIDR2 |= 1<<(TEMP_1_PIN - 8);
  324. ADCSRB = 1<<MUX5;
  325. #endif
  326. #endif
  327. #if (TEMP_2_PIN > -1)
  328. #if TEMP_2_PIN < 8
  329. DIDR0 |= 1 << TEMP_2_PIN;
  330. #else
  331. DIDR2 = 1<<(TEMP_2_PIN - 8);
  332. ADCSRB = 1<<MUX5;
  333. #endif
  334. #endif
  335. // Use timer0 for temperature measurement
  336. // Interleave temperature interrupt with millies interrupt
  337. OCR0B = 128;
  338. TIMSK0 |= (1<<OCIE0B);
  339. // Wait for temperature measurement to settle
  340. delay(200);
  341. #ifdef HEATER_0_MINTEMP
  342. minttemp_0 = temp2analog(HEATER_0_MINTEMP);
  343. #endif //MINTEMP
  344. #ifdef HEATER_0_MAXTEMP
  345. maxttemp_0 = temp2analog(HEATER_0_MAXTEMP);
  346. #endif //MAXTEMP
  347. #ifdef HEATER_1_MINTEMP
  348. minttemp_1 = temp2analog(HEATER_1_MINTEMP);
  349. #endif //MINTEMP
  350. #ifdef HEATER_1_MAXTEMP
  351. maxttemp_1 = temp2analog(HEATER_1_MAXTEMP);
  352. #endif //MAXTEMP
  353. #ifdef BED_MINTEMP
  354. bed_minttemp = temp2analog(BED_MINTEMP);
  355. #endif //BED_MINTEMP
  356. #ifdef BED_MAXTEMP
  357. bed_maxttemp = temp2analog(BED_MAXTEMP);
  358. #endif //BED_MAXTEMP
  359. }
  360. void setWatch()
  361. {
  362. #ifdef WATCHPERIOD
  363. if(isHeatingHotend0())
  364. {
  365. watchmillis = max(1,millis());
  366. watch_raw[TEMPSENSOR_HOTEND_0] = current_raw[TEMPSENSOR_HOTEND_0];
  367. }
  368. else
  369. {
  370. watchmillis = 0;
  371. }
  372. #endif
  373. }
  374. void disable_heater()
  375. {
  376. #if TEMP_0_PIN > -1
  377. target_raw[0]=0;
  378. #if HEATER_0_PIN > -1
  379. digitalWrite(HEATER_0_PIN,LOW);
  380. #endif
  381. #endif
  382. #if TEMP_1_PIN > -1
  383. target_raw[1]=0;
  384. #if HEATER_1_PIN > -1
  385. digitalWrite(HEATER_1_PIN,LOW);
  386. #endif
  387. #endif
  388. #if TEMP_2_PIN > -1
  389. target_raw[2]=0;
  390. #if HEATER_2_PIN > -1
  391. digitalWrite(HEATER_2_PIN,LOW);
  392. #endif
  393. #endif
  394. }
  395. // Timer 0 is shared with millies
  396. ISR(TIMER0_COMPB_vect)
  397. {
  398. //these variables are only accesible from the ISR, but static, so they don't loose their value
  399. static unsigned char temp_count = 0;
  400. static unsigned long raw_temp_0_value = 0;
  401. static unsigned long raw_temp_1_value = 0;
  402. static unsigned long raw_temp_2_value = 0;
  403. static unsigned char temp_state = 0;
  404. switch(temp_state) {
  405. case 0: // Prepare TEMP_0
  406. #if (TEMP_0_PIN > -1)
  407. #if TEMP_0_PIN > 7
  408. ADCSRB = 1<<MUX5;
  409. #else
  410. ADCSRB = 0;
  411. #endif
  412. ADMUX = ((1 << REFS0) | (TEMP_0_PIN & 0x07));
  413. ADCSRA |= 1<<ADSC; // Start conversion
  414. #endif
  415. #ifdef ULTIPANEL
  416. buttons_check();
  417. #endif
  418. temp_state = 1;
  419. break;
  420. case 1: // Measure TEMP_0
  421. #if (TEMP_0_PIN > -1)
  422. raw_temp_0_value += ADC;
  423. #endif
  424. temp_state = 2;
  425. break;
  426. case 2: // Prepare TEMP_1
  427. #if (TEMP_1_PIN > -1)
  428. #if TEMP_1_PIN > 7
  429. ADCSRB = 1<<MUX5;
  430. #else
  431. ADCSRB = 0;
  432. #endif
  433. ADMUX = ((1 << REFS0) | (TEMP_1_PIN & 0x07));
  434. ADCSRA |= 1<<ADSC; // Start conversion
  435. #endif
  436. #ifdef ULTIPANEL
  437. buttons_check();
  438. #endif
  439. temp_state = 3;
  440. break;
  441. case 3: // Measure TEMP_1
  442. #if (TEMP_1_PIN > -1)
  443. raw_temp_1_value += ADC;
  444. #endif
  445. temp_state = 4;
  446. break;
  447. case 4: // Prepare TEMP_2
  448. #if (TEMP_2_PIN > -1)
  449. #if TEMP_2_PIN > 7
  450. ADCSRB = 1<<MUX5;
  451. #else
  452. ADCSRB = 0;
  453. #endif
  454. ADMUX = ((1 << REFS0) | (TEMP_2_PIN & 0x07));
  455. ADCSRA |= 1<<ADSC; // Start conversion
  456. #endif
  457. #ifdef ULTIPANEL
  458. buttons_check();
  459. #endif
  460. temp_state = 5;
  461. break;
  462. case 5: // Measure TEMP_2
  463. #if (TEMP_2_PIN > -1)
  464. raw_temp_2_value += ADC;
  465. #endif
  466. temp_state = 0;
  467. temp_count++;
  468. break;
  469. default:
  470. SERIAL_ERROR_START;
  471. SERIAL_ERRORLNPGM("Temp measurement error!");
  472. break;
  473. }
  474. if(temp_count >= 16) // 6 ms * 16 = 96ms.
  475. {
  476. #ifdef HEATER_0_USES_AD595
  477. current_raw[0] = raw_temp_0_value;
  478. #else
  479. current_raw[0] = 16383 - raw_temp_0_value;
  480. #endif
  481. #ifdef HEATER_1_USES_AD595
  482. current_raw[2] = raw_temp_2_value;
  483. #else
  484. current_raw[2] = 16383 - raw_temp_2_value;
  485. #endif
  486. #ifdef BED_USES_AD595
  487. current_raw[1] = raw_temp_1_value;
  488. #else
  489. current_raw[1] = 16383 - raw_temp_1_value;
  490. #endif
  491. temp_meas_ready = true;
  492. temp_count = 0;
  493. raw_temp_0_value = 0;
  494. raw_temp_1_value = 0;
  495. raw_temp_2_value = 0;
  496. #ifdef HEATER_0_MAXTEMP
  497. #if (HEATER_0_PIN > -1)
  498. if(current_raw[TEMPSENSOR_HOTEND_0] >= maxttemp_0) {
  499. target_raw[TEMPSENSOR_HOTEND_0] = 0;
  500. digitalWrite(HEATER_0_PIN, 0);
  501. SERIAL_ERROR_START;
  502. SERIAL_ERRORLNPGM("Temperature extruder 0 switched off. MAXTEMP triggered !!");
  503. kill();
  504. }
  505. #endif
  506. #endif
  507. #ifdef HEATER_1_MAXTEMP
  508. #if (HEATER_1_PIN > -1)
  509. if(current_raw[TEMPSENSOR_HOTEND_1] >= maxttemp_1) {
  510. target_raw[TEMPSENSOR_HOTEND_1] = 0;
  511. digitalWrite(HEATER_2_PIN, 0);
  512. SERIAL_ERROR_START;
  513. SERIAL_ERRORLNPGM("Temperature extruder 1 switched off. MAXTEMP triggered !!");
  514. kill();
  515. }
  516. #endif
  517. #endif //MAXTEMP
  518. #ifdef HEATER_0_MINTEMP
  519. #if (HEATER_0_PIN > -1)
  520. if(current_raw[TEMPSENSOR_HOTEND_0] <= minttemp_0) {
  521. target_raw[TEMPSENSOR_HOTEND_0] = 0;
  522. digitalWrite(HEATER_0_PIN, 0);
  523. SERIAL_ERROR_START;
  524. SERIAL_ERRORLNPGM("Temperature extruder 0 switched off. MINTEMP triggered !!");
  525. kill();
  526. }
  527. #endif
  528. #endif
  529. #ifdef HEATER_1_MINTEMP
  530. #if (HEATER_2_PIN > -1)
  531. if(current_raw[TEMPSENSOR_HOTEND_1] <= minttemp_1) {
  532. target_raw[TEMPSENSOR_HOTEND_1] = 0;
  533. digitalWrite(HEATER_2_PIN, 0);
  534. SERIAL_ERROR_START;
  535. SERIAL_ERRORLNPGM("Temperature extruder 1 switched off. MINTEMP triggered !!");
  536. kill();
  537. }
  538. #endif
  539. #endif //MAXTEMP
  540. #ifdef BED_MINTEMP
  541. #if (HEATER_1_PIN > -1)
  542. if(current_raw[1] <= bed_minttemp) {
  543. target_raw[1] = 0;
  544. digitalWrite(HEATER_1_PIN, 0);
  545. SERIAL_ERROR_START;
  546. SERIAL_ERRORLNPGM("Temperatur heated bed switched off. MINTEMP triggered !!");
  547. kill();
  548. }
  549. #endif
  550. #endif
  551. #ifdef BED_MAXTEMP
  552. #if (HEATER_1_PIN > -1)
  553. if(current_raw[1] >= bed_maxttemp) {
  554. target_raw[1] = 0;
  555. digitalWrite(HEATER_1_PIN, 0);
  556. SERIAL_ERROR_START;
  557. SERIAL_ERRORLNPGM("Temperature heated bed switched off. MAXTEMP triggered !!");
  558. kill();
  559. }
  560. #endif
  561. #endif
  562. }
  563. }