Browse Source

Merged multiple extruder support.

Soft PWM. (Sanguinololu can also have PID temperature control)
Interrupt save WRITE for addresses > 0x0FF
Erik van der Zalm 13 years ago
parent
commit
e017228569
11 changed files with 5525 additions and 5413 deletions
  1. 49
    46
      Marlin/Configuration.h
  2. 0
    2
      Marlin/Marlin.h
  3. 27
    19
      Marlin/Marlin.pde
  4. 2581
    2572
      Marlin/fastio.h
  5. 736
    737
      Marlin/pins.h
  6. 2
    2
      Marlin/planner.cpp
  7. 56
    24
      Marlin/stepper.cpp
  8. 15
    0
      Marlin/stepper.h
  9. 74
    31
      Marlin/temperature.cpp
  10. 143
    142
      Marlin/temperature.h
  11. 1842
    1838
      Marlin/ultralcd.pde

+ 49
- 46
Marlin/Configuration.h View File

4
 
4
 
5
 
5
 
6
 // This determines the communication speed of the printer
6
 // This determines the communication speed of the printer
7
-//#define BAUDRATE 250000
8
-#define BAUDRATE 115200
7
+#define BAUDRATE 250000
8
+//#define BAUDRATE 115200
9
 //#define BAUDRATE 230400
9
 //#define BAUDRATE 230400
10
 
10
 
11
-#define EXTRUDERS 2
11
+#define EXTRUDERS 1
12
 
12
 
13
 // Frequency limit
13
 // Frequency limit
14
 // See nophead's blog for more info
14
 // See nophead's blog for more info
32
 // Sanguinololu 1.2 and above = 62
32
 // Sanguinololu 1.2 and above = 62
33
 // Ultimaker = 7,
33
 // Ultimaker = 7,
34
 // Teensylu = 8
34
 // Teensylu = 8
35
-#define MOTHERBOARD 33
35
+#define MOTHERBOARD 7
36
 
36
 
37
 //===========================================================================
37
 //===========================================================================
38
 //=============================Thermal Settings  ============================
38
 //=============================Thermal Settings  ============================
46
 // 5 is ParCan supplied 104GT-2 100K
46
 // 5 is ParCan supplied 104GT-2 100K
47
 // 6 is EPCOS 100k
47
 // 6 is EPCOS 100k
48
 // 7 is 100k Honeywell thermistor 135-104LAG-J01
48
 // 7 is 100k Honeywell thermistor 135-104LAG-J01
49
-#define THERMISTORHEATER_0 1
50
-#define THERMISTORHEATER_1 1
51
-#define HEATER_0_USES_THERMISTOR
52
-#define HEATER_1_USES_THERMISTOR
53
-//#define HEATER_0_USES_AD595
49
+
50
+//#define THERMISTORHEATER_0 3
51
+//#define THERMISTORHEATER_1 1
52
+//#define THERMISTORHEATER_2 1
53
+
54
+//#define HEATER_0_USES_THERMISTOR
55
+//#define HEATER_1_USES_THERMISTOR
56
+//#define HEATER_2_USES_THERMISTOR
57
+#define HEATER_0_USES_AD595
54
 //#define HEATER_1_USES_AD595
58
 //#define HEATER_1_USES_AD595
59
+//#define HEATER_2_USES_AD595
55
 
60
 
56
 // Select one of these only to define how the bed temp is read.
61
 // Select one of these only to define how the bed temp is read.
57
-#define THERMISTORBED 1
58
-#define BED_USES_THERMISTOR
62
+//#define THERMISTORBED 1
63
+//#define BED_USES_THERMISTOR
59
 //#define BED_USES_AD595
64
 //#define BED_USES_AD595
60
 
65
 
61
 #define BED_CHECK_INTERVAL 5000 //ms
66
 #define BED_CHECK_INTERVAL 5000 //ms
73
 //// The minimal temperature defines the temperature below which the heater will not be enabled
78
 //// The minimal temperature defines the temperature below which the heater will not be enabled
74
 #define HEATER_0_MINTEMP 5
79
 #define HEATER_0_MINTEMP 5
75
 //#define HEATER_1_MINTEMP 5
80
 //#define HEATER_1_MINTEMP 5
76
-#define BED_MINTEMP 5
81
+//#define HEATER_2_MINTEMP 5
82
+//#define BED_MINTEMP 5
77
 
83
 
78
 
84
 
79
 // When temperature exceeds max temp, your heater will be switched off.
85
 // When temperature exceeds max temp, your heater will be switched off.
81
 // You should use MINTEMP for thermistor short/failure protection.
87
 // You should use MINTEMP for thermistor short/failure protection.
82
 #define HEATER_0_MAXTEMP 275
88
 #define HEATER_0_MAXTEMP 275
83
 //#define HEATER_1_MAXTEMP 275
89
 //#define HEATER_1_MAXTEMP 275
84
-#define BED_MAXTEMP 150
90
+//#define HEATER_2_MAXTEMP 275
91
+//#define BED_MAXTEMP 150
85
 
92
 
86
 
93
 
87
 // Wait for Cooldown
94
 // Wait for Cooldown
92
 
99
 
93
 // Heating is finished if a temperature close to this degree shift is reached
100
 // Heating is finished if a temperature close to this degree shift is reached
94
 #define HEATING_EARLY_FINISH_DEG_OFFSET 1 //Degree
101
 #define HEATING_EARLY_FINISH_DEG_OFFSET 1 //Degree
102
+
95
 // PID settings:
103
 // PID settings:
96
 // Uncomment the following line to enable PID support.
104
 // Uncomment the following line to enable PID support.
97
-  
98
 #define PIDTEMP
105
 #define PIDTEMP
106
+#define PID_MAX 255 // limits current to nozzle; 255=full current
99
 #ifdef PIDTEMP
107
 #ifdef PIDTEMP
100
-  #if MOTHERBOARD == 62
101
-    #error Sanguinololu does not support PID, sorry. Please disable it.
102
-  #endif
103
   //#define PID_DEBUG // Sends debug data to the serial port. 
108
   //#define PID_DEBUG // Sends debug data to the serial port. 
104
   //#define PID_OPENLOOP 1 // Puts PID in open loop. M104 sets the output power in %
109
   //#define PID_OPENLOOP 1 // Puts PID in open loop. M104 sets the output power in %
105
-  
106
-  #define PID_MAX 255 // limits current to nozzle; 255=full current
107
   #define PID_INTEGRAL_DRIVE_MAX 255  //limit for the integral term
110
   #define PID_INTEGRAL_DRIVE_MAX 255  //limit for the integral term
108
   #define K1 0.95 //smoothing factor withing the PID
111
   #define K1 0.95 //smoothing factor withing the PID
109
-  #define PID_dT 0.1 //sampling period of the PID
112
+  #define PID_dT 0.128 //sampling period of the PID
110
 
113
 
111
   //To develop some PID settings for your machine, you can initiall follow 
114
   //To develop some PID settings for your machine, you can initiall follow 
