Browse Source

Merge pull request #3676 from thinkyhead/rc_lin_advance_feature

Advance extrusion algorithm – LIN_ADVANCE
Scott Lahteine 9 years ago
parent
commit
587de1b6b6
8 changed files with 210 additions and 44 deletions
  1. 2
    0
      .travis.yml
  2. 9
    0
      Marlin/Configuration_adv.h
  3. 16
    0
      Marlin/Marlin_main.cpp
  4. 7
    1
      Marlin/SanityCheck.h
  5. 19
    2
      Marlin/planner.cpp
  6. 5
    1
      Marlin/planner.h
  7. 122
    31
      Marlin/stepper.cpp
  8. 30
    9
      Marlin/stepper.h

+ 2
- 0
.travis.yml View File

76
   - build_marlin
76
   - build_marlin
77
   #
77
   #
78
   # Test 3 extruders on RUMBA (can use any board with >=3 extruders defined)
78
   # Test 3 extruders on RUMBA (can use any board with >=3 extruders defined)
79
+  # Include a test for LIN_ADVANCE here also
79
   #
80
   #
80
   - opt_set MOTHERBOARD BOARD_RUMBA
81
   - opt_set MOTHERBOARD BOARD_RUMBA
81
   - opt_set EXTRUDERS 3
82
   - opt_set EXTRUDERS 3
82
   - opt_set TEMP_SENSOR_2 1
83
   - opt_set TEMP_SENSOR_2 1
84
+  - opt_enable_adv LIN_ADVANCE
83
   - build_marlin
85
   - build_marlin
84
   #
86
   #
85
   # Test PIDTEMPBED
87
   # Test PIDTEMPBED

+ 9
- 0
Marlin/Configuration_adv.h View File

445
   #define D_FILAMENT 2.85
445
   #define D_FILAMENT 2.85
446
 #endif
446
 #endif
447
 
447
 
448
+// Implementation of a linear pressure control
449
+// Assumption: advance = k * (delta velocity)
450
+// K=0 means advance disabled. A good value for a gregs wade extruder will be around K=75
451
+//#define LIN_ADVANCE
452
+
453
+#if ENABLED(LIN_ADVANCE)
454
+  #define LIN_ADVANCE_K 75
455
+#endif
456
+
448
 // @section leveling
457
 // @section leveling
449
 
458
 
450
 // Default mesh area is an area with an inset margin on the print area.
459
 // Default mesh area is an area with an inset margin on the print area.

+ 16
- 0
Marlin/Marlin_main.cpp View File

6475
 
6475
 
6476
 #endif // DUAL_X_CARRIAGE
6476
 #endif // DUAL_X_CARRIAGE
6477
 
6477
 
6478
+#if ENABLED(LIN_ADVANCE)
6479
+  /**
6480
+   * M905: Set advance factor
6481
+   */
6482
+  inline void gcode_M905() {
6483
+    stepper.synchronize();
6484
+    stepper.advance_M905();
6485
+  }
6486
+#endif
6487
+
6478
 /**
6488
 /**
6479
  * M907: Set digital trimpot motor current using axis codes X, Y, Z, E, B, S
6489
  * M907: Set digital trimpot motor current using axis codes X, Y, Z, E, B, S
6480
  */
6490
  */
7347
           gcode_M605();
7357
           gcode_M605();
7348
           break;
7358
           break;
7349
       #endif // DUAL_X_CARRIAGE
7359
       #endif // DUAL_X_CARRIAGE
7360
+      
7361
+      #if ENABLED(LIN_ADVANCE)
7362
+        case 905: // M905 Set advance factor.
7363
+          gcode_M905();
7364
+          break;
7365
+      #endif
7350
 
7366
 
7351
       case 907: // M907 Set digital trimpot motor current using axis codes.
7367
       case 907: // M907 Set digital trimpot motor current using axis codes.
7352
         gcode_M907();
7368
         gcode_M907();

+ 7
- 1
Marlin/SanityCheck.h View File

