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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. #ifdef PID_ADD_EXTRUSION_RATE
  20. #include "stepper.h"
  21. #endif
  22. enum TempSensor {TEMPSENSOR_HOTEND=0,TEMPSENSOR_BED=1, TEMPSENSOR_AUX=2};
  23. // ther must be only one instance of this class, and it is created in temperature.cpp by itself and is called "htr".
  24. // all the variables are static, so that of the compiler optimization is more easy.
  25. // I honestly hope that this increases readability and structure.
  26. // none of the variables or routines should be called from an secondary process/interrupt with the exceptino of current_raw[].
  27. class Heater
  28. {
  29. public:
  30. Heater(); //treplaces tp_init();
  31. ~Heater();
  32. void static manage_heater(); /// it is critical that this is called continously.
  33. // conversion routines, const since they don't change any class variables.
  34. float const static temp2analog(const int celsius);
  35. float const static temp2analogBed(const int celsius);
  36. float const static analog2temp(const int raw);
  37. float const static analog2tempBed(const int raw);
  38. inline float const static celsius(const TempSensor s)
  39. {
  40. if(s==TEMPSENSOR_BED)
  41. return analog2tempBed(Heater::current_raw[s]);
  42. else
  43. return analog2temp(Heater::current_raw[s]);
  44. };
  45. inline float const static celsiusTarget(const TempSensor s)
  46. {
  47. if(s==TEMPSENSOR_BED)
  48. return analog2tempBed(Heater::target_raw[s]);
  49. else
  50. return analog2temp(Heater::target_raw[s]);
  51. };
  52. inline float static setCelsius(const TempSensor s, const int celsius)
  53. {
  54. #ifdef PIDTEMP
  55. if(s==TEMPSENSOR_HOTEND)
  56. Heater::pid_setpoint = celsius;
  57. #endif //PIDTEM
  58. if(s==TEMPSENSOR_BED)
  59. Heater::target_raw[s] = temp2analog(celsius);
  60. else
  61. Heater::target_raw[s] = temp2analogBed(celsius);
  62. };
  63. inline bool const static isHeating(TempSensor s)
  64. { return (Heater::target_raw[s]>Heater::current_raw[s]);};
  65. inline bool const static isCooling(TempSensor s)
  66. { return (Heater::target_raw[s]<Heater::current_raw[s]);};
  67. public:
  68. #ifdef PIDTEMP
  69. static float Kp;
  70. static float Ki;
  71. static float Kd;
  72. static float Kc;
  73. #endif
  74. static int target_raw[3];
  75. static float pid_setpoint;
  76. volatile static int current_raw[3]; //this are written by an ISR, so volatile.
  77. volatile static bool temp_meas_ready ; //also this is set by the ISR
  78. private:
  79. static unsigned long previous_millis_heater, previous_millis_bed_heater;
  80. #ifdef PIDTEMP
  81. static float temp_iState;
  82. static float temp_dState;
  83. static float pTerm;
  84. static float iTerm;
  85. static float dTerm;
  86. //int output;
  87. static float pid_error;
  88. static float temp_iState_min;
  89. static float temp_iState_max;
  90. static float pid_input;
  91. static float pid_output;
  92. static bool pid_reset;
  93. static float HeaterPower;
  94. #endif //PIDTEMP
  95. public: //but only accesed from the ISR hence not volatile
  96. #ifdef MINTEMP
  97. static int minttemp;
  98. #endif //MINTEMP
  99. #ifdef MAXTEMP
  100. static int maxttemp;
  101. #endif //MAXTEMP
  102. #ifdef BED_MINTEMP
  103. static int bed_minttemp ;
  104. #endif //BED_MINTEMP
  105. #ifdef BED_MAXTEMP
  106. static int bed_maxttemp;
  107. #endif //BED_MAXTEMP
  108. };
  109. extern Heater htr; //this creates the single, global instance
  110. #ifdef HEATER_USES_THERMISTOR
  111. #define HEATERSOURCE 1
  112. #endif
  113. #ifdef BED_USES_THERMISTOR
  114. #define BEDSOURCE 1
  115. #endif
  116. #endif