Browse Source

Merge pull request #11275 from thinkyhead/bf2_pwm_adjustments

[2.0.x] Tweak some SoftPWM code
Scott Lahteine 7 years ago
parent
commit
048dbf6eca
No account linked to committer's email address

+ 4
- 0
Marlin/src/config/examples/Creality/CR-10S/Configuration.h View File

134
 // Please choose the name from boards.h that matches your setup
134
 // Please choose the name from boards.h that matches your setup
135
 #ifndef MOTHERBOARD
135
 #ifndef MOTHERBOARD
136
   #define MOTHERBOARD BOARD_RAMPS_14_EFB
136
   #define MOTHERBOARD BOARD_RAMPS_14_EFB
137
+  #define PIN_EXP1 65 // A11
138
+  #define PIN_EXP2 66 // A12
139
+  #define PIN_EXP3 11 // SERVO0_PIN
140
+  #define PIN_EXP4 12 // PS_ON_PIN
137
 #endif
141
 #endif
138
 
142
 
139
 // Optional custom name for your RepStrap or other custom machine
143
 // Optional custom name for your RepStrap or other custom machine

+ 35
- 66
Marlin/src/module/temperature.cpp View File

267
           workKp = 0, workKi = 0, workKd = 0,
267
           workKp = 0, workKi = 0, workKd = 0,
268
           max = 0, min = 10000;
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
     #else
276
     #else
276
-      #define TV(B,H) (H)
277
+      #define GHV(B,H) H
278
+      #define SHV(S,B,H) (S [hotend] = H)
277
     #endif
279
     #endif
278
 
280
 
279
     #if WATCH_THE_BED || WATCH_HOTENDS
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
       millis_t temp_change_ms = next_temp_ms + watch_temp_period * 1000UL;
293
       millis_t temp_change_ms = next_temp_ms + watch_temp_period * 1000UL;
284
       float next_watch_temp = 0.0;
294
       float next_watch_temp = 0.0;
285
       bool heated = false;
295
       bool heated = false;
309
 
319
 
310
     disable_all_heaters(); // switch off all heaters.
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
     wait_for_heatup = true; // Can be interrupted with M108
324
     wait_for_heatup = true; // Can be interrupted with M108
324
 
325
 
331
         updateTemperaturesFromRawValues();
332
         updateTemperaturesFromRawValues();
332
 
333
 
333
         // Get the current temperature and constrain it
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
         NOLESS(max, current);
336
         NOLESS(max, current);
344
         NOMORE(min, current);
337
         NOMORE(min, current);
345
 
338
 
353
         if (heating && current > target) {
346
         if (heating && current > target) {
354
           if (ELAPSED(ms, t2 + 5000UL)) {
347
           if (ELAPSED(ms, t2 + 5000UL)) {
355
             heating = false;
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
             t1 = ms;
350
             t1 = ms;
367
             t_high = t1 - t2;
351
             t_high = t1 - t2;
368
             max = target;
352
             max = target;
375
             t2 = ms;
359
             t2 = ms;
376
             t_low = t2 - t1;
360
             t_low = t2 - t1;
377
             if (cycles > 0) {
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
               bias += (d * (t_high - t_low)) / (t_low + t_high);
363
               bias += (d * (t_high - t_low)) / (t_low + t_high);
388
               bias = constrain(bias, 20, max_pow - 20);
364
               bias = constrain(bias, 20, max_pow - 20);
389
               d = (bias > max_pow >> 1) ? max_pow - 1 - bias : bias;
365
               d = (bias > max_pow >> 1) ? max_pow - 1 - bias : bias;
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
             cycles++;
402
             cycles++;
436
             min = target;
403
             min = target;
437
           }
404
           }
460
           if (
427
           if (
461
             #if WATCH_THE_BED && WATCH_HOTENDS
428
             #if WATCH_THE_BED && WATCH_HOTENDS
462
               true
429
               true
463
-            #elif WATCH_THE_BED
464
-              hotend < 0
465
-            #else
430
+            #elif WATCH_HOTENDS
466
               hotend >= 0
431
               hotend >= 0
432
+            #else
433
+              hotend < 0
467
             #endif
434
             #endif
468
           ) {
435
           ) {
469
             if (!heated) {                                          // If not yet reached target...
436
             if (!heated) {                                          // If not yet reached target...
494
         SERIAL_PROTOCOLLNPGM(MSG_PID_AUTOTUNE_FINISHED);
461
         SERIAL_PROTOCOLLNPGM(MSG_PID_AUTOTUNE_FINISHED);
495
 
462
 
496
         #if HAS_PID_FOR_BOTH
463
         #if HAS_PID_FOR_BOTH
497
-          const char* estring = hotend < 0 ? "bed" : "";
464
+          const char* estring = GHV("bed", "");
498
           SERIAL_PROTOCOLPAIR("#define DEFAULT_", estring); SERIAL_PROTOCOLPAIR("Kp ", workKp); SERIAL_EOL();
465
           SERIAL_PROTOCOLPAIR("#define DEFAULT_", estring); SERIAL_PROTOCOLPAIR("Kp ", workKp); SERIAL_EOL();
499
           SERIAL_PROTOCOLPAIR("#define DEFAULT_", estring); SERIAL_PROTOCOLPAIR("Ki ", workKi); SERIAL_EOL();
466
           SERIAL_PROTOCOLPAIR("#define DEFAULT_", estring); SERIAL_PROTOCOLPAIR("Ki ", workKi); SERIAL_EOL();
500
           SERIAL_PROTOCOLPAIR("#define DEFAULT_", estring); SERIAL_PROTOCOLPAIR("Kd ", workKd); SERIAL_EOL();
467
           SERIAL_PROTOCOLPAIR("#define DEFAULT_", estring); SERIAL_PROTOCOLPAIR("Kd ", workKd); SERIAL_EOL();
582
 
549
 
583
     uint8_t fanDone = 0;
550
     uint8_t fanDone = 0;
584
     for (uint8_t f = 0; f < COUNT(fanPin); f++) {
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
       const uint8_t bit = pgm_read_byte(&fanBit[f]);
559
       const uint8_t bit = pgm_read_byte(&fanBit[f]);
591
       if (pin >= 0 && !TEST(fanDone, bit)) {
560
       if (pin >= 0 && !TEST(fanDone, bit)) {
592
         uint8_t newFanSpeed = TEST(fanState, bit) ? EXTRUDER_AUTO_FAN_SPEED : 0;
561
         uint8_t newFanSpeed = TEST(fanState, bit) ? EXTRUDER_AUTO_FAN_SPEED : 0;

Loading…
Cancel
Save