352
 #endif // AUTO_BED_LEVELING_FEATURE
352
 #endif // AUTO_BED_LEVELING_FEATURE
353
 
353
 
354
 /**
354
 /**
355
+ * Advance Extrusion
356
+ */
357
+#if ENABLED(ADVANCE) && ENABLED(LIN_ADVANCE)
358
+  #error You can enable ADVANCE or LIN_ADVANCE, but not both.
359
+#endif
360
+
361
+/**
355
  * Filament Width Sensor
362
  * Filament Width Sensor
356
  */
363
  */
357
 #if ENABLED(FILAMENT_WIDTH_SENSOR) && !HAS_FILAMENT_WIDTH_SENSOR
364
 #if ENABLED(FILAMENT_WIDTH_SENSOR) && !HAS_FILAMENT_WIDTH_SENSOR
358
   #error "FILAMENT_WIDTH_SENSOR requires a FILWIDTH_PIN to be defined."
365
   #error "FILAMENT_WIDTH_SENSOR requires a FILWIDTH_PIN to be defined."
359
 #endif
366
 #endif
360
 
367
 
361
-
362
 /**
368
 /**
363
  * ULTIPANEL encoder
369
  * ULTIPANEL encoder
364
  */
370
  */

+ 19
- 2
Marlin/planner.cpp View File

1050
   for (int i = 0; i < NUM_AXIS; i++) previous_speed[i] = current_speed[i];
1050
   for (int i = 0; i < NUM_AXIS; i++) previous_speed[i] = current_speed[i];
1051
   previous_nominal_speed = block->nominal_speed;
1051
   previous_nominal_speed = block->nominal_speed;
1052
 
1052
 
1053
-  #if ENABLED(ADVANCE)
1053
+  #if ENABLED(LIN_ADVANCE)
1054
+
1055
+    // bse == allsteps: A problem occurs when there's a very tiny move before a retract.
1056
+    // In this case, the retract and the move will be executed together.
1057
+    // This leads to an enormous number of advance steps due to a huge e_acceleration.
1058
+    // The math is correct, but you don't want a retract move done with advance!
1059
+    // So this situation is filtered out here.
1060
+    if (!bse || (!bsx && !bsy && !bsz) || stepper.get_advance_k() == 0 || bse == allsteps) {
1061
+      block->use_advance_lead = false;
1062
+    }
1063
+    else {
1064
+      block->use_advance_lead = true;
1065
+      block->e_speed_multiplier8 = (block->steps[E_AXIS] << 8) / block->step_event_count;
1066
+    }
1067
+
1068
+  #elif ENABLED(ADVANCE)
1069
+
1054
     // Calculate advance rate
1070
     // Calculate advance rate
