Browse Source

bed pid

Conflicts:

	Marlin/Configuration.h
Mark Finn 11 years ago
parent
commit
9698f4ea64
4 changed files with 175 additions and 52 deletions
  1. 12
    1
      Marlin/Configuration.h
  2. 30
    1
      Marlin/Marlin.pde
  3. 123
    46
      Marlin/temperature.cpp
  4. 10
    4
      Marlin/temperature.h

+ 12
- 1
Marlin/Configuration.h View File

95
 // PID settings:
95
 // PID settings:
96
 // Comment the following line to disable PID and enable bang-bang.
96
 // Comment the following line to disable PID and enable bang-bang.
97
 #define PIDTEMP
97
 #define PIDTEMP
98
+#define PIDTEMPBED
98
 #define PID_MAX 255 // limits current to nozzle; 255=full current
99
 #define PID_MAX 255 // limits current to nozzle; 255=full current
99
 #ifdef PIDTEMP
100
 #ifdef PIDTEMP
100
   //#define PID_DEBUG // Sends debug data to the serial port. 
101
   //#define PID_DEBUG // Sends debug data to the serial port. 
101
-  //#define PID_OPENLOOP 1 // Puts PID in open loop. M104 sets the output power in %
102
+  //#define PID_OPENLOOP 1 // Puts PID in open loop. M104/M140 sets the output power from 0 to PID_MAX
102
   #define PID_INTEGRAL_DRIVE_MAX 255  //limit for the integral term
103
   #define PID_INTEGRAL_DRIVE_MAX 255  //limit for the integral term
103
   #define K1 0.95 //smoothing factor withing the PID
104
   #define K1 0.95 //smoothing factor withing the PID
104
   #define PID_dT ((16.0 * 8.0)/(F_CPU / 64.0 / 256.0)) //sampling period of the
105
   #define PID_dT ((16.0 * 8.0)/(F_CPU / 64.0 / 256.0)) //sampling period of the
114
 //    #define  DEFAULT_Ki 0.1  
115
 //    #define  DEFAULT_Ki 0.1  
115
 //    #define  DEFAULT_Kd 12  
116
 //    #define  DEFAULT_Kd 12  
116
 
117
 
118
+//from FOPDT model - kp=.39 Tp=405 Tdead=66, Tc set to 79.2, argressive factor of .15 (vs .1, 1, 10)
119
+    #define  DEFAULT_bedKp 10.00
120
+    #define  DEFAULT_bedKi .023
121
+    #define  DEFAULT_bedKd 305.4
122
+
123
+//mark from pidautotune
124
+//    #define  DEFAULT_bedKp 97.1
125
+//    #define  DEFAULT_bedKi 1.41
126
+//    #define  DEFAULT_bedKd 1675.16
127
+
117
 // Mendel Parts V9 on 12V    
128
 // Mendel Parts V9 on 12V    
118
 //    #define  DEFAULT_Kp 63.0
129
 //    #define  DEFAULT_Kp 63.0
119
 //    #define  DEFAULT_Ki 2.25
130
 //    #define  DEFAULT_Ki 2.25

+ 30
- 1
Marlin/Marlin.pde View File

113
 // M221 S<factor in percent>- set extrude factor override percentage
113
 // M221 S<factor in percent>- set extrude factor override percentage
114
 // M240 - Trigger a camera to take a photograph
114
 // M240 - Trigger a camera to take a photograph
115
 // M301 - Set PID parameters P I and D
115
 // M301 - Set PID parameters P I and D
116
+// M304 - Set bed PID parameters P I and D
116
 // M302 - Allow cold extrudes
117
 // M302 - Allow cold extrudes
117
 // M303 - PID relay autotune S<temperature> sets the target temperature. (default target temperature = 150C)
118
 // M303 - PID relay autotune S<temperature> sets the target temperature. (default target temperature = 150C)
118
 // M400 - Finish all moves
119
 // M400 - Finish all moves
1003
         SERIAL_PROTOCOLPGM(" @:");
1004
         SERIAL_PROTOCOLPGM(" @:");
1004
         SERIAL_PROTOCOL(getHeaterPower(tmp_extruder));  
