Browse Source

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

Bernhard 12 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,16 +43,20 @@
43 43
 // 5 is ParCan supplied 104GT-2 100K
44 44
 // 6 is EPCOS 100k
45 45
 // 7 is 100k Honeywell thermistor 135-104LAG-J01
46
+
46 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 51
 //#define HEATER_0_USES_THERMISTOR
51 52
 //#define HEATER_1_USES_THERMISTOR
53
+//#define HEATER_2_USES_THERMISTOR
52 54
 #define HEATER_0_USES_AD595
53 55
 //#define HEATER_1_USES_AD595
56
+//#define HEATER_2_USES_AD595
54 57
 
55 58
 // Select one of these only to define how the bed temp is read.
59
+//#define THERMISTORBED 1
56 60
 //#define BED_USES_THERMISTOR
57 61
 //#define BED_USES_AD595
58 62
 
@@ -65,12 +69,13 @@
65 69
 //#define WATCHPERIOD 20000 //20 seconds
66 70
 
67 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 75
 //// The minimal temperature defines the temperature below which the heater will not be enabled
72 76
 #define HEATER_0_MINTEMP 5
73 77
 //#define HEATER_1_MINTEMP 5
78
+//#define HEATER_2_MINTEMP 5
74 79
 //#define BED_MINTEMP 5
75 80
 
76 81
 
@@ -79,6 +84,7 @@
79 84
 // You should use MINTEMP for thermistor short/failure protection.
80 85
 #define HEATER_0_MAXTEMP 275
81 86
 //#define HEATER_1_MAXTEMP 275
87
+//#define HEATER_2_MAXTEMP 275
82 88
 //#define BED_MAXTEMP 150
83 89
 
84 90
 
@@ -90,21 +96,17 @@
90 96
 
91 97
 // Heating is finished if a temperature close to this degree shift is reached
92 98
 #define HEATING_EARLY_FINISH_DEG_OFFSET 1 //Degree
99
+
93 100
 // PID settings:
94 101
 // Uncomment the following line to enable PID support.
95
-  
96 102
 #define PIDTEMP
103
+#define PID_MAX 255 // limits current to nozzle; 255=full current
97 104
 #ifdef PIDTEMP
98
-  #if MOTHERBOARD == 62
99
-    #error Sanguinololu does not support PID, sorry. Please disable it.
100
-  #endif
101 105
   //#define PID_DEBUG // Sends debug data to the serial port. 
102 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 107
   #define PID_INTEGRAL_DRIVE_MAX 255  //limit for the integral term
106 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 111
   //To develop some PID settings for your machine, you can initiall follow 
110 112
   // the Ziegler-Nichols method.
@@ -132,6 +134,11 @@
132 134
     #define  DEFAULT_Ki (1.25*PID_dT)  
133 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 142
 // Mendel Parts V9 on 12V    
136 143
 //    #define  DEFAULT_Kp  63.0
137 144
 //    #define  DEFAULT_Ki (2.25*PID_dT)  
@@ -149,7 +156,7 @@
149 156
   // if Kc is choosen well, the additional required power due to increased melting should be compensated.
150 157
   #define PID_ADD_EXTRUSION_RATE  
151 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 160
   #endif
154 161
 #endif // PIDTEMP
155 162
 
@@ -169,36 +176,39 @@
169 176
 
170 177
 // Endstop Settings
171 178
 #define ENDSTOPPULLUPS // Comment this out (using // at the start of the line) to disable the endstop pullup resistors
179
+
172 180
 // The pullups are needed if you directly connect a mechanical endswitch between the signal and ground pins.
173 181
 const bool X_ENDSTOPS_INVERTING = true; // set to true to invert the logic of the endstops. 
174 182
 const bool Y_ENDSTOPS_INVERTING = true; // set to true to invert the logic of the endstops. 
175 183
 const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of the endstops. 
176 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 188
 // For Inverting Stepper Enable Pins (Active Low) use 0, Non Inverting (Active High) use 1
181 189
 #define X_ENABLE_ON 0
182 190
 #define Y_ENABLE_ON 0
183 191
 #define Z_ENABLE_ON 0
184
-#define E_ENABLE_ON 0
192
+#define E_ENABLE_ON 0 // For all extruders
185 193
 
186 194
 // Disables axis when it's not being used.
187 195
 #define DISABLE_X false
188 196
 #define DISABLE_Y false
189 197
 #define DISABLE_Z false
190
-#define DISABLE_E false
198
+#define DISABLE_E false // For all extruders
191 199
 
192 200
 // Inverting axis direction
193 201
 //#define INVERT_X_DIR false    // for Mendel set to false, for Orca set to true
194 202
 //#define INVERT_Y_DIR true   // for Mendel set to true, for Orca set to false
195 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 207
 #define INVERT_Y_DIR false    // for Mendel set to true, for Orca set to false
200 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 213
 //// ENDSTOP SETTINGS:
204 214
 // Sets direction of endstops when homing; 1=MAX, -1=MIN
@@ -206,11 +216,11 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th
206 216
 #define Y_HOME_DIR -1
207 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 225
 //// MOVEMENT SETTINGS
216 226
 #define NUM_AXIS 4 // The axis order in all axis related arrays is X, Y, Z, E
@@ -229,7 +239,8 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th
229 239
 // default settings 
230 240
 
231 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 244
 #define DEFAULT_MAX_FEEDRATE          {500, 500, 5, 45}    // (mm/sec)    
234 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,10 +296,10 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th
285 296
 // hooke's law says:		force = k * distance
286 297
 // bernoulli's priniciple says:	v ^ 2 / 2 + g . h + pressure / density = constant
