Browse Source

Patch LIN_ADVANCE for style and forward-compatibility

Scott Lahteine 8 years ago
parent
commit
6d62a4ffc8
7 changed files with 141 additions and 168 deletions
  1. 9
    9
      Marlin/Configuration_adv.h
  2. 7
    7
      Marlin/Marlin_main.cpp
  3. 7
    1
      Marlin/SanityCheck.h
  4. 18
    13
      Marlin/planner.cpp
  5. 5
    5
      Marlin/planner.h
  6. 71
    105
      Marlin/stepper.cpp
  7. 24
    28
      Marlin/stepper.h

+ 9
- 9
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.
457
   #define MESH_MAX_Y (Y_MAX_POS - (MESH_INSET))
466
   #define MESH_MAX_Y (Y_MAX_POS - (MESH_INSET))
458
 #endif
467
 #endif
459
 
468
 
460
-//Implementation of a linear pressure control
461
-//Assumption: advance = k * (delta velocity)
462
-//K=0 means advance disabled. A good value for a gregs wade extruder will be around K=75
463
-#define LIN_ADVANCE
464
-
465
-#if ENABLED(LIN_ADVANCE)
466
-  #define LIN_K 75
467
-#endif
468
-
469
 // @section extras
469
 // @section extras
470
 
470
 
471
 // Arc interpretation settings:
471
 // Arc interpretation settings:

+ 7
- 7
Marlin/Marlin_main.cpp View File

6469
 #endif // DUAL_X_CARRIAGE
6469
 #endif // DUAL_X_CARRIAGE
6470
 
6470
 
6471
 #if ENABLED(LIN_ADVANCE)
6471
 #if ENABLED(LIN_ADVANCE)
6472
-/**
6473
- * M905: Set advance factor
6474
- */
6475
-inline void gcode_M905() {
6476
-  stepper.synchronize();
6477
-  stepper.advance_M905();
6478
-}
6472
+  /**
6473
+   * M905: Set advance factor
6474
+   */
6475
+  inline void gcode_M905() {
6476
+    stepper.synchronize();
6477
+    stepper.advance_M905();
6478
+  }
6479
 #endif
6479
 #endif
6480
 
6480
 
6481
 /**
6481
 /**

+ 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
  */

+ 18
- 13
Marlin/planner.cpp View File

1045
   // the maximum junction speed and may always be ignored for any speed reduction checks.
1045
   // the maximum junction speed and may always be ignored for any speed reduction checks.
1046
   block->nominal_length_flag = (block->nominal_speed <= v_allowable);
1046
   block->nominal_length_flag = (block->nominal_speed <= v_allowable);
1047
   block->recalculate_flag = true; // Always calculate trapezoid for new block
1047
   block->recalculate_flag = true; // Always calculate trapezoid for new block
1048
-  
1049
-  #ifdef LIN_ADVANCE
1050
-    //bse = allsteps: A problem occures if there is a very tiny move before a retract.
1051
-    //In this case, the retract and the move will be executed together. This leads to an enormus amount advance steps due to a hughe e_acceleration.
1052
-    //The math is correct, but you don't want a retract move done with advance! This situation has to be filtered out.
1053
-    if ((!bse || (!bsx && !bsy && !bsz)) || (stepper.get_advance_k() == 0) || (bse == allsteps)) {
1048
+
1049
+  // Update previous path unit_vector and nominal speed
1050
+  for (int i = 0; i < NUM_AXIS; i++) previous_speed[i] = current_speed[i];
1051
+  previous_nominal_speed = block->nominal_speed;
1052
+
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) {
1054
       block->use_advance_lead = false;
1061
       block->use_advance_lead = false;
1055
-    } else {
1062
+    }
1063
+    else {
1056
       block->use_advance_lead = true;
1064
       block->use_advance_lead = true;
1057
       block->e_speed_multiplier8 = (block->steps[E_AXIS] << 8) / block->step_event_count;
1065
       block->e_speed_multiplier8 = (block->steps[E_AXIS] << 8) / block->step_event_count;
1058
     }
1066
     }
1059
-  #endif
1060
 
1067
 