1005
         SERIAL_PROTOCOL(getHeaterPower(tmp_extruder));  
1005
       #endif
1006
       #endif
1007
+      #ifdef PIDTEMPBED
1008
+        SERIAL_PROTOCOLPGM(" B@:");
1009
+        SERIAL_PROTOCOL(getHeaterPower(-1));  
1010
+      #endif
1006
         SERIAL_PROTOCOLLN("");
1011
         SERIAL_PROTOCOLLN("");
1007
       return;
1012
       return;
1008
       break;
1013
       break;
1405
       }
1410
       }
1406
       break;
1411
       break;
1407
     #endif //PIDTEMP
1412
     #endif //PIDTEMP
1413
+    #ifdef PIDTEMPBED
1414
+    case 304: // M304
1415
+      {
1416
+        if(code_seen('P')) bedKp = code_value();
1417
+        if(code_seen('I')) bedKi = code_value()*PID_dT;
1418
+        if(code_seen('D')) bedKd = code_value()/PID_dT;
1419
+        updatePID();
1420
+        SERIAL_PROTOCOL(MSG_OK);
1421
+		SERIAL_PROTOCOL(" p:");
1422
+        SERIAL_PROTOCOL(Kp);
1423
+        SERIAL_PROTOCOL(" i:");
1424
+        SERIAL_PROTOCOL(Ki/PID_dT);
1425
+        SERIAL_PROTOCOL(" d:");
1426
+        SERIAL_PROTOCOL(Kd*PID_dT);
1427
+        SERIAL_PROTOCOLLN("");
1428
+      }
1429
+      break;
1430
+    #endif //PIDTEMP
1408
     case 240: // M240  Triggers a camera by emulating a Canon RC-1 : http://www.doc-diy.net/photo/rc-1_hacked/
1431
     case 240: // M240  Triggers a camera by emulating a Canon RC-1 : http://www.doc-diy.net/photo/rc-1_hacked/