287 298
 // so: v ^ 2 is proportional to number of steps we advance the extruder
288
-//#define ADVANCE
299
+#define ADVANCE
289 300
 
290 301
 #ifdef ADVANCE
291
-  #define EXTRUDER_ADVANCE_K .3
302
+  #define EXTRUDER_ADVANCE_K .0
292 303
 
293 304
   #define D_FILAMENT 2.85
294 305
   #define STEPS_MM_E 836
@@ -304,7 +315,7 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th
304 315
 #define SD_FINISHED_STEPPERRELEASE true  //if sd support and the file is finished: disable steppers?
305 316
 #define SD_FINISHED_RELEASECOMMAND "M84 X Y E" // no z because of layer shift.
306 317
 
307
-//#define ULTIPANEL
318
+#define ULTIPANEL
308 319
 #ifdef ULTIPANEL
309 320
   //#define NEWPANEL  //enable this if you have a click-encoder panel
310 321
   #define SDSUPPORT

+ 25
- 5
Marlin/Marlin.h View File

@@ -101,14 +101,31 @@ void manage_inactivity(byte debug);
101 101
   #define disable_z() ;
102 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 107
 #else
108
-  #define enable_e() ;
109
-  #define disable_e() ;
108
+  #define enable_e0()  /* nothing */
109
+  #define disable_e0() /* nothing */
110 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 129
 enum AxisEnum {X_AXIS=0, Y_AXIS=1, Z_AXIS=2, E_AXIS=3};
113 130
 
114 131
 
@@ -133,4 +150,7 @@ extern float current_position[NUM_AXIS] ;
133 150
 extern float add_homeing[3];
134 151
 extern bool stop_heating_wait;
135 152
 
153
+// Handling multiple extruders pins
154
+extern uint8_t active_extruder;
155
+
136 156
 #endif

+ 78
- 46
Marlin/Marlin.pde View File

@@ -122,7 +122,6 @@
122 122
 //===========================================================================
123 123
 //=============================imported variables============================
124 124
 //===========================================================================
125
-extern float HeaterPower;
126 125
 
127 126
 
128 127
 //===========================================================================
@@ -136,9 +135,11 @@ bool axis_relative_modes[] = AXIS_RELATIVE_MODES;
136 135
 volatile int feedmultiply=100; //100->1 200->2
137 136
 int saved_feedmultiply;
138 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 139
 float add_homeing[3]={0,0,0};
140
+uint8_t active_extruder = 0;
141 141
 bool stop_heating_wait=false;
142
+
142 143
 //===========================================================================
143 144
 //=============================private variables=============================
144 145
 //===========================================================================
@@ -470,16 +471,16 @@ FORCE_INLINE bool code_seen(char code)
470 471
     plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); \