112
   // the Ziegler-Nichols method.
115
   // the Ziegler-Nichols method.
130
 //    #define  DEFAULT_Kd (PID_SWING_AT_CRITIAL/8./PID_dT)  
133
 //    #define  DEFAULT_Kd (PID_SWING_AT_CRITIAL/8./PID_dT)  
131
 
134
 
132
 // Ultitmaker
135
 // Ultitmaker
133
-//    #define  DEFAULT_Kp  22.2
134
-//    #define  DEFAULT_Ki (1.25*PID_dT)  
135
-//    #define  DEFAULT_Kd (99/PID_dT)  
136
+    #define  DEFAULT_Kp  22.2
137
+    #define  DEFAULT_Ki (1.25*PID_dT)  
138
+    #define  DEFAULT_Kd (99/PID_dT)  
136
 
139
 
137
 // Makergear
140
 // Makergear
138
-    #define  DEFAULT_Kp 7.0
139
-    #define  DEFAULT_Ki 0.1  
140
-    #define  DEFAULT_Kd 12  
141
+//    #define  DEFAULT_Kp 7.0
142
+//    #define  DEFAULT_Ki 0.1  
143
+//    #define  DEFAULT_Kd 12  
141
 
144
 
142
 // Mendel Parts V9 on 12V    
145
 // Mendel Parts V9 on 12V    
143
 //    #define  DEFAULT_Kp  63.0
146
 //    #define  DEFAULT_Kp  63.0
170
 #define ENDSTOPPULLUPS // Comment this out (using // at the start of the line) to disable the endstop pullup resistors
173
 #define ENDSTOPPULLUPS // Comment this out (using // at the start of the line) to disable the endstop pullup resistors
171
 
174
 
172
 // The pullups are needed if you directly connect a mechanical endswitch between the signal and ground pins.
175
 // The pullups are needed if you directly connect a mechanical endswitch between the signal and ground pins.
173
-const bool X_ENDSTOPS_INVERTING = false; // set to true to invert the logic of the endstops. 
174
-const bool Y_ENDSTOPS_INVERTING = false; // set to true to invert the logic of the endstops. 
175
-const bool Z_ENDSTOPS_INVERTING = false; // set to true to invert the logic of the endstops. 
176
+const bool X_ENDSTOPS_INVERTING = true; // set to true to invert the logic of the endstops. 
177
+const bool Y_ENDSTOPS_INVERTING = true; // set to true to invert the logic of the endstops. 
178
+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
179
 // For optos H21LOB set to true, for Mendel-Parts newer optos TCST2103 set to false
177
 
180
 
178
-//#define ENDSTOPS_ONLY_FOR_HOMING // If defined the endstops will only be used for homing
181
+#define ENDSTOPS_ONLY_FOR_HOMING // If defined the endstops will only be used for homing
179
 
182
 
180
 // For Inverting Stepper Enable Pins (Active Low) use 0, Non Inverting (Active High) use 1
183
 // For Inverting Stepper Enable Pins (Active Low) use 0, Non Inverting (Active High) use 1
181
 #define X_ENABLE_ON 0
184
 #define X_ENABLE_ON 0
186
 // Disables axis when it's not being used.
189
 // Disables axis when it's not being used.
187
 #define DISABLE_X false
190
 #define DISABLE_X false
188
 #define DISABLE_Y false
191
 #define DISABLE_Y false
189
-#define DISABLE_Z true
192
+#define DISABLE_Z false
190
 #define DISABLE_E false // For all extruders
193
 #define DISABLE_E false // For all extruders
191
 
194
 
192
 // Inverting axis direction
195
 // Inverting axis direction
195
 //#define INVERT_Z_DIR false    // for Mendel set to false, for Orca set to true
198
 //#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, used for all extruders
199
 //#define INVERT_E*_DIR true   // for direct drive extruder v9 set to true, for geared extruder set to false, used for all extruders
197
 
200
 
198
-#define INVERT_X_DIR false    // for Mendel set to false, for Orca set to true
201
+#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
202
 #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
203
 #define INVERT_Z_DIR true     // for Mendel set to false, for Orca set to true
201
 #define INVERT_E0_DIR false   // for direct drive extruder v9 set to true, for geared extruder set to false
204
 #define INVERT_E0_DIR false   // for direct drive extruder v9 set to true, for geared extruder set to false
202
-#define INVERT_E1_DIR true    // for direct drive extruder v9 set to true, for geared extruder set to false
205
+#define INVERT_E1_DIR false    // for direct drive extruder v9 set to true, for geared extruder set to false
203
 #define INVERT_E2_DIR false   // for direct drive extruder v9 set to true, for geared extruder set to false
206
 #define INVERT_E2_DIR false   // for direct drive extruder v9 set to true, for geared extruder set to false
204
 
207
 
205
 //// ENDSTOP SETTINGS:
208
 //// ENDSTOP SETTINGS:
208
 #define Y_HOME_DIR -1
211
 #define Y_HOME_DIR -1
209
 #define Z_HOME_DIR -1
212
 #define Z_HOME_DIR -1
210
 
213
 
211
-#define min_software_endstops false //If true, axis won't move to coordinates less than zero.
212
-#define max_software_endstops false  //If true, axis won't move to coordinates greater than the defined lengths below.
213
-#define X_MAX_LENGTH 210
214
-#define Y_MAX_LENGTH 210
215
-#define Z_MAX_LENGTH 210
214
+#define min_software_endstops true //If true, axis won't move to coordinates less than zero.
215
+#define max_software_endstops true  //If true, axis won't move to coordinates greater than the defined lengths below.
216
+#define X_MAX_LENGTH 205
217
+#define Y_MAX_LENGTH 205
218
+#define Z_MAX_LENGTH 200
216
 
219
 
217
 //// MOVEMENT SETTINGS
220
 //// MOVEMENT SETTINGS
218
 #define NUM_AXIS 4 // The axis order in all axis related arrays is X, Y, Z, E
221
 #define NUM_AXIS 4 // The axis order in all axis related arrays is X, Y, Z, E
219
-#define HOMING_FEEDRATE {30*60, 30*60, 2*60, 0}  // set the homing speeds (mm/min)
222
+#define HOMING_FEEDRATE {50*60, 50*60, 4*60, 0}  // set the homing speeds (mm/min)
220
 
223
 
221
 //homing hits the endstop, then retracts by this distance, before it tries to slowly bump again:
224
 //homing hits the endstop, then retracts by this distance, before it tries to slowly bump again:
222
 #define X_HOME_RETRACT_MM 5 
225
 #define X_HOME_RETRACT_MM 5 
230
 
233
 
231
 // default settings 
234
 // default settings 
232
 
235
 
