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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. #if ENABLED(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. #if ENABLED(FILAMENT_SENSOR)
  27. // For converting raw Filament Width to milimeters
  28. float analog2widthFil();
  29. // For converting raw Filament Width to an extrusion ratio
  30. int widthFil_to_size_ratio();
  31. #endif
  32. // low level conversion routines
  33. // do not use these routines and variables outside of temperature.cpp
  34. extern int target_temperature[4];
  35. extern float current_temperature[4];
  36. #if ENABLED(SHOW_TEMP_ADC_VALUES)
  37. extern int current_temperature_raw[4];
  38. extern int current_temperature_bed_raw;
  39. #endif
  40. extern int target_temperature_bed;
  41. extern float current_temperature_bed;
  42. #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
  43. extern float redundant_temperature;
  44. #endif
  45. #if HAS_CONTROLLERFAN
  46. extern unsigned char soft_pwm_bed;
  47. #endif
  48. #if ENABLED(PIDTEMP)
  49. #if ENABLED(PID_PARAMS_PER_EXTRUDER)
  50. extern float Kp[EXTRUDERS], Ki[EXTRUDERS], Kd[EXTRUDERS], Kc[EXTRUDERS]; // one param per extruder
  51. #define PID_PARAM(param,e) param[e] // use macro to point to array value
  52. #else
  53. extern float Kp, Ki, Kd, Kc; // one param per extruder - saves 20 or 36 bytes of ram (inc array pointer)
  54. #define PID_PARAM(param, e) param // use macro to point directly to value
  55. #endif // PID_PARAMS_PER_EXTRUDER
  56. float scalePID_i(float i);
  57. float scalePID_d(float d);
  58. float unscalePID_i(float i);
  59. float unscalePID_d(float d);
  60. #endif
  61. #if ENABLED(PIDTEMPBED)
  62. extern float bedKp, bedKi, bedKd;
  63. #endif
  64. #if ENABLED(BABYSTEPPING)
  65. extern volatile int babystepsTodo[3];
  66. #endif
  67. //high level conversion routines, for use outside of temperature.cpp
  68. //inline so that there is no performance decrease.
  69. //deg=degreeCelsius
  70. FORCE_INLINE float degHotend(uint8_t extruder) { return current_temperature[extruder]; }
  71. FORCE_INLINE float degBed() { return current_temperature_bed; }
  72. #if ENABLED(SHOW_TEMP_ADC_VALUES)
  73. FORCE_INLINE float rawHotendTemp(uint8_t extruder) { return current_temperature_raw[extruder]; }
  74. FORCE_INLINE float rawBedTemp() { return current_temperature_bed_raw; }
  75. #endif
  76. FORCE_INLINE float degTargetHotend(uint8_t extruder) { return target_temperature[extruder]; }
  77. FORCE_INLINE float degTargetBed() { return target_temperature_bed; }
  78. #if ENABLED(THERMAL_PROTECTION_HOTENDS)
  79. void start_watching_heater(int e = 0);
  80. #endif
  81. FORCE_INLINE void setTargetHotend(const float& celsius, uint8_t extruder) {
  82. target_temperature[extruder] = celsius;
  83. #if ENABLED(THERMAL_PROTECTION_HOTENDS)
  84. start_watching_heater(extruder);
  85. #endif
  86. }
  87. FORCE_INLINE void setTargetBed(const float& celsius) { target_temperature_bed = celsius; }
  88. FORCE_INLINE bool isHeatingHotend(uint8_t extruder) { return target_temperature[extruder] > current_temperature[extruder]; }
  89. FORCE_INLINE bool isHeatingBed() { return target_temperature_bed > current_temperature_bed; }
  90. FORCE_INLINE bool isCoolingHotend(uint8_t extruder) { return target_temperature[extruder] < current_temperature[extruder]; }
  91. FORCE_INLINE bool isCoolingBed() { return target_temperature_bed < current_temperature_bed; }
  92. #define HOTEND_ROUTINES(NR) \
  93. FORCE_INLINE float degHotend##NR() { return degHotend(NR); } \
  94. FORCE_INLINE float degTargetHotend##NR() { return degTargetHotend(NR); } \
  95. FORCE_INLINE void setTargetHotend##NR(const float c) { setTargetHotend(c, NR); } \
  96. FORCE_INLINE bool isHeatingHotend##NR() { return isHeatingHotend(NR); } \
  97. FORCE_INLINE bool isCoolingHotend##NR() { return isCoolingHotend(NR); }
  98. HOTEND_ROUTINES(0);
  99. #if EXTRUDERS > 1
  100. HOTEND_ROUTINES(1);
  101. #else
  102. #define setTargetHotend1(c) do{}while(0)
  103. #endif
  104. #if EXTRUDERS > 2
  105. HOTEND_ROUTINES(2);
  106. #else
  107. #define setTargetHotend2(c) do{}while(0)
  108. #endif
  109. #if EXTRUDERS > 3
  110. HOTEND_ROUTINES(3);
  111. #else
  112. #define setTargetHotend3(c) do{}while(0)
  113. #endif
  114. int getHeaterPower(int heater);
  115. void disable_all_heaters();
  116. void updatePID();
  117. void PID_autotune(float temp, int extruder, int ncycles);
  118. void setExtruderAutoFanState(int pin, bool state);
  119. void checkExtruderAutoFans();
  120. FORCE_INLINE void autotempShutdown() {
  121. #if ENABLED(AUTOTEMP)
  122. if (autotemp_enabled) {
  123. autotemp_enabled = false;
  124. if (degTargetHotend(active_extruder) > autotemp_min)
  125. setTargetHotend(0, active_extruder);
  126. }
  127. #endif
  128. }
  129. #endif // TEMPERATURE_H