1061
-  // Update previous path unit_vector and nominal speed
1062
-  for (int i = 0; i < NUM_AXIS; i++) previous_speed[i] = current_speed[i];
1063
-  previous_nominal_speed = block->nominal_speed;
1068
+  #elif ENABLED(ADVANCE)
1064
 
1069
 
1065
-  #if ENABLED(ADVANCE)
1066
     // Calculate advance rate
1070
     // Calculate advance rate
1067
     if (!bse || (!bsx && !bsy && !bsz)) {
1071
     if (!bse || (!bsx && !bsy && !bsz)) {
1068
       block->advance_rate = 0;
1072
       block->advance_rate = 0;
1081
      SERIAL_ECHOPGM("advance rate :");
1085
      SERIAL_ECHOPGM("advance rate :");
1082
      SERIAL_ECHOLN(block->advance_rate/256.0);
1086
      SERIAL_ECHOLN(block->advance_rate/256.0);
1083
      */
1087
      */
1084
-  #endif // ADVANCE
1088
+
1089
+  #endif // ADVANCE or LIN_ADVANCE
1085
 
1090
 
1086
   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);
1087
 
1092
 

+ 5
- 5
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;
71
     float advance;
75
     float advance;
72
   #endif
76
   #endif
73
-  #ifdef LIN_ADVANCE
74
-    bool use_advance_lead;
75
-    int e_speed_multiplier8; //factorised by 2^8 to avoid float
76
-  #endif
77
 
77
 
78
   // Fields used by the motion planner to manage acceleration
78
   // Fields used by the motion planner to manage acceleration
79
   float nominal_speed,                               // The nominal speed for this block in mm/sec
79
   float nominal_speed,                               // The nominal speed for this block in mm/sec

+ 71
- 105
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)
348
-        counter_E += current_block->steps[E_AXIS];
349
-        if (counter_E > 0) {
350
-          counter_E -= current_block->step_event_count;
351
-          e_steps[current_block->active_extruder] += motor_direction(E_AXIS) ? -1 : 1;
352
-        }
353
-      #endif //ADVANCE
354
-      
355
       #if ENABLED(LIN_ADVANCE)
358
       #if ENABLED(LIN_ADVANCE)
359
+
356
         counter_E += current_block->steps[E_AXIS];
360
         counter_E += current_block->steps[E_AXIS];
357
         if (counter_E > 0) {
361
         if (counter_E > 0) {
358
           counter_E -= current_block->step_event_count;
362
           counter_E -= current_block->step_event_count;
359
-          count_position[_AXIS(E)] += count_direction[_AXIS(E)];
363
+          count_position[E_AXIS] += count_direction[E_AXIS];
360
           e_steps[current_block->active_extruder] += motor_direction(E_AXIS) ? -1 : 1;
364
           e_steps[current_block->active_extruder] += motor_direction(E_AXIS) ? -1 : 1;
361
         }
365
         }
362
-        
363
-        if (current_block->use_advance_lead){
366
+
367
+        if (current_block->use_advance_lead) {
364
           int delta_adv_steps; //Maybe a char would be enough?
368
           int delta_adv_steps; //Maybe a char would be enough?
365
           delta_adv_steps = (((long)extruder_advance_k * current_estep_rate[current_block->active_extruder]) >> 9) - current_adv_steps[current_block->active_extruder];
369
           delta_adv_steps = (((long)extruder_advance_k * current_estep_rate[current_block->active_extruder]) >> 9) - current_adv_steps[current_block->active_extruder];
366
           e_steps[current_block->active_extruder] += delta_adv_steps;
370
           e_steps[current_block->active_extruder] += delta_adv_steps;
367
           current_adv_steps[current_block->active_extruder] += delta_adv_steps;
371
           current_adv_steps[current_block->active_extruder] += delta_adv_steps;
368
         }
372
         }
369
-      #endif //LIN_ADVANCE
370
 
373
 
374
+      #elif ENABLED(ADVANCE)
375
+
376
+        counter_E += current_block->steps[E_AXIS];
377
+        if (counter_E > 0) {
378
+          counter_E -= current_block->step_event_count;
379
+          e_steps[current_block->active_extruder] += motor_direction(E_AXIS) ? -1 : 1;
380
+        }
381
+
382
+      #endif // ADVANCE or LIN_ADVANCE
383
+      
371
       #define _COUNTER(AXIS) counter_## AXIS
