|
@@ -267,19 +267,29 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
|
267
|
267
|
workKp = 0, workKi = 0, workKd = 0,
|
268
|
268
|
max = 0, min = 10000;
|
269
|
269
|
|
270
|
|
- #define HAS_TP_BED (ENABLED(THERMAL_PROTECTION_BED) && ENABLED(PIDTEMPBED))
|
271
|
|
- #if HAS_TP_BED && ENABLED(THERMAL_PROTECTION_HOTENDS) && ENABLED(PIDTEMP)
|
272
|
|
- #define TV(B,H) (hotend < 0 ? (B) : (H))
|
273
|
|
- #elif HAS_TP_BED
|
274
|
|
- #define TV(B,H) (B)
|
|
270
|
+ #if HAS_PID_FOR_BOTH
|
|
271
|
+ #define GHV(B,H) (hotend < 0 ? (B) : (H))
|
|
272
|
+ #define SHV(S,B,H) if (hotend < 0) S##_bed = B; else S [hotend] = H;
|
|
273
|
+ #elif ENABLED(PIDTEMPBED)
|
|
274
|
+ #define GHV(B,H) B
|
|
275
|
+ #define SHV(S,B,H) (S##_bed = B)
|
275
|
276
|
#else
|
276
|
|
- #define TV(B,H) (H)
|
|
277
|
+ #define GHV(B,H) H
|
|
278
|
+ #define SHV(S,B,H) (S [hotend] = H)
|
277
|
279
|
#endif
|
278
|
280
|
|
279
|
281
|
#if WATCH_THE_BED || WATCH_HOTENDS
|
280
|
|
- const uint16_t watch_temp_period = TV(WATCH_BED_TEMP_PERIOD, WATCH_TEMP_PERIOD);
|
281
|
|
- const uint8_t watch_temp_increase = TV(WATCH_BED_TEMP_INCREASE, WATCH_TEMP_INCREASE);
|
282
|
|
- const float watch_temp_target = target - float(watch_temp_increase + TV(TEMP_BED_HYSTERESIS, TEMP_HYSTERESIS) + 1);
|
|
282
|
+ #define HAS_TP_BED (ENABLED(THERMAL_PROTECTION_BED) && ENABLED(PIDTEMPBED))
|
|
283
|
+ #if HAS_TP_BED && ENABLED(THERMAL_PROTECTION_HOTENDS) && ENABLED(PIDTEMP)
|
|
284
|
+ #define GTV(B,H) (hotend < 0 ? (B) : (H))
|
|
285
|
+ #elif HAS_TP_BED
|
|
286
|
+ #define GTV(B,H) (B)
|
|
287
|
+ #else
|
|
288
|
+ #define GTV(B,H) (H)
|
|
289
|
+ #endif
|
|
290
|
+ const uint16_t watch_temp_period = GTV(WATCH_BED_TEMP_PERIOD, WATCH_TEMP_PERIOD);
|
|
291
|
+ const uint8_t watch_temp_increase = GTV(WATCH_BED_TEMP_INCREASE, WATCH_TEMP_INCREASE);
|
|
292
|
+ const float watch_temp_target = target - float(watch_temp_increase + GTV(TEMP_BED_HYSTERESIS, TEMP_HYSTERESIS) + 1);
|
283
|
293
|
millis_t temp_change_ms = next_temp_ms + watch_temp_period * 1000UL;
|
284
|
294
|
float next_watch_temp = 0.0;
|
285
|
295
|
bool heated = false;
|
|
@@ -309,16 +319,7 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
|
309
|
319
|
|
310
|
320
|
disable_all_heaters(); // switch off all heaters.
|
311
|
321
|
|
312
|
|
- #if HAS_PID_FOR_BOTH
|
313
|
|
- if (hotend < 0)
|
314
|
|
- soft_pwm_amount_bed = bias = d = (MAX_BED_POWER) >> 1;
|
315
|
|
- else
|
316
|
|
- soft_pwm_amount[hotend] = bias = d = (PID_MAX) >> 1;
|
317
|
|
- #elif ENABLED(PIDTEMP)
|
318
|
|
- soft_pwm_amount[hotend] = bias = d = (PID_MAX) >> 1;
|
319
|
|
- #else
|
320
|
|
- soft_pwm_amount_bed = bias = d = (MAX_BED_POWER) >> 1;
|
321
|
|
- #endif
|
|
322
|
+ SHV(soft_pwm_amount, bias = d = (MAX_BED_POWER) >> 1, bias = d = (PID_MAX) >> 1);
|
322
|
323
|
|
323
|
324
|
wait_for_heatup = true; // Can be interrupted with M108
|
324
|
325
|
|
|
@@ -331,15 +332,7 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
|
331
|
332
|
updateTemperaturesFromRawValues();
|
332
|
333
|
|
333
|
334
|
// Get the current temperature and constrain it
|
334
|
|
- current =
|
335
|
|
- #if HAS_PID_FOR_BOTH
|
336
|
|
- hotend < 0 ? current_temperature_bed : current_temperature[hotend]
|
337
|
|
- #elif ENABLED(PIDTEMP)
|
338
|
|
- current_temperature[hotend]
|
339
|
|
- #else
|
340
|
|
- current_temperature_bed
|
341
|
|
- #endif
|
342
|
|
- ;
|
|
335
|
+ current = GHV(current_temperature_bed, current_temperature[hotend]);
|
343
|
336
|
NOLESS(max, current);
|
344
|
337
|
NOMORE(min, current);
|
345
|
338
|
|
|
@@ -353,16 +346,7 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
|
353
|
346
|
if (heating && current > target) {
|
354
|
347
|
if (ELAPSED(ms, t2 + 5000UL)) {
|
355
|
348
|
heating = false;
|
356
|
|
- #if HAS_PID_FOR_BOTH
|
357
|
|
- if (hotend < 0)
|
358
|
|
- soft_pwm_amount_bed = (bias - d) >> 1;
|
359
|
|
- else
|
360
|
|
- soft_pwm_amount[hotend] = (bias - d) >> 1;
|
361
|
|
- #elif ENABLED(PIDTEMP)
|
362
|
|
- soft_pwm_amount[hotend] = (bias - d) >> 1;
|
363
|
|
- #elif ENABLED(PIDTEMPBED)
|
364
|
|
- soft_pwm_amount_bed = (bias - d) >> 1;
|
365
|
|
- #endif
|
|
349
|
+ SHV(soft_pwm_amount, (bias - d) >> 1, (bias - d) >> 1);
|
366
|
350
|
t1 = ms;
|
367
|
351
|
t_high = t1 - t2;
|
368
|
352
|
max = target;
|
|
@@ -375,15 +359,7 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
|
375
|
359
|
t2 = ms;
|
376
|
360
|
t_low = t2 - t1;
|
377
|
361
|
if (cycles > 0) {
|
378
|
|
- long max_pow =
|
379
|
|
- #if HAS_PID_FOR_BOTH
|
380
|
|
- hotend < 0 ? MAX_BED_POWER : PID_MAX
|
381
|
|
- #elif ENABLED(PIDTEMP)
|
382
|
|
- PID_MAX
|
383
|
|
- #else
|
384
|
|
- MAX_BED_POWER
|
385
|
|
- #endif
|
386
|
|
- ;
|
|
362
|
+ const long max_pow = GHV(MAX_BED_POWER, PID_MAX);
|
387
|
363
|
bias += (d * (t_high - t_low)) / (t_low + t_high);
|
388
|
364
|
bias = constrain(bias, 20, max_pow - 20);
|
389
|
365
|
d = (bias > max_pow >> 1) ? max_pow - 1 - bias : bias;
|
|
@@ -422,16 +398,7 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
|
422
|
398
|
*/
|
423
|
399
|
}
|
424
|
400
|
}
|
425
|
|
- #if HAS_PID_FOR_BOTH
|
426
|
|
- if (hotend < 0)
|
427
|
|
- soft_pwm_amount_bed = (bias + d) >> 1;
|
428
|
|
- else
|
429
|
|
- soft_pwm_amount[hotend] = (bias + d) >> 1;
|
430
|
|
- #elif ENABLED(PIDTEMP)
|
431
|
|
- soft_pwm_amount[hotend] = (bias + d) >> 1;
|
432
|
|
- #else
|
433
|
|
- soft_pwm_amount_bed = (bias + d) >> 1;
|
434
|
|
- #endif
|
|
401
|
+ SHV(soft_pwm_amount, (bias + d) >> 1, (bias + d) >> 1);
|
435
|
402
|
cycles++;
|
436
|
403
|
min = target;
|
437
|
404
|
}
|
|
@@ -460,10 +427,10 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
|
460
|
427
|
if (
|
461
|
428
|
#if WATCH_THE_BED && WATCH_HOTENDS
|
462
|
429
|
true
|
463
|
|
- #elif WATCH_THE_BED
|
464
|
|
- hotend < 0
|
465
|
|
- #else
|
|
430
|
+ #elif WATCH_HOTENDS
|
466
|
431
|
hotend >= 0
|
|
432
|
+ #else
|
|
433
|
+ hotend < 0
|
467
|
434
|
#endif
|
468
|
435
|
) {
|
469
|
436
|
if (!heated) { // If not yet reached target...
|
|
@@ -494,7 +461,7 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
|
494
|
461
|
SERIAL_PROTOCOLLNPGM(MSG_PID_AUTOTUNE_FINISHED);
|
495
|
462
|
|
496
|
463
|
#if HAS_PID_FOR_BOTH
|
497
|
|
- const char* estring = hotend < 0 ? "bed" : "";
|
|
464
|
+ const char* estring = GHV("bed", "");
|
498
|
465
|
SERIAL_PROTOCOLPAIR("#define DEFAULT_", estring); SERIAL_PROTOCOLPAIR("Kp ", workKp); SERIAL_EOL();
|
499
|
466
|
SERIAL_PROTOCOLPAIR("#define DEFAULT_", estring); SERIAL_PROTOCOLPAIR("Ki ", workKi); SERIAL_EOL();
|
500
|
467
|
SERIAL_PROTOCOLPAIR("#define DEFAULT_", estring); SERIAL_PROTOCOLPAIR("Kd ", workKd); SERIAL_EOL();
|
|
@@ -582,11 +549,13 @@ int Temperature::getHeaterPower(const int heater) {
|
582
|
549
|
|
583
|
550
|
uint8_t fanDone = 0;
|
584
|
551
|
for (uint8_t f = 0; f < COUNT(fanPin); f++) {
|
585
|
|
- #ifdef ARDUINO
|
586
|
|
- pin_t pin = pgm_read_byte(&fanPin[f]);
|
587
|
|
- #else
|
588
|
|
- pin_t pin = fanPin[f];
|
589
|
|
- #endif
|
|
552
|
+ const pin_t pin =
|
|
553
|
+ #ifdef ARDUINO
|
|
554
|
+ pgm_read_byte(&fanPin[f])
|
|
555
|
+ #else
|
|
556
|
+ fanPin[f]
|
|
557
|
+ #endif
|
|
558
|
+ ;
|
590
|
559
|
const uint8_t bit = pgm_read_byte(&fanBit[f]);
|
591
|
560
|
if (pin >= 0 && !TEST(fanDone, bit)) {
|
592
|
561
|
uint8_t newFanSpeed = TEST(fanState, bit) ? EXTRUDER_AUTO_FAN_SPEED : 0;
|