|
@@ -221,7 +221,7 @@ static void updateTemperaturesFromRawValues();
|
221
|
221
|
//================================ Functions ================================
|
222
|
222
|
//===========================================================================
|
223
|
223
|
|
224
|
|
-#if ENABLED(PIDTEMP)
|
|
224
|
+#if HAS_PID_HEATING
|
225
|
225
|
|
226
|
226
|
void PID_autotune(float temp, int extruder, int ncycles, bool set_result/*=false*/) {
|
227
|
227
|
float input = 0.0;
|
|
@@ -240,8 +240,13 @@ static void updateTemperaturesFromRawValues();
|
240
|
240
|
millis_t next_auto_fan_check_ms = temp_ms + 2500UL;
|
241
|
241
|
#endif
|
242
|
242
|
|
243
|
|
- if (extruder >= EXTRUDERS
|
244
|
|
- #if !HAS_TEMP_BED
|
|
243
|
+ if (false
|
|
244
|
+ #if ENABLED(PIDTEMP)
|
|
245
|
+ || extruder >= EXTRUDERS
|
|
246
|
+ #else
|
|
247
|
+ || extruder >= 0
|
|
248
|
+ #endif
|
|
249
|
+ #if DISABLED(PIDTEMPBED)
|
245
|
250
|
|| extruder < 0
|
246
|
251
|
#endif
|
247
|
252
|
) {
|
|
@@ -253,10 +258,16 @@ static void updateTemperaturesFromRawValues();
|
253
|
258
|
|
254
|
259
|
disable_all_heaters(); // switch off all heaters.
|
255
|
260
|
|
256
|
|
- if (extruder < 0)
|
257
|
|
- soft_pwm_bed = bias = d = (MAX_BED_POWER) / 2;
|
258
|
|
- else
|
|
261
|
+ #if HAS_PID_FOR_BOTH
|
|
262
|
+ if (extruder < 0)
|
|
263
|
+ soft_pwm_bed = bias = d = (MAX_BED_POWER) / 2;
|
|
264
|
+ else
|
|
265
|
+ soft_pwm[extruder] = bias = d = (PID_MAX) / 2;
|
|
266
|
+ #elif ENABLED(PIDTEMP)
|
259
|
267
|
soft_pwm[extruder] = bias = d = (PID_MAX) / 2;
|
|
268
|
+ #else
|
|
269
|
+ soft_pwm_bed = bias = d = (MAX_BED_POWER) / 2;
|
|
270
|
+ #endif
|
260
|
271
|
|
261
|
272
|
// PID Tuning loop
|
262
|
273
|
for (;;) {
|
|
@@ -266,7 +277,15 @@ static void updateTemperaturesFromRawValues();
|
266
|
277
|
if (temp_meas_ready) { // temp sample ready
|
267
|
278
|
updateTemperaturesFromRawValues();
|
268
|
279
|
|
269
|
|
- input = (extruder < 0) ? current_temperature_bed : current_temperature[extruder];
|
|
280
|
+ input =
|
|
281
|
+ #if HAS_PID_FOR_BOTH
|
|
282
|
+ extruder < 0 ? current_temperature_bed : current_temperature[extruder]
|
|
283
|
+ #elif ENABLED(PIDTEMP)
|
|
284
|
+ current_temperature[extruder]
|
|
285
|
+ #else
|
|
286
|
+ current_temperature_bed
|
|
287
|
+ #endif
|
|
288
|
+ ;
|
270
|
289
|
|
271
|
290
|
max = max(max, input);
|
272
|
291
|
min = min(min, input);
|
|
@@ -281,10 +300,16 @@ static void updateTemperaturesFromRawValues();
|
281
|
300
|
if (heating && input > temp) {
|
282
|
301
|
if (ELAPSED(ms, t2 + 5000UL)) {
|
283
|
302
|
heating = false;
|
284
|
|
- if (extruder < 0)
|
285
|
|
- soft_pwm_bed = (bias - d) >> 1;
|
286
|
|
- else
|
|
303
|
+ #if HAS_PID_FOR_BOTH
|
|
304
|
+ if (extruder < 0)
|
|
305
|
+ soft_pwm_bed = (bias - d) >> 1;
|
|
306
|
+ else
|
|
307
|
+ soft_pwm[extruder] = (bias - d) >> 1;
|
|
308
|
+ #elif ENABLED(PIDTEMP)
|
287
|
309
|
soft_pwm[extruder] = (bias - d) >> 1;
|
|
310
|
+ #elif ENABLED(PIDTEMPBED)
|
|
311
|
+ soft_pwm_bed = (bias - d) >> 1;
|
|
312
|
+ #endif
|
288
|
313
|
t1 = ms;
|
289
|
314
|
t_high = t1 - t2;
|
290
|
315
|
max = temp;
|
|
@@ -297,7 +322,15 @@ static void updateTemperaturesFromRawValues();
|
297
|
322
|
t2 = ms;
|
298
|
323
|
t_low = t2 - t1;
|
299
|
324
|
if (cycles > 0) {
|
300
|
|
- long max_pow = extruder < 0 ? MAX_BED_POWER : PID_MAX;
|
|
325
|
+ long max_pow =
|
|
326
|
+ #if HAS_PID_FOR_BOTH
|
|
327
|
+ extruder < 0 ? MAX_BED_POWER : PID_MAX
|
|
328
|
+ #elif ENABLED(PIDTEMP)
|
|
329
|
+ PID_MAX
|
|
330
|
+ #else
|
|
331
|
+ MAX_BED_POWER
|
|
332
|
+ #endif
|
|
333
|
+ ;
|
301
|
334
|
bias += (d * (t_high - t_low)) / (t_low + t_high);
|
302
|
335
|
bias = constrain(bias, 20, max_pow - 20);
|
303
|
336
|
d = (bias > max_pow / 2) ? max_pow - 1 - bias : bias;
|
|
@@ -336,10 +369,16 @@ static void updateTemperaturesFromRawValues();
|
336
|
369
|
*/
|
337
|
370
|
}
|
338
|
371
|
}
|
339
|
|
- if (extruder < 0)
|
340
|
|
- soft_pwm_bed = (bias + d) >> 1;
|
341
|
|
- else
|
|
372
|
+ #if HAS_PID_FOR_BOTH
|
|
373
|
+ if (extruder < 0)
|
|
374
|
+ soft_pwm_bed = (bias + d) >> 1;
|
|
375
|
+ else
|
|
376
|
+ soft_pwm[extruder] = (bias + d) >> 1;
|
|
377
|
+ #elif ENABLED(PIDTEMP)
|
342
|
378
|
soft_pwm[extruder] = (bias + d) >> 1;
|
|
379
|
+ #else
|
|
380
|
+ soft_pwm_bed = (bias + d) >> 1;
|
|
381
|
+ #endif
|
343
|
382
|
cycles++;
|
344
|
383
|
min = temp;
|
345
|
384
|
}
|
|
@@ -366,27 +405,48 @@ static void updateTemperaturesFromRawValues();
|
366
|
405
|
}
|
367
|
406
|
if (cycles > ncycles) {
|
368
|
407
|
SERIAL_PROTOCOLLNPGM(MSG_PID_AUTOTUNE_FINISHED);
|
369
|
|
- const char* estring = extruder < 0 ? "bed" : "";
|
370
|
|
- SERIAL_PROTOCOLPGM("#define DEFAULT_"); SERIAL_PROTOCOL(estring); SERIAL_PROTOCOLPGM("Kp "); SERIAL_PROTOCOLLN(workKp);
|
371
|
|
- SERIAL_PROTOCOLPGM("#define DEFAULT_"); SERIAL_PROTOCOL(estring); SERIAL_PROTOCOLPGM("Ki "); SERIAL_PROTOCOLLN(workKi);
|
372
|
|
- SERIAL_PROTOCOLPGM("#define DEFAULT_"); SERIAL_PROTOCOL(estring); SERIAL_PROTOCOLPGM("Kd "); SERIAL_PROTOCOLLN(workKd);
|
|
408
|
+
|
|
409
|
+ #if HAS_PID_FOR_BOTH
|
|
410
|
+ const char* estring = extruder < 0 ? "bed" : "";
|
|
411
|
+ SERIAL_PROTOCOLPGM("#define DEFAULT_"); SERIAL_PROTOCOL(estring); SERIAL_PROTOCOLPGM("Kp "); SERIAL_PROTOCOLLN(workKp);
|
|
412
|
+ SERIAL_PROTOCOLPGM("#define DEFAULT_"); SERIAL_PROTOCOL(estring); SERIAL_PROTOCOLPGM("Ki "); SERIAL_PROTOCOLLN(workKi);
|
|
413
|
+ SERIAL_PROTOCOLPGM("#define DEFAULT_"); SERIAL_PROTOCOL(estring); SERIAL_PROTOCOLPGM("Kd "); SERIAL_PROTOCOLLN(workKd);
|
|
414
|
+ #elif ENABLED(PIDTEMP)
|
|
415
|
+ SERIAL_PROTOCOLPGM("#define DEFAULT_Kp "); SERIAL_PROTOCOLLN(workKp);
|
|
416
|
+ SERIAL_PROTOCOLPGM("#define DEFAULT_Ki "); SERIAL_PROTOCOLLN(workKi);
|
|
417
|
+ SERIAL_PROTOCOLPGM("#define DEFAULT_Kd "); SERIAL_PROTOCOLLN(workKd);
|
|
418
|
+ #else
|
|
419
|
+ SERIAL_PROTOCOLPGM("#define DEFAULT_bedKp "); SERIAL_PROTOCOLLN(workKp);
|
|
420
|
+ SERIAL_PROTOCOLPGM("#define DEFAULT_bedKi "); SERIAL_PROTOCOLLN(workKi);
|
|
421
|
+ SERIAL_PROTOCOLPGM("#define DEFAULT_bedKd "); SERIAL_PROTOCOLLN(workKd);
|
|
422
|
+ #endif
|
|
423
|
+
|
|
424
|
+ #define _SET_BED_PID() \
|
|
425
|
+ bedKp = workKp; \
|
|
426
|
+ bedKi = scalePID_i(workKi); \
|
|
427
|
+ bedKd = scalePID_d(workKd); \
|
|
428
|
+ updatePID()
|
|
429
|
+
|
|
430
|
+ #define _SET_EXTRUDER_PID() \
|
|
431
|
+ PID_PARAM(Kp, extruder) = workKp; \
|
|
432
|
+ PID_PARAM(Ki, extruder) = scalePID_i(workKi); \
|
|
433
|
+ PID_PARAM(Kd, extruder) = scalePID_d(workKd); \
|
|
434
|
+ updatePID()
|
373
|
435
|
|
374
|
436
|
// Use the result? (As with "M303 U1")
|
375
|
437
|
if (set_result) {
|
376
|
|
- if (extruder < 0) {
|
377
|
|
- #if ENABLED(PIDTEMPBED)
|
378
|
|
- bedKp = workKp;
|
379
|
|
- bedKi = scalePID_i(workKi);
|
380
|
|
- bedKd = scalePID_d(workKd);
|
381
|
|
- updatePID();
|
382
|
|
- #endif
|
383
|
|
- }
|
384
|
|
- else {
|
385
|
|
- PID_PARAM(Kp, extruder) = workKp;
|
386
|
|
- PID_PARAM(Ki, extruder) = scalePID_i(workKi);
|
387
|
|
- PID_PARAM(Kd, extruder) = scalePID_d(workKd);
|
388
|
|
- updatePID();
|
389
|
|
- }
|
|
438
|
+ #if HAS_PID_FOR_BOTH
|
|
439
|
+ if (extruder < 0) {
|
|
440
|
+ _SET_BED_PID();
|
|
441
|
+ }
|
|
442
|
+ else {
|
|
443
|
+ _SET_EXTRUDER_PID();
|
|
444
|
+ }
|
|
445
|
+ #elif ENABLED(PIDTEMP)
|
|
446
|
+ _SET_EXTRUDER_PID();
|
|
447
|
+ #else
|
|
448
|
+ _SET_BED_PID();
|
|
449
|
+ #endif
|
390
|
450
|
}
|
391
|
451
|
return;
|
392
|
452
|
}
|