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 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. temperature.h - temperature controller
  24. Part of Marlin
  25. Copyright (c) 2011 Erik van der Zalm
  26. Grbl is free software: you can redistribute it and/or modify
  27. it under the terms of the GNU General Public License as published by
  28. the Free Software Foundation, either version 3 of the License, or
  29. (at your option) any later version.
  30. Grbl is distributed in the hope that it will be useful,
  31. but WITHOUT ANY WARRANTY; without even the implied warranty of
  32. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  33. GNU General Public License for more details.
  34. You should have received a copy of the GNU General Public License
  35. along with Grbl. If not, see <http://www.gnu.org/licenses/>.
  36. */
  37. #ifndef TEMPERATURE_H
  38. #define TEMPERATURE_H
  39. #include "Marlin.h"
  40. #include "planner.h"
  41. #if ENABLED(PID_ADD_EXTRUSION_RATE)
  42. #include "stepper.h"
  43. #endif
  44. // public functions
  45. void tp_init(); //initialize the heating
  46. void manage_heater(); //it is critical that this is called periodically.
  47. #if ENABLED(FILAMENT_WIDTH_SENSOR)
  48. // For converting raw Filament Width to milimeters
  49. float analog2widthFil();
  50. // For converting raw Filament Width to an extrusion ratio
  51. int widthFil_to_size_ratio();
  52. #endif
  53. // low level conversion routines
  54. // do not use these routines and variables outside of temperature.cpp
  55. extern int target_temperature[4];
  56. extern float current_temperature[4];
  57. #if ENABLED(SHOW_TEMP_ADC_VALUES)
  58. extern int current_temperature_raw[4];
  59. extern int current_temperature_bed_raw;
  60. #endif
  61. extern int target_temperature_bed;
  62. extern float current_temperature_bed;
  63. #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
  64. extern float redundant_temperature;
  65. #endif
  66. #if HAS_CONTROLLERFAN
  67. extern unsigned char soft_pwm_bed;
  68. #endif
  69. #if ENABLED(FAN_SOFT_PWM)
  70. extern unsigned char fanSpeedSoftPwm[FAN_COUNT];
  71. #endif
  72. #if ENABLED(PIDTEMP)
  73. #if ENABLED(PID_PARAMS_PER_EXTRUDER)
  74. extern float Kp[EXTRUDERS], Ki[EXTRUDERS], Kd[EXTRUDERS]; // one param per extruder
  75. #if ENABLED(PID_ADD_EXTRUSION_RATE)
  76. extern float Kc[EXTRUDERS];
  77. #endif
  78. #define PID_PARAM(param, e) param[e] // use macro to point to array value
  79. #else
  80. extern float Kp, Ki, Kd; // one param per extruder - saves 20 or 36 bytes of ram (inc array pointer)
  81. #if ENABLED(PID_ADD_EXTRUSION_RATE)
  82. extern float Kc;
  83. #endif
  84. #define PID_PARAM(param, e) param // use macro to point directly to value
  85. #endif // PID_PARAMS_PER_EXTRUDER
  86. float scalePID_i(float i);
  87. float scalePID_d(float d);
  88. float unscalePID_i(float i);
  89. float unscalePID_d(float d);
  90. #endif
  91. #if ENABLED(PIDTEMPBED)
  92. extern float bedKp, bedKi, bedKd;
  93. #endif
  94. #if ENABLED(BABYSTEPPING)
  95. extern volatile int babystepsTodo[3];
  96. #endif
  97. //high level conversion routines, for use outside of temperature.cpp
  98. //inline so that there is no performance decrease.
  99. //deg=degreeCelsius
  100. FORCE_INLINE float degHotend(uint8_t extruder) { return current_temperature[extruder]; }
  101. FORCE_INLINE float degBed() { return current_temperature_bed; }
  102. #if ENABLED(SHOW_TEMP_ADC_VALUES)
  103. FORCE_INLINE float rawHotendTemp(uint8_t extruder) { return current_temperature_raw[extruder]; }
  104. FORCE_INLINE float rawBedTemp() { return current_temperature_bed_raw; }
  105. #endif
  106. FORCE_INLINE float degTargetHotend(uint8_t extruder) { return target_temperature[extruder]; }
  107. FORCE_INLINE float degTargetBed() { return target_temperature_bed; }
  108. #if ENABLED(THERMAL_PROTECTION_HOTENDS) && WATCH_TEMP_PERIOD > 0
  109. void start_watching_heater(int e = 0);
  110. #endif
  111. #if ENABLED(THERMAL_PROTECTION_BED) && WATCH_BED_TEMP_PERIOD > 0
  112. void start_watching_bed();
  113. #endif
  114. FORCE_INLINE void setTargetHotend(const float& celsius, uint8_t extruder) {
  115. target_temperature[extruder] = celsius;
  116. #if ENABLED(THERMAL_PROTECTION_HOTENDS) && WATCH_TEMP_PERIOD > 0
  117. start_watching_heater(extruder);
  118. #endif
  119. }
  120. FORCE_INLINE void setTargetBed(const float& celsius) {
  121. target_temperature_bed = celsius;
  122. #if ENABLED(THERMAL_PROTECTION_BED) && WATCH_BED_TEMP_PERIOD > 0
  123. start_watching_bed();
  124. #endif
  125. }
  126. FORCE_INLINE bool isHeatingHotend(uint8_t extruder) { return target_temperature[extruder] > current_temperature[extruder]; }
  127. FORCE_INLINE bool isHeatingBed() { return target_temperature_bed > current_temperature_bed; }
  128. FORCE_INLINE bool isCoolingHotend(uint8_t extruder) { return target_temperature[extruder] < current_temperature[extruder]; }
  129. FORCE_INLINE bool isCoolingBed() { return target_temperature_bed < current_temperature_bed; }
  130. #define HOTEND_ROUTINES(NR) \
  131. FORCE_INLINE float degHotend##NR() { return degHotend(NR); } \
  132. FORCE_INLINE float degTargetHotend##NR() { return degTargetHotend(NR); } \
  133. FORCE_INLINE void setTargetHotend##NR(const float c) { setTargetHotend(c, NR); } \
  134. FORCE_INLINE bool isHeatingHotend##NR() { return isHeatingHotend(NR); } \
  135. FORCE_INLINE bool isCoolingHotend##NR() { return isCoolingHotend(NR); }
  136. HOTEND_ROUTINES(0);
  137. #if EXTRUDERS > 1
  138. HOTEND_ROUTINES(1);
  139. #else
  140. #define setTargetHotend1(c) do{}while(0)
  141. #endif
  142. #if EXTRUDERS > 2
  143. HOTEND_ROUTINES(2);
  144. #else
  145. #define setTargetHotend2(c) do{}while(0)
  146. #endif
  147. #if EXTRUDERS > 3
  148. HOTEND_ROUTINES(3);
  149. #else
  150. #define setTargetHotend3(c) do{}while(0)
  151. #endif
  152. int getHeaterPower(int heater);
  153. void disable_all_heaters();
  154. void updatePID();
  155. #if ENABLED(PIDTEMP)
  156. void PID_autotune(float temp, int extruder, int ncycles, bool set_result=false);
  157. #endif
  158. void setExtruderAutoFanState(int pin, bool state);
  159. void checkExtruderAutoFans();
  160. FORCE_INLINE void autotempShutdown() {
  161. #if ENABLED(AUTOTEMP)
  162. if (planner.autotemp_enabled) {
  163. planner.autotemp_enabled = false;
  164. if (degTargetHotend(active_extruder) > planner.autotemp_min)
  165. setTargetHotend(0, active_extruder);
  166. }
  167. #endif
  168. }
  169. #endif // TEMPERATURE_H