1055
     if (!bse || (!bsx && !bsy && !bsz)) {
1071
     if (!bse || (!bsx && !bsy && !bsz)) {
1056
       block->advance_rate = 0;
1072
       block->advance_rate = 0;
1069
      SERIAL_ECHOPGM("advance rate :");
1085
      SERIAL_ECHOPGM("advance rate :");
1070
      SERIAL_ECHOLN(block->advance_rate/256.0);
1086
      SERIAL_ECHOLN(block->advance_rate/256.0);
1071
      */
1087
      */
1072
-  #endif // ADVANCE
1088
+
1089
+  #endif // ADVANCE or LIN_ADVANCE
1073
 
1090
 
1074
   calculate_trapezoid_for_block(block, block->entry_speed / block->nominal_speed, safe_speed / block->nominal_speed);
1091
   calculate_trapezoid_for_block(block, block->entry_speed / block->nominal_speed, safe_speed / block->nominal_speed);
1075
 
1092
 

+ 5
- 1
Marlin/planner.h View File

64
 
64
 
65
   unsigned char direction_bits;             // The direction bit set for this block (refers to *_DIRECTION_BIT in config.h)
65
   unsigned char direction_bits;             // The direction bit set for this block (refers to *_DIRECTION_BIT in config.h)
66
 
66
 
67
-  #if ENABLED(ADVANCE)
67
+  // Advance extrusion
68
+  #if ENABLED(LIN_ADVANCE)
69
+    bool use_advance_lead;
70
+    int e_speed_multiplier8; // Factorised by 2^8 to avoid float
71
+  #elif ENABLED(ADVANCE)
68
     long advance_rate;
72
     long advance_rate;
69
     volatile long initial_advance;
73
     volatile long initial_advance;
70
     volatile long final_advance;
74
     volatile long final_advance;

+ 122
- 31
Marlin/stepper.cpp View File

89
 
89
 
90
 volatile unsigned long Stepper::step_events_completed = 0; // The number of step events executed in the current block
90
 volatile unsigned long Stepper::step_events_completed = 0; // The number of step events executed in the current block
91
 
91
 
92
-#if ENABLED(ADVANCE)
92
+#if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
93
+
93
   unsigned char Stepper::old_OCR0A;
94
   unsigned char Stepper::old_OCR0A;
94
-  long  Stepper::final_advance = 0,
95
-        Stepper::old_advance = 0,
96
-        Stepper::e_steps[EXTRUDERS],
97
-        Stepper::advance_rate,
98
-        Stepper::advance;
95
+  volatile unsigned char Stepper::eISR_Rate = 200; // Keep the ISR at a low rate until needed
96
+
97
+  #if ENABLED(LIN_ADVANCE)
98
+    volatile int Stepper::e_steps[EXTRUDERS];
99
+    int Stepper::extruder_advance_k = LIN_ADVANCE_K,
100
+        Stepper::final_estep_rate,
101
+        Stepper::current_estep_rate[EXTRUDERS],
102
+        Stepper::current_adv_steps[EXTRUDERS];
103
+  #else
104
+    long  Stepper::e_steps[EXTRUDERS],
105
+          Stepper::final_advance = 0,
106
+          Stepper::old_advance = 0,
107
+          Stepper::advance_rate,
108
+          Stepper::advance;
109
+  #endif
99
 #endif
110
 #endif
100
 
111
 
101
 long Stepper::acceleration_time, Stepper::deceleration_time;
112
 long Stepper::acceleration_time, Stepper::deceleration_time;
344
         customizedSerial.checkRx(); // Check for serial chars.
355
         customizedSerial.checkRx(); // Check for serial chars.
345
       #endif
356
       #endif
346
 
357
 
347
-      #if ENABLED(ADVANCE)
358
+      #if ENABLED(LIN_ADVANCE)
359
+
360
+        counter_E += current_block->steps[E_AXIS];
361
+        if (counter_E > 0) {
362
+          counter_E -= current_block->step_event_count;
363
+          count_position[E_AXIS] += count_direction[E_AXIS];
364
+          e_steps[current_block->active_extruder] += motor_direction(E_AXIS) ? -1 : 1;
365
+        }
366
+
367
+        if (current_block->use_advance_lead) {
368
+          int delta_adv_steps; //Maybe a char would be enough?
369
+          delta_adv_steps = (((long)extruder_advance_k * current_estep_rate[current_block->active_extruder]) >> 9) - current_adv_steps[current_block->active_extruder];
370
+          e_steps[current_block->active_extruder] += delta_adv_steps;
371
+          current_adv_steps[current_block->active_extruder] += delta_adv_steps;
372
+        }
373
+
374
+      #elif ENABLED(ADVANCE)
375
+
348
         counter_E += current_block->steps[E_AXIS];
376
         counter_E += current_block->steps[E_AXIS];
349
         if (counter_E > 0) {
377
         if (counter_E > 0) {
350
           counter_E -= current_block->step_event_count;
378
           counter_E -= current_block->step_event_count;
351
           e_steps[current_block->active_extruder] += motor_direction(E_AXIS) ? -1 : 1;
379
           e_steps[current_block->active_extruder] += motor_direction(E_AXIS) ? -1 : 1;
352
         }
380
         }
353
-      #endif //ADVANCE
354
 
381
 
382
+      #endif // ADVANCE or LIN_ADVANCE
383
+      
355
       #define _COUNTER(AXIS) counter_## AXIS
384
       #define _COUNTER(AXIS) counter_## AXIS
356
       #define _APPLY_STEP(AXIS) AXIS ##_APPLY_STEP
385
       #define _APPLY_STEP(AXIS) AXIS ##_APPLY_STEP
357
       #define _INVERT_STEP_PIN(AXIS) INVERT_## AXIS ##_STEP_PIN
386
       #define _INVERT_STEP_PIN(AXIS) INVERT_## AXIS ##_STEP_PIN
363
       STEP_ADD(X);
392
       STEP_ADD(X);
364
       STEP_ADD(Y);
393
       STEP_ADD(Y);
365
       STEP_ADD(Z);
394
       STEP_ADD(Z);
366
-      #if DISABLED(ADVANCE)
395
+      #if DISABLED(ADVANCE) && DISABLED(LIN_ADVANCE)
367
         STEP_ADD(E);
396
         STEP_ADD(E);
368
       #endif
397
       #endif
369
 
398
 
377
       STEP_IF_COUNTER(X);
406
       STEP_IF_COUNTER(X);
378
       STEP_IF_COUNTER(Y);
407
       STEP_IF_COUNTER(Y);
379
       STEP_IF_COUNTER(Z);
408
       STEP_IF_COUNTER(Z);
380
-      #if DISABLED(ADVANCE)
409
+      #if DISABLED(ADVANCE) && DISABLED(LIN_ADVANCE)
381
         STEP_IF_COUNTER(E);
410
         STEP_IF_COUNTER(E);
382
       #endif
411
       #endif
383
 
412
 
384
       step_events_completed++;
413
       step_events_completed++;
385
       if (step_events_completed >= current_block->step_event_count) break;
414
       if (step_events_completed >= current_block->step_event_count) break;
386
     }
415
     }
