Browse Source

Reduce / optimize LIN_ADVANCE code

Scott Lahteine 7 years ago
parent
commit
97b6fb6381
2 changed files with 23 additions and 18 deletions
  1. 10
    7
      Marlin/planner.cpp
  2. 13
    11
      Marlin/stepper.cpp

+ 10
- 7
Marlin/planner.cpp View File

672
   #endif
672
   #endif
673
 
673
 
674
   #if ENABLED(LIN_ADVANCE)
674
   #if ENABLED(LIN_ADVANCE)
675
-    const float target_float[XYZE] = { a, b, c, e },
676
-                mm_D_float = sqrt(sq(target_float[X_AXIS] - position_float[X_AXIS]) + sq(target_float[Y_AXIS] - position_float[Y_AXIS]));
675
+    const float mm_D_float = sqrt(sq(a - position_float[X_AXIS]) + sq(b - position_float[Y_AXIS]));
677
   #endif
676
   #endif
678
 
677
 
679
   const long da = target[X_AXIS] - position[X_AXIS],
678
   const long da = target[X_AXIS] - position[X_AXIS],
707
   if (DEBUGGING(DRYRUN)) {
706
   if (DEBUGGING(DRYRUN)) {
708
     position[E_AXIS] = target[E_AXIS];
707
     position[E_AXIS] = target[E_AXIS];
709
     #if ENABLED(LIN_ADVANCE)
708
     #if ENABLED(LIN_ADVANCE)
710
-      position_float[E_AXIS] = target_float[E_AXIS];
709
+      position_float[E_AXIS] = e;
711
     #endif
710
     #endif
712
   }
711
   }
713
 
712
 
714
   long de = target[E_AXIS] - position[E_AXIS];
713
   long de = target[E_AXIS] - position[E_AXIS];
714
+
715
   #if ENABLED(LIN_ADVANCE)
715
   #if ENABLED(LIN_ADVANCE)
716
-    float de_float = target_float[E_AXIS] - position_float[E_AXIS];
716
+    float de_float = e - position_float[E_AXIS];
717
   #endif
717
   #endif
718
 
718
 
719
   #if ENABLED(PREVENT_COLD_EXTRUSION)
719
   #if ENABLED(PREVENT_COLD_EXTRUSION)
722
         position[E_AXIS] = target[E_AXIS]; // Behave as if the move really took place, but ignore E part
722
         position[E_AXIS] = target[E_AXIS]; // Behave as if the move really took place, but ignore E part
723
         de = 0; // no difference
723
         de = 0; // no difference
724
         #if ENABLED(LIN_ADVANCE)
724
         #if ENABLED(LIN_ADVANCE)
725
-          position_float[E_AXIS] = target_float[E_AXIS];
725
+          position_float[E_AXIS] = e;
726
           de_float = 0;
726
           de_float = 0;
727
         #endif
727
         #endif
728
         SERIAL_ECHO_START;
728
         SERIAL_ECHO_START;
733
           position[E_AXIS] = target[E_AXIS]; // Behave as if the move really took place, but ignore E part
733
           position[E_AXIS] = target[E_AXIS]; // Behave as if the move really took place, but ignore E part
734
           de = 0; // no difference
734
           de = 0; // no difference
735
           #if ENABLED(LIN_ADVANCE)
735
           #if ENABLED(LIN_ADVANCE)
736
-            position_float[E_AXIS] = target_float[E_AXIS];
736
+            position_float[E_AXIS] = e;
737
             de_float = 0;
737
             de_float = 0;
738
           #endif
738
           #endif
739
           SERIAL_ECHO_START;
739
           SERIAL_ECHO_START;
1356
   // Update the position (only when a move was queued)
1356
   // Update the position (only when a move was queued)
1357
   memcpy(position, target, sizeof(position));
1357
   memcpy(position, target, sizeof(position));
1358
   #if ENABLED(LIN_ADVANCE)
1358
   #if ENABLED(LIN_ADVANCE)
1359
-    memcpy(position_float, target_float, sizeof(position_float));
1359
+    position_float[X_AXIS] = a;
1360
+    position_float[Y_AXIS] = b;
1361
+    position_float[Z_AXIS] = c;
1362
+    position_float[E_AXIS] = e;
1360
   #endif
1363
   #endif
1361
 
1364
 
1362
   recalculate();
1365
   recalculate();

+ 13
- 11
Marlin/stepper.cpp View File

342
   #endif
342
   #endif
343
 }
343
 }
344
 
344
 
