Browse Source

Merge branch 'Marlin_v1' of https://github.com/ErikZalm/Marlin into Marlin_v1

Bernhard 13 years ago
parent
commit
4bababf5b0
14 changed files with 5869 additions and 5595 deletions
  1. 38
    27
      Marlin/Configuration.h
  2. 25
    5
      Marlin/Marlin.h
  3. 78
    46
      Marlin/Marlin.pde
  4. 1
    1
      Marlin/cardreader.pde
  5. 2581
    2558
      Marlin/fastio.h
  6. 736
    694
      Marlin/pins.h
  7. 9
    17
      Marlin/planner.cpp
  8. 0
    2
      Marlin/planner.h
  9. 90
    37
      Marlin/stepper.cpp
  10. 15
    0
      Marlin/stepper.h
  11. 327
    220
      Marlin/temperature.cpp
  12. 67
    51
      Marlin/temperature.h
  13. 54
    93
      Marlin/thermistortables.h
  14. 1848
    1844
      Marlin/ultralcd.pde

+ 38
- 27
Marlin/Configuration.h View File

43
 // 5 is ParCan supplied 104GT-2 100K
43
 // 5 is ParCan supplied 104GT-2 100K
44
 // 6 is EPCOS 100k
44
 // 6 is EPCOS 100k
45
 // 7 is 100k Honeywell thermistor 135-104LAG-J01
45
 // 7 is 100k Honeywell thermistor 135-104LAG-J01
46
+
46
 //#define THERMISTORHEATER_0 3
47
 //#define THERMISTORHEATER_0 3
47
-//#define THERMISTORHEATER_1 3
48
-//#define THERMISTORBED 3
48
+//#define THERMISTORHEATER_1 1
49
+//#define THERMISTORHEATER_2 1
49
 
50
 
50
 //#define HEATER_0_USES_THERMISTOR
51
 //#define HEATER_0_USES_THERMISTOR
51
 //#define HEATER_1_USES_THERMISTOR
52
 //#define HEATER_1_USES_THERMISTOR
53
+//#define HEATER_2_USES_THERMISTOR
52
 #define HEATER_0_USES_AD595
54
 #define HEATER_0_USES_AD595
53
 //#define HEATER_1_USES_AD595
55
 //#define HEATER_1_USES_AD595
56
+//#define HEATER_2_USES_AD595
54
 
57
 
55
 // Select one of these only to define how the bed temp is read.
58
 // Select one of these only to define how the bed temp is read.
59
+//#define THERMISTORBED 1
56
 //#define BED_USES_THERMISTOR
60
 //#define BED_USES_THERMISTOR
57
 //#define BED_USES_AD595
61
 //#define BED_USES_AD595
58
 
62
 
65
 //#define WATCHPERIOD 20000 //20 seconds
69
 //#define WATCHPERIOD 20000 //20 seconds
66
 
70
 
67
 // Actual temperature must be close to target for this long before M109 returns success
71
 // Actual temperature must be close to target for this long before M109 returns success
68
-//#define TEMP_RESIDENCY_TIME 20  // (seconds)
69
-//#define TEMP_HYSTERESIS 5       // (C°) range of +/- temperatures considered "close" to the target one
72
+#define TEMP_RESIDENCY_TIME 30  // (seconds)
73
+#define TEMP_HYSTERESIS 3       // (C°) range of +/- temperatures considered "close" to the target one
70
 
74
 
71
 //// The minimal temperature defines the temperature below which the heater will not be enabled
75
 //// The minimal temperature defines the temperature below which the heater will not be enabled
72
 #define HEATER_0_MINTEMP 5
76
 #define HEATER_0_MINTEMP 5
73
 //#define HEATER_1_MINTEMP 5
77
 //#define HEATER_1_MINTEMP 5
78
+//#define HEATER_2_MINTEMP 5
74
 //#define BED_MINTEMP 5
79
 //#define BED_MINTEMP 5
75
 
80
 
76
 
81
 
79
 // You should use MINTEMP for thermistor short/failure protection.
84
 // You should use MINTEMP for thermistor short/failure protection.
80
 #define HEATER_0_MAXTEMP 275
85
 #define HEATER_0_MAXTEMP 275
81
 //#define HEATER_1_MAXTEMP 275
86
 //#define HEATER_1_MAXTEMP 275
87
+//#define HEATER_2_MAXTEMP 275
82
 //#define BED_MAXTEMP 150
88
 //#define BED_MAXTEMP 150
83
 
89
 
84
 
90
 
90
 
96
 
91
 // Heating is finished if a temperature close to this degree shift is reached
97
 // Heating is finished if a temperature close to this degree shift is reached
92
 #define HEATING_EARLY_FINISH_DEG_OFFSET 1 //Degree
98
 #define HEATING_EARLY_FINISH_DEG_OFFSET 1 //Degree
99
+
93
 // PID settings:
100
 // PID settings:
94
 // Uncomment the following line to enable PID support.
101
 // Uncomment the following line to enable PID support.
95
-  
96
 #define PIDTEMP
102
 #define PIDTEMP
103
+#define PID_MAX 255 // limits current to nozzle; 255=full current
97
 #ifdef PIDTEMP
104
 #ifdef PIDTEMP
98
-  #if MOTHERBOARD == 62
99
-    #error Sanguinololu does not support PID, sorry. Please disable it.
100
-  #endif
101
   //#define PID_DEBUG // Sends debug data to the serial port. 
105
   //#define PID_DEBUG // Sends debug data to the serial port. 
102
   //#define PID_OPENLOOP 1 // Puts PID in open loop. M104 sets the output power in %
106
   //#define PID_OPENLOOP 1 // Puts PID in open loop. M104 sets the output power in %
103
-  
104
-  #define PID_MAX 255 // limits current to nozzle; 255=full current
105
   #define PID_INTEGRAL_DRIVE_MAX 255  //limit for the integral term
107
   #define PID_INTEGRAL_DRIVE_MAX 255  //limit for the integral term
106
   #define K1 0.95 //smoothing factor withing the PID
108
   #define K1 0.95 //smoothing factor withing the PID
107
-  #define PID_dT 0.1 //sampling period of the PID
109
+  #define PID_dT 0.128 //sampling period of the PID
108
 
110
 
109
   //To develop some PID settings for your machine, you can initiall follow 
111
   //To develop some PID settings for your machine, you can initiall follow 
110
   // the Ziegler-Nichols method.
112
   // the Ziegler-Nichols method.
132
     #define  DEFAULT_Ki (1.25*PID_dT)  
134
     #define  DEFAULT_Ki (1.25*PID_dT)  
133
     #define  DEFAULT_Kd (99/PID_dT)  
135
     #define  DEFAULT_Kd (99/PID_dT)  
134
 
136
 
137
+// Makergear
138
+//    #define  DEFAULT_Kp 7.0
139
+//    #define  DEFAULT_Ki 0.1  
140
+//    #define  DEFAULT_Kd 12  
141
+
135
 // Mendel Parts V9 on 12V    
142
 // Mendel Parts V9 on 12V    
136
 //    #define  DEFAULT_Kp  63.0
143
 //    #define  DEFAULT_Kp  63.0
137
 //    #define  DEFAULT_Ki (2.25*PID_dT)  
144
 //    #define  DEFAULT_Ki (2.25*PID_dT)  
149
   // if Kc is choosen well, the additional required power due to increased melting should be compensated.
156
   // if Kc is choosen well, the additional required power due to increased melting should be compensated.
150
   #define PID_ADD_EXTRUSION_RATE  
157
   #define PID_ADD_EXTRUSION_RATE  
151
   #ifdef PID_ADD_EXTRUSION_RATE
158
   #ifdef PID_ADD_EXTRUSION_RATE
152
-    #define  DEFAULT_Kc (3) //heatingpower=Kc*(e_speed)
159
+    #define  DEFAULT_Kc (1) //heatingpower=Kc*(e_speed)
153
   #endif
160
   #endif
154
 #endif // PIDTEMP
161
 #endif // PIDTEMP
155
 
162
 
169
 
176
 
170
 // Endstop Settings
177
 // Endstop Settings
171
 #define ENDSTOPPULLUPS // Comment this out (using // at the start of the line) to disable the endstop pullup resistors
178
 #define ENDSTOPPULLUPS // Comment this out (using // at the start of the line) to disable the endstop pullup resistors
179
+
172
 // The pullups are needed if you directly connect a mechanical endswitch between the signal and ground pins.
180
 // The pullups are needed if you directly connect a mechanical endswitch between the signal and ground pins.
173
 const bool X_ENDSTOPS_INVERTING = true; // set to true to invert the logic of the endstops. 
181
 const bool X_ENDSTOPS_INVERTING = true; // set to true to invert the logic of the endstops. 
174
 const bool Y_ENDSTOPS_INVERTING = true; // set to true to invert the logic of the endstops. 
182
 const bool Y_ENDSTOPS_INVERTING = true; // set to true to invert the logic of the endstops. 
175
 const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of the endstops. 
183
 const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of the endstops. 
176
 // For optos H21LOB set to true, for Mendel-Parts newer optos TCST2103 set to false
184
 // For optos H21LOB set to true, for Mendel-Parts newer optos TCST2103 set to false
177
 
185
 
178
-//#define ENDSTOPS_ONLY_FOR_HOMING // If defined the endstops will only be used for homing
186
+#define ENDSTOPS_ONLY_FOR_HOMING // If defined the endstops will only be used for homing
179
 
187
 
180
 // For Inverting Stepper Enable Pins (Active Low) use 0, Non Inverting (Active High) use 1
188
 // For Inverting Stepper Enable Pins (Active Low) use 0, Non Inverting (Active High) use 1
181
 #define X_ENABLE_ON 0
189
 #define X_ENABLE_ON 0
182
 #define Y_ENABLE_ON 0
190
 #define Y_ENABLE_ON 0
183
 #define Z_ENABLE_ON 0
191
 #define Z_ENABLE_ON 0
184
-#define E_ENABLE_ON 0
192
+#define E_ENABLE_ON 0 // For all extruders
185
 
193
 
186
 // Disables axis when it's not being used.
194
 // Disables axis when it's not being used.
187
 #define DISABLE_X false
195
 #define DISABLE_X false
188
 #define DISABLE_Y false
196
 #define DISABLE_Y false
189
 #define DISABLE_Z false
197
 #define DISABLE_Z false
190
-#define DISABLE_E false
198
+#define DISABLE_E false // For all extruders
191
 
199
 
192
 // Inverting axis direction
200
 // Inverting axis direction
193
 //#define INVERT_X_DIR false    // for Mendel set to false, for Orca set to true
201
 //#define INVERT_X_DIR false    // for Mendel set to false, for Orca set to true
194
 //#define INVERT_Y_DIR true   // for Mendel set to true, for Orca set to false
202
 //#define INVERT_Y_DIR true   // for Mendel set to true, for Orca set to false
195
 //#define INVERT_Z_DIR false    // for Mendel set to false, for Orca set to true
203
 //#define INVERT_Z_DIR false    // for Mendel set to false, for Orca set to true
196
-//#define INVERT_E_DIR true   // for direct drive extruder v9 set to true, for geared extruder set to false
204
+//#define INVERT_E*_DIR true   // for direct drive extruder v9 set to true, for geared extruder set to false, used for all extruders
197
 
205
 
198
-#define INVERT_X_DIR true     // for Mendel set to false, for Orca set to true
206
+#define INVERT_X_DIR true    // for Mendel set to false, for Orca set to true
199
 #define INVERT_Y_DIR false    // for Mendel set to true, for Orca set to false
207
 #define INVERT_Y_DIR false    // for Mendel set to true, for Orca set to false
200
 #define INVERT_Z_DIR true     // for Mendel set to false, for Orca set to true
208
 #define INVERT_Z_DIR true     // for Mendel set to false, for Orca set to true
201
-#define INVERT_E_DIR false    // for direct drive extruder v9 set to true, for geared extruder set to false
209
+#define INVERT_E0_DIR false   // for direct drive extruder v9 set to true, for geared extruder set to false
210
+#define INVERT_E1_DIR false    // for direct drive extruder v9 set to true, for geared extruder set to false
211
+#define INVERT_E2_DIR false   // for direct drive extruder v9 set to true, for geared extruder set to false
202
 
212
 
203
 //// ENDSTOP SETTINGS:
213
 //// ENDSTOP SETTINGS:
204
 // Sets direction of endstops when homing; 1=MAX, -1=MIN
214
 // Sets direction of endstops when homing; 1=MAX, -1=MIN
206
 #define Y_HOME_DIR -1
216
 #define Y_HOME_DIR -1
207
 #define Z_HOME_DIR -1
217
 #define Z_HOME_DIR -1
208
 
218
 
209
-#define min_software_endstops false //If true, axis won't move to coordinates less than zero.
210
-#define max_software_endstops false  //If true, axis won't move to coordinates greater than the defined lengths below.
211
-#define X_MAX_LENGTH 210
212
-#define Y_MAX_LENGTH 210
213
-#define Z_MAX_LENGTH 210
219
+#define min_software_endstops true //If true, axis won't move to coordinates less than zero.
220
+#define max_software_endstops true  //If true, axis won't move to coordinates greater than the defined lengths below.
221
+#define X_MAX_LENGTH 205
222
+#define Y_MAX_LENGTH 205
223
+#define Z_MAX_LENGTH 200
214
 
224
 
215
 //// MOVEMENT SETTINGS
225
 //// MOVEMENT SETTINGS
216
 #define NUM_AXIS 4 // The axis order in all axis related arrays is X, Y, Z, E
226
 #define NUM_AXIS 4 // The axis order in all axis related arrays is X, Y, Z, E
229
 // default settings 
239
 // default settings 
230
 
240
 
231
 #define DEFAULT_AXIS_STEPS_PER_UNIT   {78.7402,78.7402,200*8/3,760*1.1}                    // default steps per unit for ultimaker 
241
 #define DEFAULT_AXIS_STEPS_PER_UNIT   {78.7402,78.7402,200*8/3,760*1.1}                    // default steps per unit for ultimaker 
232
-//#define DEFAULT_AXIS_STEPS_PER_UNIT   {40, 40, 3333.92, 67} //sells mendel with v9 extruder
242
+//#define DEFAULT_AXIS_STEPS_PER_UNIT   {40, 40, 3333.92, 360} //sells mendel with v9 extruder
243
+//#define DEFAULT_AXIS_STEPS_PER_UNIT   {80.3232, 80.8900, 2284.7651, 757.2218} // SAE Prusa w/ Wade extruder
233
 #define DEFAULT_MAX_FEEDRATE          {500, 500, 5, 45}    // (mm/sec)    
244
 #define DEFAULT_MAX_FEEDRATE          {500, 500, 5, 45}    // (mm/sec)    
234
 #define DEFAULT_MAX_ACCELERATION      {9000,9000,100,10000}    // X, Y, Z, E maximum start speed for accelerated moves. E default values are good for skeinforge 40+, for older versions raise them a lot.
245
 #define DEFAULT_MAX_ACCELERATION      {9000,9000,100,10000}    // X, Y, Z, E maximum start speed for accelerated moves. E default values are good for skeinforge 40+, for older versions raise them a lot.
235
 
246
 
285
 // hooke's law says:		force = k * distance
296
 // hooke's law says:		force = k * distance
