Browse Source

Tweak fan kickstart / speed code

Scott Lahteine 7 years ago
parent
commit
9e3c41f9e8
2 changed files with 77 additions and 67 deletions
  1. 1
    1
      .travis.yml
  2. 76
    66
      Marlin/src/module/planner.cpp

+ 1
- 1
.travis.yml View File

@@ -188,7 +188,7 @@ script:
188 188
   - opt_set_adv FAN_MIN_PWM 50
189 189
   - opt_set_adv FAN_KICKSTART_TIME 100
190 190
   - opt_set_adv XY_FREQUENCY_LIMIT  15
191
-  - opt_enable_adv SHOW_TEMP_ADC_VALUES HOME_Y_BEFORE_X EMERGENCY_PARSER
191
+  - opt_enable_adv SHOW_TEMP_ADC_VALUES HOME_Y_BEFORE_X EMERGENCY_PARSER FAN_KICKSTART_TIME
192 192
   - opt_enable_adv ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED ADVANCED_OK
193 193
   - opt_enable_adv VOLUMETRIC_DEFAULT_ON NO_WORKSPACE_OFFSETS ACTION_ON_KILL
194 194
   - opt_enable_adv EXTRA_FAN_SPEED FWERETRACT Z_DUAL_STEPPER_DRIVERS Z_DUAL_ENDSTOPS

+ 76
- 66
Marlin/src/module/planner.cpp View File