416
+
417
+    #if ENABLED(LIN_ADVANCE)
418
+      // If we have esteps to execute, fire the next ISR "now"
419
+      if (e_steps[current_block->active_extruder]) OCR0A = TCNT0 + 2;
420
+    #endif
421
+
387
     // Calculate new timer value
422
     // Calculate new timer value
388
     unsigned short timer, step_rate;
423
     unsigned short timer, step_rate;
389
     if (step_events_completed <= (unsigned long)current_block->accelerate_until) {
424
     if (step_events_completed <= (unsigned long)current_block->accelerate_until) {
399
       OCR1A = timer;
434
       OCR1A = timer;
400
       acceleration_time += timer;
435
       acceleration_time += timer;
401
 
436
 
402
-      #if ENABLED(ADVANCE)
437
+      #if ENABLED(LIN_ADVANCE)
438
+
439
+        if (current_block->use_advance_lead)
440
+          current_estep_rate[current_block->active_extruder] = ((unsigned long)acc_step_rate * current_block->e_speed_multiplier8) >> 8;
441
+
442
+      #elif ENABLED(ADVANCE)
403
 
443
 
404
         advance += advance_rate * step_loops;
444
         advance += advance_rate * step_loops;
405
         //NOLESS(advance, current_block->advance);
445
         //NOLESS(advance, current_block->advance);
408
         e_steps[current_block->active_extruder] += ((advance >> 8) - old_advance);
448
         e_steps[current_block->active_extruder] += ((advance >> 8) - old_advance);
409
         old_advance = advance >> 8;
449
         old_advance = advance >> 8;
410
 
450
 
411
-      #endif //ADVANCE
451
+      #endif // ADVANCE or LIN_ADVANCE
452
+
453
+      #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
454
+        eISR_Rate = (timer >> 2) / abs(e_steps[current_block->active_extruder]);
455
+      #endif
412
     }
456
     }
