Просмотр исходного кода

Reduce / optimize LIN_ADVANCE code

Scott Lahteine 7 лет назад
Родитель
Сommit
97b6fb6381
2 измененных файлов: 23 добавлений и 18 удалений
  1. 10
    7
      Marlin/planner.cpp
  2. 13
    11
      Marlin/stepper.cpp

+ 10
- 7
Marlin/planner.cpp Просмотреть файл

@@ -672,8 +672,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
672 672
   #endif
673 673
 
674 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 676
   #endif
678 677
 
679 678
   const long da = target[X_AXIS] - position[X_AXIS],
@@ -707,13 +706,14 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
707 706
   if (DEBUGGING(DRYRUN)) {
708 707
     position[E_AXIS] = target[E_AXIS];
709 708
     #if ENABLED(LIN_ADVANCE)
710
-      position_float[E_AXIS] = target_float[E_AXIS];
709
+      position_float[E_AXIS] = e;
711 710
     #endif
712 711
   }
713 712
 
714 713
   long de = target[E_AXIS] - position[E_AXIS];
714
+
715 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 717
   #endif
718 718
 
719 719
   #if ENABLED(PREVENT_COLD_EXTRUSION)
@@ -722,7 +722,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
722 722
         position[E_AXIS] = target[E_AXIS]; // Behave as if the move really took place, but ignore E part
723 723
         de = 0; // no difference
724 724
         #if ENABLED(LIN_ADVANCE)
725
-          position_float[E_AXIS] = target_float[E_AXIS];
725
+          position_float[E_AXIS] = e;
726 726
           de_float = 0;
727 727
         #endif
728 728
         SERIAL_ECHO_START;
@@ -733,7 +733,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
733 733
           position[E_AXIS] = target[E_AXIS]; // Behave as if the move really took place, but ignore E part
734 734
           de = 0; // no difference
735 735
           #if ENABLED(LIN_ADVANCE)
736
-            position_float[E_AXIS] = target_float[E_AXIS];
736
+            position_float[E_AXIS] = e;
737 737
             de_float = 0;
738 738
           #endif
739 739
           SERIAL_ECHO_START;
@@ -1356,7 +1356,10 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
1356 1356
   // Update the position (only when a move was queued)
1357 1357
   memcpy(position, target, sizeof(position));
1358 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 1363
   #endif
1361 1364
 
1362 1365
   recalculate();

+ 13
- 11
Marlin/stepper.cpp Просмотреть файл

@@ -342,13 +342,14 @@ ISR(TIMER1_COMPA_vect) {
342 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 349
   static uint32_t step_remaining = 0;
351 350
 
351
+  uint16_t ocr_val;
352
+
352 353
   #define ENDSTOP_NOMINAL_OCR_VAL 3000    // check endstops every 1.5ms to guarantee two stepper ISRs within 5ms for BLTouch
353 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,7 +367,7 @@ void Stepper::isr() {
366 367
     #define SPLIT(L) do { \
367 368
       _SPLIT(L); \
368 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 371
         ocr_val = (remainder < OCR_VAL_TOLERANCE) ? ENDSTOP_NOMINAL_OCR_VAL + remainder : ENDSTOP_NOMINAL_OCR_VAL; \
371 372
         step_remaining = (uint16_t)L - ocr_val; \
372 373
       } \
@@ -374,13 +375,16 @@ void Stepper::isr() {
374 375
 
375 376
     if (step_remaining && ENDSTOPS_ENABLED) {   // Just check endstops - not yet time for a step
376 377
       endstops.update();
377
-      ocr_val = step_remaining;
378 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 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 389
       NOLESS(OCR1A, TCNT1 + 16);
386 390
 
@@ -867,9 +871,7 @@ void Stepper::isr() {
867 871
     NOLESS(OCR1A, TCNT1 + 16);
868 872
 
869 873
     // Restore original ISR settings
870
-    cli();
871
-    SBI(TIMSK0, OCIE0B);
872
-    ENABLE_STEPPER_DRIVER_INTERRUPT();
874
+    _ENABLE_ISRs();
873 875
   }
874 876
 
875 877
 #endif // ADVANCE or LIN_ADVANCE

Загрузка…
Отмена
Сохранить