1409
      {
1432
      {
1410
       #ifdef PHOTOGRAPH_PIN
1433
       #ifdef PHOTOGRAPH_PIN
1437
     case 303: // M303 PID autotune
1460
     case 303: // M303 PID autotune
1438
     {
1461
     {
1439
       float temp = 150.0;
1462
       float temp = 150.0;
1463
+      int e=0;
1464
+      int c=5;
1465
+      if (code_seen('E')) e=code_value();
1466
+			if (e<0)
1467
+				temp=70;
1440
       if (code_seen('S')) temp=code_value();
1468
       if (code_seen('S')) temp=code_value();
1441
-      PID_autotune(temp);
1469
+      if (code_seen('C')) c=code_value();
1470
+      PID_autotune(temp, e, c);
1442
     }
1471
     }
1443
     break;
1472
     break;
1444
     case 400: // M400 finish all moves
1473
     case 400: // M400 finish all moves

+ 123
- 46
Marlin/temperature.cpp View File

57
     float Kc=DEFAULT_Kc;
57
     float Kc=DEFAULT_Kc;
58
   #endif
58
   #endif
59
 #endif //PIDTEMP
59
 #endif //PIDTEMP
60
+
61
+#ifdef PIDTEMPBED
62
+  // used external
63
+  float pid_setpoint_bed = { 0.0 };
64
+  
65
+  float bedKp=DEFAULT_bedKp;
66
+  float bedKi=(DEFAULT_bedKi*PID_dT);
67
+  float bedKd=(DEFAULT_bedKd/PID_dT);
68
+#endif //PIDTEMPBED
60
   
69
   
61
   
70
   
62
 //===========================================================================
71
 //===========================================================================
64
 //===========================================================================
73
 //===========================================================================
65
 static volatile bool temp_meas_ready = false;
74
 static volatile bool temp_meas_ready = false;
66
 
75
 
67
-static unsigned long  previous_millis_bed_heater;
68
-//static unsigned long previous_millis_heater;
69
-
70
 #ifdef PIDTEMP
76
 #ifdef PIDTEMP
71
   //static cannot be external:
77
   //static cannot be external:
72
   static float temp_iState[EXTRUDERS] = { 0 };
78
   static float temp_iState[EXTRUDERS] = { 0 };
82
   // static float pid_output[EXTRUDERS];
88
   // static float pid_output[EXTRUDERS];
83
   static bool pid_reset[EXTRUDERS];
89
   static bool pid_reset[EXTRUDERS];
84
 #endif //PIDTEMP
90
 #endif //PIDTEMP
91
+#ifdef PIDTEMPBED
92
+  //static cannot be external:
93
+  static float temp_iState_bed = { 0 };
94
+  static float temp_dState_bed = { 0 };
95
+  static float pTerm_bed;
96
+  static float iTerm_bed;
97
+  static float dTerm_bed;
98
+  //int output;
99
+  static float pid_error_bed;
100
+  static float temp_iState_min_bed;
101
+  static float temp_iState_max_bed;
102
+#endif //PIDTEMPBED
85
   static unsigned char soft_pwm[EXTRUDERS];
103
   static unsigned char soft_pwm[EXTRUDERS];
104
+  static unsigned char soft_pwm_bed;
86
   
105
   
87
 #ifdef WATCHPERIOD
106
 #ifdef WATCHPERIOD
88
   int watch_raw[EXTRUDERS] = { -1000 }; // the first value used for all
107
   int watch_raw[EXTRUDERS] = { -1000 }; // the first value used for all
122
 //=============================   functions      ============================
141
 //=============================   functions      ============================
123
 //===========================================================================
142
 //===========================================================================
124
 
143
 
125
-void PID_autotune(float temp)
144
+void PID_autotune(float temp, int extruder, int ncycles)
126
 {
145
 {
127
   float input;
146
   float input;
128
   int cycles=0;
147
   int cycles=0;
139
   float Ku, Tu;
158
   float Ku, Tu;
140
   float Kp, Ki, Kd;
159
   float Kp, Ki, Kd;
141
   float max, min;
160
   float max, min;
142
-  
161
+
162
+	if ((extruder > EXTRUDERS)
163
+  #if (TEMP_BED_PIN <= -1)
164
+		||(extruder < 0)
165
+	#endif
166
+	){
167
+  	SERIAL_ECHOLN("PID Autotune failed. Bad extruder number.");
168
+  	return;
169
+	}
170
+	
143
   SERIAL_ECHOLN("PID Autotune start");
171
   SERIAL_ECHOLN("PID Autotune start");
144
   
172
   
145
   disable_heater(); // switch off all heaters.
173
   disable_heater(); // switch off all heaters.
146
-  
147
-  soft_pwm[0] = PID_MAX/2;
148
-    
149
-  for(;;) {
174
+
175
+	if (extruder<0)
176
+	  soft_pwm_bed = PID_MAX/2;
177
+	else
178
+	  soft_pwm[extruder] = PID_MAX/2;
179
+
180
+
181
+
182
+
183
+ for(;;) {
150
 
184
 
151
     if(temp_meas_ready == true) { // temp sample ready
185
     if(temp_meas_ready == true) { // temp sample ready
152
       CRITICAL_SECTION_START;
186
       CRITICAL_SECTION_START;
153
       temp_meas_ready = false;
187
       temp_meas_ready = false;
154
       CRITICAL_SECTION_END;
188
       CRITICAL_SECTION_END;
155
-      input = analog2temp(current_raw[0], 0);
156
-      
189
+      input = (extruder<0)?analog2tempBed(current_raw_bed):analog2temp(current_raw[extruder], extruder);
190
+
157
       max=max(max,input);
191
       max=max(max,input);
158
       min=min(min,input);
192
       min=min(min,input);
159
       if(heating == true && input > temp) {
193
       if(heating == true && input > temp) {
160
         if(millis() - t2 > 5000) { 
194
         if(millis() - t2 > 5000) { 
161
           heating=false;
195
           heating=false;
162
-          soft_pwm[0] = (bias - d) >> 1;
196
+					if (extruder<0)
197
+						soft_pwm_bed = (bias - d) >> 1;
198
+					else
199
+						soft_pwm[extruder] = (bias - d) >> 1;
163
           t1=millis();
200
           t1=millis();
164
           t_high=t1 - t2;
201
           t_high=t1 - t2;
165
           max=temp;
202
           max=temp;
210
               */
247
               */
211
             }
248
             }
212
           }
249
           }
213
-          soft_pwm[0] = (bias + d) >> 1;
250
+					if (extruder<0)
251
+						soft_pwm_bed = (bias + d) >> 1;
252
+					else
253
+						soft_pwm[extruder] = (bias + d) >> 1;
214
           cycles++;
254
           cycles++;
215
           min=temp;
255
           min=temp;
216
         }
256
         }
221
       return;
261
       return;
222
     }
262
     }
223
     if(millis() - temp_millis > 2000) {
263
     if(millis() - temp_millis > 2000) {
224
-      temp_millis = millis();
225
-      SERIAL_PROTOCOLPGM("ok T:");
226
-      SERIAL_PROTOCOL(degHotend(0));   
264
+			int p;
265
+			if (extruder<0){
266
+	      p=soft_pwm_bed;       
267
+	      SERIAL_PROTOCOLPGM("ok B:");
268
+			}else{
269
+	      p=soft_pwm[extruder];       
270
+	      SERIAL_PROTOCOLPGM("ok T:");
271
+			}
272
+			
273
+      SERIAL_PROTOCOL(input);   
227
       SERIAL_PROTOCOLPGM(" @:");
274
       SERIAL_PROTOCOLPGM(" @:");
228
-      SERIAL_PROTOCOLLN(getHeaterPower(0));       
275
+      SERIAL_PROTOCOLLN(p);       
276
+
277
+      temp_millis = millis();
229
     }
278
     }
230
     if(((millis() - t1) + (millis() - t2)) > (10L*60L*1000L*2L)) {
279
     if(((millis() - t1) + (millis() - t2)) > (10L*60L*1000L*2L)) {
231
       SERIAL_PROTOCOLLNPGM("PID Autotune failed! timeout");
280
       SERIAL_PROTOCOLLNPGM("PID Autotune failed! timeout");
232
       return;
281
       return;
233
     }
282
     }
234
-    if(cycles > 5) {
283
+    if(cycles > ncycles) {
235
       SERIAL_PROTOCOLLNPGM("PID Autotune finished ! Place the Kp, Ki and Kd constants in the configuration.h");
284
       SERIAL_PROTOCOLLNPGM("PID Autotune finished ! Place the Kp, Ki and Kd constants in the configuration.h");
236
       return;
285
       return;
237
     }
286
     }
245
   for(int e = 0; e < EXTRUDERS; e++) { 
294
   for(int e = 0; e < EXTRUDERS; e++) { 
246
      temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / Ki;  
295
      temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / Ki;  
247
   }
296
   }
297
+  temp_iState_max_bed = PID_INTEGRAL_DRIVE_MAX / bedKi;  
248
 #endif
298
 #endif
249
 }
299
 }
250
   
300
   
251
 int getHeaterPower(int heater) {
301
 int getHeaterPower(int heater) {
302
+	if (heater<0)
303
+		return soft_pwm_bed;
252
   return soft_pwm[heater];
304
   return soft_pwm[heater];
253
 }
305
 }
254
 
306
 
255
 void manage_heater()
307
 void manage_heater()
256
 {
308
 {
257
-#ifdef HEATER_BED_DUTY_CYCLE_DIVIDER
258
-  static int bed_needs_heating=0;
259
-  static int bed_is_on=0;
260
-#endif
261
 
309
 
262
   #ifdef USE_WATCHDOG
310
   #ifdef USE_WATCHDOG
263
     wd_reset();
311
     wd_reset();
298
           temp_iState[e] += pid_error[e];
346
           temp_iState[e] += pid_error[e];
299
           temp_iState[e] = constrain(temp_iState[e], temp_iState_min[e], temp_iState_max[e]);
347
           temp_iState[e] = constrain(temp_iState[e], temp_iState_min[e], temp_iState_max[e]);
300
           iTerm[e] = Ki * temp_iState[e];
348
           iTerm[e] = Ki * temp_iState[e];
349
+
301
           //K1 defined in Configuration.h in the PID settings
350
           //K1 defined in Configuration.h in the PID settings
302
           #define K2 (1.0-K1)
351
           #define K2 (1.0-K1)
303
           dTerm[e] = (Kd * (pid_input - temp_dState[e]))*K2 + (K1 * dTerm[e]);
352
           dTerm[e] = (Kd * (pid_input - temp_dState[e]))*K2 + (K1 * dTerm[e]);
304
           temp_dState[e] = pid_input;
353
           temp_dState[e] = pid_input;
354
+
305
           pid_output = constrain(pTerm[e] + iTerm[e] - dTerm[e], 0, PID_MAX);
355
           pid_output = constrain(pTerm[e] + iTerm[e] - dTerm[e], 0, PID_MAX);
306
         }
356
         }
357
+    #else 
358
+          pid_output = constrain(pid_setpoint[e], 0, PID_MAX);
307
     #endif //PID_OPENLOOP
359
     #endif //PID_OPENLOOP
308
     #ifdef PID_DEBUG
360
     #ifdef PID_DEBUG
309
     SERIAL_ECHOLN(" PIDDEBUG "<<e<<": Input "<<pid_input<<" Output "<<pid_output" pTerm "<<pTerm[e]<<" iTerm "<<iTerm[e]<<" dTerm "<<dTerm[e]);  
361
     SERIAL_ECHOLN(" PIDDEBUG "<<e<<": Input "<<pid_input<<" Output "<<pid_output" pTerm "<<pTerm[e]<<" iTerm "<<iTerm[e]<<" dTerm "<<dTerm[e]);  
338
     }
390
     }