413
     else if (step_events_completed > (unsigned long)current_block->decelerate_after) {
457
     else if (step_events_completed > (unsigned long)current_block->decelerate_after) {
414
       MultiU24X32toH16(step_rate, deceleration_time, current_block->acceleration_rate);
458
       MultiU24X32toH16(step_rate, deceleration_time, current_block->acceleration_rate);
424
       timer = calc_timer(step_rate);
468
       timer = calc_timer(step_rate);
425
       OCR1A = timer;
469
       OCR1A = timer;
426
       deceleration_time += timer;
470
       deceleration_time += timer;
471
+      
472
+      #if ENABLED(LIN_ADVANCE)
473
+
474
+        if (current_block->use_advance_lead)
475
+          current_estep_rate[current_block->active_extruder] = ((unsigned long)step_rate * current_block->e_speed_multiplier8) >> 8;
476
+
477
+      #elif ENABLED(ADVANCE)
427
 
478
 
428
-      #if ENABLED(ADVANCE)
429
         advance -= advance_rate * step_loops;
479
         advance -= advance_rate * step_loops;
430
         NOLESS(advance, final_advance);
480
         NOLESS(advance, final_advance);
431
 
481
 
433
         uint32_t advance_whole = advance >> 8;
483
         uint32_t advance_whole = advance >> 8;
434
         e_steps[current_block->active_extruder] += advance_whole - old_advance;
484
         e_steps[current_block->active_extruder] += advance_whole - old_advance;
435
         old_advance = advance_whole;
485
         old_advance = advance_whole;
436
-      #endif //ADVANCE
486
+
487
+      #endif // ADVANCE or LIN_ADVANCE
488
+
489
+      #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
490
+        eISR_Rate = (timer >> 2) / abs(e_steps[current_block->active_extruder]);
491
+      #endif
437
     }
492
     }
438
     else {
493
     else {
494
+
495
+      #if ENABLED(LIN_ADVANCE)
496
+
497
+        if (current_block->use_advance_lead)
498
+          current_estep_rate[current_block->active_extruder] = final_estep_rate;
499
+
500
+        eISR_Rate = (OCR1A_nominal >> 2) / abs(e_steps[current_block->active_extruder]);
501
+
502
+      #endif
503
+
439
       OCR1A = OCR1A_nominal;
504
       OCR1A = OCR1A_nominal;
440
       // ensure we're running at the correct step rate, even if we just came off an acceleration
505
       // ensure we're running at the correct step rate, even if we just came off an acceleration
441
       step_loops = step_loops_nominal;
506
       step_loops = step_loops_nominal;
451
   }
516
   }
452
 }
517
 }
453
 
518
 
454
-#if ENABLED(ADVANCE)
519
+#if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
520
+
455
   // Timer interrupt for E. e_steps is set in the main routine;
521
   // Timer interrupt for E. e_steps is set in the main routine;
456
   // Timer 0 is shared with millies
522
   // Timer 0 is shared with millies
457
   ISR(TIMER0_COMPA_vect) { Stepper::advance_isr(); }
523
   ISR(TIMER0_COMPA_vect) { Stepper::advance_isr(); }
458
 
524
 
459
   void Stepper::advance_isr() {
525
   void Stepper::advance_isr() {
460
-    old_OCR0A += 52; // ~10kHz interrupt (250000 / 26 = 9615kHz)
526
+
527
+    old_OCR0A += eISR_Rate;
461
     OCR0A = old_OCR0A;
528
     OCR0A = old_OCR0A;
462
 
529
 
463
     #define STEP_E_ONCE(INDEX) \
530
     #define STEP_E_ONCE(INDEX) \
474
         E## INDEX ##_STEP_WRITE(!INVERT_E_STEP_PIN); \
541
         E## INDEX ##_STEP_WRITE(!INVERT_E_STEP_PIN); \
475
       }
542
       }
476
 
543
 