@@ -421,24 +421,77 @@ void Planner::check_axes_activity() {
421 421
   unsigned char axis_active[NUM_AXIS] = { 0 },
422 422
                 tail_fan_speed[FAN_COUNT];
423 423
 
424
-  #if FAN_COUNT > 0
425
-    for (uint8_t i = 0; i < FAN_COUNT; i++) tail_fan_speed[i] = fanSpeeds[i];
426
-  #endif
427
-
428 424
   #if ENABLED(BARICUDA)
429 425
     #if HAS_HEATER_1
430
-      uint8_t tail_valve_pressure = baricuda_valve_pressure;
426
+      uint8_t tail_valve_pressure;
431 427
     #endif
432 428
     #if HAS_HEATER_2
433
-      uint8_t tail_e_to_p_pressure = baricuda_e_to_p_pressure;
429
+      uint8_t tail_e_to_p_pressure;
434 430
     #endif
435 431
   #endif
436 432
 
437 433
   if (blocks_queued()) {
438 434
 
439 435
     #if FAN_COUNT > 0
440
-      for (uint8_t i = 0; i < FAN_COUNT; i++) tail_fan_speed[i] = block_buffer[block_buffer_tail].fan_speed[i];
441
-    #endif
436
+
437
+      for (uint8_t i = 0; i < FAN_COUNT; i++)
438
+        tail_fan_speed[i] = block_buffer[block_buffer_tail].fan_speed[i];
439
+
440
+      #ifdef FAN_KICKSTART_TIME
441
+
442
+        static millis_t fan_kick_end[FAN_COUNT] = { 0 };
443
+
444
+        #define KICKSTART_FAN(f)                         \
445
+          if (tail_fan_speed[f]) {                       \ // is the fan turned on?
446
+            millis_t ms = millis();                      \
447
+            if (fan_kick_end[f] == 0) {                  \ // not yet kickstarted?
448
+              fan_kick_end[f] = ms + FAN_KICKSTART_TIME; \ // kickstart until this time
449
+              tail_fan_speed[f] = 255;                   \ // full speed
450
+            } else if (PENDING(ms, fan_kick_end[f]))     \ // kickstart in progress?
451
+              tail_fan_speed[f] = 255;                   \ // keep full speed going
452
+          } else fan_kick_end[f] = 0                       // fan off? kick next time
453
+
454
+        #if HAS_FAN0
455
+          KICKSTART_FAN(0);
456
+        #endif
457
+        #if HAS_FAN1
458
+          KICKSTART_FAN(1);
459
+        #endif
460
+        #if HAS_FAN2
461
+          KICKSTART_FAN(2);
462
+        #endif
463
+
464
+      #endif // FAN_KICKSTART_TIME
465
+
466
+      #ifdef FAN_MIN_PWM
467
+        #define CALC_FAN_SPEED(f) (tail_fan_speed[f] ? ( FAN_MIN_PWM + (tail_fan_speed[f] * (255 - FAN_MIN_PWM)) / 255 ) : 0)
468
+      #else
469
+        #define CALC_FAN_SPEED(f) tail_fan_speed[f]
470
+      #endif
471
+
472
+      #if ENABLED(FAN_SOFT_PWM)
473
+        #if HAS_FAN0
474
+          thermalManager.soft_pwm_amount_fan[0] = CALC_FAN_SPEED(0);
475
+        #endif
476
+        #if HAS_FAN1
477
+          thermalManager.soft_pwm_amount_fan[1] = CALC_FAN_SPEED(1);
478
+        #endif
479
+        #if HAS_FAN2
480
+          thermalManager.soft_pwm_amount_fan[2] = CALC_FAN_SPEED(2);
481
+        #endif
482
+      #else
483
+        #if HAS_FAN0
484
+          analogWrite(FAN_PIN, CALC_FAN_SPEED(0));
485
+        #endif
486
+        #if HAS_FAN1
487
+          analogWrite(FAN1_PIN, CALC_FAN_SPEED(1));
488
+        #endif
489
+        #if HAS_FAN2
490
+          analogWrite(FAN2_PIN, CALC_FAN_SPEED(2));
491
+        #endif
492
+      #endif
493
+
494
+    #endif // FAN_COUNT > 0
442 495
 
443 496
     block_t* block;
444 497
 
@@ -457,6 +510,21 @@ void Planner::check_axes_activity() {
457 510
       LOOP_XYZE(i) if (block->steps[i]) axis_active[i]++;
458 511
     }
459 512
   }
513
+  else {
514
+    #if FAN_COUNT > 0
515
+      for (uint8_t i = 0; i < FAN_COUNT; i++) tail_fan_speed[i] = fanSpeeds[i];
516
+    #endif
517
+
518
+    #if ENABLED(BARICUDA)
519
+      #if HAS_HEATER_1
520
+        tail_valve_pressure = baricuda_valve_pressure;
521
+      #endif
522
+      #if HAS_HEATER_2
523
+        tail_e_to_p_pressure = baricuda_e_to_p_pressure;
524
+      #endif
525
+    #endif
526
+  }
527
+
460 528
   #if ENABLED(DISABLE_X)
461 529
     if (!axis_active[X_AXIS]) disable_X();
462 530
   #endif
@@ -470,64 +538,6 @@ void Planner::check_axes_activity() {
470 538
     if (!axis_active[E_AXIS]) disable_e_steppers();
471 539
   #endif
472 540
 
473
-  #if FAN_COUNT > 0
474
-
475
-    #ifdef FAN_MIN_PWM
476
-      #define CALC_FAN_SPEED(f) (tail_fan_speed[f] ? ( FAN_MIN_PWM + (tail_fan_speed[f] * (255 - FAN_MIN_PWM)) / 255 ) : 0)
477
-    #else
478
-      #define CALC_FAN_SPEED(f) tail_fan_speed[f]
479
-    #endif
480
-
481
-    #ifdef FAN_KICKSTART_TIME
482
-
483
-      static millis_t fan_kick_end[FAN_COUNT] = { 0 };
484
-
485
-      #define KICKSTART_FAN(f) \
486
-        if (tail_fan_speed[f]) { \
487
-          millis_t ms = millis(); \
488
-          if (fan_kick_end[f] == 0) { \
489
-            fan_kick_end[f] = ms + FAN_KICKSTART_TIME; \
490
-            tail_fan_speed[f] = 255; \
491
-          } else if (PENDING(ms, fan_kick_end[f])) \
492
-            tail_fan_speed[f] = 255; \
493
-        } else fan_kick_end[f] = 0
494
-
495
-      #if HAS_FAN0
496
-        KICKSTART_FAN(0);
497
-      #endif
498
-      #if HAS_FAN1
499
-        KICKSTART_FAN(1);
500
-      #endif
501
-      #if HAS_FAN2
502
-        KICKSTART_FAN(2);
503
-      #endif
504
-
505
-    #endif // FAN_KICKSTART_TIME
506
-
507
-    #if ENABLED(FAN_SOFT_PWM)
508
-      #if HAS_FAN0
509
-        thermalManager.soft_pwm_amount_fan[0] = CALC_FAN_SPEED(0);
510
-      #endif
511
-      #if HAS_FAN1
512
-        thermalManager.soft_pwm_amount_fan[1] = CALC_FAN_SPEED(1);
513
-      #endif
514
-      #if HAS_FAN2
515
-        thermalManager.soft_pwm_amount_fan[2] = CALC_FAN_SPEED(2);
516
-      #endif
517
-    #else
518
-      #if HAS_FAN0
519
-        analogWrite(FAN_PIN, CALC_FAN_SPEED(0));
520
-      #endif
521
-      #if HAS_FAN1
522
-        analogWrite(FAN1_PIN, CALC_FAN_SPEED(1));
523
-      #endif
524
-      #if HAS_FAN2
525
-        analogWrite(FAN2_PIN, CALC_FAN_SPEED(2));
526
-      #endif
527
-    #endif
528
-
529
-  #endif // FAN_COUNT > 0
530
-
531 541
   #if ENABLED(AUTOTEMP)
532 542
     getHighESpeed();
533 543
   #endif

Loading…
Cancel
Save