339
   #endif
391
   #endif
340
   
392
   
341
-#ifdef HEATER_BED_DUTY_CYCLE_DIVIDER
342
-  if (bed_needs_heating){
343
-    if (bed_is_on==0)
344
-        WRITE(HEATER_BED_PIN,HIGH);
345
-    if (bed_is_on==1)
346
-        WRITE(HEATER_BED_PIN,LOW);
347
-    bed_is_on=(bed_is_on+1) % HEATER_BED_DUTY_CYCLE_DIVIDER;
348
-  }
349
-#endif
350
 
393
 
394
+		#ifndef PIDTEMPBED
351
   if(millis() - previous_millis_bed_heater < BED_CHECK_INTERVAL)
395
   if(millis() - previous_millis_bed_heater < BED_CHECK_INTERVAL)
352
     return;
396
     return;
353
   previous_millis_bed_heater = millis();
397
   previous_millis_bed_heater = millis();
354
-  
398
+    #endif
399
+
355
   #if TEMP_BED_PIN > -1
400
   #if TEMP_BED_PIN > -1
356
   
401
   
357
-    #ifdef HEATER_BED_DUTY_CYCLE_DIVIDER
358
-    bed_needs_heating=0;
359
-    #endif
402
+		#ifdef PIDTEMPBED
403
+    pid_input = analog2tempBed(current_raw_bed);
404
+
405
+    #ifndef PID_OPENLOOP
406
+		  pid_error_bed = pid_setpoint_bed - pid_input;
407
+		  pTerm_bed = bedKp * pid_error_bed;
408
+		  temp_iState_bed += pid_error_bed;
409
+		  temp_iState_bed = constrain(temp_iState_bed, temp_iState_min_bed, temp_iState_max_bed);
410
+		  iTerm_bed = bedKi * temp_iState_bed;
411
+
412
+		  //K1 defined in Configuration.h in the PID settings
413
+		  #define K2 (1.0-K1)
414
+		  dTerm_bed= (bedKd * (pid_input - temp_dState_bed))*K2 + (K1 * dTerm_bed);
415
+		  temp_dState_bed = pid_input;
416
+
417
+		  pid_output = constrain(pTerm_bed + iTerm_bed - dTerm_bed, 0, PID_MAX);
418
+
419
+    #else 
420
+      pid_output = constrain(pid_setpoint_bed, 0, PID_MAX);
421
+    #endif //PID_OPENLOOP
360
 
