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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 "planner.h"
  20. #ifdef PID_ADD_EXTRUSION_RATE
  21. #include "stepper.h"
  22. #endif
  23. // public functions
  24. void tp_init(); //initialize the heating
  25. void manage_heater(); //it is critical that this is called periodically.
  26. // low level conversion routines
  27. // do not use these routines and variables outside of temperature.cpp
  28. extern int target_temperature[EXTRUDERS];
  29. extern float current_temperature[EXTRUDERS];
  30. #ifdef SHOW_TEMP_ADC_VALUES
  31. extern int current_temperature_raw[EXTRUDERS];
  32. extern int current_temperature_bed_raw;
  33. #endif
  34. extern int target_temperature_bed;
  35. extern float current_temperature_bed;
  36. #ifdef TEMP_SENSOR_1_AS_REDUNDANT
  37. extern float redundant_temperature;
  38. #endif
  39. #if defined(CONTROLLERFAN_PIN) && CONTROLLERFAN_PIN > -1
  40. extern unsigned char soft_pwm_bed;
  41. #endif
  42. #ifdef PIDTEMP
  43. extern float Kp,Ki,Kd,Kc;
  44. float scalePID_i(float i);
  45. float scalePID_d(float d);
  46. float unscalePID_i(float i);
  47. float unscalePID_d(float d);
  48. #endif
  49. #ifdef PIDTEMPBED
  50. extern float bedKp,bedKi,bedKd;
  51. #endif
  52. #ifdef BABYSTEPPING
  53. extern volatile int babystepsTodo[3];
  54. #endif
  55. //high level conversion routines, for use outside of temperature.cpp
  56. //inline so that there is no performance decrease.
  57. //deg=degreeCelsius
  58. FORCE_INLINE float degHotend(uint8_t extruder) {
  59. return current_temperature[extruder];
  60. };
  61. #ifdef SHOW_TEMP_ADC_VALUES
  62. FORCE_INLINE float rawHotendTemp(uint8_t extruder) {
  63. return current_temperature_raw[extruder];
  64. };
  65. FORCE_INLINE float rawBedTemp() {
  66. return current_temperature_bed_raw;
  67. };
  68. #endif
  69. FORCE_INLINE float degBed() {
  70. return current_temperature_bed;
  71. };
  72. FORCE_INLINE float degTargetHotend(uint8_t extruder) {
  73. return target_temperature[extruder];
  74. };
  75. FORCE_INLINE float degTargetBed() {
  76. return target_temperature_bed;
  77. };
  78. FORCE_INLINE void setTargetHotend(const float &celsius, uint8_t extruder) {
  79. target_temperature[extruder] = celsius;
  80. };
  81. FORCE_INLINE void setTargetBed(const float &celsius) {
  82. target_temperature_bed = celsius;
  83. };
  84. FORCE_INLINE bool isHeatingHotend(uint8_t extruder){
  85. return target_temperature[extruder] > current_temperature[extruder];
  86. };
  87. FORCE_INLINE bool isHeatingBed() {
  88. return target_temperature_bed > current_temperature_bed;
  89. };
  90. FORCE_INLINE bool isCoolingHotend(uint8_t extruder) {
  91. return target_temperature[extruder] < current_temperature[extruder];
  92. };
  93. FORCE_INLINE bool isCoolingBed() {
  94. return target_temperature_bed < current_temperature_bed;
  95. };
  96. #define degHotend0() degHotend(0)
  97. #define degTargetHotend0() degTargetHotend(0)
  98. #define setTargetHotend0(_celsius) setTargetHotend((_celsius), 0)
  99. #define isHeatingHotend0() isHeatingHotend(0)
  100. #define isCoolingHotend0() isCoolingHotend(0)
  101. #if EXTRUDERS > 1
  102. #define degHotend1() degHotend(1)
  103. #define degTargetHotend1() degTargetHotend(1)
  104. #define setTargetHotend1(_celsius) setTargetHotend((_celsius), 1)
  105. #define isHeatingHotend1() isHeatingHotend(1)
  106. #define isCoolingHotend1() isCoolingHotend(1)
  107. #else
  108. #define setTargetHotend1(_celsius) do{}while(0)
  109. #endif
  110. #if EXTRUDERS > 2
  111. #define degHotend2() degHotend(2)
  112. #define degTargetHotend2() degTargetHotend(2)
  113. #define setTargetHotend2(_celsius) setTargetHotend((_celsius), 2)
  114. #define isHeatingHotend2() isHeatingHotend(2)
  115. #define isCoolingHotend2() isCoolingHotend(2)
  116. #else
  117. #define setTargetHotend2(_celsius) do{}while(0)
  118. #endif
  119. #if EXTRUDERS > 3
  120. #error Invalid number of extruders
  121. #endif
  122. int getHeaterPower(int heater);
  123. void disable_heater();
  124. void setWatch();
  125. void updatePID();
  126. FORCE_INLINE void autotempShutdown(){
  127. #ifdef AUTOTEMP
  128. if(autotemp_enabled)
  129. {
  130. autotemp_enabled=false;
  131. if(degTargetHotend(active_extruder)>autotemp_min)
  132. setTargetHotend(0,active_extruder);
  133. }
  134. #endif
  135. }
  136. void PID_autotune(float temp, int extruder, int ncycles);
  137. #endif