temperature.h

changeset 0
2c8ba1964db7
equal deleted inserted replaced
-1:000000000000 0:2c8ba1964db7
1 /*
2 temperature.h - temperature controller
3 Part of Marlin
4
5 Copyright (c) 2011 Erik van der Zalm
6
7 Grbl is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 Grbl is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Grbl. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #ifndef temperature_h
22 #define temperature_h
23
24 #include "Marlin.h"
25 #include "planner.h"
26 #include "slave_comms.h"
27
28 // If we are using a slave board we have multiple extruders, but we only have to worry
29 // about the temperature of the first one of them.
30
31 #ifdef REPRAPPRO_MULTIMATERIALS
32 #define EXTRUDERS_T 1
33 #else
34 #define EXTRUDERS_T EXTRUDERS
35 #endif
36
37 // public functions
38 void tp_init(); //initialise the heating
39 void manage_heater(); //it is critical that this is called periodically.
40
41 //low leven conversion routines
42 // do not use this routines and variables outsie of temperature.cpp
43 int temp2analog(int celsius, uint8_t e);
44 int temp2analogBed(int celsius);
45 float analog2temp(int raw, uint8_t e);
46 float analog2tempBed(int raw);
47 extern int target_raw[EXTRUDERS_T];
48 extern int heatingtarget_raw[EXTRUDERS_T];
49 extern int current_raw[EXTRUDERS_T];
50 static int minttemp[EXTRUDERS_T] = { 50 };
51 static int maxttemp[EXTRUDERS_T] = { 16383 }; // the first value used for all
52 extern int target_raw_bed;
53 extern int current_raw_bed;
54 extern int b_beta;
55 extern int b_resistor;
56 extern long b_thermistor;
57 extern float b_inf;
58
59 extern int n_beta;
60 extern int n_resistor;
61 extern long n_thermistor;
62 extern float n_inf;
63
64 extern float Kp,Ki,Kd,Kc;
65 extern int Ki_Max;
66
67 #ifdef PIDTEMP
68 extern float pid_setpoint[EXTRUDERS_T];
69 #endif
70
71 //high level conversion routines, for use outside of temperature.cpp
72 //inline so that there is no performance decrease.
73 //deg=degreeCelsius
74
75 #ifdef REPRAPPRO_MULTIMATERIALS
76 FORCE_INLINE float degHotend(uint8_t extruder)
77 {
78 if(extruder == 0)
79 return analog2temp(current_raw[extruder], extruder);
80 else
81 return slaveDegHotend(extruder);
82 };
83
84 FORCE_INLINE void setTargetHotend(const float &celsius, uint8_t extruder)
85 {
86 if(extruder == 0)
87 {
88 target_raw[extruder] = temp2analog(celsius, extruder);
89 #ifdef PIDTEMP
90 pid_setpoint[extruder] = celsius;
91 #endif //PIDTEMP
92 } else
93 slaveSetTargetHotend(celsius, extruder);
94 };
95
96 FORCE_INLINE float degTargetHotend(uint8_t extruder)
97 {
98 if(extruder == 0)
99 return analog2temp(target_raw[extruder], extruder);
100 else
101 return slaveDegTargetHotend(extruder);
102 };
103
104 FORCE_INLINE bool isHeatingHotend(uint8_t extruder)
105 {
106 if(extruder == 0)
107 return target_raw[extruder] > current_raw[extruder];
108 else
109 return slaveIsHeatingHotend(extruder);
110 };
111
112 FORCE_INLINE bool isCoolingHotend(uint8_t extruder)
113 {
114 if(extruder == 0)
115 return target_raw[extruder] < current_raw[extruder];
116 else
117 return slaveIsCoolingHotend(extruder);
118 };
119
120 #else
121
122 FORCE_INLINE float degHotend(uint8_t extruder) {
123 return analog2temp(current_raw[extruder], extruder);
124 };
125 FORCE_INLINE int rawHotend(uint8_t extruder) {
126 return current_raw[extruder];
127 };
128 FORCE_INLINE int minHotend(uint8_t extruder) {
129 return minttemp[extruder];
130 };
131 FORCE_INLINE int maxHotend(uint8_t extruder) {
132 return maxttemp[extruder];
133 };
134
135 FORCE_INLINE void setTargetHotend(const float &celsius, uint8_t extruder) {
136 target_raw[extruder] = temp2analog(celsius, extruder);
137 #ifdef PIDTEMP
138 pid_setpoint[extruder] = celsius;
139 #endif //PIDTEMP
140 };
141
142 FORCE_INLINE float degTargetHotend(uint8_t extruder) {
143 return analog2temp(target_raw[extruder], extruder);
144 };
145
146 FORCE_INLINE bool isHeatingHotend(uint8_t extruder){
147 return target_raw[extruder] > current_raw[extruder];
148 };
149
150 FORCE_INLINE bool isCoolingHotend(uint8_t extruder) {
151 return target_raw[extruder] < current_raw[extruder];
152 };
153 #endif // REPRAPPRO_MULTIMATERIALS
154
155
156
157 FORCE_INLINE float degBed() {
158 return analog2tempBed(current_raw_bed);
159 };
160
161 FORCE_INLINE float degTargetBed() {
162 return analog2tempBed(target_raw_bed);
163 };
164
165 FORCE_INLINE void setTargetBed(const float &celsius) {
166
167 target_raw_bed = temp2analogBed(celsius);
168 };
169
170 FORCE_INLINE bool isHeatingBed() {
171 return target_raw_bed > current_raw_bed;
172 };
173
174 FORCE_INLINE bool isCoolingBed() {
175 return target_raw_bed < current_raw_bed;
176 };
177
178 #define degHotend0() degHotend(0)
179 #define degTargetHotend0() degTargetHotend(0)
180 #define setTargetHotend0(_celsius) setTargetHotend((_celsius), 0)
181 #define isHeatingHotend0() isHeatingHotend(0)
182 #define isCoolingHotend0() isCoolingHotend(0)
183 #if EXTRUDERS_T > 1
184 #define degHotend1() degHotend(1)
185 #define degTargetHotend1() degTargetHotend(1)
186 #define setTargetHotend1(_celsius) setTargetHotend((_celsius), 1)
187 #define isHeatingHotend1() isHeatingHotend(1)
188 #define isCoolingHotend1() isCoolingHotend(1)
189 #else
190 #define setTargetHotend1(_celsius) do{}while(0)
191 #endif
192 #if EXTRUDERS_T > 2
193 #define degHotend2() degHotend(2)
194 #define degTargetHotend2() degTargetHotend(2)
195 #define setTargetHotend2(_celsius) setTargetHotend((_celsius), 2)
196 #define isHeatingHotend2() isHeatingHotend(2)
197 #define isCoolingHotend2() isCoolingHotend(2)
198 #else
199 #define setTargetHotend2(_celsius) do{}while(0)
200 #endif
201 #if EXTRUDERS_T > 3
202 #error Invalid number of extruders
203 #endif
204
205
206
207 int getHeaterPower(int heater);
208 void disable_heater();
209 void updatePID();
210
211 FORCE_INLINE void autotempShutdown(){
212 }
213
214 void PID_autotune(float temp);
215
216 #endif
217

mercurial