384
       #define _COUNTER(AXIS) counter_## AXIS
372
       #define _APPLY_STEP(AXIS) AXIS ##_APPLY_STEP
385
       #define _APPLY_STEP(AXIS) AXIS ##_APPLY_STEP
373
       #define _INVERT_STEP_PIN(AXIS) INVERT_## AXIS ##_STEP_PIN
386
       #define _INVERT_STEP_PIN(AXIS) INVERT_## AXIS ##_STEP_PIN
379
       STEP_ADD(X);
392
       STEP_ADD(X);
380
       STEP_ADD(Y);
393
       STEP_ADD(Y);
381
       STEP_ADD(Z);
394
       STEP_ADD(Z);
382
-      #if (DISABLED(ADVANCE) && DISABLED(LIN_ADVANCE))
395
+      #if DISABLED(ADVANCE) && DISABLED(LIN_ADVANCE)
383
         STEP_ADD(E);
396
         STEP_ADD(E);
384
       #endif
397
       #endif
385
 
398
 
393
       STEP_IF_COUNTER(X);
406
       STEP_IF_COUNTER(X);
394
       STEP_IF_COUNTER(Y);
407
       STEP_IF_COUNTER(Y);
395
       STEP_IF_COUNTER(Z);
408
       STEP_IF_COUNTER(Z);
396
-      #if (DISABLED(ADVANCE) && DISABLED(LIN_ADVANCE))
409
+      #if DISABLED(ADVANCE) && DISABLED(LIN_ADVANCE)
397
         STEP_IF_COUNTER(E);
410
         STEP_IF_COUNTER(E);
398
       #endif
411
       #endif
399
 
412
 
416
       acceleration_time += timer;
429
       acceleration_time += timer;
417
       
430
       
418
       #if ENABLED(LIN_ADVANCE)
431
       #if ENABLED(LIN_ADVANCE)
419
-        if (current_block->use_advance_lead){
432
+
433
+        if (current_block->use_advance_lead)
420
           current_estep_rate[current_block->active_extruder] = ((unsigned long)acc_step_rate * current_block->e_speed_multiplier8) >> 8;
434
           current_estep_rate[current_block->active_extruder] = ((unsigned long)acc_step_rate * current_block->e_speed_multiplier8) >> 8;
421
-        }
422
-      #endif
423
 
435
 
424
-      #if ENABLED(ADVANCE)
436
+      #elif ENABLED(ADVANCE)
425
 
437
 
426
         advance += advance_rate * step_loops;
438
         advance += advance_rate * step_loops;
427
         //NOLESS(advance, current_block->advance);
439
         //NOLESS(advance, current_block->advance);
430
         e_steps[current_block->active_extruder] += ((advance >> 8) - old_advance);
442
         e_steps[current_block->active_extruder] += ((advance >> 8) - old_advance);
431
         old_advance = advance >> 8;
443
         old_advance = advance >> 8;
432
 
444
 
433
-      #endif //ADVANCE
445
+      #endif // ADVANCE or LIN_ADVANCE
446
+
434
     }
447
     }
435
     else if (step_events_completed > (unsigned long)current_block->decelerate_after) {
448
     else if (step_events_completed > (unsigned long)current_block->decelerate_after) {
436
       MultiU24X32toH16(step_rate, deceleration_time, current_block->acceleration_rate);
449
       MultiU24X32toH16(step_rate, deceleration_time, current_block->acceleration_rate);
448
       deceleration_time += timer;
461
       deceleration_time += timer;
449
       
462
       
450
       #if ENABLED(LIN_ADVANCE)
463
       #if ENABLED(LIN_ADVANCE)
451
-        if (current_block->use_advance_lead){
464
+
465
+        if (current_block->use_advance_lead)
452
           current_estep_rate[current_block->active_extruder] = ((unsigned long)step_rate * current_block->e_speed_multiplier8) >> 8;
466
           current_estep_rate[current_block->active_extruder] = ((unsigned long)step_rate * current_block->e_speed_multiplier8) >> 8;
453
-        }
454
-      #endif
455
 
467
 
456
-      #if ENABLED(ADVANCE)
468
+      #elif ENABLED(ADVANCE)
469
+
457
         advance -= advance_rate * step_loops;
470
         advance -= advance_rate * step_loops;
458
         NOLESS(advance, final_advance);
471
         NOLESS(advance, final_advance);
459
 
472
 
461
         uint32_t advance_whole = advance >> 8;
474
         uint32_t advance_whole = advance >> 8;
462
         e_steps[current_block->active_extruder] += advance_whole - old_advance;
475
         e_steps[current_block->active_extruder] += advance_whole - old_advance;
463
         old_advance = advance_whole;
476
         old_advance = advance_whole;
464
-      #endif //ADVANCE
477
+
478
+      #endif // ADVANCE or LIN_ADVANCE
465
     }
479
     }