477
-    // Step all E steppers that have steps, up to 4 steps per interrupt
478
-    for (unsigned char i = 0; i < 4; i++) {
479
-      STEP_E_ONCE(0);
480
-      #if EXTRUDERS > 1
481
-        STEP_E_ONCE(1);
482
-        #if EXTRUDERS > 2
483
-          STEP_E_ONCE(2);
484
-          #if EXTRUDERS > 3
485
-            STEP_E_ONCE(3);
486
-          #endif
544
+    // Step all E steppers that have steps
545
+    STEP_E_ONCE(0);
546
+    #if EXTRUDERS > 1
547
+      STEP_E_ONCE(1);
548
+      #if EXTRUDERS > 2
549
+        STEP_E_ONCE(2);
550
+        #if EXTRUDERS > 3
551
+          STEP_E_ONCE(3);
487
         #endif
552
         #endif
488
       #endif
553
       #endif
489
-    }
554
+    #endif
555
+
490
   }
556
   }
491
 
557
 
492
-#endif // ADVANCE
558
+#endif // ADVANCE or LIN_ADVANCE
493
 
559
 
494
 void Stepper::init() {
560
 void Stepper::init() {
495
 
561
 
656
   TCNT1 = 0;
722
   TCNT1 = 0;
657
   ENABLE_STEPPER_DRIVER_INTERRUPT();
723
   ENABLE_STEPPER_DRIVER_INTERRUPT();
658
 
724
 
659
-  #if ENABLED(ADVANCE)
725
+  #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
726
+
727
+    #if ENABLED(LIN_ADVANCE)
728
+
729
+      for (int i = 0; i < EXTRUDERS; i++) {
730
+        e_steps[i] = 0;
731
+        current_adv_steps[i] = 0;
732
+      }
733
+
734
+    #elif ENABLED(ADVANCE)
735
+
736
+      for (uint8_t i = 0; i < EXTRUDERS; i++) e_steps[i] = 0;
737
+
738
+    #endif
739
+
660
     #if defined(TCCR0A) && defined(WGM01)
740
     #if defined(TCCR0A) && defined(WGM01)
661
       CBI(TCCR0A, WGM01);
741
       CBI(TCCR0A, WGM01);
662
       CBI(TCCR0A, WGM00);
742
       CBI(TCCR0A, WGM00);
663
     #endif
743
     #endif
664
-    for (uint8_t i = 0; i < EXTRUDERS; i++) e_steps[i] = 0;
665
     SBI(TIMSK0, OCIE0A);
744
     SBI(TIMSK0, OCIE0A);
666
-  #endif //ADVANCE
745
+
746
+  #endif // ADVANCE or LIN_ADVANCE
667
 
747
 
668
   endstops.enable(true); // Start with endstops active. After homing they can be disabled
748
   endstops.enable(true); // Start with endstops active. After homing they can be disabled
669
   sei();
749
   sei();
1040
     SERIAL_PROTOCOLLN(digitalRead(E1_MS2_PIN));
1120
     SERIAL_PROTOCOLLN(digitalRead(E1_MS2_PIN));
1041
   #endif
1121
   #endif
1042
 }
1122
 }
1123
+
1124
+#if ENABLED(LIN_ADVANCE)
1125
+
1126
+  void Stepper::advance_M905() {
1127
+    if (code_seen('K')) extruder_advance_k = code_value();
1128
+    SERIAL_ECHO_START;
1129
+    SERIAL_ECHOPAIR("Advance factor: ", extruder_advance_k);
1130
+    SERIAL_EOL;
1131
+  }
1132
+
1133
+#endif // LIN_ADVANCE

+ 30
- 9
Marlin/stepper.h View File

22
 
22
 