233
-//#define DEFAULT_AXIS_STEPS_PER_UNIT   {78.7402,78.7402,200*8/3,760*1.1}                    // default steps per unit for ultimaker 
234
-//#define DEFAULT_AXIS_STEPS_PER_UNIT   {40, 40, 3333.92, 67} //sells mendel with v9 extruder
235
-#define DEFAULT_AXIS_STEPS_PER_UNIT   {80.3232, 80.8900, 2284.7651, 757.2218} // SAE Prusa w/ Wade extruder
236
+#define DEFAULT_AXIS_STEPS_PER_UNIT   {78.7402,78.7402,200*8/3,760*1.1}                    // default steps per unit for ultimaker 
237
+//#define DEFAULT_AXIS_STEPS_PER_UNIT   {40, 40, 3333.92, 360} //sells mendel with v9 extruder
238
+//#define DEFAULT_AXIS_STEPS_PER_UNIT   {80.3232, 80.8900, 2284.7651, 757.2218} // SAE Prusa w/ Wade extruder
236
 #define DEFAULT_MAX_FEEDRATE          {500, 500, 5, 45}    // (mm/sec)    
239
 #define DEFAULT_MAX_FEEDRATE          {500, 500, 5, 45}    // (mm/sec)    
237
 #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.
240
 #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.
238
 
241
 
283
 // hooke's law says:		force = k * distance
286
 // hooke's law says:		force = k * distance
284
 // bernoulli's priniciple says:	v ^ 2 / 2 + g . h + pressure / density = constant
287
 // bernoulli's priniciple says:	v ^ 2 / 2 + g . h + pressure / density = constant
285
 // so: v ^ 2 is proportional to number of steps we advance the extruder
288
 // so: v ^ 2 is proportional to number of steps we advance the extruder
286
-//#define ADVANCE
289
+#define ADVANCE
287
 
290
 
288
 #ifdef ADVANCE
291
 #ifdef ADVANCE
289
-  #define EXTRUDER_ADVANCE_K .3
292
+  #define EXTRUDER_ADVANCE_K .0
290
 
293
 
291
   #define D_FILAMENT 2.85
294
   #define D_FILAMENT 2.85
292
   #define STEPS_MM_E 836
295
   #define STEPS_MM_E 836
298
 
301
 
299
 //LCD and SD support
302
 //LCD and SD support
300
 //#define ULTRA_LCD  //general lcd support, also 16x2
303
 //#define ULTRA_LCD  //general lcd support, also 16x2
301
-#define SDSUPPORT // Enable SD Card Support in Hardware Console
304
+//#define SDSUPPORT // Enable SD Card Support in Hardware Console
302
 #define SD_FINISHED_STEPPERRELEASE true  //if sd support and the file is finished: disable steppers?
305
 #define SD_FINISHED_STEPPERRELEASE true  //if sd support and the file is finished: disable steppers?
303
 
306
 
304
-//#define ULTIPANEL
307
+#define ULTIPANEL
305
 #ifdef ULTIPANEL
308
 #ifdef ULTIPANEL
306
   //#define NEWPANEL  //enable this if you have a click-encoder panel
309
   //#define NEWPANEL  //enable this if you have a click-encoder panel
307
   #define SDSUPPORT
310
   #define SDSUPPORT

+ 0
- 2
Marlin/Marlin.h View File

57
 
57
 
58
 #define SERIAL_ECHOPAIR(name,value) {SERIAL_ECHOPGM(name);SERIAL_ECHO(value);}
58
 #define SERIAL_ECHOPAIR(name,value) {SERIAL_ECHOPGM(name);SERIAL_ECHO(value);}
59
 
59
 
60
-// Macro for getting current active extruder
61
-#define ACTIVE_EXTRUDER (active_extruder)
62
 
60
 
63
 //things to write to serial from Programmemory. saves 400 to 2k of RAM.
61
 //things to write to serial from Programmemory. saves 400 to 2k of RAM.
64
 #define SerialprintPGM(x) serialprintPGM(MYPGM(x))
62
 #define SerialprintPGM(x) serialprintPGM(MYPGM(x))

+ 27
- 19
Marlin/Marlin.pde View File

465
     plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); \
465
     plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); \