466
     else {
480
     else {
467
-      #ifdef LIN_ADVANCE
468
-        if (current_block->use_advance_lead){
481
+      #if ENABLED(LIN_ADVANCE)
482
+        if (current_block->use_advance_lead)
469
           current_estep_rate[current_block->active_extruder] = final_estep_rate;
483
           current_estep_rate[current_block->active_extruder] = final_estep_rate;
470
-        }
471
       #endif
484
       #endif
472
-      
485
+
473
       OCR1A = OCR1A_nominal;
486
       OCR1A = OCR1A_nominal;
474
       // ensure we're running at the correct step rate, even if we just came off an acceleration
487
       // ensure we're running at the correct step rate, even if we just came off an acceleration
475
       step_loops = step_loops_nominal;
488
       step_loops = step_loops_nominal;
485
   }
498
   }
486
 }
499
 }
487
 
500
 
488
-#if ENABLED(ADVANCE)
501
+#if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
502
+
489
   // Timer interrupt for E. e_steps is set in the main routine;
503
   // Timer interrupt for E. e_steps is set in the main routine;
490
   // Timer 0 is shared with millies
504
   // Timer 0 is shared with millies
491
   ISR(TIMER0_COMPA_vect) { Stepper::advance_isr(); }
505
   ISR(TIMER0_COMPA_vect) { Stepper::advance_isr(); }
492
 
506
 
493
   void Stepper::advance_isr() {
507
   void Stepper::advance_isr() {
508
+
494
     old_OCR0A += 52; // ~10kHz interrupt (250000 / 26 = 9615kHz)
509
     old_OCR0A += 52; // ~10kHz interrupt (250000 / 26 = 9615kHz)
495
     OCR0A = old_OCR0A;
510
     OCR0A = old_OCR0A;
496
 
511
 
521
         #endif
536
         #endif
522
       #endif
537
       #endif
523
     }
538
     }
524
-  }
525
 
539
 
526
-#endif // ADVANCE
527
-
528
-#if ENABLED(LIN_ADVANCE)
529
-unsigned char old_OCR0A;
530
-// Timer interrupt for E. e_steps is set in the main routine;
531
-// Timer 0 is shared with millies
532
-ISR(TIMER0_COMPA_vect) { stepper.advance_isr(); }
533
-
534
-void Stepper::advance_isr() {
535
-  old_OCR0A += 52; // ~10kHz interrupt (250000 / 26 = 9615kHz) war 52
536
-  OCR0A = old_OCR0A;
537
-
538
-#define STEP_E_ONCE(INDEX) \
539
-  if (e_steps[INDEX] != 0) { \
540
-    E## INDEX ##_STEP_WRITE(INVERT_E_STEP_PIN); \
541
-    if (e_steps[INDEX] < 0) { \
542
-      E## INDEX ##_DIR_WRITE(INVERT_E## INDEX ##_DIR); \
543
-      e_steps[INDEX]++; \
544
-    } \
545
-    else if (e_steps[INDEX] > 0) { \
546
-      E## INDEX ##_DIR_WRITE(!INVERT_E## INDEX ##_DIR); \
547
-      e_steps[INDEX]--; \
548
-    } \
549
-    E## INDEX ##_STEP_WRITE(!INVERT_E_STEP_PIN); \
550
   }
540
   }
551
 
541
 