23
 /**
23
 /**
24
  * stepper.h - stepper motor driver: executes motion plans of planner.c using the stepper motors
24
  * stepper.h - stepper motor driver: executes motion plans of planner.c using the stepper motors
25
- * Part of Grbl
25
+ * Derived from Grbl
26
  *
26
  *
27
  * Copyright (c) 2009-2011 Simen Svale Skogsrud
27
  * Copyright (c) 2009-2011 Simen Svale Skogsrud
28
  *
28
  *
90
       static bool performing_homing;
90
       static bool performing_homing;
91
     #endif
91
     #endif
92
 
92
 
93
-    #if ENABLED(ADVANCE)
94
-      static long e_steps[EXTRUDERS];
95
-    #endif
96
-
97
   private:
93
   private:
98
 
94
 
99
     static unsigned char last_direction_bits;        // The next stepping-bits to be output
95
     static unsigned char last_direction_bits;        // The next stepping-bits to be output
107
     static long counter_X, counter_Y, counter_Z, counter_E;
103
     static long counter_X, counter_Y, counter_Z, counter_E;
108
     static volatile unsigned long step_events_completed; // The number of step events executed in the current block
104
     static volatile unsigned long step_events_completed; // The number of step events executed in the current block
109
 
105
 
110
-    #if ENABLED(ADVANCE)
106
+    #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
111
       static unsigned char old_OCR0A;
107
       static unsigned char old_OCR0A;
112
-      static long advance_rate, advance, old_advance, final_advance;
113
-    #endif
108
+      static volatile unsigned char eISR_Rate;
109
+      #if ENABLED(LIN_ADVANCE)
110
+        static volatile int e_steps[EXTRUDERS];
111
+        static int extruder_advance_k;
112
+        static int final_estep_rate;
113
+        static int current_estep_rate[EXTRUDERS]; // Actual extruder speed [steps/s]
114
+        static int current_adv_steps[EXTRUDERS];  // The amount of current added esteps due to advance.
115
+                                                  // i.e., the current amount of pressure applied
116
+                                                  // to the spring (=filament).
117
+      #else
118
+        static long e_steps[EXTRUDERS];
119
+        static long advance_rate, advance, final_advance;
120
+        static long old_advance;
121
+      #endif
122
+    #endif // ADVANCE or LIN_ADVANCE
114
 
123
 
115
     static long acceleration_time, deceleration_time;
124
     static long acceleration_time, deceleration_time;
116
     //unsigned long accelerate_until, decelerate_after, acceleration_rate, initial_rate, final_rate, nominal_rate;
125
     //unsigned long accelerate_until, decelerate_after, acceleration_rate, initial_rate, final_rate, nominal_rate;
156
 
165
 
157
     static void isr();
166
     static void isr();
158
 
167
 
159
-    #if ENABLED(ADVANCE)
168
+    #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
160
       static void advance_isr();
169
       static void advance_isr();
161
     #endif
170
     #endif
162
 
171
 
246
       return endstops_trigsteps[axis] / planner.axis_steps_per_mm[axis];
255
       return endstops_trigsteps[axis] / planner.axis_steps_per_mm[axis];
247
     }
256
     }
248
 
257
 
258
+    #if ENABLED(LIN_ADVANCE)
259
+      void advance_M905();
260
+      FORCE_INLINE int get_advance_k() { return extruder_advance_k; }
261
+    #endif
262
+
249
   private:
263
   private:
250
 
264
 
251
     static FORCE_INLINE unsigned short calc_timer(unsigned short step_rate) {
265
     static FORCE_INLINE unsigned short calc_timer(unsigned short step_rate) {
315
       acc_step_rate = current_block->initial_rate;
329
       acc_step_rate = current_block->initial_rate;
316
       acceleration_time = calc_timer(acc_step_rate);
330
       acceleration_time = calc_timer(acc_step_rate);
317
       OCR1A = acceleration_time;
331
       OCR1A = acceleration_time;
332
+      
333
+      #if ENABLED(LIN_ADVANCE)
334
+        if (current_block->use_advance_lead) {
335
+          current_estep_rate[current_block->active_extruder] = ((unsigned long)acc_step_rate * current_block->e_speed_multiplier8) >> 8;
336
+          final_estep_rate = (current_block->nominal_rate * current_block->e_speed_multiplier8) >> 8;
337
+        }
338
+      #endif
318
 
339
 
319
       // SERIAL_ECHO_START;
340
       // SERIAL_ECHO_START;
320
       // SERIAL_ECHOPGM("advance :");
341
       // SERIAL_ECHOPGM("advance :");

Loading…
Cancel
Save