286
 // bernoulli's priniciple says:	v ^ 2 / 2 + g . h + pressure / density = constant
297
 // bernoulli's priniciple says:	v ^ 2 / 2 + g . h + pressure / density = constant
287
 // so: v ^ 2 is proportional to number of steps we advance the extruder
298
 // so: v ^ 2 is proportional to number of steps we advance the extruder
288
-//#define ADVANCE
299
+#define ADVANCE
289
 
300
 
290
 #ifdef ADVANCE
301
 #ifdef ADVANCE
291
-  #define EXTRUDER_ADVANCE_K .3
302
+  #define EXTRUDER_ADVANCE_K .0
292
 
303
 
293
   #define D_FILAMENT 2.85
304
   #define D_FILAMENT 2.85
294
   #define STEPS_MM_E 836
305
   #define STEPS_MM_E 836
304
 #define SD_FINISHED_STEPPERRELEASE true  //if sd support and the file is finished: disable steppers?
315
 #define SD_FINISHED_STEPPERRELEASE true  //if sd support and the file is finished: disable steppers?
305
 #define SD_FINISHED_RELEASECOMMAND "M84 X Y E" // no z because of layer shift.
316
 #define SD_FINISHED_RELEASECOMMAND "M84 X Y E" // no z because of layer shift.
306
 
317
 
307
-//#define ULTIPANEL
318
+#define ULTIPANEL
308
 #ifdef ULTIPANEL
319
 #ifdef ULTIPANEL
309
   //#define NEWPANEL  //enable this if you have a click-encoder panel
320
   //#define NEWPANEL  //enable this if you have a click-encoder panel
310
   #define SDSUPPORT
321
   #define SDSUPPORT

+ 25
- 5
Marlin/Marlin.h View File

101
   #define disable_z() ;
101
   #define disable_z() ;
102
 #endif
102
 #endif
103
 
103
 
104
-#if E_ENABLE_PIN > -1
105
-  #define  enable_e() WRITE(E_ENABLE_PIN, E_ENABLE_ON)
106
-  #define disable_e() WRITE(E_ENABLE_PIN,!E_ENABLE_ON)
104
+#if defined(E0_ENABLE_PIN) && (E0_ENABLE_PIN > -1)
105
+  #define enable_e0() WRITE(E0_ENABLE_PIN, E_ENABLE_ON)
106
+  #define disable_e0() WRITE(E0_ENABLE_PIN,!E_ENABLE_ON)
107
 #else
107
 #else
108
-  #define enable_e() ;
109
-  #define disable_e() ;
108
+  #define enable_e0()  /* nothing */
109
+  #define disable_e0() /* nothing */
110
 #endif
110
 #endif
111
 
111
 
112
+#if (EXTRUDERS > 1) && defined(E1_ENABLE_PIN) && (E1_ENABLE_PIN > -1)
113
+  #define enable_e1() WRITE(E1_ENABLE_PIN, E_ENABLE_ON)
114
+  #define disable_e1() WRITE(E1_ENABLE_PIN,!E_ENABLE_ON)
115
+#else
116
+  #define enable_e1()  /* nothing */
117
+  #define disable_e1() /* nothing */
118
+#endif
119
+
120
+#if (EXTRUDERS > 2) && defined(E2_ENABLE_PIN) && (E2_ENABLE_PIN > -1)
121
+  #define enable_e2() WRITE(E2_ENABLE_PIN, E_ENABLE_ON)
122
+  #define disable_e2() WRITE(E2_ENABLE_PIN,!E_ENABLE_ON)
123
+#else
124
+  #define enable_e2()  /* nothing */
125
+  #define disable_e2() /* nothing */
126
+#endif
127
+
128
+
112
 enum AxisEnum {X_AXIS=0, Y_AXIS=1, Z_AXIS=2, E_AXIS=3};
129
 enum AxisEnum {X_AXIS=0, Y_AXIS=1, Z_AXIS=2, E_AXIS=3};
113
 
130
 
114
 
131
 
133
 extern float add_homeing[3];
150
 extern float add_homeing[3];
134
 extern bool stop_heating_wait;
151
 extern bool stop_heating_wait;
135
 
152
 
153
+// Handling multiple extruders pins
154
+extern uint8_t active_extruder;
155
+
136
 #endif
156
 #endif

+ 78
- 46
Marlin/Marlin.pde View File

122
 //===========================================================================
122
 //===========================================================================
123
 //=============================imported variables============================
123
 //=============================imported variables============================
124
 //===========================================================================
124
 //===========================================================================
125
-extern float HeaterPower;
126
 
125
 
127
 
126
 
128
 //===========================================================================
127
 //===========================================================================
136
 volatile int feedmultiply=100; //100->1 200->2
135
 volatile int feedmultiply=100; //100->1 200->2
137
 int saved_feedmultiply;
136
 int saved_feedmultiply;
138
 volatile bool feedmultiplychanged=false;
137
 volatile bool feedmultiplychanged=false;
139
-float current_position[NUM_AXIS] = {  0.0, 0.0, 0.0, 0.0};
138
+float current_position[NUM_AXIS] = { 0.0, 0.0, 0.0, 0.0 };
140
 float add_homeing[3]={0,0,0};
139
 float add_homeing[3]={0,0,0};
140
+uint8_t active_extruder = 0;
141
 bool stop_heating_wait=false;
141
 bool stop_heating_wait=false;
142
+
142
 //===========================================================================
143
 //===========================================================================
143
 //=============================private variables=============================
144
 //=============================private variables=============================
144
 //===========================================================================
145
 //===========================================================================
470
     plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); \
471
     plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); \