466
     destination[LETTER##_AXIS] = 1.5 * LETTER##_MAX_LENGTH * LETTER##_HOME_DIR; \
466
     destination[LETTER##_AXIS] = 1.5 * LETTER##_MAX_LENGTH * LETTER##_HOME_DIR; \
467
     feedrate = homing_feedrate[LETTER##_AXIS]; \
467
     feedrate = homing_feedrate[LETTER##_AXIS]; \
468
-    prepare_move(); \
468
+    plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); \
469
     \
469
     \
470
     current_position[LETTER##_AXIS] = 0;\
470
     current_position[LETTER##_AXIS] = 0;\
471
     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]);\
472
     destination[LETTER##_AXIS] = -LETTER##_HOME_RETRACT_MM * LETTER##_HOME_DIR;\
472
     destination[LETTER##_AXIS] = -LETTER##_HOME_RETRACT_MM * LETTER##_HOME_DIR;\
473
-    prepare_move(); \
473
+    plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); \
474
     \
474
     \
475
     destination[LETTER##_AXIS] = 2*LETTER##_HOME_RETRACT_MM * LETTER##_HOME_DIR;\
475
     destination[LETTER##_AXIS] = 2*LETTER##_HOME_RETRACT_MM * LETTER##_HOME_DIR;\
476
     feedrate = homing_feedrate[LETTER##_AXIS]/2 ;  \
476
     feedrate = homing_feedrate[LETTER##_AXIS]/2 ;  \
477
-    prepare_move(); \
477
+    plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); \
478
     \
478
     \
479
     current_position[LETTER##_AXIS] = (LETTER##_HOME_DIR == -1) ? 0 : LETTER##_MAX_LENGTH;\
479
     current_position[LETTER##_AXIS] = (LETTER##_HOME_DIR == -1) ? 0 : LETTER##_MAX_LENGTH;\
480
     plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);\
480
     plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);\
541
       if( code_seen(axis_codes[0]) && code_seen(axis_codes[1]) )  //first diagonal move
541
       if( code_seen(axis_codes[0]) && code_seen(axis_codes[1]) )  //first diagonal move
542
       {
542
       {
543
         current_position[X_AXIS] = 0; current_position[Y_AXIS] = 0;
543
         current_position[X_AXIS] = 0; current_position[Y_AXIS] = 0;
544
+
544
         plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); 
545
         plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); 
545
         destination[X_AXIS] = 1.5 * X_MAX_LENGTH * X_HOME_DIR;
546
         destination[X_AXIS] = 1.5 * X_MAX_LENGTH * X_HOME_DIR;
546
         destination[Y_AXIS] = 1.5 * Y_MAX_LENGTH * Y_HOME_DIR; 
547
         destination[Y_AXIS] = 1.5 * Y_MAX_LENGTH * Y_HOME_DIR; 
723
       if (code_seen('S')) setTargetBed(code_value());
724
       if (code_seen('S')) setTargetBed(code_value());
724
       break;
725
       break;
725
     case 105 : // M105
726
     case 105 : // M105
726
-      tmp_extruder = ACTIVE_EXTRUDER;
727
+      tmp_extruder = active_extruder;
727
       if(code_seen('T')) {
728
       if(code_seen('T')) {
728
         tmp_extruder = code_value();
729
         tmp_extruder = code_value();
729
         if(tmp_extruder >= EXTRUDERS) {
730
         if(tmp_extruder >= EXTRUDERS) {
744
         SERIAL_ERROR_START;
745
         SERIAL_ERROR_START;
745
         SERIAL_ERRORLNPGM("No thermistors - no temp");
746
         SERIAL_ERRORLNPGM("No thermistors - no temp");
746
       #endif
747
       #endif
748
+      #ifdef PIDTEMP
749
+        SERIAL_PROTOCOLPGM(" @:");
750
+        SERIAL_PROTOCOL(getHeaterPower(tmp_extruder));  
751
+      #endif
747
         SERIAL_PROTOCOLLN("");
752
         SERIAL_PROTOCOLLN("");
748
       return;
753
       return;
749
       break;
754
       break;
788
         while((residencyStart == -1) ||
793
         while((residencyStart == -1) ||
789
               (residencyStart > -1 && (millis() - residencyStart) < TEMP_RESIDENCY_TIME*1000) ) {
794
               (residencyStart > -1 && (millis() - residencyStart) < TEMP_RESIDENCY_TIME*1000) ) {
790
       #else
795
       #else
791
-        while ( target_direction ? (isHeatingHotend(tmp_extruder)) : (isCoolingHotend(tmp_extruder)&&(CooldownNoWait==false)) ) {
796
+        while ( target_direction ? (isHeatingHotend(tmp_extruder)) : (isCoolingHotend(tmp_extruder)&&(CooldownNoWait==false)) ) {
792
       #endif //TEMP_RESIDENCY_TIME
797
       #endif //TEMP_RESIDENCY_TIME
793
           if( (millis() - codenum) > 1000 ) 
798
           if( (millis() - codenum) > 1000 ) 
794
           { //Print Temp Reading and remaining time every 1 second while heating up/cooling down
799
           { //Print Temp Reading and remaining time every 1 second while heating up/cooling down
795
             SERIAL_PROTOCOLPGM("T:");
800
             SERIAL_PROTOCOLPGM("T:");
796
-            SERIAL_PROTOCOLLN( degHotend(tmp_extruder) ); 
801
+            SERIAL_PROTOCOL( degHotend(tmp_extruder) ); 
797
             SERIAL_PROTOCOLPGM(" E:");
802
             SERIAL_PROTOCOLPGM(" E:");
798
             SERIAL_PROTOCOLLN( (int)tmp_extruder ); 
803
             SERIAL_PROTOCOLLN( (int)tmp_extruder ); 
799
-            SERIAL_PROTOCOLPGM(" W:");
800
-            if(residencyStart > -1)
801
-            {
802
-               codenum = TEMP_RESIDENCY_TIME - ((millis() - residencyStart) / 1000);
803
-               SERIAL_PROTOCOLLN( codenum );
804
-            }
805
-            else 
806
-            {
807
-               SERIAL_PROTOCOLLN( "?" );
808
-            }
804
+            #ifdef TEMP_RESIDENCY_TIME
805
+              SERIAL_PROTOCOLPGM(" W:");
806
+              if(residencyStart > -1)
807
+              {
808
+                 codenum = TEMP_RESIDENCY_TIME - ((millis() - residencyStart) / 1000);
809
+                 SERIAL_PROTOCOLLN( codenum );
810
+              }
811
+              else 
812
+              {
813
+                 SERIAL_PROTOCOLLN( "?" );
814
+              }
815
+            #endif
809
             codenum = millis();
816
             codenum = millis();
810
           }
817
           }
811
           manage_heater();
818
           manage_heater();
834
         {
841
         {
835
           if( (millis()-codenum) > 1000 ) //Print Temp Reading every 1 second while heating up.
842
           if( (millis()-codenum) > 1000 ) //Print Temp Reading every 1 second while heating up.
836
           {
843
           {
837
-            float tt=degHotend(ACTIVE_EXTRUDER);
844
+            float tt=degHotend(active_extruder);
838
             SERIAL_PROTOCOLPGM("T:");
845
             SERIAL_PROTOCOLPGM("T:");
839
             SERIAL_PROTOCOL(tt);
846
             SERIAL_PROTOCOL(tt);
840
             SERIAL_PROTOCOLPGM(" E:");
847
             SERIAL_PROTOCOLPGM(" E:");
841
-            SERIAL_PROTOCOLLN( (int)tmp_extruder ); 
848
+            SERIAL_PROTOCOLLN( (int)active_extruder ); 
842
             SERIAL_PROTOCOLPGM(" B:");
849
             SERIAL_PROTOCOLPGM(" B:");
843
             SERIAL_PROTOCOLLN(degBed()); 
850
             SERIAL_PROTOCOLLN(degBed()); 
844
             codenum = millis(); 
851
             codenum = millis(); 
1191
 
1198
 
1192
 void kill()
1199
 void kill()
1193
 {
1200
 {
1201
+  cli(); // Stop interrupts
1194
   disable_heater();
1202
   disable_heater();
1195
 
1203
 
1196
   disable_x();
1204
   disable_x();
1207
   while(1); // Wait for reset
1215
   while(1); // Wait for reset
1208
 }
1216
 }
1209
 
1217
 
1210
-
1218
+

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


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


+ 2
- 2
Marlin/planner.cpp View File

191
   }
191
   }
192
 
192
 
193
   #ifdef ADVANCE
193
   #ifdef ADVANCE
194
-    long initial_advance = block->advance*entry_factor*entry_factor;
195
-    long final_advance = block->advance*exit_factor*exit_factor;
194
+    volatile long initial_advance = block->advance*entry_factor*entry_factor; 
195
+    volatile long final_advance = block->advance*exit_factor*exit_factor;
196
   #endif // ADVANCE
196
   #endif // ADVANCE
197
   
197
   
198
  // block->accelerate_until = accelerate_steps;
198
  // block->accelerate_until = accelerate_steps;

+ 56
- 24
Marlin/stepper.cpp View File

57
   static long advance_rate, advance, final_advance = 0;
57
   static long advance_rate, advance, final_advance = 0;
58
   static long old_advance = 0;
58
   static long old_advance = 0;
59
 #endif
59
 #endif
60
-static long e_steps;
60
+static long e_steps[3];
61
 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.
62
 static long acceleration_time, deceleration_time;
62
 static long acceleration_time, deceleration_time;
63
 //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;
266
     advance = current_block->initial_advance;
266
     advance = current_block->initial_advance;
267
     final_advance = current_block->final_advance;
267
     final_advance = current_block->final_advance;
268
     // Do E steps + advance steps
268
     // Do E steps + advance steps
269
-    e_steps += ((advance >>8) - old_advance);
269
+    e_steps[current_block->active_extruder] += ((advance >>8) - old_advance);
270
     old_advance = advance >>8;  
270
     old_advance = advance >>8;  
271
   #endif
271
   #endif
272
   deceleration_time = 0;
272
   deceleration_time = 0;
303
       counter_z = counter_x;
303
       counter_z = counter_x;
304
       counter_e = counter_x;
304
       counter_e = counter_x;
305
       step_events_completed = 0;
305
       step_events_completed = 0;
306
- //     #ifdef ADVANCE
307
-      e_steps = 0;
306
+//      #ifdef ADVANCE
307
+//      e_steps[current_block->active_extruder] = 0;
308
 //      #endif
308
 //      #endif
309
     } 
309
     } 
310
     else {
310
     else {
418
 
418
 
419
     #ifndef ADVANCE
419
     #ifndef ADVANCE
420
       if ((out_bits & (1<<E_AXIS)) != 0) {  // -direction
420
       if ((out_bits & (1<<E_AXIS)) != 0) {  // -direction
421
-        NORM_E_DIR();
421
+        REV_E_DIR();
422
         count_direction[E_AXIS]=-1;
422
         count_direction[E_AXIS]=-1;
423
       }
423
       }
424
       else { // +direction
424
       else { // +direction
425
-        REV_E_DIR();
425
+        NORM_E_DIR();
426
         count_direction[E_AXIS]=-1;
426
         count_direction[E_AXIS]=-1;
427
       }
427
       }
428
     #endif //!ADVANCE
428
     #endif //!ADVANCE
437
       if (counter_e > 0) {
437
       if (counter_e > 0) {
438
         counter_e -= current_block->step_event_count;
438
         counter_e -= current_block->step_event_count;
439
         if ((out_bits & (1<<E_AXIS)) != 0) { // - direction
439
         if ((out_bits & (1<<E_AXIS)) != 0) { // - direction
440
-          e_steps--;
440
+          e_steps[current_block->active_extruder]--;
441
         }
441
         }
442
         else {
442
         else {
443
-          e_steps++;
443
+          e_steps[current_block->active_extruder]++;
444
         }
444
         }
445
       }    
445
       }    
446
       #endif //ADVANCE
446
       #endif //ADVANCE
503
         }
503
         }
504
         //if(advance > current_block->advance) advance = current_block->advance;
504
         //if(advance > current_block->advance) advance = current_block->advance;
505
         // Do E steps + advance steps
505
         // Do E steps + advance steps
506
-        e_steps += ((advance >>8) - old_advance);
506
+        e_steps[current_block->active_extruder] += ((advance >>8) - old_advance);
507
         old_advance = advance >>8;  
507
         old_advance = advance >>8;  
508
         
508
         
509
       #endif
509
       #endif
532
         }
532
         }
533
         if(advance < final_advance) advance = final_advance;
533
         if(advance < final_advance) advance = final_advance;
534
         // Do E steps + advance steps
534
         // Do E steps + advance steps
535
-        e_steps += ((advance >>8) - old_advance);
535
+        e_steps[current_block->active_extruder] += ((advance >>8) - old_advance);
536
         old_advance = advance >>8;  
536
         old_advance = advance >>8;  
537
       #endif //ADVANCE
537
       #endif //ADVANCE
538
     }
538
     }
557
     old_OCR0A += 52; // ~10kHz interrupt (250000 / 26 = 9615kHz)
557
     old_OCR0A += 52; // ~10kHz interrupt (250000 / 26 = 9615kHz)
558
     OCR0A = old_OCR0A;
558
     OCR0A = old_OCR0A;
559
     // Set E direction (Depends on E direction + advance)
559
     // Set E direction (Depends on E direction + advance)
560
-    for(unsigned char i=0; i<4;) {
561
-      WRITE_E_STEP(LOW);
562
-      if (e_steps == 0) break;
563
-      i++;
564
-      if (e_steps < 0) {
565
-        WRITE_E_DIR(INVERT_E_DIR);    
566
-        e_steps++;
567
-        WRITE_E_STEP(HIGH);
568
-      } 
569
-      else if (e_steps > 0) {
570
-        WRITE_E_DIR(!INVERT_E_DIR);
571
-        e_steps--;
572
-        WRITE_E_STEP(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
+        }
573
       }
602
       }
603
+ #endif
574
     }
604
     }
575
   }
605
   }
576
 #endif // ADVANCE
606
 #endif // ADVANCE
712
     TCCR0A &= ~(1<<WGM01);
742
     TCCR0A &= ~(1<<WGM01);
713
     TCCR0A &= ~(1<<WGM00);
743
     TCCR0A &= ~(1<<WGM00);
714
   #endif  
744
   #endif  
715
-    e_steps = 0;
745
+    e_steps[0] = 0;
746
+    e_steps[1] = 0;
747
+    e_steps[2] = 0;
716
     TIMSK0 |= (1<<OCIE0A);
748
     TIMSK0 |= (1<<OCIE0A);
717
   #endif //ADVANCE
749
   #endif //ADVANCE
718
   
750
   

+ 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
 

+ 74
- 31
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
 
82
   // static float pid_output[EXTRUDERS];
81
   // static float pid_output[EXTRUDERS];
83
   static bool pid_reset[EXTRUDERS];
82
   static bool pid_reset[EXTRUDERS];
84
 #endif //PIDTEMP
83
 #endif //PIDTEMP
84
+  static unsigned char soft_pwm[EXTRUDERS];
85
   
85
   
86
 #ifdef WATCHPERIOD
86
 #ifdef WATCHPERIOD
87
   static int watch_raw[EXTRUDERS] = { -1000 }; // the first value used for all
87
   static int watch_raw[EXTRUDERS] = { -1000 }; // the first value used for all
140
 #endif
140
 #endif
141
 }
141
 }
142
   
142
   
143
+int getHeaterPower(int heater) {
144
+  return soft_pwm[heater];
145
+}
146
+
143
 void manage_heater()
147
 void manage_heater()
144
 {
148
 {
145
   #ifdef USE_WATCHDOG
149
   #ifdef USE_WATCHDOG
198
     }
202
     }
199
   #endif
203
   #endif
200
 
204
 
201
-  // Check if temperature is within the correct range
202
-  if((current_raw[e] > minttemp[e]) && (current_raw[e] < maxttemp[e])) 
203
-  {
204
-    analogWrite(heater_pin_map[e], pid_output);
205
-  }
206
-  else {
207
-    analogWrite(heater_pin_map[e], 0);
208
-  }
209
-
205
+    // Check if temperature is within the correct range
206
+    if((current_raw[e] > minttemp[e]) && (current_raw[e] < maxttemp[e])) 
207
+    {
208
+      //analogWrite(heater_pin_map[e], pid_output);
209
+      soft_pwm[e] = (int)pid_output >> 1;
210
+    }
211
+    else {
212
+      //analogWrite(heater_pin_map[e], 0);
213
+      soft_pwm[e] = 0;
214
+    }
210
   } // End extruder for loop
215
   } // End extruder for loop
211
     
216
     
212
   if(millis() - previous_millis_bed_heater < BED_CHECK_INTERVAL)
217
   if(millis() - previous_millis_bed_heater < BED_CHECK_INTERVAL)
418
        DIDR0 |= 1 << TEMP_0_PIN; 
423
        DIDR0 |= 1 << TEMP_0_PIN; 
419
     #else
424
     #else
420
        DIDR2 |= 1<<(TEMP_0_PIN - 8); 
425
        DIDR2 |= 1<<(TEMP_0_PIN - 8); 
421
-       ADCSRB = 1<<MUX5;
422
     #endif
426
     #endif
423
   #endif
427
   #endif
424
   #if (TEMP_1_PIN > -1)
428
   #if (TEMP_1_PIN > -1)
426
        DIDR0 |= 1<<TEMP_1_PIN; 
430
        DIDR0 |= 1<<TEMP_1_PIN; 
427
     #else
431
     #else
428
        DIDR2 |= 1<<(TEMP_1_PIN - 8); 
432
        DIDR2 |= 1<<(TEMP_1_PIN - 8); 
429
-       ADCSRB = 1<<MUX5;
430
     #endif
433
     #endif
431
   #endif
434
   #endif
432
   #if (TEMP_2_PIN > -1)
435
   #if (TEMP_2_PIN > -1)
434
        DIDR0 |= 1 << TEMP_2_PIN; 
437
        DIDR0 |= 1 << TEMP_2_PIN; 
435
     #else
438
     #else
436
        DIDR2 = 1<<(TEMP_2_PIN - 8); 
439
        DIDR2 = 1<<(TEMP_2_PIN - 8); 
437
-       ADCSRB = 1<<MUX5;
438
     #endif
440
     #endif
439
   #endif
441
   #endif
440
   #if (TEMP_BED_PIN > -1)
442
   #if (TEMP_BED_PIN > -1)
442
        DIDR0 |= 1<<TEMP_BED_PIN; 
444
        DIDR0 |= 1<<TEMP_BED_PIN; 
443
     #else
445
     #else
444
        DIDR2 |= 1<<(TEMP_BED_PIN - 8); 
446
        DIDR2 |= 1<<(TEMP_BED_PIN - 8); 
445
-       ADCSRB = 1<<MUX5;
446
     #endif
447
     #endif
447
   #endif
448
   #endif
448
   
449
   
506
 {
507
 {
507
   #if TEMP_0_PIN > -1
508
   #if TEMP_0_PIN > -1
508
   target_raw[0]=0;
509
   target_raw[0]=0;
510
+  soft_pwm[0]=0;
509
    #if HEATER_0_PIN > -1  
511
    #if HEATER_0_PIN > -1  
510
      digitalWrite(HEATER_0_PIN,LOW);
512
      digitalWrite(HEATER_0_PIN,LOW);
511
    #endif
513
    #endif
513
      
515
      
514
   #if TEMP_1_PIN > -1
516
   #if TEMP_1_PIN > -1
515
     target_raw[1]=0;
517
     target_raw[1]=0;
518
+    soft_pwm[1]=0;
516
     #if HEATER_1_PIN > -1 
519
     #if HEATER_1_PIN > -1 
517
       digitalWrite(HEATER_1_PIN,LOW);
520
       digitalWrite(HEATER_1_PIN,LOW);
518
     #endif
521
     #endif
520
       
523
       
521
   #if TEMP_2_PIN > -1
524
   #if TEMP_2_PIN > -1
522
     target_raw[2]=0;
525
     target_raw[2]=0;
526
+    soft_pwm[2]=0;
523
     #if HEATER_2_PIN > -1  
527
     #if HEATER_2_PIN > -1  
524
       digitalWrite(HEATER_2_PIN,LOW);
528
       digitalWrite(HEATER_2_PIN,LOW);
525
     #endif
529
     #endif
533
   #endif 
537
   #endif 
534
 }
538
 }
535
 
539
 
540
+void max_temp_error(uint8_t e) {
541
+  digitalWrite(heater_pin_map[e], 0);
542
+  SERIAL_ERROR_START;
543
+  SERIAL_ERRORLN(e);
544
+  SERIAL_ERRORLNPGM(": Extruder switched off. MAXTEMP triggered !");
545
+}
546
+
547
+void min_temp_error(uint8_t e) {
548
+  digitalWrite(heater_pin_map[e], 0);
549
+  SERIAL_ERROR_START;
550
+  SERIAL_ERRORLN(e);
551
+  SERIAL_ERRORLNPGM(": Extruder switched off. MINTEMP triggered !");
552
+}
553
+
554
+void bed_max_temp_error(void) {
555
+  digitalWrite(HEATER_BED_PIN, 0);
556
+  SERIAL_ERROR_START;
557
+  SERIAL_ERRORLNPGM("Temperature heated bed switched off. MAXTEMP triggered !!");
558
+}
559
+
536
 // Timer 0 is shared with millies
560
 // Timer 0 is shared with millies
537
 ISR(TIMER0_COMPB_vect)
561
 ISR(TIMER0_COMPB_vect)
538
 {
562
 {
543
   static unsigned long raw_temp_2_value = 0;
567
   static unsigned long raw_temp_2_value = 0;
544
   static unsigned long raw_temp_bed_value = 0;
568
   static unsigned long raw_temp_bed_value = 0;
545
   static unsigned char temp_state = 0;
569
   static unsigned char temp_state = 0;
570
+  static unsigned char pwm_count = 1;
571
+  static unsigned char soft_pwm_0;
572
+  static unsigned char soft_pwm_1;
573
+  static unsigned char soft_pwm_2;
574
+  
575
+  if(pwm_count == 0){
576
+    soft_pwm_0 = soft_pwm[0];
577
+    if(soft_pwm_0 > 0) WRITE(HEATER_0_PIN,1);
578
+    #if EXTRUDERS > 1
579
+    soft_pwm_1 = soft_pwm[1];
580
+    if(soft_pwm_1 > 0) WRITE(HEATER_1_PIN,1);
581
+    #endif
582
+    #if EXTRUDERS > 2
583
+    soft_pwm_2 = soft_pwm[2];
584
+    if(soft_pwm_2 > 0) WRITE(HEATER_2_PIN,1);
585
+    #endif
586
+  }
587
+  if(soft_pwm_0 <= pwm_count) WRITE(HEATER_0_PIN,0);
588
+  #if EXTRUDERS > 1
589
+  if(soft_pwm_1 <= pwm_count) WRITE(HEATER_1_PIN,0);
590
+  #endif
591
+  #if EXTRUDERS > 2
592
+  if(soft_pwm_2 <= pwm_count) WRITE(HEATER_2_PIN,0);
593
+  #endif
594
+  
595
+  pwm_count++;
596
+  pwm_count &= 0x7f;
546
   
597
   
547
   switch(temp_state) {
598
   switch(temp_state) {
548
     case 0: // Prepare TEMP_0
599
     case 0: // Prepare TEMP_0
628
       temp_state = 0;
679
       temp_state = 0;
629
       temp_count++;
680
       temp_count++;
630
       break;
681
       break;
631
-    default:
632
-      SERIAL_ERROR_START;
633
-      SERIAL_ERRORLNPGM("Temp measurement error!");
634
-      break;
682
+//    default:
683
+//      SERIAL_ERROR_START;
684
+//      SERIAL_ERRORLNPGM("Temp measurement error!");
685
+//      break;
635
   }
686
   }
636
     
687
     
637
   if(temp_count >= 16) // 8 ms * 16 = 128ms.
688
   if(temp_count >= 16) // 8 ms * 16 = 128ms.
671
     raw_temp_2_value = 0;
722
     raw_temp_2_value = 0;
672
     raw_temp_bed_value = 0;
723
     raw_temp_bed_value = 0;
673
 
724
 
674
-    for(int e = 0; e < EXTRUDERS; e++) {
725
+    for(unsigned char e = 0; e < EXTRUDERS; e++) {
675
        if(current_raw[e] >= maxttemp[e]) {
726
        if(current_raw[e] >= maxttemp[e]) {
676
           target_raw[e] = 0;
727
           target_raw[e] = 0;
677
-          digitalWrite(heater_pin_map[e], 0);
678
-          SERIAL_ERROR_START;
679
-          SERIAL_ERRORLN((int)e);
680
-          SERIAL_ERRORLNPGM(": Extruder switched off. MAXTEMP triggered !");
681
-          kill();
728
+          max_temp_error(e);
729
+          kill();;
682
        }
730
        }
683
        if(current_raw[e] <= minttemp[e]) {
731
        if(current_raw[e] <= minttemp[e]) {
684
           target_raw[e] = 0;
732
           target_raw[e] = 0;
685
-          digitalWrite(heater_pin_map[e], 0);
686
-          SERIAL_ERROR_START;
687
-          SERIAL_ERRORLN(e);
688
-          SERIAL_ERRORLNPGM(": Extruder switched off. MINTEMP triggered !");
733
+          min_temp_error(e);
689
           kill();
734
           kill();
690
        }
735
        }
691
     }
736
     }
693
 #if defined(BED_MAXTEMP) && (HEATER_BED_PIN > -1)
738
 #if defined(BED_MAXTEMP) && (HEATER_BED_PIN > -1)
694
     if(current_raw_bed >= bed_maxttemp) {
739
     if(current_raw_bed >= bed_maxttemp) {
695
        target_raw_bed = 0;
740
        target_raw_bed = 0;
696
-       digitalWrite(HEATER_BED_PIN, 0);
697
-       SERIAL_ERROR_START;
698
-       SERIAL_ERRORLNPGM("Temperature heated bed switched off. MAXTEMP triggered !!");
741
+       bed_max_temp_error();
699
        kill();
742
        kill();
700
     }
743
     }
701
 #endif
744
 #endif

+ 143
- 142
Marlin/temperature.h View File

1
-/*
2
-  temperature.h - temperature controller
3
-  Part of Marlin
4
-
5
-  Copyright (c) 2011 Erik van der Zalm
6
-
7
-  Grbl is free software: you can redistribute it and/or modify
8
-  it under the terms of the GNU General Public License as published by
9
-  the Free Software Foundation, either version 3 of the License, or
10
-  (at your option) any later version.
11
-
12
-  Grbl is distributed in the hope that it will be useful,
13
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
-  GNU General Public License for more details.
16
-
17
-  You should have received a copy of the GNU General Public License
18
-  along with Grbl.  If not, see <http://www.gnu.org/licenses/>.
19
-*/
20
-
21
-#ifndef temperature_h
22
-#define temperature_h 
23
-
24
-#include "Marlin.h"
25
-#include "fastio.h"
26
-#ifdef PID_ADD_EXTRUSION_RATE
27
-  #include "stepper.h"
28
-#endif
29
-
30
-// public functions
31
-void tp_init();  //initialise the heating
32
-void manage_heater(); //it is critical that this is called periodically.
33
-
34
-//low leven conversion routines
35
-// do not use this routines and variables outsie of temperature.cpp
36
-int temp2analog(int celsius, uint8_t e);
37
-int temp2analogBed(int celsius);
38
-float analog2temp(int raw, uint8_t e);
39
-float analog2tempBed(int raw);
40
-extern int target_raw[EXTRUDERS];  
41
-extern int heatingtarget_raw[EXTRUDERS];  
42
-extern int current_raw[EXTRUDERS];
43
-extern int target_raw_bed;
44
-extern int current_raw_bed;
45
-extern float Kp,Ki,Kd,Kc;
46
-
47
-#ifdef PIDTEMP
48
-  extern float pid_setpoint[EXTRUDERS];
49
-#endif
50
-  
51
-#ifdef WATCHPERIOD
52
-  extern int watch_raw[EXTRUDERS] ;
53
-  extern unsigned long watchmillis;
54
-#endif
55
-
56
-
57
-//high level conversion routines, for use outside of temperature.cpp
58
-//inline so that there is no performance decrease.
59
-//deg=degreeCelsius
60
-
61
-FORCE_INLINE float degHotend(uint8_t extruder) {  
62
-  return analog2temp(current_raw[extruder], extruder);
63
-};
64
-
65
-FORCE_INLINE float degBed() {
66
-  return analog2tempBed(current_raw_bed);
67
-};
68
-
69
-FORCE_INLINE float degTargetHotend(uint8_t extruder) {  
70
-  return analog2temp(target_raw[extruder], extruder);
71
-};
72
-
73
-FORCE_INLINE float degTargetBed() {   
74
-  return analog2tempBed(target_raw_bed);
75
-};
76
-
77
-FORCE_INLINE void setTargetHotend(const float &celsius, uint8_t extruder) {  
78
-  target_raw[extruder] = temp2analog(celsius, extruder);
79
-#ifdef PIDTEMP
80
-  pid_setpoint[extruder] = celsius;
81
-#endif //PIDTEMP
82
-};
83
-
84
-FORCE_INLINE void setTargetBed(const float &celsius) {  
85
-  target_raw_bed = temp2analogBed(celsius);
86
-};
87
-
88
-FORCE_INLINE bool isHeatingHotend(uint8_t extruder){  
89
-  return target_raw[extruder] > current_raw[extruder];
90
-};
91
-
92
-FORCE_INLINE bool isHeatingBed() {
93
-  return target_raw_bed > current_raw_bed;
94
-};
95
-
96
-FORCE_INLINE bool isCoolingHotend(uint8_t extruder) {  
97
-  return target_raw[extruder] < current_raw[extruder];
98
-};
99
-
100
-FORCE_INLINE bool isCoolingBed() {
101
-  return target_raw_bed < current_raw_bed;
102
-};
103
-
104
-#define degHotend0() degHotend(0)
105
-#define degTargetHotend0() degTargetHotend(0)
106
-#define setTargetHotend0(_celsius) setTargetHotend((_celsius), 0)
107
-#define isHeatingHotend0() isHeatingHotend(0)
108
-#define isCoolingHotend0() isCoolingHotend(0)
109
-#if EXTRUDERS > 1
110
-#define degHotend1() degHotend(1)
111
-#define degTargetHotend1() degTargetHotend(1)
112
-#define setTargetHotend1(_celsius) setTargetHotend((_celsius), 1)
113
-#define isHeatingHotend1() isHeatingHotend(1)
114
-#define isCoolingHotend1() isCoolingHotend(1)
115
-#endif
116
-#if EXTRUDERS > 2
117
-#define degHotend2() degHotend(2)
118
-#define degTargetHotend2() degTargetHotend(2)
119
-#define setTargetHotend2(_celsius) setTargetHotend((_celsius), 2)
120
-#define isHeatingHotend2() isHeatingHotend(2)
121
-#define isCoolingHotend2() isCoolingHotend(2)
122
-#endif
123
-#if EXTRUDERS > 3
124
-#error Invalid number of extruders
125
-#endif
126
-
127
-FORCE_INLINE void autotempShutdown(){
128
- #ifdef AUTOTEMP
129
- if(autotemp_enabled)
130
- {
131
-  autotemp_enabled=false;
132
-  if(degTargetHotend(ACTIVE_EXTRUDER)>autotemp_min)
133
-    setTargetHotend(0,ACTIVE_EXTRUDER);
134
- }
135
- #endif
136
-}
137
-
138
-void disable_heater();
139
-void setWatch();
140
-void updatePID();
141
-
142
-#endif
1
+/*
2
+  temperature.h - temperature controller
3
+  Part of Marlin
4
+
5
+  Copyright (c) 2011 Erik van der Zalm
6
+
7
+  Grbl is free software: you can redistribute it and/or modify
8
+  it under the terms of the GNU General Public License as published by
9
+  the Free Software Foundation, either version 3 of the License, or
10
+  (at your option) any later version.
11
+
12
+  Grbl is distributed in the hope that it will be useful,
13
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
+  GNU General Public License for more details.
16
+
17
+  You should have received a copy of the GNU General Public License
18
+  along with Grbl.  If not, see <http://www.gnu.org/licenses/>.
19
+*/
20
+
21
+#ifndef temperature_h
22
+#define temperature_h 
23
+
24
+#include "Marlin.h"
25
+#include "fastio.h"
26
+#ifdef PID_ADD_EXTRUSION_RATE
27
+  #include "stepper.h"
28
+#endif
29
+
30
+// public functions
31
+void tp_init();  //initialise the heating
32
+void manage_heater(); //it is critical that this is called periodically.
33
+
34
+//low leven conversion routines
35
+// do not use this routines and variables outsie of temperature.cpp
36
+int temp2analog(int celsius, uint8_t e);
37
+int temp2analogBed(int celsius);
38
+float analog2temp(int raw, uint8_t e);
39
+float analog2tempBed(int raw);
40
+extern int target_raw[EXTRUDERS];  
41
+extern int heatingtarget_raw[EXTRUDERS];  
42
+extern int current_raw[EXTRUDERS];
43
+extern int target_raw_bed;
44
+extern int current_raw_bed;
45
+extern float Kp,Ki,Kd,Kc;
46
+
47
+#ifdef PIDTEMP
48
+  extern float pid_setpoint[EXTRUDERS];
49
+#endif
50
+  
51
+#ifdef WATCHPERIOD
52
+  extern int watch_raw[EXTRUDERS] ;
53
+  extern unsigned long watchmillis;
54
+#endif
55
+
56
+
57
+//high level conversion routines, for use outside of temperature.cpp
58
+//inline so that there is no performance decrease.
59
+//deg=degreeCelsius
60
+
61
+FORCE_INLINE float degHotend(uint8_t extruder) {  
62
+  return analog2temp(current_raw[extruder], extruder);
63
+};
64
+
65
+FORCE_INLINE float degBed() {
66
+  return analog2tempBed(current_raw_bed);
67
+};
68
+
69
+FORCE_INLINE float degTargetHotend(uint8_t extruder) {  
70
+  return analog2temp(target_raw[extruder], extruder);
71
+};
72
+
73
+FORCE_INLINE float degTargetBed() {   
74
+  return analog2tempBed(target_raw_bed);
75
+};
76
+
77
+FORCE_INLINE void setTargetHotend(const float &celsius, uint8_t extruder) {  
78
+  target_raw[extruder] = temp2analog(celsius, extruder);
79
+#ifdef PIDTEMP
80
+  pid_setpoint[extruder] = celsius;
81
+#endif //PIDTEMP
82
+};
83
+
84
+FORCE_INLINE void setTargetBed(const float &celsius) {  
85
+  target_raw_bed = temp2analogBed(celsius);
86
+};
87
+
88
+FORCE_INLINE bool isHeatingHotend(uint8_t extruder){  
89
+  return target_raw[extruder] > current_raw[extruder];
90
+};
91
+
92
+FORCE_INLINE bool isHeatingBed() {
93
+  return target_raw_bed > current_raw_bed;
94
+};
95
+
96
+FORCE_INLINE bool isCoolingHotend(uint8_t extruder) {  
97
+  return target_raw[extruder] < current_raw[extruder];
98
+};
99
+
100
+FORCE_INLINE bool isCoolingBed() {
101
+  return target_raw_bed < current_raw_bed;
102
+};
103
+
104
+#define degHotend0() degHotend(0)
105
+#define degTargetHotend0() degTargetHotend(0)
106
+#define setTargetHotend0(_celsius) setTargetHotend((_celsius), 0)
107
+#define isHeatingHotend0() isHeatingHotend(0)
108
+#define isCoolingHotend0() isCoolingHotend(0)
109
+#if EXTRUDERS > 1
110
+#define degHotend1() degHotend(1)
111
+#define degTargetHotend1() degTargetHotend(1)
112
+#define setTargetHotend1(_celsius) setTargetHotend((_celsius), 1)
113
+#define isHeatingHotend1() isHeatingHotend(1)
114
+#define isCoolingHotend1() isCoolingHotend(1)
115
+#endif
116
+#if EXTRUDERS > 2
117
+#define degHotend2() degHotend(2)
118
+#define degTargetHotend2() degTargetHotend(2)
119
+#define setTargetHotend2(_celsius) setTargetHotend((_celsius), 2)
120
+#define isHeatingHotend2() isHeatingHotend(2)
121
+#define isCoolingHotend2() isCoolingHotend(2)
122
+#endif
123
+#if EXTRUDERS > 3
124
+#error Invalid number of extruders
125
+#endif
126
+
127
+FORCE_INLINE void autotempShutdown(){
128
+ #ifdef AUTOTEMP
129
+ if(autotemp_enabled)
130
+ {
131
+  autotemp_enabled=false;
132
+  if(degTargetHotend(ACTIVE_EXTRUDER)>autotemp_min)
133
+    setTargetHotend(0,ACTIVE_EXTRUDER);
134
+ }
135
+ #endif
136
+}
137
+
138
+int getHeaterPower(int heater);
139
+void disable_heater();
140
+void setWatch();
141
+void updatePID();
142
+
143
+#endif
143
 
144
 

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


Loading…
Cancel
Save