422
 
361
-    #ifndef BED_LIMIT_SWITCHING
423
+	  if((current_raw_bed > bed_minttemp) && (current_raw_bed < bed_maxttemp)) 
424
+	  {
425
+	    soft_pwm_bed = (int)pid_output >> 1;
426
+	  }
427
+	  else {
428
+	    soft_pwm_bed = 0;
429
+	  }
430
+
431
+    #elif not defined BED_LIMIT_SWITCHING
362
       // Check if temperature is within the correct range
432
       // Check if temperature is within the correct range
363
       if((current_raw_bed > bed_minttemp) && (current_raw_bed < bed_maxttemp)) {
433
       if((current_raw_bed > bed_minttemp) && (current_raw_bed < bed_maxttemp)) {
364
         if(current_raw_bed >= target_raw_bed)
434
         if(current_raw_bed >= target_raw_bed)
365
         {
435
         {
366
-          WRITE(HEATER_BED_PIN,LOW);
436
+					soft_pwm_bed = 0;
367
         }
437
         }
368
         else 
438
         else 
369
         {
439
         {
370
-          #ifdef HEATER_BED_DUTY_CYCLE_DIVIDER
371
-          bed_needs_heating=1;
372
-          #endif
373
-          WRITE(HEATER_BED_PIN,HIGH);
440
+					soft_pwm_bed = 100;
374
         }
441
         }
375
       }
442
       }
