My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

temperature.h 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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(); //initialise the heating
  25. void manage_heater(); //it is critical that this is called periodically.
  26. //low leven conversion routines
  27. // do not use this routines and variables outsie of temperature.cpp
  28. int temp2analog(int celsius, uint8_t e);
  29. int temp2analogBed(int celsius);
  30. float analog2temp(int raw, uint8_t e);
  31. float analog2tempBed(int raw);
  32. extern int target_raw[EXTRUDERS];
  33. extern int heatingtarget_raw[EXTRUDERS];
  34. extern int current_raw[EXTRUDERS];
  35. extern int target_raw_bed;
  36. extern int current_raw_bed;
  37. #ifdef BED_LIMIT_SWITCHING
  38. extern int target_bed_low_temp ;
  39. extern int target_bed_high_temp ;
  40. #endif
  41. #ifdef PIDTEMP
  42. extern float Kp,Ki,Kd,Kc;
  43. extern float pid_setpoint[EXTRUDERS];
  44. #endif
  45. #ifdef PIDTEMPBED
  46. extern float bedKp,bedKi,bedKd;
  47. extern float pid_setpoint_bed;
  48. #endif
  49. // #ifdef WATCHPERIOD
  50. extern int watch_raw[EXTRUDERS] ;
  51. // extern unsigned long watchmillis;
  52. // #endif
  53. //high level conversion routines, for use outside of temperature.cpp
  54. //inline so that there is no performance decrease.
  55. //deg=degreeCelsius
  56. FORCE_INLINE float degHotend(uint8_t extruder) {
  57. return analog2temp(current_raw[extruder], extruder);
  58. };
  59. FORCE_INLINE float degBed() {
  60. return analog2tempBed(current_raw_bed);
  61. };
  62. FORCE_INLINE float degTargetHotend(uint8_t extruder) {
  63. return analog2temp(target_raw[extruder], extruder);
  64. };
  65. FORCE_INLINE float degTargetBed() {
  66. return analog2tempBed(target_raw_bed);
  67. };
  68. FORCE_INLINE void setTargetHotend(const float &celsius, uint8_t extruder) {
  69. target_raw[extruder] = temp2analog(celsius, extruder);
  70. #ifdef PIDTEMP
  71. pid_setpoint[extruder] = celsius;
  72. #endif //PIDTEMP
  73. };
  74. FORCE_INLINE void setTargetBed(const float &celsius) {
  75. target_raw_bed = temp2analogBed(celsius);
  76. #ifdef PIDTEMPBED
  77. pid_setpoint_bed = celsius;
  78. #elif defined BED_LIMIT_SWITCHING
  79. if(celsius>BED_HYSTERESIS)
  80. {
  81. target_bed_low_temp= temp2analogBed(celsius-BED_HYSTERESIS);
  82. target_bed_high_temp= temp2analogBed(celsius+BED_HYSTERESIS);
  83. }
  84. else
  85. {
  86. target_bed_low_temp=0;
  87. target_bed_high_temp=0;
  88. }
  89. #endif
  90. };
  91. FORCE_INLINE bool isHeatingHotend(uint8_t extruder){
  92. return target_raw[extruder] > current_raw[extruder];
  93. };
  94. FORCE_INLINE bool isHeatingBed() {
  95. return target_raw_bed > current_raw_bed;
  96. };
  97. FORCE_INLINE bool isCoolingHotend(uint8_t extruder) {
  98. return target_raw[extruder] < current_raw[extruder];
  99. };
  100. FORCE_INLINE bool isCoolingBed() {
  101. return target_raw_bed < current_raw_bed;
  102. };
  103. #define degHotend0() degHotend(0)
  104. #define degTargetHotend0() degTargetHotend(0)
  105. #define setTargetHotend0(_celsius) setTargetHotend((_celsius), 0)
  106. #define isHeatingHotend0() isHeatingHotend(0)
  107. #define isCoolingHotend0() isCoolingHotend(0)
  108. #if EXTRUDERS > 1
  109. #define degHotend1() degHotend(1)
  110. #define degTargetHotend1() degTargetHotend(1)
  111. #define setTargetHotend1(_celsius) setTargetHotend((_celsius), 1)
  112. #define isHeatingHotend1() isHeatingHotend(1)
  113. #define isCoolingHotend1() isCoolingHotend(1)
  114. #else
  115. #define setTargetHotend1(_celsius) do{}while(0)
  116. #endif
  117. #if EXTRUDERS > 2
  118. #define degHotend2() degHotend(2)
  119. #define degTargetHotend2() degTargetHotend(2)
  120. #define setTargetHotend2(_celsius) setTargetHotend((_celsius), 2)
  121. #define isHeatingHotend2() isHeatingHotend(2)
  122. #define isCoolingHotend2() isCoolingHotend(2)
  123. #else
  124. #define setTargetHotend2(_celsius) do{}while(0)
  125. #endif
  126. #if EXTRUDERS > 3
  127. #error Invalid number of extruders
  128. #endif
  129. int getHeaterPower(int heater);
  130. void disable_heater();
  131. void setWatch();
  132. void updatePID();
  133. FORCE_INLINE void autotempShutdown(){
  134. #ifdef AUTOTEMP
  135. if(autotemp_enabled)
  136. {
  137. autotemp_enabled=false;
  138. if(degTargetHotend(active_extruder)>autotemp_min)
  139. setTargetHotend(0,active_extruder);
  140. }
  141. #endif
  142. }
  143. void PID_autotune(float temp, int extruder, int ncycles);
  144. #endif