My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

temperature.h 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. // public functions
  24. void tp_init(); //initialise the heating
  25. void manage_heater(); //it is critical that this is called periodically.
  26. enum TempSensor {TEMPSENSOR_HOTEND_0=0,TEMPSENSOR_BED=1, TEMPSENSOR_HOTEND_1=2};
  27. //low leven conversion routines
  28. // do not use this routines and variables outsie of temperature.cpp
  29. int temp2analog(int celsius);
  30. int temp2analogBed(int celsius);
  31. float analog2temp(int raw);
  32. float analog2tempBed(int raw);
  33. extern int target_raw[3];
  34. extern int heatingtarget_raw[3];
  35. extern int current_raw[3];
  36. extern float Kp,Ki,Kd,Kc;
  37. #ifdef PIDTEMP
  38. extern float pid_setpoint ;
  39. #endif
  40. #ifdef WATCHPERIOD
  41. extern int watch_raw[3] ;
  42. extern unsigned long watchmillis;
  43. #endif
  44. //high level conversion routines, for use outside of temperature.cpp
  45. //inline so that there is no performance decrease.
  46. //deg=degreeCelsius
  47. FORCE_INLINE float degHotend0(){ return analog2temp(current_raw[TEMPSENSOR_HOTEND_0]);};
  48. FORCE_INLINE float degHotend1(){ return analog2temp(current_raw[TEMPSENSOR_HOTEND_1]);};
  49. FORCE_INLINE float degBed() { return analog2tempBed(current_raw[TEMPSENSOR_BED]);};
  50. FORCE_INLINE float degHotend(uint8_t extruder){
  51. if(extruder == 0) return analog2temp(current_raw[TEMPSENSOR_HOTEND_0]);
  52. if(extruder == 1) return analog2temp(current_raw[TEMPSENSOR_HOTEND_1]);
  53. };
  54. FORCE_INLINE float degTargetHotend0() { return analog2temp(target_raw[TEMPSENSOR_HOTEND_0]);};
  55. FORCE_INLINE float degTargetHotend1() { return analog2temp(target_raw[TEMPSENSOR_HOTEND_1]);};
  56. FORCE_INLINE float degTargetHotend(uint8_t extruder){
  57. if(extruder == 0) return analog2temp(target_raw[TEMPSENSOR_HOTEND_0]);
  58. if(extruder == 1) return analog2temp(target_raw[TEMPSENSOR_HOTEND_1]);
  59. };
  60. FORCE_INLINE float degTargetBed() { return analog2tempBed(target_raw[TEMPSENSOR_BED]);};
  61. FORCE_INLINE void setTargetHotend0(const float &celsius)
  62. {
  63. target_raw[TEMPSENSOR_HOTEND_0]=temp2analog(celsius);
  64. heatingtarget_raw[TEMPSENSOR_HOTEND_0]=temp2analog(celsius-HEATING_EARLY_FINISH_DEG_OFFSET);
  65. #ifdef PIDTEMP
  66. pid_setpoint = celsius;
  67. #endif //PIDTEMP
  68. };
  69. FORCE_INLINE void setTargetHotend1(const float &celsius) { target_raw[TEMPSENSOR_HOTEND_1]=temp2analog(celsius);};
  70. FORCE_INLINE float setTargetHotend(const float &celcius, uint8_t extruder){
  71. if(extruder == 0) setTargetHotend0(celcius);
  72. if(extruder == 1) setTargetHotend1(celcius);
  73. };
  74. FORCE_INLINE void setTargetBed(const float &celsius) { target_raw[TEMPSENSOR_BED ]=temp2analogBed(celsius);};
  75. FORCE_INLINE bool isHeatingHotend0() {return heatingtarget_raw[TEMPSENSOR_HOTEND_0] > current_raw[TEMPSENSOR_HOTEND_0];};
  76. FORCE_INLINE bool isHeatingHotend1() {return target_raw[TEMPSENSOR_HOTEND_1] > current_raw[TEMPSENSOR_HOTEND_1];};
  77. FORCE_INLINE float isHeatingHotend(uint8_t extruder){
  78. if(extruder == 0) return heatingtarget_raw[TEMPSENSOR_HOTEND_0] > current_raw[TEMPSENSOR_HOTEND_0];
  79. if(extruder == 1) return target_raw[TEMPSENSOR_HOTEND_1] > current_raw[TEMPSENSOR_HOTEND_1];
  80. };
  81. FORCE_INLINE bool isHeatingBed() {return target_raw[TEMPSENSOR_BED] > current_raw[TEMPSENSOR_BED];};
  82. FORCE_INLINE bool isCoolingHotend0() {return target_raw[TEMPSENSOR_HOTEND_0] < current_raw[TEMPSENSOR_HOTEND_0];};
  83. FORCE_INLINE bool isCoolingHotend1() {return target_raw[TEMPSENSOR_HOTEND_1] < current_raw[TEMPSENSOR_HOTEND_1];};
  84. FORCE_INLINE float isCoolingHotend(uint8_t extruder){
  85. if(extruder == 0) return target_raw[TEMPSENSOR_HOTEND_0] < current_raw[TEMPSENSOR_HOTEND_0];
  86. if(extruder == 1) return target_raw[TEMPSENSOR_HOTEND_1] < current_raw[TEMPSENSOR_HOTEND_1];
  87. };
  88. FORCE_INLINE bool isCoolingBed() {return target_raw[TEMPSENSOR_BED] < current_raw[TEMPSENSOR_BED];};
  89. void disable_heater();
  90. void setWatch();
  91. void updatePID();
  92. #endif