552
-  // Step all E steppers that have steps, up to 4 steps per interrupt
553
-  for (unsigned char i = 0; i < 4; i++) {
554
-    #if EXTRUDERS > 3
555
-      switch(current_block->active_extruder){case 3:STEP_E_ONCE(3);break;case 2:STEP_E_ONCE(2);break;case 1:STEP_E_ONCE(1);break;default:STEP_E_ONCE(0);}
556
-    #elif EXTRUDERS > 2
557
-      switch(current_block->active_extruder){case 2:STEP_E_ONCE(2);break;case 1:STEP_E_ONCE(1);break;default:STEP_E_ONCE(0);}
558
-    #elif EXTRUDERS > 1
559
-      #if DISABLED(DUAL_X_CARRIAGE)
560
-        if(current_block->active_extruder == 1){STEP_E_ONCE(1)}else{STEP_E_ONCE(0);}
561
-      #else
562
-        extern bool extruder_duplication_enabled;
563
-        if(extruder_duplication_enabled){
564
-          STEP_E_ONCE(0);
565
-          STEP_E_ONCE(1);
566
-        }else {
567
-          if(current_block->active_extruder == 1){STEP_E_ONCE(1)}else{STEP_E_ONCE(0);}
568
-        }
569
-      #endif
570
-    #else
571
-      STEP_E_ONCE(0);
572
-    #endif
573
-  }
574
-}
575
-#endif // LIN_ADVANCE
542
+#endif // ADVANCE or LIN_ADVANCE
576
 
543
 
577
 void Stepper::init() {
544
 void Stepper::init() {
578
 
545
 
738
   OCR1A = 0x4000;
705
   OCR1A = 0x4000;
739
   TCNT1 = 0;
706
   TCNT1 = 0;
740
   ENABLE_STEPPER_DRIVER_INTERRUPT();
707
   ENABLE_STEPPER_DRIVER_INTERRUPT();
741
-  
742
-  #if ENABLED(LIN_ADVANCE)
743
-    for (int i = 0; i < EXTRUDERS; i++){
744
-      e_steps[i] = 0;
745
-      current_adv_steps[i] = 0;
746
-    }
747
-    #if defined(TCCR0A) && defined(WGM01)
748
-      CBI(TCCR0A, WGM01);
749
-      CBI(TCCR0A, WGM00);
708
+
709
+  #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
710
+
711
+    #if ENABLED(LIN_ADVANCE)
712
+
713
+      for (int i = 0; i < EXTRUDERS; i++) {
714
+        e_steps[i] = 0;
715
+        current_adv_steps[i] = 0;
716
+      }
717
+
718
+    #elif ENABLED(ADVANCE)
719
+
720
+      for (uint8_t i = 0; i < EXTRUDERS; i++) e_steps[i] = 0;
721
+
750
     #endif
722
     #endif
751
-    SBI(TIMSK0, OCIE0A);
752
-  #endif //LIN_ADVANCE
753
 
723
 
754
-  #if ENABLED(ADVANCE)
755
     #if defined(TCCR0A) && defined(WGM01)
724
     #if defined(TCCR0A) && defined(WGM01)
756
       CBI(TCCR0A, WGM01);
725
       CBI(TCCR0A, WGM01);
757
       CBI(TCCR0A, WGM00);
726
       CBI(TCCR0A, WGM00);
758
     #endif
727
     #endif
759
-    for (uint8_t i = 0; i < EXTRUDERS; i++) e_steps[i] = 0;
760
     SBI(TIMSK0, OCIE0A);
728
     SBI(TIMSK0, OCIE0A);
761
-  #endif //ADVANCE
729
+
730
+  #endif // ADVANCE or LIN_ADVANCE
762
 
731
 
763
   endstops.enable(true); // Start with endstops active. After homing they can be disabled
732
   endstops.enable(true); // Start with endstops active. After homing they can be disabled
764
   sei();
733
   sei();
1137
 }
1106
 }
1138
 
1107
 
1139
 #if ENABLED(LIN_ADVANCE)
1108
 #if ENABLED(LIN_ADVANCE)