345
-void Stepper::isr() {
346
-  #define _ENABLE_ISRs() cli(); SBI(TIMSK0, OCIE0B); ENABLE_STEPPER_DRIVER_INTERRUPT()
345
+#define _ENABLE_ISRs() do { cli(); if (thermalManager.in_temp_isr) CBI(TIMSK0, OCIE0B); else SBI(TIMSK0, OCIE0B); ENABLE_STEPPER_DRIVER_INTERRUPT(); } while(0)
347
 
346
 
348
-  uint16_t timer, remainder, ocr_val;
347
+void Stepper::isr() {
349
 
348
 
350
   static uint32_t step_remaining = 0;
349
   static uint32_t step_remaining = 0;
351
 
350
 
351
+  uint16_t ocr_val;
352
+
352
   #define ENDSTOP_NOMINAL_OCR_VAL 3000    // check endstops every 1.5ms to guarantee two stepper ISRs within 5ms for BLTouch
353
   #define ENDSTOP_NOMINAL_OCR_VAL 3000    // check endstops every 1.5ms to guarantee two stepper ISRs within 5ms for BLTouch
353
   #define OCR_VAL_TOLERANCE 1000          // First max delay is 2.0ms, last min delay is 0.5ms, all others 1.5ms
354
   #define OCR_VAL_TOLERANCE 1000          // First max delay is 2.0ms, last min delay is 0.5ms, all others 1.5ms
354
 
355
 
366
     #define SPLIT(L) do { \
367
     #define SPLIT(L) do { \
367
       _SPLIT(L); \
368
       _SPLIT(L); \
368
       if (ENDSTOPS_ENABLED && L > ENDSTOP_NOMINAL_OCR_VAL) { \
369
       if (ENDSTOPS_ENABLED && L > ENDSTOP_NOMINAL_OCR_VAL) { \
369
-        remainder = (uint16_t)L % (ENDSTOP_NOMINAL_OCR_VAL); \
370
+        uint16_t remainder = (uint16_t)L % (ENDSTOP_NOMINAL_OCR_VAL); \
370
         ocr_val = (remainder < OCR_VAL_TOLERANCE) ? ENDSTOP_NOMINAL_OCR_VAL + remainder : ENDSTOP_NOMINAL_OCR_VAL; \
371
         ocr_val = (remainder < OCR_VAL_TOLERANCE) ? ENDSTOP_NOMINAL_OCR_VAL + remainder : ENDSTOP_NOMINAL_OCR_VAL; \
371
         step_remaining = (uint16_t)L - ocr_val; \
372
         step_remaining = (uint16_t)L - ocr_val; \
372
       } \
373
       } \
374
 
375
 
375
     if (step_remaining && ENDSTOPS_ENABLED) {   // Just check endstops - not yet time for a step
376
     if (step_remaining && ENDSTOPS_ENABLED) {   // Just check endstops - not yet time for a step
376
       endstops.update();
377
       endstops.update();
377
-      ocr_val = step_remaining;
378
       if (step_remaining > ENDSTOP_NOMINAL_OCR_VAL) {
378
       if (step_remaining > ENDSTOP_NOMINAL_OCR_VAL) {
379
-        step_remaining = step_remaining - ENDSTOP_NOMINAL_OCR_VAL;
379
+        step_remaining -= ENDSTOP_NOMINAL_OCR_VAL;
380
         ocr_val = ENDSTOP_NOMINAL_OCR_VAL;
380
         ocr_val = ENDSTOP_NOMINAL_OCR_VAL;
381
       }
381
       }
382
-      else step_remaining = 0;  //  last one before the ISR that does the step
383
-      _NEXT_ISR(ocr_val);  //
382
+      else {
383
+        ocr_val = step_remaining;
384
+        step_remaining = 0;  //  last one before the ISR that does the step
385
+      }
386
+
387
+      _NEXT_ISR(ocr_val);
384
 
388
 
385
       NOLESS(OCR1A, TCNT1 + 16);
389
       NOLESS(OCR1A, TCNT1 + 16);
386
 
390
 
867
     NOLESS(OCR1A, TCNT1 + 16);
871
     NOLESS(OCR1A, TCNT1 + 16);
868
 
872
 
869
     // Restore original ISR settings
873
     // Restore original ISR settings
870
-    cli();
871
-    SBI(TIMSK0, OCIE0B);
872
-    ENABLE_STEPPER_DRIVER_INTERRUPT();
874
+    _ENABLE_ISRs();
873
   }
875
   }
874
 
876
 
875
 #endif // ADVANCE or LIN_ADVANCE
877
 #endif // ADVANCE or LIN_ADVANCE

Loading…
Cancel
Save