376
       else {
443
       else {
444
+					soft_pwm_bed = 0;
377
         WRITE(HEATER_BED_PIN,LOW);
445
         WRITE(HEATER_BED_PIN,LOW);
378
       }
446
       }
379
     #else //#ifdef BED_LIMIT_SWITCHING
447
     #else //#ifdef BED_LIMIT_SWITCHING
381
       if((current_raw_bed > bed_minttemp) && (current_raw_bed < bed_maxttemp)) {
449
       if((current_raw_bed > bed_minttemp) && (current_raw_bed < bed_maxttemp)) {
382
         if(current_raw_bed > target_bed_high_temp)
450
         if(current_raw_bed > target_bed_high_temp)
383
         {
451
         {
384
-          WRITE(HEATER_BED_PIN,LOW);
452
+					soft_pwm_bed = 0;
385
         }
453
         }
386
         else 
454
         else 
387
           if(current_raw_bed <= target_bed_low_temp)
455
           if(current_raw_bed <= target_bed_low_temp)
388
         {
456
         {
389
-          #ifdef HEATER_BED_DUTY_CYCLE_DIVIDER
390
-          bed_needs_heating=1;
391
-          #endif
392
-          WRITE(HEATER_BED_PIN,HIGH);
457
+					soft_pwm_bed = 100;
393
         }
458
         }
394
       }
459
       }
395
       else {
460
       else {
461
+					soft_pwm_bed = 0;
396
         WRITE(HEATER_BED_PIN,LOW);
462
         WRITE(HEATER_BED_PIN,LOW);
397
       }
463
       }
398
     #endif
464
     #endif
567
 #ifdef PIDTEMP
633
 #ifdef PIDTEMP
568
     temp_iState_min[e] = 0.0;
634
     temp_iState_min[e] = 0.0;
569
     temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / Ki;
635
     temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / Ki;
636
+    temp_iState_min_bed = 0.0;
637
+    temp_iState_max_bed = PID_INTEGRAL_DRIVE_MAX / bedKi;
570
 #endif //PIDTEMP
638
 #endif //PIDTEMP
571
   }
639
   }
572
 
640
 
728
 
796
 
729
   #if TEMP_BED_PIN > -1
797
   #if TEMP_BED_PIN > -1
730
     target_raw_bed=0;
798
     target_raw_bed=0;
799
+    soft_pwm_bed=0;
731
     #if HEATER_BED_PIN > -1  
800
     #if HEATER_BED_PIN > -1  
732
       WRITE(HEATER_BED_PIN,LOW);
801
       WRITE(HEATER_BED_PIN,LOW);
733
     #endif
802
     #endif
832
   static unsigned char soft_pwm_0;
901
   static unsigned char soft_pwm_0;
833
   static unsigned char soft_pwm_1;
