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