471 472
     destination[LETTER##_AXIS] = 1.5 * LETTER##_MAX_LENGTH * LETTER##_HOME_DIR; \
472 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 476
     current_position[LETTER##_AXIS] = 0;\
476 477
     plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);\
477 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 481
     destination[LETTER##_AXIS] = 2*LETTER##_HOME_RETRACT_MM * LETTER##_HOME_DIR;\
481 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 485
     current_position[LETTER##_AXIS] = (LETTER##_HOME_DIR == -1) ? 0 : LETTER##_MAX_LENGTH;\
485 486
     plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);\
@@ -543,6 +544,7 @@ FORCE_INLINE void process_commands()
543 544
       if( code_seen(axis_codes[0]) && code_seen(axis_codes[1]) )  //first diagonal move
544 545
       {
545 546
         current_position[X_AXIS] = 0;current_position[Y_AXIS] = 0;  
547
+
546 548
         plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); 
547 549
         destination[X_AXIS] = 1.5 * X_MAX_LENGTH * X_HOME_DIR;destination[Y_AXIS] = 1.5 * Y_MAX_LENGTH * Y_HOME_DIR;  
548 550
         feedrate = homing_feedrate[X_AXIS]; 
@@ -582,7 +584,7 @@ FORCE_INLINE void process_commands()
582 584
       }
583 585
 
584 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 590
       if(code_seen(axis_codes[Z_AXIS])) {
@@ -610,9 +612,11 @@ FORCE_INLINE void process_commands()
610 612
         if(code_seen(axis_codes[i])) { 
611 613
            current_position[i] = code_value()+add_homeing[i];  
612 614
            if(i == E_AXIS) {
615
+             current_position[i] = code_value();  
613 616
              plan_set_e_position(current_position[E_AXIS]);
614 617
            }
615 618
            else {
619
+             current_position[i] = code_value()+add_homeing[i];  
616 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,7 +627,6 @@ FORCE_INLINE void process_commands()
623 627
 
624 628
   else if(code_seen('M'))
625 629
   {
626
-
627 630
     switch( (int)code_value() ) 
628 631
     {
629 632
     case 17:
@@ -631,10 +634,12 @@ FORCE_INLINE void process_commands()
631 634
         enable_x(); 
632 635
         enable_y(); 
633 636
         enable_z(); 
634
-        enable_e(); 
637
+        enable_e0(); 
638
+        enable_e1(); 
639
+        enable_e2(); 
635 640
       break;
636
-    #ifdef SDSUPPORT
637 641
 
642
+#ifdef SDSUPPORT
638 643
     case 20: // M20 - list SD card
639 644
       SERIAL_PROTOCOLLNPGM("Begin file list");
640 645
       card.ls();
@@ -663,9 +668,8 @@ FORCE_INLINE void process_commands()
663 668
       card.pauseSDPrint();
664 669
       break;
665 670
     case 26: //M26 - Set SD index
666
-      if(card.cardOK && code_seen('S')){
671
+      if(card.cardOK && code_seen('S')) {
667 672
         card.setIndex(code_value_long());
668
-        
669 673
       }
670 674
       break;
671 675
     case 27: //M27 - Get SD status
@@ -679,16 +683,15 @@ FORCE_INLINE void process_commands()
679 683
         *(starpos-1) = '\0';
680 684
       }
681 685
       card.openFile(strchr_pointer+4,false);
682
-      
683 686
       break;
684 687
     case 29: //M29 - Stop SD write
685 688
       //processed in write to file routine above
686 689
       //card,saving = false;
687 690
       break;
688
-    #endif //SDSUPPORT
691
+#endif //SDSUPPORT
689 692
 
690 693
     case 30: //M30 take time since the start of the SD print or an M109 command
691
-    {
694
+      {
692 695
       stoptime=millis();
693 696
       char time[30];
694 697
       unsigned long t=(stoptime-starttime)/1000;
@@ -700,8 +703,8 @@ FORCE_INLINE void process_commands()
700 703
       SERIAL_ECHOLN(time);
701 704
       LCD_MESSAGE(time);
702 705
       autotempShutdown();
703
-    }
704
-    break;
706
+      }
707
+      break;
705 708
     case 42: //M42 -Change pin status via gcode
706 709
       if (code_seen('S'))
707 710
       {
@@ -755,21 +758,20 @@ FORCE_INLINE void process_commands()
755 758
           break;
756 759
         }
757 760
       }
758
-      #if (TEMP_0_PIN > -1) || (TEMP_2_PIN > -1)
761
+      #if (TEMP_0_PIN > -1)
759 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 765
           SERIAL_PROTOCOLPGM(" B:");  
763 766
           SERIAL_PROTOCOL(degBed());
764
-        #endif //TEMP_1_PIN
767
+        #endif //TEMP_BED_PIN
765 768
       #else
766 769
         SERIAL_ERROR_START;
767 770
         SERIAL_ERRORLNPGM("No thermistors - no temp");
768 771
       #endif
769 772
       #ifdef PIDTEMP
770 773
         SERIAL_PROTOCOLPGM(" @:");
771
-        SERIAL_PROTOCOL( HeaterPower); 
772
-       
774
+        SERIAL_PROTOCOL(getHeaterPower(tmp_extruder));  
773 775
       #endif
774 776
         SERIAL_PROTOCOLLN("");
775 777
       return;
@@ -812,19 +814,33 @@ FORCE_INLINE void process_commands()
812 814
         residencyStart = -1;
813 815
         /* continue to loop until we have reached the target temp   
814 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 819
       #else
818 820
         while ( target_direction ? (isHeatingHotend(tmp_extruder)) : (isCoolingHotend(tmp_extruder)&&(CooldownNoWait==false)) ) {
819 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 844
         if(stop_heating_wait) break;
829 845
         #ifdef TEMP_RESIDENCY_TIME
830 846
             /* start/restart the TEMP_RESIDENCY_TIME timer whenever we reach target temp for the first time
@@ -842,8 +858,8 @@ FORCE_INLINE void process_commands()
842 858
         previous_millis_cmd = millis();
843 859
       }
844 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 863
         LCD_MESSAGEPGM("Bed Heating.");
848 864
         if (code_seen('S')) setTargetBed(code_value());
849 865
         codenum = millis(); 
@@ -851,13 +867,13 @@ FORCE_INLINE void process_commands()
851 867
         {
852 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 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 875
             SERIAL_PROTOCOLPGM(" B:");
860
-            SERIAL_PROTOCOLLN(degBed() ); 
876
+            SERIAL_PROTOCOLLN(degBed()); 
861 877
             codenum = millis(); 
862 878
           }
863 879
           manage_heater();
@@ -910,6 +926,9 @@ FORCE_INLINE void process_commands()
910 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 927
         if(all_axis)
912 928
         {
929
+          disable_e0();
930
+          disable_e1();
931
+          disable_e2();
913 932
           finishAndDisableSteppers();
914 933
         }
915 934
         else
@@ -918,8 +937,12 @@ FORCE_INLINE void process_commands()
918 937
           if(code_seen('X')) disable_x();
919 938
           if(code_seen('Y')) disable_y();
920 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 946
           #endif 
924 947
           LCD_MESSAGEPGM("Partial Release");
925 948
         }
@@ -1100,7 +1123,9 @@ FORCE_INLINE void process_commands()
1100 1123
 
1101 1124
     }
1102 1125
   }
1103
-  else if(code_seen('T')) {
1126
+
1127
+  else if(code_seen('T')) 
1128
+  {
1104 1129
     tmp_extruder = code_value();
1105 1130
     if(tmp_extruder >= EXTRUDERS) {
1106 1131
       SERIAL_ECHO_START;
@@ -1110,8 +1135,12 @@ FORCE_INLINE void process_commands()
1110 1135
     }
1111 1136
     else {
1112 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 1144
   else
1116 1145
   {
1117 1146
     SERIAL_ECHO_START;
@@ -1219,8 +1248,8 @@ void manage_inactivity(byte debug)
1219 1248
     if( (millis()-previous_millis_cmd) >  EXTRUDER_RUNOUT_SECONDS*1000 ) 
1220 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 1253
      float oldepos=current_position[E_AXIS];
1225 1254
      float oldedes=destination[E_AXIS];
1226 1255
      plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], 
@@ -1232,7 +1261,7 @@ void manage_inactivity(byte debug)
1232 1261
      previous_millis_cmd=millis();
1233 1262
      //enquecommand(DEFAULT_STEPPER_DEACTIVE_COMMAND);
1234 1263
      st_synchronize();
1235
-     WRITE(E_ENABLE_PIN,oldstatus);
1264
+     WRITE(E0_ENABLE_PIN,oldstatus);
1236 1265
     }
1237 1266
   #endif
1238 1267
   check_axes_activity();
@@ -1240,12 +1269,15 @@ void manage_inactivity(byte debug)
1240 1269
 
1241 1270
 void kill()
1242 1271
 {
1272
+  cli(); // Stop interrupts
1243 1273
   disable_heater();
1244 1274
 
1245 1275
   disable_x();
1246 1276
   disable_y();
1247 1277
   disable_z();
1248
-  disable_e();
1278
+  disable_e0();
1279
+  disable_e1();
1280
+  disable_e2();
1249 1281
   
1250 1282
   if(PS_ON_PIN > -1) pinMode(PS_ON_PIN,INPUT);
1251 1283
   SERIAL_ERROR_START;

+ 1
- 1
Marlin/cardreader.pde View File

@@ -442,4 +442,4 @@ void CardReader::printingHasFinished()
442 442
  }
443 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,9 +56,9 @@
56 56
 //#include <math.h>       
57 57
 //#include <stdlib.h>
58 58
 
59
-#include "Marlin.h"
60 59
 #include "Configuration.h"
61 60
 #include "pins.h"
61
+#include "Marlin.h"
62 62
 #include "fastio.h"
63 63
 #include "planner.h"
64 64
 #include "stepper.h"
@@ -81,8 +81,6 @@ float max_z_jerk;
81 81
 float mintravelfeedrate;
82 82
 unsigned long axis_steps_per_sqr_second[NUM_AXIS];
83 83
 
84
-uint8_t active_extruder = 0;
85
-
86 84
 // The current position of the tool in absolute steps
87 85
 long position[4];   //rescaled from extern when axis_steps_per_unit are changed by gcode
88 86
 static float previous_speed[4]; // Speed of previous path line segment
@@ -95,7 +93,6 @@ static float previous_nominal_speed; // Nominal speed of previous path line segm
95 93
     bool autotemp_enabled=false;
96 94
 #endif
97 95
 
98
-    
99 96
 //===========================================================================
100 97
 //=================semi-private variables, used in inline  functions    =====
101 98
 //===========================================================================
@@ -196,8 +193,8 @@ void calculate_trapezoid_for_block(block_t *block, float entry_factor, float exi
196 193
   }
197 194
 
198 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 198
   #endif // ADVANCE
202 199
   
203 200
  // block->accelerate_until = accelerate_steps;
@@ -439,7 +436,7 @@ void check_axes_activity() {
439 436
   if((DISABLE_X) && (x_active == 0)) disable_x();
440 437
   if((DISABLE_Y) && (y_active == 0)) disable_y();
441 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,15 +511,10 @@ void plan_buffer_line(const float &x, const float &y, const float &z, const floa
514 511
   if(block->steps_x != 0) enable_x();
515 512
   if(block->steps_y != 0) enable_y();
516 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 518
   float delta_mm[4];
527 519
   delta_mm[X_AXIS] = (target[X_AXIS]-position[X_AXIS])/axis_steps_per_unit[X_AXIS];
528 520
   delta_mm[Y_AXIS] = (target[Y_AXIS]-position[Y_AXIS])/axis_steps_per_unit[Y_AXIS];
@@ -809,4 +801,4 @@ void allow_cold_extrudes(bool allow)
809 801
   #ifdef PREVENT_DANGEROUS_EXTRUDE
810 802
     allow_cold_extrude=allow;
811 803
   #endif
812
-}
804
+}

+ 0
- 2
Marlin/planner.h View File

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

+ 90
- 37
Marlin/stepper.cpp View File

@@ -24,9 +24,9 @@
24 24
 
25 25
 #include "stepper.h"
26 26
 #include "Configuration.h"
27
+#include "pins.h"
27 28
 #include "Marlin.h"
28 29
 #include "planner.h"
29
-#include "pins.h"
30 30
 #include "fastio.h"
31 31
 #include "temperature.h"
32 32
 #include "ultralcd.h"
@@ -41,7 +41,6 @@
41 41
 block_t *current_block;  // A pointer to the block currently being traced
42 42
 
43 43
 
44
-
45 44
 //===========================================================================
46 45
 //=============================private variables ============================
47 46
 //===========================================================================
@@ -58,7 +57,7 @@ volatile static unsigned long step_events_completed; // The number of step event
58 57
   static long advance_rate, advance, final_advance = 0;
59 58
   static long old_advance = 0;
60 59
 #endif
61
-static long e_steps;
60
+static long e_steps[3];
62 61
 static unsigned char busy = false; // TRUE when SIG_OUTPUT_COMPARE1A is being serviced. Used to avoid retriggering that handler.
63 62
 static long acceleration_time, deceleration_time;
64 63
 //static unsigned long accelerate_until, decelerate_after, acceleration_rate, initial_rate, final_rate, nominal_rate;
@@ -267,7 +266,7 @@ FORCE_INLINE void trapezoid_generator_reset() {
267 266
     advance = current_block->initial_advance;
268 267
     final_advance = current_block->final_advance;
269 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 270
     old_advance = advance >>8;  
272 271
   #endif
273 272
   deceleration_time = 0;
@@ -304,8 +303,8 @@ ISR(TIMER1_COMPA_vect)
304 303
       counter_z = counter_x;
305 304
       counter_e = counter_x;
306 305
       step_events_completed = 0;
307
- //     #ifdef ADVANCE
308
-      e_steps = 0;
306
+//      #ifdef ADVANCE
307
+//      e_steps[current_block->active_extruder] = 0;
309 308
 //      #endif
310 309
     } 
311 310
     else {
@@ -419,11 +418,11 @@ ISR(TIMER1_COMPA_vect)
419 418
 
420 419
     #ifndef ADVANCE
421 420
       if ((out_bits & (1<<E_AXIS)) != 0) {  // -direction
422
-        WRITE(E_DIR_PIN,INVERT_E_DIR);
421
+        REV_E_DIR();
423 422
         count_direction[E_AXIS]=-1;
424 423
       }
425 424
       else { // +direction
426
-        WRITE(E_DIR_PIN,!INVERT_E_DIR);
425
+        NORM_E_DIR();
427 426
         count_direction[E_AXIS]=-1;
428 427
       }
429 428
     #endif //!ADVANCE
@@ -438,10 +437,10 @@ ISR(TIMER1_COMPA_vect)
438 437
       if (counter_e > 0) {
439 438
         counter_e -= current_block->step_event_count;
440 439
         if ((out_bits & (1<<E_AXIS)) != 0) { // - direction
441
-          e_steps--;
440
+          e_steps[current_block->active_extruder]--;
442 441
         }
443 442
         else {
444
-          e_steps++;
443
+          e_steps[current_block->active_extruder]++;
445 444
         }
446 445
       }    
447 446
       #endif //ADVANCE
@@ -473,9 +472,9 @@ ISR(TIMER1_COMPA_vect)
473 472
       #ifndef ADVANCE
474 473
         counter_e += current_block->steps_e;
475 474
         if (counter_e > 0) {
476
-          WRITE(E_STEP_PIN, HIGH);
475
+          WRITE_E_STEP(HIGH);
477 476
           counter_e -= current_block->step_event_count;
478
-          WRITE(E_STEP_PIN, LOW);
477
+          WRITE_E_STEP(LOW);
479 478
           count_position[E_AXIS]+=count_direction[E_AXIS];
480 479
         }
481 480
       #endif //!ADVANCE
@@ -504,7 +503,7 @@ ISR(TIMER1_COMPA_vect)
504 503
         }
505 504
         //if(advance > current_block->advance) advance = current_block->advance;
506 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 507
         old_advance = advance >>8;  
509 508
         
510 509
       #endif
@@ -533,7 +532,7 @@ ISR(TIMER1_COMPA_vect)
533 532
         }
534 533
         if(advance < final_advance) advance = final_advance;
535 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 536
         old_advance = advance >>8;  
538 537
       #endif //ADVANCE
539 538
     }
@@ -558,27 +557,57 @@ ISR(TIMER1_COMPA_vect)
558 557
     old_OCR0A += 52; // ~10kHz interrupt (250000 / 26 = 9615kHz)
559 558
     OCR0A = old_OCR0A;
560 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 606
 #endif // ADVANCE
578 607
 
579 608
 void st_init()
580 609
 {
581
-    //Initialize Dir Pins
610
+  //Initialize Dir Pins
582 611
   #if X_DIR_PIN > -1
583 612
     SET_OUTPUT(X_DIR_PIN);
584 613
   #endif
@@ -588,8 +617,14 @@ void st_init()
588 617
   #if Z_DIR_PIN > -1 
589 618
     SET_OUTPUT(Z_DIR_PIN);
590 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 628
   #endif
594 629
 
595 630
   //Initialize Enable Pins - steppers default to disabled.
@@ -606,9 +641,17 @@ void st_init()
606 641
     SET_OUTPUT(Z_ENABLE_PIN);
607 642
     if(!Z_ENABLE_ON) WRITE(Z_ENABLE_PIN,HIGH);
608 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 655
   #endif
613 656
 
614 657
   //endstops and pullups
@@ -669,8 +712,14 @@ void st_init()
669 712
   #if (Z_STEP_PIN > -1) 
670 713
     SET_OUTPUT(Z_STEP_PIN);
671 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 723
   #endif  
675 724
 
676 725
   // waveform generation = 0100 = CTC
@@ -693,7 +742,9 @@ void st_init()
693 742
     TCCR0A &= ~(1<<WGM01);
694 743
     TCCR0A &= ~(1<<WGM00);
695 744
   #endif  
696
-    e_steps = 0;
745
+    e_steps[0] = 0;
746
+    e_steps[1] = 0;
747
+    e_steps[2] = 0;
697 748
     TIMSK0 |= (1<<OCIE0A);
698 749
   #endif //ADVANCE
699 750
   
@@ -750,7 +801,9 @@ void finishAndDisableSteppers()
750 801
   disable_x(); 
751 802
   disable_y(); 
752 803
   disable_z(); 
753
-  disable_e(); 
804
+  disable_e0(); 
805
+  disable_e1(); 
806
+  disable_e2(); 
754 807
 }
755 808
 
756 809
 void quickStop()

+ 15
- 0
Marlin/stepper.h View File

@@ -23,6 +23,21 @@
23 23
 
24 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 41
 // Initialize and start the stepper motor subsystem
27 42
 void st_init();
28 43
 

+ 327
- 220
Marlin/temperature.cpp View File

@@ -26,7 +26,6 @@
26 26
  It has preliminary support for Matthew Roberts advance algorithm 
27 27
     http://reprap.org/pipermail/reprap-dev/2011-May/003323.html
28 28
 
29
- This firmware is optimized for gen6 electronics.
30 29
  */
31 30
 #include <avr/pgmspace.h>
32 31
 
@@ -41,17 +40,14 @@
41 40
 //===========================================================================
42 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 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 52
   float Kp=DEFAULT_Kp;
57 53
   float Ki=DEFAULT_Ki;
@@ -72,45 +68,83 @@ static unsigned long  previous_millis_bed_heater;
72 68
 
73 69
 #ifdef PIDTEMP
74 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 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 83
 #endif //PIDTEMP
84
+  static unsigned char soft_pwm[EXTRUDERS];
89 85
   
90 86
 #ifdef WATCHPERIOD
87
+  static int watch_raw[EXTRUDERS] = { -1000 }; // the first value used for all
91 88
   static int watch_oldtemp[3] = {0,0,0};
92 89
   static unsigned long watchmillis = 0;
93 90
 #endif //WATCHPERIOD
94 91
 
95 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 95
   static int bed_minttemp = 0;
101 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 135
 void updatePID()
108 136
 {
109 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 141
 #endif
112 142
 }
113 143
   
144
+int getHeaterPower(int heater) {
145
+  return soft_pwm[heater];
146
+}
147
+
114 148
 void manage_heater()
115 149
 {
116 150
   #ifdef USE_WATCHDOG
@@ -119,73 +153,67 @@ void manage_heater()
119 153
   
120 154
   float pid_input;
121 155
   float pid_output;
156
+
122 157
   if(temp_meas_ready != true)   //better readability
123 158
     return; 
124 159
 
125 160
   CRITICAL_SECTION_START;
126
-    temp_meas_ready = false;
161
+  temp_meas_ready = false;
127 162
   CRITICAL_SECTION_END;
128 163
 
164
+  for(int e = 0; e < EXTRUDERS; e++) 
165
+  {
166
+
129 167
   #ifdef PIDTEMP
130
-    pid_input = analog2temp(current_raw[TEMPSENSOR_HOTEND_0]);
168
+    pid_input = analog2temp(current_raw[e], e);
131 169
 
132 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 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 177
           pid_output = 0;
140
-          pid_reset = true;
178
+          pid_reset[e] = true;
141 179
         }
142 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 189
           //K1 defined in Configuration.h in the PID settings
152 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 195
     #endif //PID_OPENLOOP
162 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 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 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 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 218
   #ifdef WATCHPERIOD
191 219
     if(watchmillis && millis() - watchmillis > WATCHPERIOD){
@@ -204,20 +232,20 @@ void manage_heater()
204 232
     return;
205 233
   previous_millis_bed_heater = millis();
206 234
   
207
-  #if TEMP_1_PIN > -1
235
+  #if TEMP_BED_PIN > -1
208 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 242
       else 
215 243
       {
216
-        WRITE(HEATER_1_PIN,HIGH);
244
+        WRITE(HEATER_BED_PIN,HIGH);
217 245
       }
218 246
     }
219 247
     else {
220
-      WRITE(HEATER_1_PIN,LOW);
248
+      WRITE(HEATER_BED_PIN,LOW);
221 249
     }  
222 250
   #endif
223 251
 }
@@ -227,30 +255,38 @@ void manage_heater()
227 255
 // For a thermistor, it uses the RepRap thermistor temp table.
228 256
 // This is needed because PID in hydra firmware hovers around a given analog value, not a temp value.
229 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 268
     int raw = 0;
233 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 280
         break;
244 281
       }
245 282
     }
246 283
 
247 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 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 292
 // Takes bed temperature value as input and returns corresponding raw value. 
@@ -258,12 +294,11 @@ int temp2analog(int celsius) {
258 294
 // This is needed because PID in hydra firmware hovers around a given analog value, not a temp value.
259 295
 // This function is derived from inversing the logic from a portion of getTemperature() in FiveD RepRap firmware.
260 296
 int temp2analogBed(int celsius) {
261
-  #ifdef BED_USES_THERMISTOR
262
-
297
+#ifdef BED_USES_THERMISTOR
263 298
     int raw = 0;
264 299
     byte i;
265 300
     
266
-    for (i=1; i<BNUMTEMPS; i++)
301
+    for (i=1; i<bedtemptable_len; i++)
267 302
     {
268 303
       if (PGM_RD_W(bedtemptable[i][1]) < celsius)
269 304
       {
@@ -277,45 +312,52 @@ int temp2analogBed(int celsius) {
277 312
     }
278 313
 
279 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 317
     return (1023 * OVERSAMPLENR) - raw;
283
-  #elif defined BED_USES_AD595
318
+#elif defined BED_USES_AD595
284 319
     return lround(celsius * (1024.0 * OVERSAMPLENR/ (5.0 * 100.0) ) );
285
-  #else
320
+#else
286 321
     #warning No heater-type defined for the bed.
287
-  #endif
288
-  return 0;
322
+    return 0;
323
+#endif
289 324
 }
290 325
 
291 326
 // Derived from RepRap FiveD extruder::getTemperature()
292 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 338
     float celsius = 0;
296 339
     byte i;  
340
+    short (*tt)[][2] = (short (*)[][2])(heater_ttbl_map[e]);
341
+
297 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 351
         break;
307 352
       }
308 353
     }
309 354
 
310 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 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 363
 // Derived from RepRap FiveD extruder::getTemperature()
@@ -327,7 +369,7 @@ float analog2tempBed(int raw) {
327 369
 
328 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 374
       if (PGM_RD_W(bedtemptable[i][0]) > raw)
333 375
       {
@@ -341,7 +383,7 @@ float analog2tempBed(int raw) {
341 383
     }
342 384
 
343 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 388
     return celsius;
347 389
     
@@ -355,6 +397,19 @@ float analog2tempBed(int raw) {
355 397
 
356 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 413
   #if (HEATER_0_PIN > -1) 
359 414
     SET_OUTPUT(HEATER_0_PIN);
360 415
   #endif  
@@ -364,11 +419,12 @@ void tp_init()
364 419
   #if (HEATER_2_PIN > -1) 
365 420
     SET_OUTPUT(HEATER_2_PIN);
366 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 429
   // Set analog inputs
374 430
   ADCSRA = 1<<ADEN | 1<<ADSC | 1<<ADIF | 0x07;
@@ -381,7 +437,6 @@ void tp_init()
381 437
        DIDR0 |= 1 << TEMP_0_PIN; 
382 438
     #else
383 439
        DIDR2 |= 1<<(TEMP_0_PIN - 8); 
384
-       ADCSRB = 1<<MUX5;
385 440
     #endif
386 441
   #endif
387 442
   #if (TEMP_1_PIN > -1)
@@ -389,7 +444,6 @@ void tp_init()
389 444
        DIDR0 |= 1<<TEMP_1_PIN; 
390 445
     #else
391 446
        DIDR2 |= 1<<(TEMP_1_PIN - 8); 
392
-       ADCSRB = 1<<MUX5;
393 447
     #endif
394 448
   #endif
395 449
   #if (TEMP_2_PIN > -1)
@@ -397,7 +451,13 @@ void tp_init()
397 451
        DIDR0 |= 1 << TEMP_2_PIN; 
398 452
     #else
399 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 461
     #endif
402 462
   #endif
403 463
   
@@ -407,27 +467,34 @@ void tp_init()
407 467
   TIMSK0 |= (1<<OCIE0B);  
408 468
   
409 469
   // Wait for temperature measurement to settle
410
-  delay(200);
470
+  delay(250);
411 471
 
412 472
 #ifdef HEATER_0_MINTEMP
413
-  minttemp_0 = temp2analog(HEATER_0_MINTEMP);
473
+  minttemp[0] = temp2analog(HEATER_0_MINTEMP, 0);
414 474
 #endif //MINTEMP
415 475
 #ifdef HEATER_0_MAXTEMP
416
-  maxttemp_0 = temp2analog(HEATER_0_MAXTEMP);
476
+  maxttemp[0] = temp2analog(HEATER_0_MAXTEMP, 0);
417 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 493
 #ifdef BED_MINTEMP
427
-  bed_minttemp = temp2analog(BED_MINTEMP);
494
+  bed_minttemp = temp2analogBed(BED_MINTEMP);
428 495
 #endif //BED_MINTEMP
429 496
 #ifdef BED_MAXTEMP
430
-  bed_maxttemp = temp2analog(BED_MAXTEMP);
497
+  bed_maxttemp = temp2analogBed(BED_MAXTEMP);
431 498
 #endif //BED_MAXTEMP
432 499
 }
433 500
 
@@ -436,15 +503,17 @@ void tp_init()
436 503
 void setWatch() 
437 504
 {  
438 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 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 517
 #endif 
449 518
 }
450 519
 
@@ -453,6 +522,7 @@ void disable_heater()
453 522
 {
454 523
   #if TEMP_0_PIN > -1
455 524
   target_raw[0]=0;
525
+  soft_pwm[0]=0;
456 526
    #if HEATER_0_PIN > -1  
457 527
      digitalWrite(HEATER_0_PIN,LOW);
458 528
    #endif
@@ -460,6 +530,7 @@ void disable_heater()
460 530
      
461 531
   #if TEMP_1_PIN > -1
462 532
     target_raw[1]=0;
533
+    soft_pwm[1]=0;
463 534
     #if HEATER_1_PIN > -1 
464 535
       digitalWrite(HEATER_1_PIN,LOW);
465 536
     #endif
@@ -467,10 +538,38 @@ void disable_heater()
467 538
       
468 539
   #if TEMP_2_PIN > -1
469 540
     target_raw[2]=0;
541
+    soft_pwm[2]=0;
470 542
     #if HEATER_2_PIN > -1  
471 543
       digitalWrite(HEATER_2_PIN,LOW);
472 544
     #endif
473 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 575
 // Timer 0 is shared with millies
@@ -481,7 +580,35 @@ ISR(TIMER0_COMPB_vect)
481 580
   static unsigned long raw_temp_0_value = 0;
482 581
   static unsigned long raw_temp_1_value = 0;
483 582
   static unsigned long raw_temp_2_value = 0;
583
+  static unsigned long raw_temp_bed_value = 0;
484 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 613
   switch(temp_state) {
487 614
     case 0: // Prepare TEMP_0
@@ -505,7 +632,26 @@ ISR(TIMER0_COMPB_vect)
505 632
       #endif
506 633
       temp_state = 2;
507 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 655
       #if (TEMP_1_PIN > -1)
510 656
         #if TEMP_1_PIN > 7
511 657
           ADCSRB = 1<<MUX5;
@@ -518,15 +664,15 @@ ISR(TIMER0_COMPB_vect)
518 664
       #ifdef ULTIPANEL
519 665
         buttons_check();
520 666
       #endif
521
-      temp_state = 3;
667
+      temp_state = 5;
522 668
       break;
523
-    case 3: // Measure TEMP_1
669
+    case 5: // Measure TEMP_1
524 670
       #if (TEMP_1_PIN > -1)
525 671
         raw_temp_1_value += ADC;
526 672
       #endif
527
-      temp_state = 4;
673
+      temp_state = 6;
528 674
       break;
529
-    case 4: // Prepare TEMP_2
675
+    case 6: // Prepare TEMP_2
530 676
       #if (TEMP_2_PIN > -1)
531 677
         #if TEMP_2_PIN > 7
532 678
           ADCSRB = 1<<MUX5;
@@ -539,39 +685,49 @@ ISR(TIMER0_COMPB_vect)
539 685
       #ifdef ULTIPANEL
540 686
         buttons_check();
541 687
       #endif
542
-      temp_state = 5;
688
+      temp_state = 7;
543 689
       break;
544
-    case 5: // Measure TEMP_2
690
+    case 7: // Measure TEMP_2
545 691
       #if (TEMP_2_PIN > -1)
546 692
         raw_temp_2_value += ADC;
547 693
       #endif
548 694
       temp_state = 0;
549 695
       temp_count++;
550 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 705
     #ifdef HEATER_0_USES_AD595
560 706
       current_raw[0] = raw_temp_0_value;
561 707
     #else
562 708
       current_raw[0] = 16383 - raw_temp_0_value;
563 709
     #endif
564
-    
710
+
711
+#if EXTRUDERS > 1    
565 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 721
       current_raw[2] = raw_temp_2_value;
567 722
     #else
568 723
       current_raw[2] = 16383 - raw_temp_2_value;
569 724
     #endif
725
+#endif
570 726
     
571 727
     #ifdef BED_USES_AD595
572
-      current_raw[1] = raw_temp_1_value;
728
+      current_raw_bed = raw_temp_bed_value;
573 729
     #else
574
-      current_raw[1] = 16383 - raw_temp_1_value;
730
+      current_raw_bed = 16383 - raw_temp_bed_value;
575 731
     #endif
576 732
     
577 733
     temp_meas_ready = true;
@@ -579,77 +735,28 @@ ISR(TIMER0_COMPB_vect)
579 735
     raw_temp_0_value = 0;
580 736
     raw_temp_1_value = 0;
581 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 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,95 +32,111 @@
32 32
 void tp_init();  //initialise the heating
33 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 35
 //low leven conversion routines
39 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 38
 int temp2analogBed(int celsius);
42
-float analog2temp(int raw);
39
+float analog2temp(int raw, uint8_t e);
43 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 46
 extern float Kp,Ki,Kd,Kc;
48 47
 
49 48
 #ifdef PIDTEMP
50
-  extern float pid_setpoint ;
49
+  extern float pid_setpoint[EXTRUDERS];
51 50
 #endif
52 51
   
53 52
 // #ifdef WATCHPERIOD
54
-//   extern int watch_raw[3] ;
53
+  extern int watch_raw[EXTRUDERS] ;
55 54
 //   extern unsigned long watchmillis;
56 55
 // #endif
57 56
 
58 57
 
59
-
60 58
 //high level conversion routines, for use outside of temperature.cpp
61 59
 //inline so that there is no performance decrease.
62 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 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 128
 FORCE_INLINE void autotempShutdown(){
115 129
  #ifdef AUTOTEMP
116 130
  if(autotemp_enabled)
117 131
  {
118 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 136
  #endif
123 137
 }
138
+
139
+int getHeaterPower(int heater);
124 140
 void disable_heater();
125 141
 void setWatch();
126 142
 void updatePID();

+ 54
- 93
Marlin/thermistortables.h View File

@@ -5,10 +5,9 @@
5 5
 
6 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 11
 {       23*OVERSAMPLENR ,       300     },
13 12
 {       25*OVERSAMPLENR ,       295     },
14 13
 {       27*OVERSAMPLENR ,       290     },
@@ -72,9 +71,8 @@ const short temptable_1[NUMTEMPS_1][2] PROGMEM = {
72 71
 {       1008*OVERSAMPLENR       ,       0       } //safety
73 72
 };
74 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 76
    {1*OVERSAMPLENR, 848},
79 77
    {54*OVERSAMPLENR, 275},
80 78
    {107*OVERSAMPLENR, 228},
@@ -99,9 +97,8 @@ const short temptable_2[NUMTEMPS_2][2] PROGMEM = {
99 97
 };
100 98
 
101 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 102
                 {1*OVERSAMPLENR,864},
106 103
                 {21*OVERSAMPLENR,300},
107 104
                 {25*OVERSAMPLENR,290},
@@ -133,10 +130,8 @@ const short temptable_3[NUMTEMPS_3][2] PROGMEM = {
133 130
         };
134 131
 
135 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 135
    {1*OVERSAMPLENR, 430},
141 136
    {54*OVERSAMPLENR, 137},
142 137
    {107*OVERSAMPLENR, 107},
@@ -160,10 +155,8 @@ const short temptable_4[NUMTEMPS_4][2] PROGMEM = {
160 155
 };
161 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 160
 {1*OVERSAMPLENR, 713},
168 161
 {18*OVERSAMPLENR, 316},
169 162
 {35*OVERSAMPLENR, 266},
@@ -228,9 +221,8 @@ const short temptable_5[NUMTEMPS_5][2] PROGMEM = {
228 221
 };
229 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 226
    {28*OVERSAMPLENR, 250},
235 227
    {31*OVERSAMPLENR, 245},
236 228
    {35*OVERSAMPLENR, 240},
@@ -270,9 +262,8 @@ const short temptable_6[NUMTEMPS_6][2] PROGMEM = {
270 262
 };
271 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 267
    {46*OVERSAMPLENR, 270},
277 268
    {50*OVERSAMPLENR, 265},
278 269
    {54*OVERSAMPLENR, 260},
@@ -330,82 +321,52 @@ const short temptable_7[NUMTEMPS_7][2] PROGMEM = {
330 321
 };
331 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 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 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 370
 #endif
410 371
 
411 372
 #endif //THERMISTORTABLES_H_

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


Loading…
Cancel
Save