1109
+
1140
   void Stepper::advance_M905() {
1110
   void Stepper::advance_M905() {
1141
     if (code_seen('K')) extruder_advance_k = code_value();
1111
     if (code_seen('K')) extruder_advance_k = code_value();
1142
     SERIAL_ECHO_START;
1112
     SERIAL_ECHO_START;
1143
-    SERIAL_ECHOPGM("Advance factor:");
1144
-    SERIAL_CHAR(' ');
1145
-    SERIAL_ECHOLN(extruder_advance_k);
1113
+    SERIAL_ECHOPAIR("Advance factor: ", extruder_advance_k);
1114
+    SERIAL_EOL;
1146
   }
1115
   }
1147
 
1116
 
1148
-  int Stepper::get_advance_k(){
1149
-    return extruder_advance_k;
1150
-  }
1151
-#endif
1117
+#endif // LIN_ADVANCE

+ 24
- 28
Marlin/stepper.h View File

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
-    #if ENABLED(LIN_ADVANCE)
98
-      int extruder_advance_k = LIN_K;
99
-    #endif
100
-
101
   private:
93
   private:
102
 
94
 
103
     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
111
     static long counter_X, counter_Y, counter_Z, counter_E;
103
     static long counter_X, counter_Y, counter_Z, counter_E;
112
     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
113
 
105
 
114
-    #if ENABLED(ADVANCE)
106
+    #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
115
       static unsigned char old_OCR0A;
107
       static unsigned char old_OCR0A;
116
-      static long advance_rate, advance, old_advance, final_advance;
117
-    #endif
118
-    
119
-    #if ENABLED(LIN_ADVANCE)
120
-      unsigned char old_OCR0A;
121
-      volatile int e_steps[EXTRUDERS];
122
-      int final_estep_rate;
123
-      int current_estep_rate[EXTRUDERS]; //Actual extruder speed [steps/s]
124
-      int current_adv_steps[EXTRUDERS]; //The amount of current added esteps due to advance. Think of it as the current amount of pressure applied to the spring (=filament).
125
-    #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
126
 
123
 
127
     static long acceleration_time, deceleration_time;
124
     static long acceleration_time, deceleration_time;
128
     //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;
168
 
165
 
169
     static void isr();
166
     static void isr();
170
 
167
 
171
-    #if ENABLED(ADVANCE)
168
+    #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
172
       static void advance_isr();
169
       static void advance_isr();
173
     #endif
170
     #endif
174
-    
175
-    #if ENABLED(LIN_ADVANCE)
176
-      void advance_isr();
177
-      void advance_M905();
178
-      int get_advance_k();
179
-    #endif
180
 
171
 
181
     //
172
     //
182
     // Block until all buffered steps are executed
173
     // Block until all buffered steps are executed
264
       return endstops_trigsteps[axis] / planner.axis_steps_per_mm[axis];
255
       return endstops_trigsteps[axis] / planner.axis_steps_per_mm[axis];
265
     }
256
     }
266
 
257
 
258
+    #if ENABLED(LIN_ADVANCE)
259
+      void advance_M905();
260
+      FORCE_INLINE int get_advance_k() { return extruder_advance_k; }
261
+    #endif
262
+
267
   private:
263
   private:
268
 
264
 
269
     static FORCE_INLINE unsigned short calc_timer(unsigned short step_rate) {
265
     static FORCE_INLINE unsigned short calc_timer(unsigned short step_rate) {
335
       OCR1A = acceleration_time;
331
       OCR1A = acceleration_time;
336
       
332
       
337
       #if ENABLED(LIN_ADVANCE)
333
       #if ENABLED(LIN_ADVANCE)
338
-        if (current_block->use_advance_lead){
334
+        if (current_block->use_advance_lead) {
339
           current_estep_rate[current_block->active_extruder] = ((unsigned long)acc_step_rate * current_block->e_speed_multiplier8) >> 8;
335
           current_estep_rate[current_block->active_extruder] = ((unsigned long)acc_step_rate * current_block->e_speed_multiplier8) >> 8;
340
           final_estep_rate = (current_block->nominal_rate * current_block->e_speed_multiplier8) >> 8;
336
           final_estep_rate = (current_block->nominal_rate * current_block->e_speed_multiplier8) >> 8;
341
         }
337
         }
357
 
353
 
358
 };
354
 };
359
 
355
 
360
-#endif // STEPPER_H
356
+#endif // STEPPER_H

Loading…
Cancel
Save