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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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(PIDTEMP)
  70. #if ENABLED(PID_PARAMS_PER_EXTRUDER)
  71. extern float Kp[EXTRUDERS], Ki[EXTRUDERS], Kd[EXTRUDERS]; // one param per extruder
  72. #if ENABLED(PID_ADD_EXTRUSION_RATE)
  73. extern float Kc[EXTRUDERS];
  74. #endif
  75. #define PID_PARAM(param, e) param[e] // use macro to point to array value
  76. #else
  77. extern float Kp, Ki, Kd; // one param per extruder - saves 20 or 36 bytes of ram (inc array pointer)
  78. #if ENABLED(PID_ADD_EXTRUSION_RATE)
  79. extern float Kc;
  80. #endif
  81. #define PID_PARAM(param, e) param // use macro to point directly to value
  82. #endif // PID_PARAMS_PER_EXTRUDER
  83. float scalePID_i(float i);
  84. float scalePID_d(float d);
  85. float unscalePID_i(float i);
  86. float unscalePID_d(float d);
  87. #endif
  88. #if ENABLED(PIDTEMPBED)
  89. extern float bedKp, bedKi, bedKd;
  90. #endif
  91. #if ENABLED(BABYSTEPPING)
  92. extern volatile int babystepsTodo[3];
  93. #endif
  94. //high level conversion routines, for use outside of temperature.cpp
  95. //inline so that there is no performance decrease.
  96. //deg=degreeCelsius
  97. FORCE_INLINE float degHotend(uint8_t extruder) { return current_temperature[extruder]; }
  98. FORCE_INLINE float degBed() { return current_temperature_bed; }
  99. #if ENABLED(SHOW_TEMP_ADC_VALUES)
  100. FORCE_INLINE float rawHotendTemp(uint8_t extruder) { return current_temperature_raw[extruder]; }
  101. FORCE_INLINE float rawBedTemp() { return current_temperature_bed_raw; }
  102. #endif
  103. FORCE_INLINE float degTargetHotend(uint8_t extruder) { return target_temperature[extruder]; }
  104. FORCE_INLINE float degTargetBed() { return target_temperature_bed; }
  105. #if ENABLED(THERMAL_PROTECTION_HOTENDS)
  106. void start_watching_heater(int e = 0);
  107. #endif
  108. FORCE_INLINE void setTargetHotend(const float& celsius, uint8_t extruder) {
  109. target_temperature[extruder] = celsius;
  110. #if ENABLED(THERMAL_PROTECTION_HOTENDS)
  111. start_watching_heater(extruder);
  112. #endif
  113. }
  114. FORCE_INLINE void setTargetBed(const float& celsius) { target_temperature_bed = celsius; }
  115. FORCE_INLINE bool isHeatingHotend(uint8_t extruder) { return target_temperature[extruder] > current_temperature[extruder]; }
  116. FORCE_INLINE bool isHeatingBed() { return target_temperature_bed > current_temperature_bed; }
  117. FORCE_INLINE bool isCoolingHotend(uint8_t extruder) { return target_temperature[extruder] < current_temperature[extruder]; }
  118. FORCE_INLINE bool isCoolingBed() { return target_temperature_bed < current_temperature_bed; }
  119. #define HOTEND_ROUTINES(NR) \
  120. FORCE_INLINE float degHotend##NR() { return degHotend(NR); } \
  121. FORCE_INLINE float degTargetHotend##NR() { return degTargetHotend(NR); } \
  122. FORCE_INLINE void setTargetHotend##NR(const float c) { setTargetHotend(c, NR); } \
  123. FORCE_INLINE bool isHeatingHotend##NR() { return isHeatingHotend(NR); } \
  124. FORCE_INLINE bool isCoolingHotend##NR() { return isCoolingHotend(NR); }
  125. HOTEND_ROUTINES(0);
  126. #if EXTRUDERS > 1
  127. HOTEND_ROUTINES(1);
  128. #else
  129. #define setTargetHotend1(c) do{}while(0)
  130. #endif
  131. #if EXTRUDERS > 2
  132. HOTEND_ROUTINES(2);
  133. #else
  134. #define setTargetHotend2(c) do{}while(0)
  135. #endif
  136. #if EXTRUDERS > 3
  137. HOTEND_ROUTINES(3);
  138. #else
  139. #define setTargetHotend3(c) do{}while(0)
  140. #endif
  141. int getHeaterPower(int heater);
  142. void disable_all_heaters();
  143. void updatePID();
  144. #if ENABLED(PIDTEMP)
  145. void PID_autotune(float temp, int extruder, int ncycles, bool set_result=false);
  146. #endif
  147. void setExtruderAutoFanState(int pin, bool state);
  148. void checkExtruderAutoFans();
  149. FORCE_INLINE void autotempShutdown() {
  150. #if ENABLED(AUTOTEMP)
  151. if (autotemp_enabled) {
  152. autotemp_enabled = false;
  153. if (degTargetHotend(active_extruder) > autotemp_min)
  154. setTargetHotend(0, active_extruder);
  155. }
  156. #endif
  157. }
  158. #endif // TEMPERATURE_H