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.h 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 current_raw[3];
  35. extern float Kp,Ki,Kd,Kc;
  36. #ifdef PIDTEMP
  37. extern float pid_setpoint ;
  38. #endif
  39. #ifdef WATCHPERIOD
  40. extern int watch_raw[3] ;
  41. extern unsigned long watchmillis;
  42. #endif
  43. //high level conversion routines, for use outside of temperature.cpp
  44. //inline so that there is no performance decrease.
  45. //deg=degreeCelsius
  46. FORCE_INLINE float degHotend0(){ return analog2temp(current_raw[TEMPSENSOR_HOTEND_0]);};
  47. FORCE_INLINE float degHotend1(){ return analog2temp(current_raw[TEMPSENSOR_HOTEND_1]);};
  48. FORCE_INLINE float degBed() { return analog2tempBed(current_raw[TEMPSENSOR_BED]);};
  49. FORCE_INLINE float degHotend(uint8_t extruder){
  50. if(extruder == 0) return analog2temp(current_raw[TEMPSENSOR_HOTEND_0]);
  51. if(extruder == 1) return analog2temp(current_raw[TEMPSENSOR_HOTEND_1]);
  52. };
  53. FORCE_INLINE float degTargetHotend0() { return analog2temp(target_raw[TEMPSENSOR_HOTEND_0]);};
  54. FORCE_INLINE float degTargetHotend1() { return analog2temp(target_raw[TEMPSENSOR_HOTEND_1]);};
  55. FORCE_INLINE float degTargetHotend(uint8_t extruder){
  56. if(extruder == 0) return analog2temp(target_raw[TEMPSENSOR_HOTEND_0]);
  57. if(extruder == 1) return analog2temp(target_raw[TEMPSENSOR_HOTEND_1]);
  58. };
  59. FORCE_INLINE float degTargetBed() { return analog2tempBed(target_raw[TEMPSENSOR_BED]);};
  60. FORCE_INLINE void setTargetHotend0(const float &celsius)
  61. {
  62. target_raw[TEMPSENSOR_HOTEND_0]=temp2analog(celsius);
  63. #ifdef PIDTEMP
  64. pid_setpoint = celsius;
  65. #endif //PIDTEMP
  66. };
  67. FORCE_INLINE void setTargetHotend1(const float &celsius) { target_raw[TEMPSENSOR_HOTEND_1]=temp2analog(celsius);};
  68. FORCE_INLINE float setTargetHotend(const float &celcius, uint8_t extruder){
  69. if(extruder == 0) setTargetHotend0(celcius);
  70. if(extruder == 1) setTargetHotend1(celcius);
  71. };
  72. FORCE_INLINE void setTargetBed(const float &celsius) { target_raw[TEMPSENSOR_BED ]=temp2analogBed(celsius);};
  73. FORCE_INLINE bool isHeatingHotend0() {return target_raw[TEMPSENSOR_HOTEND_0] > current_raw[TEMPSENSOR_HOTEND_0];};
  74. FORCE_INLINE bool isHeatingHotend1() {return target_raw[TEMPSENSOR_HOTEND_1] > current_raw[TEMPSENSOR_HOTEND_1];};
  75. FORCE_INLINE float isHeatingHotend(uint8_t extruder){
  76. if(extruder == 0) return target_raw[TEMPSENSOR_HOTEND_0] > current_raw[TEMPSENSOR_HOTEND_0];
  77. if(extruder == 1) return target_raw[TEMPSENSOR_HOTEND_1] > current_raw[TEMPSENSOR_HOTEND_1];
  78. };
  79. FORCE_INLINE bool isHeatingBed() {return target_raw[TEMPSENSOR_BED] > current_raw[TEMPSENSOR_BED];};
  80. FORCE_INLINE bool isCoolingHotend0() {return target_raw[TEMPSENSOR_HOTEND_0] < current_raw[TEMPSENSOR_HOTEND_0];};
  81. FORCE_INLINE bool isCoolingHotend1() {return target_raw[TEMPSENSOR_HOTEND_1] < current_raw[TEMPSENSOR_HOTEND_1];};
  82. FORCE_INLINE float isCoolingHotend(uint8_t extruder){
  83. if(extruder == 0) return target_raw[TEMPSENSOR_HOTEND_0] < current_raw[TEMPSENSOR_HOTEND_0];
  84. if(extruder == 1) return target_raw[TEMPSENSOR_HOTEND_1] < current_raw[TEMPSENSOR_HOTEND_1];
  85. };
  86. FORCE_INLINE bool isCoolingBed() {return target_raw[TEMPSENSOR_BED] < current_raw[TEMPSENSOR_BED];};
  87. void disable_heater();
  88. void setWatch();
  89. void updatePID();
  90. #endif