902
   static unsigned char soft_pwm_1;
834
   static unsigned char soft_pwm_2;
903
   static unsigned char soft_pwm_2;
904
+  static unsigned char soft_pwm_b;
835
   
905
   
836
   if(pwm_count == 0){
906
   if(pwm_count == 0){
837
     soft_pwm_0 = soft_pwm[0];
907
     soft_pwm_0 = soft_pwm[0];
844
     soft_pwm_2 = soft_pwm[2];
914
     soft_pwm_2 = soft_pwm[2];
845
     if(soft_pwm_2 > 0) WRITE(HEATER_2_PIN,1);
915
     if(soft_pwm_2 > 0) WRITE(HEATER_2_PIN,1);
846
     #endif
916
     #endif
917
+    #if HEATER_BED_PIN > -1
918
+    soft_pwm_b = soft_pwm_bed;
919
+    if(soft_pwm_b > 0) WRITE(HEATER_BED_PIN,1);
920
+    #endif
847
   }
921
   }
848
   if(soft_pwm_0 <= pwm_count) WRITE(HEATER_0_PIN,0);
922
   if(soft_pwm_0 <= pwm_count) WRITE(HEATER_0_PIN,0);
849
   #if EXTRUDERS > 1
923
   #if EXTRUDERS > 1
852
   #if EXTRUDERS > 2
926
   #if EXTRUDERS > 2
853
   if(soft_pwm_2 <= pwm_count) WRITE(HEATER_2_PIN,0);
927
   if(soft_pwm_2 <= pwm_count) WRITE(HEATER_2_PIN,0);
854
   #endif
928
   #endif
929
+  #if HEATER_BED_PIN > -1
930
+  if(soft_pwm_b <= pwm_count) WRITE(HEATER_BED_PIN,0);
931
+  #endif
855
   
932
   
856
   pwm_count++;
933
   pwm_count++;
857
   pwm_count &= 0x7f;
934
   pwm_count &= 0x7f;

+ 10
- 4
Marlin/temperature.h View File

46
   extern int target_bed_low_temp ;  
46
   extern int target_bed_low_temp ;  
47
   extern int target_bed_high_temp ;
47
   extern int target_bed_high_temp ;
48
 #endif
48
 #endif
49
-extern float Kp,Ki,Kd,Kc;
50
 
49
 
51
 #ifdef PIDTEMP
50
 #ifdef PIDTEMP
51
+  extern float Kp,Ki,Kd,Kc;
52
   extern float pid_setpoint[EXTRUDERS];
52
   extern float pid_setpoint[EXTRUDERS];
53
 #endif
53
 #endif
54
+#ifdef PIDTEMPBED
55
+  extern float bedKp,bedKi,bedKd;
56
+  extern float pid_setpoint_bed;
57
+#endif
54
   
58
   
55
 // #ifdef WATCHPERIOD
59
 // #ifdef WATCHPERIOD
56
   extern int watch_raw[EXTRUDERS] ;
60
   extern int watch_raw[EXTRUDERS] ;
88
 FORCE_INLINE void setTargetBed(const float &celsius) {  
92
 FORCE_INLINE void setTargetBed(const float &celsius) {  
89
   
93
   
90
   target_raw_bed = temp2analogBed(celsius);
94
   target_raw_bed = temp2analogBed(celsius);
91
-  #ifdef BED_LIMIT_SWITCHING
95
+	#ifdef PIDTEMPBED
96
+  pid_setpoint_bed = celsius;
97
+  #elif defined BED_LIMIT_SWITCHING
92
     if(celsius>BED_HYSTERESIS)
98
     if(celsius>BED_HYSTERESIS)
93
     {
99
     {
94
     target_bed_low_temp= temp2analogBed(celsius-BED_HYSTERESIS);
100
     target_bed_low_temp= temp2analogBed(celsius-BED_HYSTERESIS);
163
  #endif
169
  #endif
164
 }
170
 }
165
 
171
 
166
-void PID_autotune(float temp);
172
+void PID_autotune(float temp, int extruder, int ncycles);
167
 
173
 
168
 #endif
174
 #endif
169
-
175
+

Loading…
Cancel
Save