My Marlin configs for Fabrikator Mini and CTC i3 Pro B
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

temperature.h 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. temperature.h - temperature controller
  3. Part of Marlin
  4. Copyright (c) 2011 Erik van der Zalm
  5. Grbl 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. Grbl 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 Grbl. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef temperature_h
  17. #define temperature_h
  18. #include "Marlin.h"
  19. #include "fastio.h"
  20. #ifdef PID_ADD_EXTRUSION_RATE
  21. #include "stepper.h"
  22. #endif
  23. void tp_init(); //initialise the heating
  24. void manage_heater(); //it is critical that this is called periodically.
  25. enum TempSensor {TEMPSENSOR_HOTEND_0=0,TEMPSENSOR_BED=1, TEMPSENSOR_HOTEND_1=2};
  26. //low leven conversion routines
  27. // do not use this routines and variables outsie of temperature.cpp
  28. int temp2analog(int celsius);
  29. int temp2analogBed(int celsius);
  30. float analog2temp(int raw);
  31. float analog2tempBed(int raw);
  32. extern int target_raw[3];
  33. extern int current_raw[3];
  34. extern float Kp,Ki,Kd,Kc;
  35. #ifdef PIDTEMP
  36. float pid_setpoint = 0.0;
  37. #endif
  38. #ifdef WATCHPERIOD
  39. extern int watch_raw[3] ;
  40. extern unsigned long watchmillis;
  41. #endif
  42. //high level conversion routines, for use outside of temperature.cpp
  43. //inline so that there is no performance decrease.
  44. //deg=degreeCelsius
  45. inline float degHotend0(){ return analog2temp(current_raw[TEMPSENSOR_HOTEND_0]);};
  46. inline float degHotend1(){ return analog2temp(current_raw[TEMPSENSOR_HOTEND_1]);};
  47. inline float degBed() { return analog2tempBed(current_raw[TEMPSENSOR_BED]);};
  48. inline float degTargetHotend0() { return analog2temp(target_raw[TEMPSENSOR_HOTEND_0]);};
  49. inline float degTargetHotend1() { return analog2temp(target_raw[TEMPSENSOR_HOTEND_1]);};
  50. inline float degTargetBed() { return analog2tempBed(target_raw[TEMPSENSOR_BED]);};
  51. inline void setTargetHotend0(float celsius)
  52. {
  53. target_raw[TEMPSENSOR_HOTEND_0]=temp2analog(celsius);
  54. #ifdef PIDTEMP
  55. pid_setpoint = celsius;
  56. #endif //PIDTEMP
  57. };
  58. inline void setTargetHotend1(float celsius) { target_raw[TEMPSENSOR_HOTEND_1]=temp2analog(celsius);};
  59. inline void setTargetBed(float celsius) { target_raw[TEMPSENSOR_BED ]=temp2analogBed(celsius);};
  60. inline bool isHeatingHotend0() {return target_raw[TEMPSENSOR_HOTEND_0] > current_raw[TEMPSENSOR_HOTEND_0];};
  61. inline bool isHeatingHotend1() {return target_raw[TEMPSENSOR_HOTEND_1] > current_raw[TEMPSENSOR_HOTEND_1];};
  62. inline bool isHeatingBed() {return target_raw[TEMPSENSOR_BED] > current_raw[TEMPSENSOR_BED];};
  63. inline bool isCoolingHotend0() {return target_raw[TEMPSENSOR_HOTEND_0] < current_raw[TEMPSENSOR_HOTEND_0];};
  64. inline bool isCoolingHotend1() {return target_raw[TEMPSENSOR_HOTEND_1] < current_raw[TEMPSENSOR_HOTEND_1];};
  65. inline bool isCoolingBed() {return target_raw[TEMPSENSOR_BED] < current_raw[TEMPSENSOR_BED];};
  66. inline void disable_heater()
  67. {
  68. #if TEMP_0_PIN > -1
  69. target_raw[0]=0;
  70. #if HEATER_0_PIN > -1
  71. WRITE(HEATER_0_PIN,LOW);
  72. #endif
  73. #endif
  74. #if TEMP_1_PIN > -1
  75. target_raw[1]=0;
  76. #if HEATER_1_PIN > -1
  77. WRITE(HEATER_1_PIN,LOW);
  78. #endif
  79. #endif
  80. #if TEMP_2_PIN > -1
  81. target_raw[2]=0;
  82. #if HEATER_2_PIN > -1
  83. WRITE(HEATER_2_PIN,LOW);
  84. #endif
  85. #endif
  86. }
  87. void setWatch() {
  88. if(isHeatingHotend0())
  89. {
  90. watchmillis = max(1,millis());
  91. watch_raw[TEMPSENSOR_HOTEND_0] = current_raw[TEMPSENSOR_HOTEND_0];
  92. }
  93. else
  94. {
  95. watchmillis = 0;
  96. }
  97. }
  98. #ifdef HEATER_0_USES_THERMISTOR
  99. #define HEATERSOURCE 1
  100. #endif
  101. #ifdef BED_USES_THERMISTOR
  102. #define BEDSOURCE 1
  103. #endif
  104. #endif