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.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. #include "planner.h"
  21. #ifdef PID_ADD_EXTRUSION_RATE
  22. #include "stepper.h"
  23. #endif
  24. // public functions
  25. void tp_init(); //initialise the heating
  26. void manage_heater(); //it is critical that this is called periodically.
  27. //low leven conversion routines
  28. // do not use this routines and variables outsie of temperature.cpp
  29. int temp2analog(int celsius, uint8_t e);
  30. int temp2analogBed(int celsius);
  31. float analog2temp(int raw, uint8_t e);
  32. float analog2tempBed(int raw);
  33. extern int target_raw[EXTRUDERS];
  34. extern int heatingtarget_raw[EXTRUDERS];
  35. extern int current_raw[EXTRUDERS];
  36. extern int target_raw_bed;
  37. extern int current_raw_bed;
  38. extern float Kp,Ki,Kd,Kc;
  39. #ifdef PIDTEMP
  40. extern float pid_setpoint[EXTRUDERS];
  41. #endif
  42. // #ifdef WATCHPERIOD
  43. extern int watch_raw[EXTRUDERS] ;
  44. // extern unsigned long watchmillis;
  45. // #endif
  46. //high level conversion routines, for use outside of temperature.cpp
  47. //inline so that there is no performance decrease.
  48. //deg=degreeCelsius
  49. FORCE_INLINE float degHotend(uint8_t extruder) {
  50. return analog2temp(current_raw[extruder], extruder);
  51. };
  52. FORCE_INLINE float degBed() {
  53. return analog2tempBed(current_raw_bed);
  54. };
  55. FORCE_INLINE float degTargetHotend(uint8_t extruder) {
  56. return analog2temp(target_raw[extruder], extruder);
  57. };
  58. FORCE_INLINE float degTargetBed() {
  59. return analog2tempBed(target_raw_bed);
  60. };
  61. FORCE_INLINE void setTargetHotend(const float &celsius, uint8_t extruder) {
  62. target_raw[extruder] = temp2analog(celsius, extruder);
  63. #ifdef PIDTEMP
  64. pid_setpoint[extruder] = celsius;
  65. #endif //PIDTEMP
  66. };
  67. FORCE_INLINE void setTargetBed(const float &celsius) {
  68. target_raw_bed = temp2analogBed(celsius);
  69. };
  70. FORCE_INLINE bool isHeatingHotend(uint8_t extruder){
  71. return target_raw[extruder] > current_raw[extruder];
  72. };
  73. FORCE_INLINE bool isHeatingBed() {
  74. return target_raw_bed > current_raw_bed;
  75. };
  76. FORCE_INLINE bool isCoolingHotend(uint8_t extruder) {
  77. return target_raw[extruder] < current_raw[extruder];
  78. };
  79. FORCE_INLINE bool isCoolingBed() {
  80. return target_raw_bed < current_raw_bed;
  81. };
  82. #define degHotend0() degHotend(0)
  83. #define degTargetHotend0() degTargetHotend(0)
  84. #define setTargetHotend0(_celsius) setTargetHotend((_celsius), 0)
  85. #define isHeatingHotend0() isHeatingHotend(0)
  86. #define isCoolingHotend0() isCoolingHotend(0)
  87. #if EXTRUDERS > 1
  88. #define degHotend1() degHotend(1)
  89. #define degTargetHotend1() degTargetHotend(1)
  90. #define setTargetHotend1(_celsius) setTargetHotend((_celsius), 1)
  91. #define isHeatingHotend1() isHeatingHotend(1)
  92. #define isCoolingHotend1() isCoolingHotend(1)
  93. #endif
  94. #if EXTRUDERS > 2
  95. #define degHotend2() degHotend(2)
  96. #define degTargetHotend2() degTargetHotend(2)
  97. #define setTargetHotend2(_celsius) setTargetHotend((_celsius), 2)
  98. #define isHeatingHotend2() isHeatingHotend(2)
  99. #define isCoolingHotend2() isCoolingHotend(2)
  100. #endif
  101. #if EXTRUDERS > 3
  102. #error Invalid number of extruders
  103. #endif
  104. FORCE_INLINE void autotempShutdown(){
  105. #ifdef AUTOTEMP
  106. if(autotemp_enabled)
  107. {
  108. autotemp_enabled=false;
  109. if(degTargetHotend(ACTIVE_EXTRUDER)>autotemp_min)
  110. setTargetHotend(0,ACTIVE_EXTRUDER);
  111. }
  112. #endif
  113. }
  114. int getHeaterPower(int heater);
  115. void disable_heater();
  116. void setWatch();
  117. void updatePID();
  118. #endif