471
     destination[LETTER##_AXIS] = 1.5 * LETTER##_MAX_LENGTH * LETTER##_HOME_DIR; \
472
     destination[LETTER##_AXIS] = 1.5 * LETTER##_MAX_LENGTH * LETTER##_HOME_DIR; \
472
     feedrate = homing_feedrate[LETTER##_AXIS]; \
473
     feedrate = homing_feedrate[LETTER##_AXIS]; \
473
-    prepare_move(); \
474
+    plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); \
474
     \
475
     \
475
     current_position[LETTER##_AXIS] = 0;\
476
     current_position[LETTER##_AXIS] = 0;\
476
     plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);\
477
     plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);\
477
     destination[LETTER##_AXIS] = -LETTER##_HOME_RETRACT_MM * LETTER##_HOME_DIR;\
478
     destination[LETTER##_AXIS] = -LETTER##_HOME_RETRACT_MM * LETTER##_HOME_DIR;\
478
-    prepare_move(); \
479
+    plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); \
479
     \
480
     \
480
     destination[LETTER##_AXIS] = 2*LETTER##_HOME_RETRACT_MM * LETTER##_HOME_DIR;\
481
     destination[LETTER##_AXIS] = 2*LETTER##_HOME_RETRACT_MM * LETTER##_HOME_DIR;\
481
     feedrate = homing_feedrate[LETTER##_AXIS]/2 ;  \
482
     feedrate = homing_feedrate[LETTER##_AXIS]/2 ;  \
482
-    prepare_move(); \
483
+    plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); \
483
     \
484
     \
484
     current_position[LETTER##_AXIS] = (LETTER##_HOME_DIR == -1) ? 0 : LETTER##_MAX_LENGTH;\
485
     current_position[LETTER##_AXIS] = (LETTER##_HOME_DIR == -1) ? 0 : LETTER##_MAX_LENGTH;\
485
     plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);\
486
     plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);\
543
       if( code_seen(axis_codes[0]) && code_seen(axis_codes[1]) )  //first diagonal move
544
       if( code_seen(axis_codes[0]) && code_seen(axis_codes[1]) )  //first diagonal move
544
       {
545
       {
545
         current_position[X_AXIS] = 0;current_position[Y_AXIS] = 0;  
546
         current_position[X_AXIS] = 0;current_position[Y_AXIS] = 0;  
547
+
546
         plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); 
548
         plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); 
547
         destination[X_AXIS] = 1.5 * X_MAX_LENGTH * X_HOME_DIR;destination[Y_AXIS] = 1.5 * Y_MAX_LENGTH * Y_HOME_DIR;  
549
         destination[X_AXIS] = 1.5 * X_MAX_LENGTH * X_HOME_DIR;destination[Y_AXIS] = 1.5 * Y_MAX_LENGTH * Y_HOME_DIR;  
548
         feedrate = homing_feedrate[X_AXIS]; 
550
         feedrate = homing_feedrate[X_AXIS]; 
582
       }
584
       }
583
 
585
 
584
       if(code_seen(axis_codes[Y_AXIS])) {
586
       if(code_seen(axis_codes[Y_AXIS])) {
585
-       current_position[1]=code_value()+add_homeing[1];
587
+        current_position[1]=code_value()+add_homeing[1];
586
       }
588
       }
587
 
589
 
588
       if(code_seen(axis_codes[Z_AXIS])) {
590
       if(code_seen(axis_codes[Z_AXIS])) {
610
         if(code_seen(axis_codes[i])) { 
612
         if(code_seen(axis_codes[i])) { 
611
            current_position[i] = code_value()+add_homeing[i];  
613
            current_position[i] = code_value()+add_homeing[i];  
612
            if(i == E_AXIS) {
614
            if(i == E_AXIS) {
615
+             current_position[i] = code_value();  
613
              plan_set_e_position(current_position[E_AXIS]);
616
              plan_set_e_position(current_position[E_AXIS]);
614
            }
617
            }
615
            else {
618
            else {
619
+             current_position[i] = code_value()+add_homeing[i];  
616
              plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
620
              plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
617
            }
621
            }
618
         }
622
         }
623
 
627
 
624
   else if(code_seen('M'))
628
   else if(code_seen('M'))
625
   {
629
   {
626
-
627
     switch( (int)code_value() ) 
630
     switch( (int)code_value() ) 
628
     {
631
     {
629
     case 17:
632
     case 17:
631
         enable_x(); 
634
         enable_x(); 
632
         enable_y(); 
635
         enable_y(); 
633
         enable_z(); 
636
         enable_z(); 
634
-        enable_e(); 
637
+        enable_e0(); 
638
+        enable_e1(); 
639
+        enable_e2(); 
635
       break;
640
       break;
636
-    #ifdef SDSUPPORT
637
 
641
 
642
+#ifdef SDSUPPORT
638
     case 20: // M20 - list SD card
643
     case 20: // M20 - list SD card
639
       SERIAL_PROTOCOLLNPGM("Begin file list");
644
       SERIAL_PROTOCOLLNPGM("Begin file list");
640
       card.ls();
645
       card.ls();
663
       card.pauseSDPrint();
668
       card.pauseSDPrint();
664
       break;
669
       break;
665
     case 26: //M26 - Set SD index
670
     case 26: //M26 - Set SD index
666
-      if(card.cardOK && code_seen('S')){
671
+      if(card.cardOK && code_seen('S')) {
667
         card.setIndex(code_value_long());
672
         card.setIndex(code_value_long());
668
-        
669
       }
673
       }
670
       break;
674
       break;
671
     case 27: //M27 - Get SD status
675
     case 27: //M27 - Get SD status
679
         *(starpos-1) = '\0';
683
         *(starpos-1) = '\0';
680
       }
684
       }
681
       card.openFile(strchr_pointer+4,false);
685
       card.openFile(strchr_pointer+4,false);
682
-      
683
       break;
686
       break;
684
     case 29: //M29 - Stop SD write
687
     case 29: //M29 - Stop SD write
685
       //processed in write to file routine above
688
       //processed in write to file routine above
686
       //card,saving = false;
689
       //card,saving = false;
687
       break;
690
       break;
688
-    #endif //SDSUPPORT
691
+#endif //SDSUPPORT
689
 
692
 
690
     case 30: //M30 take time since the start of the SD print or an M109 command
693
     case 30: //M30 take time since the start of the SD print or an M109 command
691
-    {
694
+      {
692
       stoptime=millis();
695
       stoptime=millis();
693
       char time[30];
696
       char time[30];
694
       unsigned long t=(stoptime-starttime)/1000;
697
       unsigned long t=(stoptime-starttime)/1000;
700
       SERIAL_ECHOLN(time);
703
       SERIAL_ECHOLN(time);
701
       LCD_MESSAGE(time);
704
       LCD_MESSAGE(time);
702
       autotempShutdown();
705
       autotempShutdown();
703
-    }
704
-    break;
706
+      }
707
+      break;
705
     case 42: //M42 -Change pin status via gcode
708
     case 42: //M42 -Change pin status via gcode
706
       if (code_seen('S'))
709
       if (code_seen('S'))
707
       {
710
       {
755
           break;
758
           break;
756
         }
759
         }
757
       }
760
       }
758
-      #if (TEMP_0_PIN > -1) || (TEMP_2_PIN > -1)
761
+      #if (TEMP_0_PIN > -1)
759
         SERIAL_PROTOCOLPGM("ok T:");
762
         SERIAL_PROTOCOLPGM("ok T:");
760
-        SERIAL_PROTOCOL( degHotend(tmp_extruder)); 
761
-        #if TEMP_1_PIN > -1 
763
+        SERIAL_PROTOCOL(degHotend(tmp_extruder)); 
764
+        #if TEMP_BED_PIN > -1 
762
           SERIAL_PROTOCOLPGM(" B:");  
765
           SERIAL_PROTOCOLPGM(" B:");  
763
           SERIAL_PROTOCOL(degBed());
766
           SERIAL_PROTOCOL(degBed());
764
-        #endif //TEMP_1_PIN
767
+        #endif //TEMP_BED_PIN
765
       #else
768
       #else
766
         SERIAL_ERROR_START;
769
         SERIAL_ERROR_START;
767
         SERIAL_ERRORLNPGM("No thermistors - no temp");
770
         SERIAL_ERRORLNPGM("No thermistors - no temp");
768
       #endif
771
       #endif
769
       #ifdef PIDTEMP
772
       #ifdef PIDTEMP
770
         SERIAL_PROTOCOLPGM(" @:");
773
         SERIAL_PROTOCOLPGM(" @:");
771
-        SERIAL_PROTOCOL( HeaterPower); 
772
-       
774
+        SERIAL_PROTOCOL(getHeaterPower(tmp_extruder));  
773
       #endif
775
       #endif
774
         SERIAL_PROTOCOLLN("");
776
         SERIAL_PROTOCOLLN("");
775
       return;
777
       return;
812
         residencyStart = -1;
814
         residencyStart = -1;
813
         /* continue to loop until we have reached the target temp   
815
         /* continue to loop until we have reached the target temp   
814
           _and_ until TEMP_RESIDENCY_TIME hasn't passed since we reached it */
816
           _and_ until TEMP_RESIDENCY_TIME hasn't passed since we reached it */
815
-        while((target_direction ? (isHeatingHotend(tmp_extruder)) : (isCoolingHotend(tmp_extruder))) ||
816
-                (residencyStart > -1 && (millis() - residencyStart) < TEMP_RESIDENCY_TIME*1000) ) {
817
+        while((residencyStart == -1) ||
818
+              (residencyStart > -1 && (millis() - residencyStart) < TEMP_RESIDENCY_TIME*1000) ) {
817
       #else
819
       #else
818
         while ( target_direction ? (isHeatingHotend(tmp_extruder)) : (isCoolingHotend(tmp_extruder)&&(CooldownNoWait==false)) ) {
820
         while ( target_direction ? (isHeatingHotend(tmp_extruder)) : (isCoolingHotend(tmp_extruder)&&(CooldownNoWait==false)) ) {
819
       #endif //TEMP_RESIDENCY_TIME
821
       #endif //TEMP_RESIDENCY_TIME
820
-        if( (millis() - codenum) > 1000 ) 
821
-        { //Print Temp Reading every 1 second while heating up/cooling down
822
-          SERIAL_PROTOCOLPGM("T:");
823
-          SERIAL_PROTOCOLLN( degHotend(tmp_extruder) ); 
824
-          codenum = millis();
825
-        }
826
-        manage_heater();
827
-        LCD_STATUS;
822
+          if( (millis() - codenum) > 1000 ) 
823
+          { //Print Temp Reading and remaining time every 1 second while heating up/cooling down
824
+            SERIAL_PROTOCOLPGM("T:");
825
+            SERIAL_PROTOCOL( degHotend(tmp_extruder) ); 
826
+            SERIAL_PROTOCOLPGM(" E:");
827
+            SERIAL_PROTOCOL( (int)tmp_extruder ); 
828
+            #ifdef TEMP_RESIDENCY_TIME
829
+              SERIAL_PROTOCOLPGM(" W:");
830
+              if(residencyStart > -1)
831
+              {
832
+                 codenum = TEMP_RESIDENCY_TIME - ((millis() - residencyStart) / 1000);
833
+                 SERIAL_PROTOCOLLN( codenum );
834
+              }
835
+              else 
836
+              {
837
+                 SERIAL_PROTOCOLLN( "?" );
838
+              }
839
+            #endif
840
+            codenum = millis();
841
+          }
842
+          manage_heater();
843
+          LCD_STATUS;
828
         if(stop_heating_wait) break;
844
         if(stop_heating_wait) break;
829
         #ifdef TEMP_RESIDENCY_TIME
845
         #ifdef TEMP_RESIDENCY_TIME
830
             /* start/restart the TEMP_RESIDENCY_TIME timer whenever we reach target temp for the first time
846
             /* start/restart the TEMP_RESIDENCY_TIME timer whenever we reach target temp for the first time
842
         previous_millis_cmd = millis();
858
         previous_millis_cmd = millis();
843
       }
859
       }
844
       break;
860
       break;
845
-    case 190: // M190 - Wait bed for heater to reach target.
846
-    #if TEMP_1_PIN > -1
861
+    case 190: // M190 - Wait for bed heater to reach target.
862
+    #if TEMP_BED_PIN > -1
847
         LCD_MESSAGEPGM("Bed Heating.");
863
         LCD_MESSAGEPGM("Bed Heating.");
848
         if (code_seen('S')) setTargetBed(code_value());
864
         if (code_seen('S')) setTargetBed(code_value());
849
         codenum = millis(); 
865
         codenum = millis(); 
851
         {
867
         {
852
           if( (millis()-codenum) > 1000 ) //Print Temp Reading every 1 second while heating up.
868
           if( (millis()-codenum) > 1000 ) //Print Temp Reading every 1 second while heating up.
853
           {
869
           {
854
-            float tt=degHotend0();
870
+            float tt=degHotend(active_extruder);
855
             SERIAL_PROTOCOLPGM("T:");
871
             SERIAL_PROTOCOLPGM("T:");
856
-            SERIAL_PROTOCOLLN(tt );
857
-            SERIAL_PROTOCOLPGM("ok T:");
858
-            SERIAL_PROTOCOL(tt );
872
+            SERIAL_PROTOCOL(tt);
873
+            SERIAL_PROTOCOLPGM(" E:");
874
+            SERIAL_PROTOCOL( (int)active_extruder ); 
859
             SERIAL_PROTOCOLPGM(" B:");
875
             SERIAL_PROTOCOLPGM(" B:");
860
-            SERIAL_PROTOCOLLN(degBed() ); 
876
+            SERIAL_PROTOCOLLN(degBed()); 
861
             codenum = millis(); 
877
             codenum = millis(); 
862
           }
878
           }
863
           manage_heater();
879
           manage_heater();
910
         bool all_axis = !((code_seen(axis_codes[0])) || (code_seen(axis_codes[1])) || (code_seen(axis_codes[2]))|| (code_seen(axis_codes[3])));
926
         bool all_axis = !((code_seen(axis_codes[0])) || (code_seen(axis_codes[1])) || (code_seen(axis_codes[2]))|| (code_seen(axis_codes[3])));
911
         if(all_axis)
927
         if(all_axis)
912
         {
928
         {
929
+          disable_e0();
930
+          disable_e1();
931
+          disable_e2();
913
           finishAndDisableSteppers();
932
           finishAndDisableSteppers();
914
         }
933
         }
915
         else
934
         else
918
           if(code_seen('X')) disable_x();
937
           if(code_seen('X')) disable_x();
919
           if(code_seen('Y')) disable_y();
938
           if(code_seen('Y')) disable_y();
920
           if(code_seen('Z')) disable_z();
939
           if(code_seen('Z')) disable_z();
921
-          #if ((E_ENABLE_PIN != X_ENABLE_PIN) && (E_ENABLE_PIN != Y_ENABLE_PIN)) // Only enable on boards that have seperate ENABLE_PINS
922
-            if(code_seen('E')) disable_e();
940
+          #if ((E0_ENABLE_PIN != X_ENABLE_PIN) && (E1_ENABLE_PIN != Y_ENABLE_PIN)) // Only enable on boards that have seperate ENABLE_PINS
941
+            if(code_seen('E')) {
942
+              disable_e0();
943
+              disable_e1();
944
+              disable_e2();
945
+            }
923
           #endif 
946
           #endif 
924
           LCD_MESSAGEPGM("Partial Release");
947
           LCD_MESSAGEPGM("Partial Release");
925
         }
948
         }
1100
 
1123
 
1101
     }
1124
     }
1102
   }
1125
   }
1103
-  else if(code_seen('T')) {
1126
+
1127
+  else if(code_seen('T')) 
1128
+  {
1104
     tmp_extruder = code_value();
1129
     tmp_extruder = code_value();
1105
     if(tmp_extruder >= EXTRUDERS) {
1130
     if(tmp_extruder >= EXTRUDERS) {
1106
       SERIAL_ECHO_START;
1131
       SERIAL_ECHO_START;
1110
     }
1135
     }
1111
     else {
1136
     else {
1112
       active_extruder = tmp_extruder;
1137
       active_extruder = tmp_extruder;
1138
+      SERIAL_ECHO_START;
1139
+      SERIAL_ECHO("Active Extruder: ");
1140
+      SERIAL_PROTOCOLLN((int)active_extruder);
1113
     }
1141
     }
1114
   }
1142
   }
1143
+
1115
   else
1144
   else
1116
   {
1145
   {
1117
     SERIAL_ECHO_START;
1146
     SERIAL_ECHO_START;
1219
     if( (millis()-previous_millis_cmd) >  EXTRUDER_RUNOUT_SECONDS*1000 ) 
1248
     if( (millis()-previous_millis_cmd) >  EXTRUDER_RUNOUT_SECONDS*1000 ) 
1220
     if(degHotend(active_extruder)>EXTRUDER_RUNOUT_MINTEMP)
1249
     if(degHotend(active_extruder)>EXTRUDER_RUNOUT_MINTEMP)
1221
     {
1250
     {
1222
-     bool oldstatus=READ(E_ENABLE_PIN);
1223
-     enable_e();
1251
+     bool oldstatus=READ(E0_ENABLE_PIN);
1252
+     enable_e0();
1224
      float oldepos=current_position[E_AXIS];
1253
      float oldepos=current_position[E_AXIS];
1225
      float oldedes=destination[E_AXIS];
1254
      float oldedes=destination[E_AXIS];
1226
      plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], 
1255
      plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], 
1232
      previous_millis_cmd=millis();
1261
      previous_millis_cmd=millis();
1233
      //enquecommand(DEFAULT_STEPPER_DEACTIVE_COMMAND);
1262
      //enquecommand(DEFAULT_STEPPER_DEACTIVE_COMMAND);
1234
      st_synchronize();
1263
      st_synchronize();
1235
-     WRITE(E_ENABLE_PIN,oldstatus);
1264
+     WRITE(E0_ENABLE_PIN,oldstatus);
1236
     }
1265
     }
1237
   #endif
1266
   #endif
1238
   check_axes_activity();
1267
   check_axes_activity();
1240
 
1269
 
1241
 void kill()
1270
 void kill()
1242
 {
1271
 {
1272
+  cli(); // Stop interrupts
1243
   disable_heater();
1273
   disable_heater();
1244
 
1274
 
1245
   disable_x();
1275
   disable_x();
1246
   disable_y();
1276
   disable_y();
1247
   disable_z();
1277
   disable_z();
1248
-  disable_e();
1278
+  disable_e0();
1279
+  disable_e1();
1280
+  disable_e2();
1249
   
1281
   
1250
   if(PS_ON_PIN > -1) pinMode(PS_ON_PIN,INPUT);
1282
   if(PS_ON_PIN > -1) pinMode(PS_ON_PIN,INPUT);
1251
   SERIAL_ERROR_START;
1283
   SERIAL_ERROR_START;

+ 1
- 1
Marlin/cardreader.pde View File

442
  }
442
  }
443
  autotempShutdown();
443
  autotempShutdown();
444
 }
444
 }
445
-#endif //SDSUPPORT
445
+#endif //SDSUPPORT

+ 2581
- 2558
Marlin/fastio.h
File diff suppressed because it is too large
View File


+ 736
- 694
Marlin/pins.h
File diff suppressed because it is too large
View File


+ 9
- 17
Marlin/planner.cpp View File

56
 //#include <math.h>       
56
 //#include <math.h>       
57
 //#include <stdlib.h>
57
 //#include <stdlib.h>
58
 
58
 
59
-#include "Marlin.h"
60
 #include "Configuration.h"
59
 #include "Configuration.h"
61
 #include "pins.h"
60
 #include "pins.h"
61
+#include "Marlin.h"
62
 #include "fastio.h"
62
 #include "fastio.h"
63
 #include "planner.h"
63
 #include "planner.h"
64
 #include "stepper.h"
64
 #include "stepper.h"
81
 float mintravelfeedrate;
81
 float mintravelfeedrate;
82
 unsigned long axis_steps_per_sqr_second[NUM_AXIS];
82
 unsigned long axis_steps_per_sqr_second[NUM_AXIS];
83
 
83
 
84
-uint8_t active_extruder = 0;
85
-
86
 // The current position of the tool in absolute steps
84
 // The current position of the tool in absolute steps
87
 long position[4];   //rescaled from extern when axis_steps_per_unit are changed by gcode
85
 long position[4];   //rescaled from extern when axis_steps_per_unit are changed by gcode
88
 static float previous_speed[4]; // Speed of previous path line segment
86
 static float previous_speed[4]; // Speed of previous path line segment
95
     bool autotemp_enabled=false;
93
     bool autotemp_enabled=false;
96
 #endif
94
 #endif
97
 
95
 
98
-    
99
 //===========================================================================
96
 //===========================================================================
100
 //=================semi-private variables, used in inline  functions    =====
97
 //=================semi-private variables, used in inline  functions    =====
101
 //===========================================================================
98
 //===========================================================================
196
   }
193
   }
197
 
194
 
198
   #ifdef ADVANCE
195
   #ifdef ADVANCE
199
-    long initial_advance = block->advance*entry_factor*entry_factor;
200
-    long final_advance = block->advance*exit_factor*exit_factor;
196
+    volatile long initial_advance = block->advance*entry_factor*entry_factor; 
197
+    volatile long final_advance = block->advance*exit_factor*exit_factor;
201
   #endif // ADVANCE
198
   #endif // ADVANCE
202
   
199
   
203
  // block->accelerate_until = accelerate_steps;
200
  // block->accelerate_until = accelerate_steps;
439
   if((DISABLE_X) && (x_active == 0)) disable_x();
436
   if((DISABLE_X) && (x_active == 0)) disable_x();
440
   if((DISABLE_Y) && (y_active == 0)) disable_y();
437
   if((DISABLE_Y) && (y_active == 0)) disable_y();
441
   if((DISABLE_Z) && (z_active == 0)) disable_z();
438
   if((DISABLE_Z) && (z_active == 0)) disable_z();
442
-  if((DISABLE_E) && (e_active == 0)) disable_e();
439
+  if((DISABLE_E) && (e_active == 0)) { disable_e0();disable_e1();disable_e2(); }
443
 }
440
 }
444
 
441
 
445
 
442
 
514
   if(block->steps_x != 0) enable_x();
511
   if(block->steps_x != 0) enable_x();
515
   if(block->steps_y != 0) enable_y();
512
   if(block->steps_y != 0) enable_y();
516
   if(block->steps_z != 0) enable_z();
513
   if(block->steps_z != 0) enable_z();
517
-  if(extruder == 0) {
518
-    if(block->steps_e != 0) enable_e();
519
-  }
520
-  #if (EXTRUDERS > 1)
521
-  if(extruder == 1) {
522
-    if(block->steps_e != 0) enable_e1();
523
-  }
524
-  #endif
525
-  
514
+
515
+  // Enable all
516
+  if(block->steps_e != 0) { enable_e0();enable_e1();enable_e2(); }
517
+
526
   float delta_mm[4];
518
   float delta_mm[4];
527
   delta_mm[X_AXIS] = (target[X_AXIS]-position[X_AXIS])/axis_steps_per_unit[X_AXIS];
519
   delta_mm[X_AXIS] = (target[X_AXIS]-position[X_AXIS])/axis_steps_per_unit[X_AXIS];
528
   delta_mm[Y_AXIS] = (target[Y_AXIS]-position[Y_AXIS])/axis_steps_per_unit[Y_AXIS];
520
   delta_mm[Y_AXIS] = (target[Y_AXIS]-position[Y_AXIS])/axis_steps_per_unit[Y_AXIS];
809
   #ifdef PREVENT_DANGEROUS_EXTRUDE
801
   #ifdef PREVENT_DANGEROUS_EXTRUDE
810
     allow_cold_extrude=allow;
802
     allow_cold_extrude=allow;
811
   #endif
803
   #endif
812
-}
804
+}

+ 0
- 2
Marlin/planner.h View File

91
 extern float mintravelfeedrate;
91
 extern float mintravelfeedrate;
92
 extern unsigned long axis_steps_per_sqr_second[NUM_AXIS];
92
 extern unsigned long axis_steps_per_sqr_second[NUM_AXIS];
93
 
93
 
94
-extern uint8_t active_extruder;
95
-
96
 #ifdef AUTOTEMP
94
 #ifdef AUTOTEMP
97
     extern bool autotemp_enabled;
95
     extern bool autotemp_enabled;
98
     extern float autotemp_max;
96
     extern float autotemp_max;

+ 90
- 37
Marlin/stepper.cpp View File

24
 
24
 
25
 #include "stepper.h"
25
 #include "stepper.h"
26
 #include "Configuration.h"
26
 #include "Configuration.h"
27
+#include "pins.h"
27
 #include "Marlin.h"
28
 #include "Marlin.h"
28
 #include "planner.h"
29
 #include "planner.h"
29
-#include "pins.h"
30
 #include "fastio.h"
30
 #include "fastio.h"
31
 #include "temperature.h"
31
 #include "temperature.h"
32
 #include "ultralcd.h"
32
 #include "ultralcd.h"
41
 block_t *current_block;  // A pointer to the block currently being traced
41
 block_t *current_block;  // A pointer to the block currently being traced
42
 
42
 
43
 
43
 
44
-
45
 //===========================================================================
44
 //===========================================================================
46
 //=============================private variables ============================
45
 //=============================private variables ============================
47
 //===========================================================================
46
 //===========================================================================
58
   static long advance_rate, advance, final_advance = 0;
57
   static long advance_rate, advance, final_advance = 0;
59
   static long old_advance = 0;
58
   static long old_advance = 0;
60
 #endif
59
 #endif
61
-static long e_steps;
60
+static long e_steps[3];
62
 static unsigned char busy = false; // TRUE when SIG_OUTPUT_COMPARE1A is being serviced. Used to avoid retriggering that handler.
61
 static unsigned char busy = false; // TRUE when SIG_OUTPUT_COMPARE1A is being serviced. Used to avoid retriggering that handler.
63
 static long acceleration_time, deceleration_time;
62
 static long acceleration_time, deceleration_time;
64
 //static unsigned long accelerate_until, decelerate_after, acceleration_rate, initial_rate, final_rate, nominal_rate;
63
 //static unsigned long accelerate_until, decelerate_after, acceleration_rate, initial_rate, final_rate, nominal_rate;
267
     advance = current_block->initial_advance;
266
     advance = current_block->initial_advance;
268
     final_advance = current_block->final_advance;
267
     final_advance = current_block->final_advance;
269
     // Do E steps + advance steps
268
     // Do E steps + advance steps
270
-    e_steps += ((advance >>8) - old_advance);
269
+    e_steps[current_block->active_extruder] += ((advance >>8) - old_advance);
271
     old_advance = advance >>8;  
270
     old_advance = advance >>8;  
272
   #endif
271
   #endif
273
   deceleration_time = 0;
272
   deceleration_time = 0;
304
       counter_z = counter_x;
303
       counter_z = counter_x;
305
       counter_e = counter_x;
304
       counter_e = counter_x;
306
       step_events_completed = 0;
305
       step_events_completed = 0;
307
- //     #ifdef ADVANCE
308
-      e_steps = 0;
306
+//      #ifdef ADVANCE
307
+//      e_steps[current_block->active_extruder] = 0;
309
 //      #endif
308
 //      #endif
310
     } 
309
     } 
311
     else {
310
     else {
419
 
418
 
420
     #ifndef ADVANCE
419
     #ifndef ADVANCE
421
       if ((out_bits & (1<<E_AXIS)) != 0) {  // -direction
420
       if ((out_bits & (1<<E_AXIS)) != 0) {  // -direction
422
-        WRITE(E_DIR_PIN,INVERT_E_DIR);
421
+        REV_E_DIR();
423
         count_direction[E_AXIS]=-1;
422
         count_direction[E_AXIS]=-1;
424
       }
423
       }
425
       else { // +direction
424
       else { // +direction
426
-        WRITE(E_DIR_PIN,!INVERT_E_DIR);
425
+        NORM_E_DIR();
427
         count_direction[E_AXIS]=-1;
426
         count_direction[E_AXIS]=-1;
428
       }
427
       }
429
     #endif //!ADVANCE
428
     #endif //!ADVANCE
438
       if (counter_e > 0) {
437
       if (counter_e > 0) {
439
         counter_e -= current_block->step_event_count;
438
         counter_e -= current_block->step_event_count;
440
         if ((out_bits & (1<<E_AXIS)) != 0) { // - direction
439
         if ((out_bits & (1<<E_AXIS)) != 0) { // - direction
441
-          e_steps--;
440
+          e_steps[current_block->active_extruder]--;
442
         }
441
         }
443
         else {
442
         else {
444
-          e_steps++;
443
+          e_steps[current_block->active_extruder]++;
445
         }
444
         }
446
       }    
445
       }    
447
       #endif //ADVANCE
446
       #endif //ADVANCE
473
       #ifndef ADVANCE
472
       #ifndef ADVANCE
474
         counter_e += current_block->steps_e;
473
         counter_e += current_block->steps_e;
475
         if (counter_e > 0) {
474
         if (counter_e > 0) {
476
-          WRITE(E_STEP_PIN, HIGH);
475
+          WRITE_E_STEP(HIGH);
477
           counter_e -= current_block->step_event_count;
476
           counter_e -= current_block->step_event_count;
478
-          WRITE(E_STEP_PIN, LOW);
477
+          WRITE_E_STEP(LOW);
479
           count_position[E_AXIS]+=count_direction[E_AXIS];
478
           count_position[E_AXIS]+=count_direction[E_AXIS];
480
         }
479
         }
481
       #endif //!ADVANCE
480
       #endif //!ADVANCE
504
         }
503
         }
505
         //if(advance > current_block->advance) advance = current_block->advance;
504
         //if(advance > current_block->advance) advance = current_block->advance;
506
         // Do E steps + advance steps
505
         // Do E steps + advance steps
507
-        e_steps += ((advance >>8) - old_advance);
506
+        e_steps[current_block->active_extruder] += ((advance >>8) - old_advance);
508
         old_advance = advance >>8;  
507
         old_advance = advance >>8;  
509
         
508
         
510
       #endif
509
       #endif
533
         }
532
         }
534
         if(advance < final_advance) advance = final_advance;
533
         if(advance < final_advance) advance = final_advance;
535
         // Do E steps + advance steps
534
         // Do E steps + advance steps
536
-        e_steps += ((advance >>8) - old_advance);
535
+        e_steps[current_block->active_extruder] += ((advance >>8) - old_advance);
537
         old_advance = advance >>8;  
536
         old_advance = advance >>8;  
538
       #endif //ADVANCE
537
       #endif //ADVANCE
539
     }
538
     }
558
     old_OCR0A += 52; // ~10kHz interrupt (250000 / 26 = 9615kHz)
557
     old_OCR0A += 52; // ~10kHz interrupt (250000 / 26 = 9615kHz)
559
     OCR0A = old_OCR0A;
558
     OCR0A = old_OCR0A;
560
     // Set E direction (Depends on E direction + advance)
559
     // Set E direction (Depends on E direction + advance)
561
-    for(unsigned char i=0; i<4;) {
562
-      WRITE(E_STEP_PIN, LOW);
563
-      if (e_steps == 0) break;
564
-      i++;
565
-      if (e_steps < 0) {
566
-        WRITE(E_DIR_PIN,INVERT_E_DIR);    
567
-        e_steps++;
568
-        WRITE(E_STEP_PIN, HIGH);
569
-      } 
570
-      else if (e_steps > 0) {
571
-        WRITE(E_DIR_PIN,!INVERT_E_DIR);
572
-        e_steps--;
573
-        WRITE(E_STEP_PIN, HIGH);
560
+    for(unsigned char i=0; i<4;i++) {
561
+      if (e_steps[0] != 0) {
562
+        WRITE(E0_STEP_PIN, LOW);
563
+        if (e_steps[0] < 0) {
564
+          WRITE(E0_DIR_PIN, INVERT_E0_DIR);
565
+          e_steps[0]++;
566
+          WRITE(E0_STEP_PIN, HIGH);
567
+        } 
568
+        else if (e_steps[0] > 0) {
569
+          WRITE(E0_DIR_PIN, !INVERT_E0_DIR);
570
+          e_steps[0]--;
571
+          WRITE(E0_STEP_PIN, HIGH);
572
+        }
573
+      }
574
+ #if EXTRUDERS > 1
575
+      if (e_steps[1] != 0) {
576
+        WRITE(E1_STEP_PIN, LOW);
577
+        if (e_steps[1] < 0) {
578
+          WRITE(E1_DIR_PIN, INVERT_E1_DIR);
579
+          e_steps[1]++;
580
+          WRITE(E1_STEP_PIN, HIGH);
581
+        } 
582
+        else if (e_steps[1] > 0) {
583
+          WRITE(E1_DIR_PIN, !INVERT_E1_DIR);
584
+          e_steps[1]--;
585
+          WRITE(E1_STEP_PIN, HIGH);
586
+        }
587
+      }
588
+ #endif
589
+ #if EXTRUDERS > 2
590
+      if (e_steps[2] != 0) {
591
+        WRITE(E2_STEP_PIN, LOW);
592
+        if (e_steps[2] < 0) {
593
+          WRITE(E2_DIR_PIN, INVERT_E2_DIR);
594
+          e_steps[2]++;
595
+          WRITE(E2_STEP_PIN, HIGH);
596
+        } 
597
+        else if (e_steps[2] > 0) {
598
+          WRITE(E2_DIR_PIN, !INVERT_E2_DIR);
599
+          e_steps[2]--;
600
+          WRITE(E2_STEP_PIN, HIGH);
601
+        }
574
       }
602
       }
603
+ #endif
575
     }
604
     }
576
   }
605
   }
577
 #endif // ADVANCE
606
 #endif // ADVANCE
578
 
607
 
579
 void st_init()
608
 void st_init()
580
 {
609
 {
581
-    //Initialize Dir Pins
610
+  //Initialize Dir Pins
582
   #if X_DIR_PIN > -1
611
   #if X_DIR_PIN > -1
583
     SET_OUTPUT(X_DIR_PIN);
612
     SET_OUTPUT(X_DIR_PIN);
584
   #endif
613
   #endif
588
   #if Z_DIR_PIN > -1 
617
   #if Z_DIR_PIN > -1 
589
     SET_OUTPUT(Z_DIR_PIN);
618
     SET_OUTPUT(Z_DIR_PIN);
590
   #endif
619
   #endif
591
-  #if E_DIR_PIN > -1 
592
-    SET_OUTPUT(E_DIR_PIN);
620
+  #if E0_DIR_PIN > -1 
621
+    SET_OUTPUT(E0_DIR_PIN);
622
+  #endif
623
+  #if defined(E1_DIR_PIN) && (E1_DIR_PIN > -1)
624
+    SET_OUTPUT(E1_DIR_PIN);
625
+  #endif
626
+  #if defined(E2_DIR_PIN) && (E2_DIR_PIN > -1)
627
+    SET_OUTPUT(E2_DIR_PIN);
593
   #endif
628
   #endif
594
 
629
 
595
   //Initialize Enable Pins - steppers default to disabled.
630
   //Initialize Enable Pins - steppers default to disabled.
606
     SET_OUTPUT(Z_ENABLE_PIN);
641
     SET_OUTPUT(Z_ENABLE_PIN);
607
     if(!Z_ENABLE_ON) WRITE(Z_ENABLE_PIN,HIGH);
642
     if(!Z_ENABLE_ON) WRITE(Z_ENABLE_PIN,HIGH);
608
   #endif
643
   #endif
609
-  #if (E_ENABLE_PIN > -1)
610
-    SET_OUTPUT(E_ENABLE_PIN);
611
-    if(!E_ENABLE_ON) WRITE(E_ENABLE_PIN,HIGH);
644
+  #if (E0_ENABLE_PIN > -1)
645
+    SET_OUTPUT(E0_ENABLE_PIN);
646
+    if(!E_ENABLE_ON) WRITE(E0_ENABLE_PIN,HIGH);
647
+  #endif
648
+  #if defined(E1_ENABLE_PIN) && (E1_ENABLE_PIN > -1)
649
+    SET_OUTPUT(E1_ENABLE_PIN);
650
+    if(!E_ENABLE_ON) WRITE(E1_ENABLE_PIN,HIGH);
651
+  #endif
652
+  #if defined(E2_ENABLE_PIN) && (E2_ENABLE_PIN > -1)
653
+    SET_OUTPUT(E2_ENABLE_PIN);
654
+    if(!E_ENABLE_ON) WRITE(E2_ENABLE_PIN,HIGH);
612
   #endif
655
   #endif
613
 
656
 
614
   //endstops and pullups
657
   //endstops and pullups
669
   #if (Z_STEP_PIN > -1) 
712
   #if (Z_STEP_PIN > -1) 
670
     SET_OUTPUT(Z_STEP_PIN);
713
     SET_OUTPUT(Z_STEP_PIN);
671
   #endif  
714
   #endif  
672
-  #if (E_STEP_PIN > -1) 
673
-    SET_OUTPUT(E_STEP_PIN);
715
+  #if (E0_STEP_PIN > -1) 
716
+    SET_OUTPUT(E0_STEP_PIN);
717
+  #endif  
718
+  #if defined(E1_STEP_PIN) && (E1_STEP_PIN > -1) 
719
+    SET_OUTPUT(E1_STEP_PIN);
720
+  #endif  
721
+  #if defined(E2_STEP_PIN) && (E2_STEP_PIN > -1) 
722
+    SET_OUTPUT(E2_STEP_PIN);
674
   #endif  
723
   #endif  
675
 
724
 
676
   // waveform generation = 0100 = CTC
725
   // waveform generation = 0100 = CTC
693
     TCCR0A &= ~(1<<WGM01);
742
     TCCR0A &= ~(1<<WGM01);
694
     TCCR0A &= ~(1<<WGM00);
743
     TCCR0A &= ~(1<<WGM00);
695
   #endif  
744
   #endif  
696
-    e_steps = 0;
745
+    e_steps[0] = 0;
746
+    e_steps[1] = 0;
747
+    e_steps[2] = 0;
697
     TIMSK0 |= (1<<OCIE0A);
748
     TIMSK0 |= (1<<OCIE0A);
698
   #endif //ADVANCE
749
   #endif //ADVANCE
699
   
750
   
750
   disable_x(); 
801
   disable_x(); 
751
   disable_y(); 
802
   disable_y(); 
752
   disable_z(); 
803
   disable_z(); 
753
-  disable_e(); 
804
+  disable_e0(); 
805
+  disable_e1(); 
806
+  disable_e2(); 
754
 }
807
 }
755
 
808
 
756
 void quickStop()
809
 void quickStop()

+ 15
- 0
Marlin/stepper.h View File

23
 
23
 
24
 #include "planner.h"
24
 #include "planner.h"
25
 
25
 
26
+#if EXTRUDERS > 2
27
+  #define WRITE_E_STEP(v) { if(current_block->active_extruder == 2) { WRITE(E2_STEP_PIN, v); } else { if(current_block->active_extruder == 1) { WRITE(E1_STEP_PIN, v); } else { WRITE(E0_STEP_PIN, v); }}}
28
+  #define NORM_E_DIR() { if(current_block->active_extruder == 2) { WRITE(!E2_DIR_PIN, INVERT_E2_DIR); } else { if(current_block->active_extruder == 1) { WRITE(!E1_DIR_PIN, INVERT_E1_DIR); } else { WRITE(E0_DIR_PIN, !INVERT_E0_DIR); }}}
29
+  #define REV_E_DIR() { if(current_block->active_extruder == 2) { WRITE(E2_DIR_PIN, INVERT_E2_DIR); } else { if(current_block->active_extruder == 1) { WRITE(E1_DIR_PIN, INVERT_E1_DIR); } else { WRITE(E0_DIR_PIN, INVERT_E0_DIR); }}}
30
+#elif EXTRUDERS > 1
31
+  #define WRITE_E_STEP(v) { if(current_block->active_extruder == 1) { WRITE(E1_STEP_PIN, v); } else { WRITE(E0_STEP_PIN, v); }}
32
+  #define NORM_E_DIR() { if(current_block->active_extruder == 1) { WRITE(E1_DIR_PIN, !INVERT_E1_DIR); } else { WRITE(E0_DIR_PIN, !INVERT_E0_DIR); }}
33
+  #define REV_E_DIR() { if(current_block->active_extruder == 1) { WRITE(E1_DIR_PIN, INVERT_E1_DIR); } else { WRITE(E0_DIR_PIN, INVERT_E0_DIR); }}
34
+#else
35
+  #define WRITE_E_STEP(v) WRITE(E0_STEP_PIN, v)
36
+  #define NORM_E_DIR() WRITE(E0_DIR_PIN, !INVERT_E0_DIR)
37
+  #define REV_E_DIR() WRITE(E0_DIR_PIN, INVERT_E0_DIR)
38
+#endif
39
+
40
+
26
 // Initialize and start the stepper motor subsystem
41
 // Initialize and start the stepper motor subsystem
27
 void st_init();
42
 void st_init();
28
 
43
 

+ 327
- 220
Marlin/temperature.cpp View File

26
  It has preliminary support for Matthew Roberts advance algorithm 
26
  It has preliminary support for Matthew Roberts advance algorithm 
27
     http://reprap.org/pipermail/reprap-dev/2011-May/003323.html
27
     http://reprap.org/pipermail/reprap-dev/2011-May/003323.html
28
 
28
 
29
- This firmware is optimized for gen6 electronics.
30
  */
29
  */
31
 #include <avr/pgmspace.h>
30
 #include <avr/pgmspace.h>
32
 
31
 
41
 //===========================================================================
40
 //===========================================================================
42
 //=============================public variables============================
41
 //=============================public variables============================
43
 //===========================================================================
42
 //===========================================================================
44
-int target_raw[3] = {0, 0, 0};
45
-int current_raw[3] = {0, 0, 0};
46
-int heatingtarget_raw[3]= {0, 0, 0};
47
-
43
+int target_raw[EXTRUDERS] = { 0 };
44
+int target_raw_bed = 0;
45
+int current_raw[EXTRUDERS] = { 0 };
46
+int current_raw_bed = 0;
48
 
47
 
49
 #ifdef PIDTEMP
48
 #ifdef PIDTEMP
50
-  
51
-  // probably used external
52
-  float HeaterPower;
53
-  float pid_setpoint = 0.0;
54
-
49
+  // used external
50
+  float pid_setpoint[EXTRUDERS] = { 0.0 };
55
   
51
   
56
   float Kp=DEFAULT_Kp;
52
   float Kp=DEFAULT_Kp;
57
   float Ki=DEFAULT_Ki;
53
   float Ki=DEFAULT_Ki;
72
 
68
 
73
 #ifdef PIDTEMP
69
 #ifdef PIDTEMP
74
   //static cannot be external:
70
   //static cannot be external:
75
-  static float temp_iState = 0;
76
-  static float temp_dState = 0;
77
-  static float pTerm;
78
-  static float iTerm;
79
-  static float dTerm;
71
+  static float temp_iState[EXTRUDERS] = { 0 };
72
+  static float temp_dState[EXTRUDERS] = { 0 };
73
+  static float pTerm[EXTRUDERS];
74
+  static float iTerm[EXTRUDERS];
75
+  static float dTerm[EXTRUDERS];
80
   //int output;
76
   //int output;
81
-  static float pid_error;
82
-  static float temp_iState_min;
83
-  static float temp_iState_max;
84
- // static float pid_input; 
85
- // static float pid_output;
86
-  static bool pid_reset;
87
- 
77
+  static float pid_error[EXTRUDERS];
78
+  static float temp_iState_min[EXTRUDERS];
79
+  static float temp_iState_max[EXTRUDERS];
80
+  // static float pid_input[EXTRUDERS];
81
+  // static float pid_output[EXTRUDERS];
82
+  static bool pid_reset[EXTRUDERS];
88
 #endif //PIDTEMP
83
 #endif //PIDTEMP
84
+  static unsigned char soft_pwm[EXTRUDERS];
89
   
85
   
90
 #ifdef WATCHPERIOD
86
 #ifdef WATCHPERIOD
87
+  static int watch_raw[EXTRUDERS] = { -1000 }; // the first value used for all
91
   static int watch_oldtemp[3] = {0,0,0};
88
   static int watch_oldtemp[3] = {0,0,0};
92
   static unsigned long watchmillis = 0;
89
   static unsigned long watchmillis = 0;
93
 #endif //WATCHPERIOD
90
 #endif //WATCHPERIOD
94
 
91
 
95
 // Init min and max temp with extreme values to prevent false errors during startup
92
 // Init min and max temp with extreme values to prevent false errors during startup
96
-  static int minttemp_0   = 0;
97
-  static int maxttemp_0   = 16383;
98
-  //static int minttemp_1   = 0;
99
-  //static int maxttemp_1   = 16383;
93
+  static int minttemp[EXTRUDERS] = { 0 };
94
+  static int maxttemp[EXTRUDERS] = { 16383 }; // the first value used for all
100
   static int bed_minttemp = 0;
95
   static int bed_minttemp = 0;
101
   static int bed_maxttemp = 16383;
96
   static int bed_maxttemp = 16383;
97
+  static int heater_pin_map[EXTRUDERS] = { HEATER_0_PIN
98
+#if EXTRUDERS > 1
99
+                                         , HEATER_1_PIN
100
+#endif
101
+#if EXTRUDERS > 2
102
+                                         , HEATER_2_PIN
103
+#endif
104
+#if EXTRUDERS > 3
105
+  #error Unsupported number of extruders
106
+#endif
107
+  };
108
+  static void *heater_ttbl_map[EXTRUDERS] = { (void *)heater_0_temptable
109
+#if EXTRUDERS > 1
110
+                                            , (void *)heater_1_temptable
111
+#endif
112
+#if EXTRUDERS > 2
113
+                                            , (void *)heater_2_temptable
114
+#endif
115
+#if EXTRUDERS > 3
116
+  #error Unsupported number of extruders
117
+#endif
118
+  };
119
+  static int heater_ttbllen_map[EXTRUDERS] = { heater_0_temptable_len
120
+#if EXTRUDERS > 1
121
+                                             , heater_1_temptable_len
122
+#endif
123
+#if EXTRUDERS > 2
124
+                                             , heater_2_temptable_len
125
+#endif
126
+#if EXTRUDERS > 3
127
+  #error Unsupported number of extruders
128
+#endif
129
+  };
102
 
130
 
103
 //===========================================================================
131
 //===========================================================================
104
-//=============================functions         ============================
132
+//=============================   functions      ============================
105
 //===========================================================================
133
 //===========================================================================
106
   
134
   
107
 void updatePID()
135
 void updatePID()
108
 {
136
 {
109
 #ifdef PIDTEMP
137
 #ifdef PIDTEMP
110
-  temp_iState_max = PID_INTEGRAL_DRIVE_MAX / Ki;
138
+  for(int e = 0; e < EXTRUDERS; e++) { 
139
+     temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / Ki;  
140
+  }
111
 #endif
141
 #endif
112
 }
142
 }
113
   
143
   
144
+int getHeaterPower(int heater) {
145
+  return soft_pwm[heater];
146
+}
147
+
114
 void manage_heater()
148
 void manage_heater()
115
 {
149
 {
116
   #ifdef USE_WATCHDOG
150
   #ifdef USE_WATCHDOG
119
   
153
   
120
   float pid_input;
154
   float pid_input;
121
   float pid_output;
155
   float pid_output;
156
+
122
   if(temp_meas_ready != true)   //better readability
157
   if(temp_meas_ready != true)   //better readability
123
     return; 
158
     return; 
124
 
159
 
125
   CRITICAL_SECTION_START;
160
   CRITICAL_SECTION_START;
126
-    temp_meas_ready = false;
161
+  temp_meas_ready = false;
127
   CRITICAL_SECTION_END;
162
   CRITICAL_SECTION_END;
128
 
163
 
164
+  for(int e = 0; e < EXTRUDERS; e++) 
165
+  {
166
+
129
   #ifdef PIDTEMP
167
   #ifdef PIDTEMP
130
-    pid_input = analog2temp(current_raw[TEMPSENSOR_HOTEND_0]);
168
+    pid_input = analog2temp(current_raw[e], e);
131
 
169
 
132
     #ifndef PID_OPENLOOP
170
     #ifndef PID_OPENLOOP
133
-        pid_error = pid_setpoint - pid_input;
134
-        if(pid_error > 10){
171
+        pid_error[e] = pid_setpoint[e] - pid_input;
172
+        if(pid_error[e] > 10) {
135
           pid_output = PID_MAX;
173
           pid_output = PID_MAX;
136
-          pid_reset = true;
174
+          pid_reset[e] = true;
137
         }
175
         }
138
-        else if(pid_error < -10) {
176
+        else if(pid_error[e] < -10) {
139
           pid_output = 0;
177
           pid_output = 0;
140
-          pid_reset = true;
178
+          pid_reset[e] = true;
141
         }
179
         }
142
         else {
180
         else {
143
-          if(pid_reset == true) {
144
-            temp_iState = 0.0;
145
-            pid_reset = false;
181
+          if(pid_reset[e] == true) {
182
+            temp_iState[e] = 0.0;
183
+            pid_reset[e] = false;
146
           }
184
           }
147
-          pTerm = Kp * pid_error;
148
-          temp_iState += pid_error;
149
-          temp_iState = constrain(temp_iState, temp_iState_min, temp_iState_max);
150
-          iTerm = Ki * temp_iState;
185
+          pTerm[e] = Kp * pid_error[e];
186
+          temp_iState[e] += pid_error[e];
187
+          temp_iState[e] = constrain(temp_iState[e], temp_iState_min[e], temp_iState_max[e]);
188
+          iTerm[e] = Ki * temp_iState[e];
151
           //K1 defined in Configuration.h in the PID settings
189
           //K1 defined in Configuration.h in the PID settings
152
           #define K2 (1.0-K1)
190
           #define K2 (1.0-K1)
153
-          dTerm = (Kd * (pid_input - temp_dState))*K2 + (K1 * dTerm);
154
-          temp_dState = pid_input;
155
-//          #ifdef PID_ADD_EXTRUSION_RATE
156
-//            pTerm+=Kc*current_block->speed_e; //additional heating if extrusion speed is high
157
-//          #endif
158
-          pid_output = constrain(pTerm + iTerm - dTerm, 0, PID_MAX);
159
-          
191
+          dTerm[e] = (Kd * (pid_input - temp_dState[e]))*K2 + (K1 * dTerm[e]);
192
+          temp_dState[e] = pid_input;
193
+          pid_output = constrain(pTerm[e] + iTerm[e] - dTerm[e], 0, PID_MAX);
160
         }
194
         }
161
     #endif //PID_OPENLOOP
195
     #endif //PID_OPENLOOP
162
     #ifdef PID_DEBUG
196
     #ifdef PID_DEBUG
163
-     //SERIAL_ECHOLN(" PIDDEBUG Input "<<pid_input<<" Output "<<pid_output" pTerm "<<pTerm<<" iTerm "<<iTerm<<" dTerm "<<dTerm);  
197
+    SERIAL_ECHOLN(" PIDDEBUG "<<e<<": Input "<<pid_input<<" Output "<<pid_output" pTerm "<<pTerm[e]<<" iTerm "<<iTerm[e]<<" dTerm "<<dTerm[e]);  
164
     #endif //PID_DEBUG
198
     #endif //PID_DEBUG
165
-    HeaterPower=pid_output;
166
-    // Check if temperature is within the correct range
167
-    if((current_raw[TEMPSENSOR_HOTEND_0] > minttemp_0) && (current_raw[TEMPSENSOR_HOTEND_0] < maxttemp_0)) {
168
-      analogWrite(HEATER_0_PIN, pid_output);
199
+  #else /* PID off */
200
+    pid_output = 0;
201
+    if(current_raw[e] < target_raw[e]) {
202
+      pid_output = PID_MAX;
169
     }
203
     }
170
-    else {
171
-      analogWrite(HEATER_0_PIN, 0);
172
-    }
173
-  #endif //PIDTEMP
204
+  #endif
174
 
205
 
175
-  #ifndef PIDTEMP
176
     // Check if temperature is within the correct range
206
     // Check if temperature is within the correct range
177
-    if((current_raw[TEMPSENSOR_HOTEND_0] > minttemp_0) && (current_raw[TEMPSENSOR_HOTEND_0] < maxttemp_0)) {
178
-      if(current_raw[TEMPSENSOR_HOTEND_0] >= target_raw[TEMPSENSOR_HOTEND_0]) {
179
-        WRITE(HEATER_0_PIN,LOW);
180
-      }
181
-      else {
182
-        WRITE(HEATER_0_PIN,HIGH);
183
-      }
207
+    if((current_raw[e] > minttemp[e]) && (current_raw[e] < maxttemp[e])) 
208
+    {
209
+      //analogWrite(heater_pin_map[e], pid_output);
210
+      soft_pwm[e] = (int)pid_output >> 1;
184
     }
211
     }
185
     else {
212
     else {
186
-      WRITE(HEATER_0_PIN,LOW);
187
-    }    
188
-  #endif
213
+      //analogWrite(heater_pin_map[e], 0);
214
+      soft_pwm[e] = 0;
215
+    }
216
+  } // End extruder for loop
189
   
217
   
190
   #ifdef WATCHPERIOD
218
   #ifdef WATCHPERIOD
191
     if(watchmillis && millis() - watchmillis > WATCHPERIOD){
219
     if(watchmillis && millis() - watchmillis > WATCHPERIOD){
204
     return;
232
     return;
205
   previous_millis_bed_heater = millis();
233
   previous_millis_bed_heater = millis();
206
   
234
   
207
-  #if TEMP_1_PIN > -1
235
+  #if TEMP_BED_PIN > -1
208
     // Check if temperature is within the correct range
236
     // Check if temperature is within the correct range
209
-    if((current_raw[TEMPSENSOR_BED] > bed_minttemp) && (current_raw[TEMPSENSOR_BED] < bed_maxttemp)) {
210
-      if(current_raw[TEMPSENSOR_BED] >= target_raw[TEMPSENSOR_BED])
237
+    if((current_raw_bed > bed_minttemp) && (current_raw_bed < bed_maxttemp)) {
238
+      if(current_raw_bed >= target_raw_bed)
211
       {
239
       {
212
-        WRITE(HEATER_1_PIN,LOW);
240
+        WRITE(HEATER_BED_PIN,LOW);
213
       }
241
       }
214
       else 
242
       else 
215
       {
243
       {
216
-        WRITE(HEATER_1_PIN,HIGH);
244
+        WRITE(HEATER_BED_PIN,HIGH);
217
       }
245
       }
218
     }
246
     }
219
     else {
247
     else {
220
-      WRITE(HEATER_1_PIN,LOW);
248
+      WRITE(HEATER_BED_PIN,LOW);
221
     }  
249
     }  
222
   #endif
250
   #endif
223
 }
251
 }
227
 // For a thermistor, it uses the RepRap thermistor temp table.
255
 // For a thermistor, it uses the RepRap thermistor temp table.
228
 // This is needed because PID in hydra firmware hovers around a given analog value, not a temp value.
256
 // This is needed because PID in hydra firmware hovers around a given analog value, not a temp value.
229
 // This function is derived from inversing the logic from a portion of getTemperature() in FiveD RepRap firmware.
257
 // This function is derived from inversing the logic from a portion of getTemperature() in FiveD RepRap firmware.
230
-int temp2analog(int celsius) {
231
-  #ifdef HEATER_0_USES_THERMISTOR
258
+int temp2analog(int celsius, uint8_t e) {
259
+  if(e >= EXTRUDERS)
260
+  {
261
+      SERIAL_ERROR_START;
262
+      SERIAL_ERROR((int)e);
263
+      SERIAL_ERRORLNPGM(" - Invalid extruder number!");
264
+      kill();
265
+  }
266
+  if(heater_ttbl_map[e] != 0)
267
+  {
232
     int raw = 0;
268
     int raw = 0;
233
     byte i;
269
     byte i;
270
+    short (*tt)[][2] = (short (*)[][2])(heater_ttbl_map[e]);
234
 
271
 
235
-    for (i=1; i<NUMTEMPS_HEATER_0; i++)
272
+    for (i=1; i<heater_ttbllen_map[e]; i++)
236
     {
273
     {
237
-      if (PGM_RD_W(heater_0_temptable[i][1]) < celsius)
274
+      if (PGM_RD_W((*tt)[i][1]) < celsius)
238
       {
275
       {
239
-        raw = PGM_RD_W(heater_0_temptable[i-1][0]) + 
240
-          (celsius - PGM_RD_W(heater_0_temptable[i-1][1])) * 
241
-          (PGM_RD_W(heater_0_temptable[i][0]) - PGM_RD_W(heater_0_temptable[i-1][0])) /
242
-          (PGM_RD_W(heater_0_temptable[i][1]) - PGM_RD_W(heater_0_temptable[i-1][1]));  
276
+        raw = PGM_RD_W((*tt)[i-1][0]) + 
277
+          (celsius - PGM_RD_W((*tt)[i-1][1])) * 
278
+          (PGM_RD_W((*tt)[i][0]) - PGM_RD_W((*tt)[i-1][0])) /
279
+          (PGM_RD_W((*tt)[i][1]) - PGM_RD_W((*tt)[i-1][1]));  
243
         break;
280
         break;
244
       }
281
       }
245
     }
282
     }
246
 
283
 
247
     // Overflow: Set to last value in the table
284
     // Overflow: Set to last value in the table
248
-    if (i == NUMTEMPS_HEATER_0) raw = PGM_RD_W(heater_0_temptable[i-1][0]);
285
+    if (i == heater_ttbllen_map[e]) raw = PGM_RD_W((*tt)[i-1][0]);
249
 
286
 
250
     return (1023 * OVERSAMPLENR) - raw;
287
     return (1023 * OVERSAMPLENR) - raw;
251
-  #elif defined HEATER_0_USES_AD595
252
-    return celsius * (1024.0 / (5.0 * 100.0) ) * OVERSAMPLENR;
253
-  #endif
288
+  }
289
+  return celsius * (1024.0 / (5.0 * 100.0) ) * OVERSAMPLENR;
254
 }
290
 }
255
 
291
 
256
 // Takes bed temperature value as input and returns corresponding raw value. 
292
 // Takes bed temperature value as input and returns corresponding raw value. 
258
 // This is needed because PID in hydra firmware hovers around a given analog value, not a temp value.
294
 // This is needed because PID in hydra firmware hovers around a given analog value, not a temp value.
259
 // This function is derived from inversing the logic from a portion of getTemperature() in FiveD RepRap firmware.
295
 // This function is derived from inversing the logic from a portion of getTemperature() in FiveD RepRap firmware.
260
 int temp2analogBed(int celsius) {
296
 int temp2analogBed(int celsius) {
261
-  #ifdef BED_USES_THERMISTOR
262
-
297
+#ifdef BED_USES_THERMISTOR
263
     int raw = 0;
298
     int raw = 0;
264
     byte i;
299
     byte i;
265
     
300
     
266
-    for (i=1; i<BNUMTEMPS; i++)
301
+    for (i=1; i<bedtemptable_len; i++)
267
     {
302
     {
268
       if (PGM_RD_W(bedtemptable[i][1]) < celsius)
303
       if (PGM_RD_W(bedtemptable[i][1]) < celsius)
269
       {
304
       {
277
     }
312
     }
278
 
313
 
279
     // Overflow: Set to last value in the table
314
     // Overflow: Set to last value in the table
280
-    if (i == BNUMTEMPS) raw = PGM_RD_W(bedtemptable[i-1][0]);
315
+    if (i == bedtemptable_len) raw = PGM_RD_W(bedtemptable[i-1][0]);
281
 
316
 
282
     return (1023 * OVERSAMPLENR) - raw;
317
     return (1023 * OVERSAMPLENR) - raw;
283
-  #elif defined BED_USES_AD595
318
+#elif defined BED_USES_AD595
284
     return lround(celsius * (1024.0 * OVERSAMPLENR/ (5.0 * 100.0) ) );
319
     return lround(celsius * (1024.0 * OVERSAMPLENR/ (5.0 * 100.0) ) );
285
-  #else
320
+#else
286
     #warning No heater-type defined for the bed.
321
     #warning No heater-type defined for the bed.
287
-  #endif
288
-  return 0;
322
+    return 0;
323
+#endif
289
 }
324
 }
290
 
325
 
291
 // Derived from RepRap FiveD extruder::getTemperature()
326
 // Derived from RepRap FiveD extruder::getTemperature()
292
 // For hot end temperature measurement.
327
 // For hot end temperature measurement.
293
-float analog2temp(int raw) {
294
-  #ifdef HEATER_0_USES_THERMISTOR
328
+float analog2temp(int raw, uint8_t e) {
329
+  if(e >= EXTRUDERS)
330
+  {
331
+      SERIAL_ERROR_START;
332
+      SERIAL_ERROR((int)e);
333
+      SERIAL_ERRORLNPGM(" - Invalid extruder number !");
334
+      kill();
335
+  }
336
+  if(heater_ttbl_map[e] != 0)
337
+  {
295
     float celsius = 0;
338
     float celsius = 0;
296
     byte i;  
339
     byte i;  
340
+    short (*tt)[][2] = (short (*)[][2])(heater_ttbl_map[e]);
341
+
297
     raw = (1023 * OVERSAMPLENR) - raw;
342
     raw = (1023 * OVERSAMPLENR) - raw;
298
-    for (i=1; i<NUMTEMPS_HEATER_0; i++)
343
+    for (i=1; i<heater_ttbllen_map[e]; i++)
299
     {
344
     {
300
-      if (PGM_RD_W(heater_0_temptable[i][0]) > raw)
345
+      if (PGM_RD_W((*tt)[i][0]) > raw)
301
       {
346
       {
302
-        celsius  = PGM_RD_W(heater_0_temptable[i-1][1]) + 
303
-          (raw - PGM_RD_W(heater_0_temptable[i-1][0])) * 
304
-          (float)(PGM_RD_W(heater_0_temptable[i][1]) - PGM_RD_W(heater_0_temptable[i-1][1])) /
305
-          (float)(PGM_RD_W(heater_0_temptable[i][0]) - PGM_RD_W(heater_0_temptable[i-1][0]));
347
+        celsius = PGM_RD_W((*tt)[i-1][1]) + 
348
+          (raw - PGM_RD_W((*tt)[i-1][0])) * 
349
+          (float)(PGM_RD_W((*tt)[i][1]) - PGM_RD_W((*tt)[i-1][1])) /
350
+          (float)(PGM_RD_W((*tt)[i][0]) - PGM_RD_W((*tt)[i-1][0]));
306
         break;
351
         break;
307
       }
352
       }
308
     }
353
     }
309
 
354
 
310
     // Overflow: Set to last value in the table
355
     // Overflow: Set to last value in the table
311
-    if (i == NUMTEMPS_HEATER_0) celsius = PGM_RD_W(heater_0_temptable[i-1][1]);
356
+    if (i == heater_ttbllen_map[e]) celsius = PGM_RD_W((*tt)[i-1][1]);
312
 
357
 
313
     return celsius;
358
     return celsius;
314
-  #elif defined HEATER_0_USES_AD595
315
-    return raw * ((5.0 * 100.0) / 1024.0) / OVERSAMPLENR;
316
-  #else
317
-    #error PLEASE DEFINE HEATER TYPE 
318
-  #endif
359
+  }
360
+  return raw * ((5.0 * 100.0) / 1024.0) / OVERSAMPLENR;
319
 }
361
 }
320
 
362
 
321
 // Derived from RepRap FiveD extruder::getTemperature()
363
 // Derived from RepRap FiveD extruder::getTemperature()
327
 
369
 
328
     raw = (1023 * OVERSAMPLENR) - raw;
370
     raw = (1023 * OVERSAMPLENR) - raw;
329
 
371
 
330
-    for (i=1; i<BNUMTEMPS; i++)
372
+    for (i=1; i<bedtemptable_len; i++)
331
     {
373
     {
332
       if (PGM_RD_W(bedtemptable[i][0]) > raw)
374
       if (PGM_RD_W(bedtemptable[i][0]) > raw)
333
       {
375
       {
341
     }
383
     }
342
 
384
 
343
     // Overflow: Set to last value in the table
385
     // Overflow: Set to last value in the table
344
-    if (i == BNUMTEMPS) celsius = PGM_RD_W(bedtemptable[i-1][1]);
386
+    if (i == bedtemptable_len) celsius = PGM_RD_W(bedtemptable[i-1][1]);
345
 
387
 
346
     return celsius;
388
     return celsius;
347
     
389
     
355
 
397
 
356
 void tp_init()
398
 void tp_init()
357
 {
399
 {
400
+  // Finish init of mult extruder arrays 
401
+  for(int e = 0; e < EXTRUDERS; e++) {
402
+    // populate with the first value 
403
+#ifdef WATCHPERIOD
404
+    watch_raw[e] = watch_raw[0];
405
+#endif
406
+    maxttemp[e] = maxttemp[0];
407
+#ifdef PIDTEMP
408
+    temp_iState_min[e] = 0.0;
409
+    temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / Ki;
410
+#endif //PIDTEMP
411
+  }
412
+
358
   #if (HEATER_0_PIN > -1) 
413
   #if (HEATER_0_PIN > -1) 
359
     SET_OUTPUT(HEATER_0_PIN);
414
     SET_OUTPUT(HEATER_0_PIN);
360
   #endif  
415
   #endif  
364
   #if (HEATER_2_PIN > -1) 
419
   #if (HEATER_2_PIN > -1) 
365
     SET_OUTPUT(HEATER_2_PIN);
420
     SET_OUTPUT(HEATER_2_PIN);
366
   #endif  
421
   #endif  
367
-
368
-  #ifdef PIDTEMP
369
-    temp_iState_min = 0.0;
370
-    temp_iState_max = PID_INTEGRAL_DRIVE_MAX / Ki;
371
-  #endif //PIDTEMP
422
+  #if (HEATER_BED_PIN > -1) 
423
+    SET_OUTPUT(HEATER_BED_PIN);
424
+  #endif  
425
+  #if (FAN_PIN > -1) 
426
+    SET_OUTPUT(FAN_PIN);
427
+  #endif  
372
 
428
 
373
   // Set analog inputs
429
   // Set analog inputs
374
   ADCSRA = 1<<ADEN | 1<<ADSC | 1<<ADIF | 0x07;
430
   ADCSRA = 1<<ADEN | 1<<ADSC | 1<<ADIF | 0x07;
381
        DIDR0 |= 1 << TEMP_0_PIN; 
437
        DIDR0 |= 1 << TEMP_0_PIN; 
382
     #else
438
     #else
383
        DIDR2 |= 1<<(TEMP_0_PIN - 8); 
439
        DIDR2 |= 1<<(TEMP_0_PIN - 8); 
384
-       ADCSRB = 1<<MUX5;
385
     #endif
440
     #endif
386
   #endif
441
   #endif
387
   #if (TEMP_1_PIN > -1)
442
   #if (TEMP_1_PIN > -1)
389
        DIDR0 |= 1<<TEMP_1_PIN; 
444
        DIDR0 |= 1<<TEMP_1_PIN; 
390
     #else
445
     #else
391
        DIDR2 |= 1<<(TEMP_1_PIN - 8); 
446
        DIDR2 |= 1<<(TEMP_1_PIN - 8); 
392
-       ADCSRB = 1<<MUX5;
393
     #endif
447
     #endif
394
   #endif
448
   #endif
395
   #if (TEMP_2_PIN > -1)
449
   #if (TEMP_2_PIN > -1)
397
        DIDR0 |= 1 << TEMP_2_PIN; 
451
        DIDR0 |= 1 << TEMP_2_PIN; 
398
     #else
452
     #else
399
        DIDR2 = 1<<(TEMP_2_PIN - 8); 
453
        DIDR2 = 1<<(TEMP_2_PIN - 8); 
400
-       ADCSRB = 1<<MUX5;
454
+    #endif
455
+  #endif
456
+  #if (TEMP_BED_PIN > -1)
457
+    #if TEMP_BED_PIN < 8
458
+       DIDR0 |= 1<<TEMP_BED_PIN; 
459
+    #else
460
+       DIDR2 |= 1<<(TEMP_BED_PIN - 8); 
401
     #endif
461
     #endif
402
   #endif
462
   #endif
403
   
463
   
407
   TIMSK0 |= (1<<OCIE0B);  
467
   TIMSK0 |= (1<<OCIE0B);  
408
   
468
   
409
   // Wait for temperature measurement to settle
469
   // Wait for temperature measurement to settle
410
-  delay(200);
470
+  delay(250);
411
 
471
 
412
 #ifdef HEATER_0_MINTEMP
472
 #ifdef HEATER_0_MINTEMP
413
-  minttemp_0 = temp2analog(HEATER_0_MINTEMP);
473
+  minttemp[0] = temp2analog(HEATER_0_MINTEMP, 0);
414
 #endif //MINTEMP
474
 #endif //MINTEMP
415
 #ifdef HEATER_0_MAXTEMP
475
 #ifdef HEATER_0_MAXTEMP
416
-  maxttemp_0 = temp2analog(HEATER_0_MAXTEMP);
476
+  maxttemp[0] = temp2analog(HEATER_0_MAXTEMP, 0);
417
 #endif //MAXTEMP
477
 #endif //MAXTEMP
418
 
478
 
419
-#ifdef HEATER_1_MINTEMP
420
-  minttemp_1 = temp2analog(HEATER_1_MINTEMP);
421
-#endif //MINTEMP
422
-#ifdef HEATER_1_MAXTEMP
423
-  maxttemp_1 = temp2analog(HEATER_1_MAXTEMP);
424
-#endif //MAXTEMP
479
+#if (EXTRUDERS > 1) && defined(HEATER_1_MINTEMP)
480
+  minttemp[1] = temp2analog(HEATER_1_MINTEMP, 1);
481
+#endif // MINTEMP 1
482
+#if (EXTRUDERS > 1) && defined(HEATER_1_MAXTEMP)
483
+  maxttemp[1] = temp2analog(HEATER_1_MAXTEMP, 1);
484
+#endif //MAXTEMP 1
485
+
486
+#if (EXTRUDERS > 2) && defined(HEATER_2_MINTEMP)
487
+  minttemp[2] = temp2analog(HEATER_2_MINTEMP, 2);
488
+#endif //MINTEMP 2
489
+#if (EXTRUDERS > 2) && defined(HEATER_2_MAXTEMP)
490
+  maxttemp[2] = temp2analog(HEATER_2_MAXTEMP, 2);
491
+#endif //MAXTEMP 2
425
 
492
 
426
 #ifdef BED_MINTEMP
493
 #ifdef BED_MINTEMP
427
-  bed_minttemp = temp2analog(BED_MINTEMP);
494
+  bed_minttemp = temp2analogBed(BED_MINTEMP);
428
 #endif //BED_MINTEMP
495
 #endif //BED_MINTEMP
429
 #ifdef BED_MAXTEMP
496
 #ifdef BED_MAXTEMP
430
-  bed_maxttemp = temp2analog(BED_MAXTEMP);
497
+  bed_maxttemp = temp2analogBed(BED_MAXTEMP);
431
 #endif //BED_MAXTEMP
498
 #endif //BED_MAXTEMP
432
 }
499
 }
433
 
500
 
436
 void setWatch() 
503
 void setWatch() 
437
 {  
504
 {  
438
 #ifdef WATCHPERIOD
505
 #ifdef WATCHPERIOD
439
-  if(isHeatingHotend0())
506
+  int t = 0;
507
+  for (int e = 0; e < EXTRUDERS; e++)
440
   {
508
   {
441
-    watchmillis = max(1,millis());
509
+    if(isHeatingHotend(e))
442
     watch_oldtemp[TEMPSENSOR_HOTEND_0] = degHotend(0);
510
     watch_oldtemp[TEMPSENSOR_HOTEND_0] = degHotend(0);
511
+    {
512
+      t = max(t,millis());
513
+      watch_raw[e] = current_raw[e];
514
+    } 
443
   }
515
   }
444
-  else
445
-  {
446
-    watchmillis = 0;
447
-  } 
516
+  watchmillis = t;
448
 #endif 
517
 #endif 
449
 }
518
 }
450
 
519
 
453
 {
522
 {
454
   #if TEMP_0_PIN > -1
523
   #if TEMP_0_PIN > -1
455
   target_raw[0]=0;
524
   target_raw[0]=0;
525
+  soft_pwm[0]=0;
456
    #if HEATER_0_PIN > -1  
526
    #if HEATER_0_PIN > -1  
457
      digitalWrite(HEATER_0_PIN,LOW);
527
      digitalWrite(HEATER_0_PIN,LOW);
458
    #endif
528
    #endif
460
      
530
      
461
   #if TEMP_1_PIN > -1
531
   #if TEMP_1_PIN > -1
462
     target_raw[1]=0;
532
     target_raw[1]=0;
533
+    soft_pwm[1]=0;
463
     #if HEATER_1_PIN > -1 
534
     #if HEATER_1_PIN > -1 
464
       digitalWrite(HEATER_1_PIN,LOW);
535
       digitalWrite(HEATER_1_PIN,LOW);
465
     #endif
536
     #endif
467
       
538
       
468
   #if TEMP_2_PIN > -1
539
   #if TEMP_2_PIN > -1
469
     target_raw[2]=0;
540
     target_raw[2]=0;
541
+    soft_pwm[2]=0;
470
     #if HEATER_2_PIN > -1  
542
     #if HEATER_2_PIN > -1  
471
       digitalWrite(HEATER_2_PIN,LOW);
543
       digitalWrite(HEATER_2_PIN,LOW);
472
     #endif
544
     #endif
473
   #endif 
545
   #endif 
546
+
547
+  #if TEMP_BED_PIN > -1
548
+    target_raw_bed=0;
549
+    #if HEATER_BED_PIN > -1  
550
+      digitalWrite(HEATER_BED_PIN,LOW);
551
+    #endif
552
+  #endif 
553
+}
554
+
555
+void max_temp_error(uint8_t e) {
556
+  digitalWrite(heater_pin_map[e], 0);
557
+  SERIAL_ERROR_START;
558
+  SERIAL_ERRORLN(e);
559
+  SERIAL_ERRORLNPGM(": Extruder switched off. MAXTEMP triggered !");
560
+}
561
+
562
+void min_temp_error(uint8_t e) {
563
+  digitalWrite(heater_pin_map[e], 0);
564
+  SERIAL_ERROR_START;
565
+  SERIAL_ERRORLN(e);
566
+  SERIAL_ERRORLNPGM(": Extruder switched off. MINTEMP triggered !");
567
+}
568
+
569
+void bed_max_temp_error(void) {
570
+  digitalWrite(HEATER_BED_PIN, 0);
571
+  SERIAL_ERROR_START;
572
+  SERIAL_ERRORLNPGM("Temperature heated bed switched off. MAXTEMP triggered !!");
474
 }
573
 }
475
 
574
 
476
 // Timer 0 is shared with millies
575
 // Timer 0 is shared with millies
481
   static unsigned long raw_temp_0_value = 0;
580
   static unsigned long raw_temp_0_value = 0;
482
   static unsigned long raw_temp_1_value = 0;
581
   static unsigned long raw_temp_1_value = 0;
483
   static unsigned long raw_temp_2_value = 0;
582
   static unsigned long raw_temp_2_value = 0;
583
+  static unsigned long raw_temp_bed_value = 0;
484
   static unsigned char temp_state = 0;
584
   static unsigned char temp_state = 0;
585
+  static unsigned char pwm_count = 1;
586
+  static unsigned char soft_pwm_0;
587
+  static unsigned char soft_pwm_1;
588
+  static unsigned char soft_pwm_2;
589
+  
590
+  if(pwm_count == 0){
591
+    soft_pwm_0 = soft_pwm[0];
592
+    if(soft_pwm_0 > 0) WRITE(HEATER_0_PIN,1);
593
+    #if EXTRUDERS > 1
594
+    soft_pwm_1 = soft_pwm[1];
595
+    if(soft_pwm_1 > 0) WRITE(HEATER_1_PIN,1);
596
+    #endif
597
+    #if EXTRUDERS > 2
598
+    soft_pwm_2 = soft_pwm[2];
599
+    if(soft_pwm_2 > 0) WRITE(HEATER_2_PIN,1);
600
+    #endif
601
+  }
602
+  if(soft_pwm_0 <= pwm_count) WRITE(HEATER_0_PIN,0);
603
+  #if EXTRUDERS > 1
604
+  if(soft_pwm_1 <= pwm_count) WRITE(HEATER_1_PIN,0);
605
+  #endif
606
+  #if EXTRUDERS > 2
607
+  if(soft_pwm_2 <= pwm_count) WRITE(HEATER_2_PIN,0);
608
+  #endif
609
+  
610
+  pwm_count++;
611
+  pwm_count &= 0x7f;
485
   
612
   
486
   switch(temp_state) {
613
   switch(temp_state) {
487
     case 0: // Prepare TEMP_0
614
     case 0: // Prepare TEMP_0
505
       #endif
632
       #endif
506
       temp_state = 2;
633
       temp_state = 2;
507
       break;
634
       break;
508
-    case 2: // Prepare TEMP_1
635
+    case 2: // Prepare TEMP_BED
636
+      #if (TEMP_BED_PIN > -1)
637
+        #if TEMP_BED_PIN > 7
638
+          ADCSRB = 1<<MUX5;
639
+        #endif
640
+        ADMUX = ((1 << REFS0) | (TEMP_BED_PIN & 0x07));
641
+        ADCSRA |= 1<<ADSC; // Start conversion
642
+      #endif
643
+      #ifdef ULTIPANEL
644
+        buttons_check();
645
+      #endif
646
+      temp_state = 3;
647
+      break;
648
+    case 3: // Measure TEMP_BED
649
+      #if (TEMP_BED_PIN > -1)
650
+        raw_temp_bed_value += ADC;
651
+      #endif
652
+      temp_state = 4;
653
+      break;
654
+    case 4: // Prepare TEMP_1
509
       #if (TEMP_1_PIN > -1)
655
       #if (TEMP_1_PIN > -1)
510
         #if TEMP_1_PIN > 7
656
         #if TEMP_1_PIN > 7
511
           ADCSRB = 1<<MUX5;
657
           ADCSRB = 1<<MUX5;
518
       #ifdef ULTIPANEL
664
       #ifdef ULTIPANEL
519
         buttons_check();
665
         buttons_check();
520
       #endif
666
       #endif
521
-      temp_state = 3;
667
+      temp_state = 5;
522
       break;
668
       break;
523
-    case 3: // Measure TEMP_1
669
+    case 5: // Measure TEMP_1
524
       #if (TEMP_1_PIN > -1)
670
       #if (TEMP_1_PIN > -1)
525
         raw_temp_1_value += ADC;
671
         raw_temp_1_value += ADC;
526
       #endif
672
       #endif
527
-      temp_state = 4;
673
+      temp_state = 6;
528
       break;
674
       break;
529
-    case 4: // Prepare TEMP_2
675
+    case 6: // Prepare TEMP_2
530
       #if (TEMP_2_PIN > -1)
676
       #if (TEMP_2_PIN > -1)
531
         #if TEMP_2_PIN > 7
677
         #if TEMP_2_PIN > 7
532
           ADCSRB = 1<<MUX5;
678
           ADCSRB = 1<<MUX5;
539
       #ifdef ULTIPANEL
685
       #ifdef ULTIPANEL
540
         buttons_check();
686
         buttons_check();
541
       #endif
687
       #endif
542
-      temp_state = 5;
688
+      temp_state = 7;
543
       break;
689
       break;
544
-    case 5: // Measure TEMP_2
690
+    case 7: // Measure TEMP_2
545
       #if (TEMP_2_PIN > -1)
691
       #if (TEMP_2_PIN > -1)
546
         raw_temp_2_value += ADC;
692
         raw_temp_2_value += ADC;
547
       #endif
693
       #endif
548
       temp_state = 0;
694
       temp_state = 0;
549
       temp_count++;
695
       temp_count++;
550
       break;
696
       break;
551
-    default:
552
-      SERIAL_ERROR_START;
553
-      SERIAL_ERRORLNPGM("Temp measurement error!");
554
-      break;
697
+//    default:
698
+//      SERIAL_ERROR_START;
699
+//      SERIAL_ERRORLNPGM("Temp measurement error!");
700
+//      break;
555
   }
701
   }
556
     
702
     
557
-  if(temp_count >= 16) // 6 ms * 16 = 96ms.
703
+  if(temp_count >= 16) // 8 ms * 16 = 128ms.
558
   {
704
   {
559
     #ifdef HEATER_0_USES_AD595
705
     #ifdef HEATER_0_USES_AD595
560
       current_raw[0] = raw_temp_0_value;
706
       current_raw[0] = raw_temp_0_value;
561
     #else
707
     #else
562
       current_raw[0] = 16383 - raw_temp_0_value;
708
       current_raw[0] = 16383 - raw_temp_0_value;
563
     #endif
709
     #endif
564
-    
710
+
711
+#if EXTRUDERS > 1    
565
     #ifdef HEATER_1_USES_AD595
712
     #ifdef HEATER_1_USES_AD595
713
+      current_raw[1] = raw_temp_1_value;
714
+    #else
715
+      current_raw[1] = 16383 - raw_temp_1_value;
716
+    #endif
717
+#endif
718
+    
719
+#if EXTRUDERS > 2
720
+    #ifdef HEATER_2_USES_AD595
566
       current_raw[2] = raw_temp_2_value;
721
       current_raw[2] = raw_temp_2_value;
567
     #else
722
     #else
568
       current_raw[2] = 16383 - raw_temp_2_value;
723
       current_raw[2] = 16383 - raw_temp_2_value;
569
     #endif
724
     #endif
725
+#endif
570
     
726
     
571
     #ifdef BED_USES_AD595
727
     #ifdef BED_USES_AD595
572
-      current_raw[1] = raw_temp_1_value;
728
+      current_raw_bed = raw_temp_bed_value;
573
     #else
729
     #else
574
-      current_raw[1] = 16383 - raw_temp_1_value;
730
+      current_raw_bed = 16383 - raw_temp_bed_value;
575
     #endif
731
     #endif
576
     
732
     
577
     temp_meas_ready = true;
733
     temp_meas_ready = true;
579
     raw_temp_0_value = 0;
735
     raw_temp_0_value = 0;
580
     raw_temp_1_value = 0;
736
     raw_temp_1_value = 0;
581
     raw_temp_2_value = 0;
737
     raw_temp_2_value = 0;
582
-    #ifdef HEATER_0_MAXTEMP
583
-      #if (HEATER_0_PIN > -1)
584
-        if(current_raw[TEMPSENSOR_HOTEND_0] >= maxttemp_0) {
585
-          target_raw[TEMPSENSOR_HOTEND_0] = 0;
586
-          digitalWrite(HEATER_0_PIN, 0);
587
-          SERIAL_ERROR_START;
588
-          SERIAL_ERRORLNPGM("Temperature extruder 0 switched off. MAXTEMP triggered !!");
738
+    raw_temp_bed_value = 0;
739
+
740
+    for(unsigned char e = 0; e < EXTRUDERS; e++) {
741
+       if(current_raw[e] >= maxttemp[e]) {
742
+          target_raw[e] = 0;
743
+          max_temp_error(e);
744
+          kill();;
745
+       }
746
+       if(current_raw[e] <= minttemp[e]) {
747
+          target_raw[e] = 0;
748
+          min_temp_error(e);
589
           kill();
749
           kill();
590
-        }
591
-      #endif
592
-    #endif
593
-  #ifdef HEATER_1_MAXTEMP
594
-    #if (HEATER_1_PIN > -1)
595
-      if(current_raw[TEMPSENSOR_HOTEND_1] >= maxttemp_1) {
596
-        target_raw[TEMPSENSOR_HOTEND_1] = 0;
597
-        digitalWrite(HEATER_2_PIN, 0);
598
-        SERIAL_ERROR_START;
599
-        SERIAL_ERRORLNPGM("Temperature extruder 1 switched off. MAXTEMP triggered !!");
600
-        kill();
601
-      }
602
-    #endif
603
-  #endif //MAXTEMP
604
-  
605
-  #ifdef HEATER_0_MINTEMP
606
-    #if (HEATER_0_PIN > -1)
607
-      if(current_raw[TEMPSENSOR_HOTEND_0] <= minttemp_0) {
608
-        target_raw[TEMPSENSOR_HOTEND_0] = 0;
609
-        digitalWrite(HEATER_0_PIN, 0);
610
-        SERIAL_ERROR_START;
611
-        SERIAL_ERRORLNPGM("Temperature extruder 0 switched off. MINTEMP triggered !!");
612
-        kill();
613
-      }
614
-    #endif
615
-  #endif
616
-  
617
-  #ifdef HEATER_1_MINTEMP
618
-    #if (HEATER_2_PIN > -1)
619
-      if(current_raw[TEMPSENSOR_HOTEND_1] <= minttemp_1) {
620
-        target_raw[TEMPSENSOR_HOTEND_1] = 0;
621
-        digitalWrite(HEATER_2_PIN, 0);
622
-        SERIAL_ERROR_START;
623
-        SERIAL_ERRORLNPGM("Temperature extruder 1 switched off. MINTEMP triggered !!");
624
-        kill();
625
-      }
626
-    #endif
627
-  #endif //MAXTEMP
628
-  
629
-  #ifdef BED_MINTEMP
630
-    #if (HEATER_1_PIN > -1)
631
-      if(current_raw[1] <= bed_minttemp) {
632
-        target_raw[1] = 0;
633
-        digitalWrite(HEATER_1_PIN, 0);
634
-        SERIAL_ERROR_START;
635
-        SERIAL_ERRORLNPGM("Temperatur heated bed switched off. MINTEMP triggered !!");
636
-        kill();
637
-      }
638
-    #endif
639
-  #endif
750
+       }
751
+    }
640
   
752
   
641
-  #ifdef BED_MAXTEMP
642
-    #if (HEATER_1_PIN > -1)
643
-      if(current_raw[1] >= bed_maxttemp) {
644
-        target_raw[1] = 0;
645
-        digitalWrite(HEATER_1_PIN, 0);
646
-        SERIAL_ERROR_START;
647
-        SERIAL_ERRORLNPGM("Temperature heated bed switched off. MAXTEMP triggered !!");
648
-        kill();
649
-      }
650
-    #endif
651
-  #endif
753
+#if defined(BED_MAXTEMP) && (HEATER_BED_PIN > -1)
754
+    if(current_raw_bed >= bed_maxttemp) {
755
+       target_raw_bed = 0;
756
+       bed_max_temp_error();
757
+       kill();
758
+    }
759
+#endif
652
   }
760
   }
653
 }
761
 }
654
 
762
 
655
-

+ 67
- 51
Marlin/temperature.h View File

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

+ 54
- 93
Marlin/thermistortables.h View File

5
 
5
 
6
 #define OVERSAMPLENR 16
6
 #define OVERSAMPLENR 16
7
 
7
 
8
-#if (THERMISTORHEATER_0 == 1) || (THERMISTORHEATER_1 == 1) || (THERMISTORBED == 1) //100k bed thermistor
8
+#if (THERMISTORHEATER_0 == 1) || (THERMISTORHEATER_1 == 1)  || (THERMISTORHEATER_2 == 1) || (THERMISTORBED == 1) //100k bed thermistor
9
 
9
 
10
-#define NUMTEMPS_1 61
11
-const short temptable_1[NUMTEMPS_1][2] PROGMEM = {
10
+const short temptable_1[][2] PROGMEM = {
12
 {       23*OVERSAMPLENR ,       300     },
11
 {       23*OVERSAMPLENR ,       300     },
13
 {       25*OVERSAMPLENR ,       295     },
12
 {       25*OVERSAMPLENR ,       295     },
14
 {       27*OVERSAMPLENR ,       290     },
13
 {       27*OVERSAMPLENR ,       290     },
72
 {       1008*OVERSAMPLENR       ,       0       } //safety
71
 {       1008*OVERSAMPLENR       ,       0       } //safety
73
 };
72
 };
74
 #endif
73
 #endif
75
-#if (THERMISTORHEATER_0 == 2) || (THERMISTORHEATER_1 == 2) || (THERMISTORBED == 2) //200k bed thermistor
76
-#define NUMTEMPS_2 21
77
-const short temptable_2[NUMTEMPS_2][2] PROGMEM = {
74
+#if (THERMISTORHEATER_0 == 2) || (THERMISTORHEATER_1 == 2) || (THERMISTORHEATER_2 == 2) || (THERMISTORBED == 2) //200k bed thermistor
75
+const short temptable_2[][2] PROGMEM = {
78
    {1*OVERSAMPLENR, 848},
76
    {1*OVERSAMPLENR, 848},
79
    {54*OVERSAMPLENR, 275},
77
    {54*OVERSAMPLENR, 275},
80
    {107*OVERSAMPLENR, 228},
78
    {107*OVERSAMPLENR, 228},
99
 };
97
 };
100
 
98
 
101
 #endif
99
 #endif
102
-#if (THERMISTORHEATER_0 == 3) || (THERMISTORHEATER_1 == 3) || (THERMISTORBED == 3) //mendel-parts
103
-#define NUMTEMPS_3 28
104
-const short temptable_3[NUMTEMPS_3][2] PROGMEM = {
100
+#if (THERMISTORHEATER_0 == 3) || (THERMISTORHEATER_1 == 3) || (THERMISTORHEATER_2 == 3) || (THERMISTORBED == 3) //mendel-parts
101
+const short temptable_3[][2] PROGMEM = {
105
                 {1*OVERSAMPLENR,864},
102
                 {1*OVERSAMPLENR,864},
106
                 {21*OVERSAMPLENR,300},
103
                 {21*OVERSAMPLENR,300},
107
                 {25*OVERSAMPLENR,290},
104
                 {25*OVERSAMPLENR,290},
133
         };
130
         };
134
 
131
 
135
 #endif
132
 #endif
136
-#if (THERMISTORHEATER_0 == 4) || (THERMISTORHEATER_1 == 4) || (THERMISTORBED == 4) //10k thermistor
137
-
138
-#define NUMTEMPS_4 20
139
-const short temptable_4[NUMTEMPS_4][2] PROGMEM = {
133
+#if (THERMISTORHEATER_0 == 4) || (THERMISTORHEATER_1 == 4) || (THERMISTORHEATER_2 == 4) || (THERMISTORBED == 4) //10k thermistor
134
+const short temptable_4[][2] PROGMEM = {
140
    {1*OVERSAMPLENR, 430},
135
    {1*OVERSAMPLENR, 430},
141
    {54*OVERSAMPLENR, 137},
136
    {54*OVERSAMPLENR, 137},
142
    {107*OVERSAMPLENR, 107},
137
    {107*OVERSAMPLENR, 107},
160
 };
155
 };
161
 #endif
156
 #endif
162
 
157
 
163
-#if (THERMISTORHEATER_0 == 5) || (THERMISTORHEATER_1 == 5) || (THERMISTORBED == 5) //100k ParCan thermistor (104GT-2)
164
-
165
-#define NUMTEMPS_5 61
166
-const short temptable_5[NUMTEMPS_5][2] PROGMEM = {
158
+#if (THERMISTORHEATER_0 == 5) || (THERMISTORHEATER_1 == 5) || (THERMISTORHEATER_2 == 5) || (THERMISTORBED == 5) //100k ParCan thermistor (104GT-2)
159
+const short temptable_5[][2] PROGMEM = {
167
 {1*OVERSAMPLENR, 713},
160
 {1*OVERSAMPLENR, 713},
168
 {18*OVERSAMPLENR, 316},
161
 {18*OVERSAMPLENR, 316},
169
 {35*OVERSAMPLENR, 266},
162
 {35*OVERSAMPLENR, 266},
228
 };
221
 };
229
 #endif
222
 #endif
230
 
223
 
231
-#if (THERMISTORHEATER_0 == 6) || (THERMISTORHEATER_1 == 6) || (THERMISTORBED == 6) // 100k Epcos thermistor
232
-#define NUMTEMPS_6 36
233
-const short temptable_6[NUMTEMPS_6][2] PROGMEM = {
224
+#if (THERMISTORHEATER_0 == 6) || (THERMISTORHEATER_1 == 6) || (THERMISTORHEATER_2 == 6) || (THERMISTORBED == 6) // 100k Epcos thermistor
225
+const short temptable_6[][2] PROGMEM = {
234
    {28*OVERSAMPLENR, 250},
226
    {28*OVERSAMPLENR, 250},
235
    {31*OVERSAMPLENR, 245},
227
    {31*OVERSAMPLENR, 245},
236
    {35*OVERSAMPLENR, 240},
228
    {35*OVERSAMPLENR, 240},
270
 };
262
 };
271
 #endif
263
 #endif
272
 
264
 
273
-#if (THERMISTORHEATER_0 == 7) || (THERMISTORHEATER_1 == 7) || (THERMISTORBED == 7) // 100k Honeywell 135-104LAG-J01
274
-#define NUMTEMPS_7 54
275
-const short temptable_7[NUMTEMPS_7][2] PROGMEM = {
265
+#if (THERMISTORHEATER_0 == 7) || (THERMISTORHEATER_1 == 7) || (THERMISTORHEATER_2 == 7) || (THERMISTORBED == 7) // 100k Honeywell 135-104LAG-J01
266
+const short temptable_7[][2] PROGMEM = {
276
    {46*OVERSAMPLENR, 270},
267
    {46*OVERSAMPLENR, 270},
277
    {50*OVERSAMPLENR, 265},
268
    {50*OVERSAMPLENR, 265},
278
    {54*OVERSAMPLENR, 260},
269
    {54*OVERSAMPLENR, 260},
330
 };
321
 };
331
 #endif
322
 #endif
332
 
323
 
324
+#define _TT_NAME(_N) temptable_ ## _N
325
+#define TT_NAME(_N) _TT_NAME(_N)
333
 
326
 
334
-
335
-#if THERMISTORHEATER_0 == 1
336
-#define NUMTEMPS_HEATER_0 NUMTEMPS_1
337
-#define heater_0_temptable temptable_1
338
-#elif THERMISTORHEATER_0 == 2
339
-#define NUMTEMPS_HEATER_0 NUMTEMPS_2
340
-#define heater_0_temptable temptable_2
341
-#elif THERMISTORHEATER_0 == 3
342
-#define NUMTEMPS_HEATER_0 NUMTEMPS_3
343
-#define heater_0_temptable temptable_3
344
-#elif THERMISTORHEATER_0 == 4
345
-#define NUMTEMPS_HEATER_0 NUMTEMPS_4
346
-#define heater_0_temptable temptable_4
347
-#elif THERMISTORHEATER_0 == 5
348
-#define NUMTEMPS_HEATER_0 NUMTEMPS_5
349
-#define heater_0_temptable temptable_5
350
-#elif THERMISTORHEATER_0 == 6
351
-#define NUMTEMPS_HEATER_0 NUMTEMPS_6
352
-#define heater_0_temptable temptable_6
353
-#elif THERMISTORHEATER_0 == 7
354
-#define NUMTEMPS_HEATER_0 NUMTEMPS_7
355
-#define heater_0_temptable temptable_7
356
-#elif defined HEATER_0_USES_THERMISTOR
357
-#error No heater 0 thermistor table specified
327
+#ifdef THERMISTORHEATER_0
328
+  #define heater_0_temptable TT_NAME(THERMISTORHEATER_0)
329
+  #define heater_0_temptable_len (sizeof(heater_0_temptable)/sizeof(*heater_0_temptable))
330
+#else
331
+#ifdef HEATER_0_USES_THERMISTOR
332
+  #error No heater 0 thermistor table specified
333
+#else  // HEATER_0_USES_THERMISTOR
334
+  #define heater_0_temptable 0
335
+  #define heater_0_temptable_len 0
336
+#endif // HEATER_0_USES_THERMISTOR
358
 #endif
337
 #endif
359
 
338
 
360
-#if THERMISTORHEATER_1 == 1
361
-#define NUMTEMPS_HEATER_1 NUMTEMPS_1
362
-#define heater_1_temptable temptable_1
363
-#elif THERMISTORHEATER_1 == 2
364
-#define NUMTEMPS_HEATER_1 NUMTEMPS_2
365
-#define heater_1_temptable temptable_2
366
-#elif THERMISTORHEATER_1 == 3
367
-#define NUMTEMPS_HEATER_1 NUMTEMPS_3
368
-#define heater_1_temptable temptable_3
369
-#elif THERMISTORHEATER_1 == 4
370
-#define NUMTEMPS_HEATER_1 NUMTEMPS_4
371
-#define heater_1_temptable temptable_4
372
-#elif THERMISTORHEATER_1 == 5
373
-#define NUMTEMPS_HEATER_1 NUMTEMPS_5
374
-#define heater_1_temptable temptable_5
375
-#elif THERMISTORHEATER_1 == 6
376
-#define NUMTEMPS_HEATER_1 NUMTEMPS_6
377
-#define heater_1_temptable temptable_6
378
-#elif THERMISTORHEATER_1 == 7
379
-#define NUMTEMPS_HEATER_1 NUMTEMPS_7
380
-#define heater_1_temptable temptable_7
381
-#elif defined HEATER_1_USES_THERMISTOR
382
-#error No heater 1 thermistor table specified
339
+#ifdef THERMISTORHEATER_1
340
+  #define heater_1_temptable TT_NAME(THERMISTORHEATER_1)
341
+  #define heater_1_temptable_len (sizeof(heater_1_temptable)/sizeof(*heater_1_temptable))
342
+#else
343
+#ifdef HEATER_1_USES_THERMISTOR
344
+  #error No heater 1 thermistor table specified
345
+#else  // HEATER_1_USES_THERMISTOR
346
+  #define heater_1_temptable 0
347
+  #define heater_1_temptable_len 0
348
+#endif // HEATER_1_USES_THERMISTOR
383
 #endif
349
 #endif
384
 
350
 
351
+#ifdef THERMISTORHEATER_2
352
+  #define heater_2_temptable TT_NAME(THERMISTORHEATER_2)
353
+  #define heater_2_temptable_len (sizeof(heater_2_temptable)/sizeof(*heater_2_temptable))
354
+#else
355
+#ifdef HEATER_2_USES_THERMISTOR
356
+  #error No heater 2 thermistor table specified
357
+#else  // HEATER_2_USES_THERMISTOR
358
+  #define heater_2_temptable 0
359
+  #define heater_2_temptable_len 0
360
+#endif // HEATER_2_USES_THERMISTOR
361
+#endif
385
 
362
 
386
-#if THERMISTORBED == 1
387
-#define BNUMTEMPS NUMTEMPS_1
388
-#define bedtemptable temptable_1
389
-#elif THERMISTORBED == 2
390
-#define BNUMTEMPS NUMTEMPS_2
391
-#define bedtemptable temptable_2
392
-#elif THERMISTORBED == 3
393
-#define BNUMTEMPS NUMTEMPS_3
394
-#define bedtemptable temptable_3
395
-#elif THERMISTORBED == 4
396
-#define BNUMTEMPS NUMTEMPS_4
397
-#define bedtemptable temptable_4
398
-#elif THERMISTORBED == 5
399
-#define BNUMTEMPS NUMTEMPS_5
400
-#define bedtemptable temptable_5
401
-#elif THERMISTORBED == 6
402
-#define BNUMTEMPS NUMTEMPS_6
403
-#define bedtemptable temptable_6
404
-#elif THERMISTORBED == 7
405
-#define BNUMTEMPS NUMTEMPS_7
406
-#define bedtemptable temptable_7
407
-#elif defined BED_USES_THERMISTOR
408
-#error No bed thermistor table specified
363
+#ifdef THERMISTORBED
364
+  #define bedtemptable TT_NAME(THERMISTORBED)
365
+  #define bedtemptable_len (sizeof(bedtemptable)/sizeof(*bedtemptable))
366
+#else
367
+#ifdef BED_USES_THERMISTOR
368
+  #error No bed thermistor table specified
369
+#endif // BED_USES_THERMISTOR
409
 #endif
370
 #endif
410
 
371
 
411
 #endif //THERMISTORTABLES_H_
372
 #endif //THERMISTORTABLES_H_

+ 1848
- 1844
Marlin/ultralcd.pde
File diff suppressed because it is too large
View File


Loading…
Cancel
Save