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

Less indentation in Stepper::isr

Scott Lahteine 8 лет назад
Родитель
Сommit
cc639d7d9c
1 измененных файлов: 238 добавлений и 240 удалений
  1. 238
    240
      Marlin/stepper.cpp

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

@@ -357,316 +357,314 @@ void Stepper::isr() {
357 357
     }
358 358
     else {
359 359
       OCR1A = 2000; // 1kHz.
360
+      return;
360 361
     }
361 362
   }
362 363
 
363
-  if (current_block) {
364
+  // Update endstops state, if enabled
365
+  if (endstops.enabled
366
+    #if HAS_BED_PROBE
367
+      || endstops.z_probe_enabled
368
+    #endif
369
+  ) endstops.update();
364 370
 
365
-    // Update endstops state, if enabled
366
-    if (endstops.enabled
367
-      #if HAS_BED_PROBE
368
-        || endstops.z_probe_enabled
369
-      #endif
370
-    ) endstops.update();
371
+  // Take multiple steps per interrupt (For high speed moves)
372
+  bool all_steps_done = false;
373
+  for (int8_t i = 0; i < step_loops; i++) {
374
+    #ifndef USBCON
375
+      customizedSerial.checkRx(); // Check for serial chars.
376
+    #endif
371 377
 
372
-    // Take multiple steps per interrupt (For high speed moves)
373
-    bool all_steps_done = false;
374
-    for (int8_t i = 0; i < step_loops; i++) {
375
-      #ifndef USBCON
376
-        customizedSerial.checkRx(); // Check for serial chars.
377
-      #endif
378
+    #if ENABLED(LIN_ADVANCE)
378 379
 
379
-      #if ENABLED(LIN_ADVANCE)
380
+      counter_E += current_block->steps[E_AXIS];
381
+      if (counter_E > 0) {
382
+        counter_E -= current_block->step_event_count;
383
+        #if DISABLED(MIXING_EXTRUDER)
384
+          // Don't step E here for mixing extruder
385
+          count_position[E_AXIS] += count_direction[E_AXIS];
386
+          motor_direction(E_AXIS) ? --e_steps[TOOL_E_INDEX] : ++e_steps[TOOL_E_INDEX];
387
+        #endif
388
+      }
380 389
 
381
-        counter_E += current_block->steps[E_AXIS];
382
-        if (counter_E > 0) {
383
-          counter_E -= current_block->step_event_count;
384
-          #if DISABLED(MIXING_EXTRUDER)
385
-            // Don't step E here for mixing extruder
386
-            count_position[E_AXIS] += count_direction[E_AXIS];
387
-            motor_direction(E_AXIS) ? --e_steps[TOOL_E_INDEX] : ++e_steps[TOOL_E_INDEX];
388
-          #endif
390
+      #if ENABLED(MIXING_EXTRUDER)
391
+        // Step mixing steppers proportionally
392
+        bool dir = motor_direction(E_AXIS);
393
+        MIXING_STEPPERS_LOOP(j) {
394
+          counter_m[j] += current_block->steps[E_AXIS];
395
+          if (counter_m[j] > 0) {
396
+            counter_m[j] -= current_block->mix_event_count[j];
397
+            dir ? --e_steps[j] : ++e_steps[j];
398
+          }
389 399
         }
400
+      #endif
390 401
 
402
+      if (current_block->use_advance_lead) {
403
+        int delta_adv_steps = (((long)extruder_advance_k * current_estep_rate[TOOL_E_INDEX]) >> 9) - current_adv_steps[TOOL_E_INDEX];
391 404
         #if ENABLED(MIXING_EXTRUDER)
392
-          // Step mixing steppers proportionally
393
-          bool dir = motor_direction(E_AXIS);
405
+          // Mixing extruders apply advance lead proportionally
394 406
           MIXING_STEPPERS_LOOP(j) {
395
-            counter_m[j] += current_block->steps[E_AXIS];
396
-            if (counter_m[j] > 0) {
397
-              counter_m[j] -= current_block->mix_event_count[j];
398
-              dir ? --e_steps[j] : ++e_steps[j];
399
-            }
407
+            int steps = delta_adv_steps * current_block->step_event_count / current_block->mix_event_count[j];
408
+            e_steps[j] += steps;
409
+            current_adv_steps[j] += steps;
400 410
           }
411
+        #else
412
+          // For most extruders, advance the single E stepper
413
+          e_steps[TOOL_E_INDEX] += delta_adv_steps;
414
+          current_adv_steps[TOOL_E_INDEX] += delta_adv_steps;
401 415
         #endif
416
+      }
402 417
 
403
-        if (current_block->use_advance_lead) {
404
-          int delta_adv_steps = (((long)extruder_advance_k * current_estep_rate[TOOL_E_INDEX]) >> 9) - current_adv_steps[TOOL_E_INDEX];
405
-          #if ENABLED(MIXING_EXTRUDER)
406
-            // Mixing extruders apply advance lead proportionally
407
-            MIXING_STEPPERS_LOOP(j) {
408
-              int steps = delta_adv_steps * current_block->step_event_count / current_block->mix_event_count[j];
409
-              e_steps[j] += steps;
410
-              current_adv_steps[j] += steps;
411
-            }
412
-          #else
413
-            // For most extruders, advance the single E stepper
414
-            e_steps[TOOL_E_INDEX] += delta_adv_steps;
415
-            current_adv_steps[TOOL_E_INDEX] += delta_adv_steps;
416
-          #endif
417
-        }
418
-
419
-      #elif ENABLED(ADVANCE)
418
+    #elif ENABLED(ADVANCE)
420 419
 
421
-        // Always count the unified E axis
422
-        counter_E += current_block->steps[E_AXIS];
423
-        if (counter_E > 0) {
424
-          counter_E -= current_block->step_event_count;
425
-          #if DISABLED(MIXING_EXTRUDER)
426
-            // Don't step E here for mixing extruder
427
-            motor_direction(E_AXIS) ? --e_steps[TOOL_E_INDEX] : ++e_steps[TOOL_E_INDEX];
428
-          #endif
429
-        }
420
+      // Always count the unified E axis
421
+      counter_E += current_block->steps[E_AXIS];
422
+      if (counter_E > 0) {
423
+        counter_E -= current_block->step_event_count;
424
+        #if DISABLED(MIXING_EXTRUDER)
425
+          // Don't step E here for mixing extruder
426
+          motor_direction(E_AXIS) ? --e_steps[TOOL_E_INDEX] : ++e_steps[TOOL_E_INDEX];
427
+        #endif
428
+      }
430 429
 
431
-        #if ENABLED(MIXING_EXTRUDER)
430
+      #if ENABLED(MIXING_EXTRUDER)
432 431
 
433
-          // Step mixing steppers proportionally
434
-          bool dir = motor_direction(E_AXIS);
435
-          MIXING_STEPPERS_LOOP(j) {
436
-            counter_m[j] += current_block->steps[E_AXIS];
437
-            if (counter_m[j] > 0) {
438
-              counter_m[j] -= current_block->mix_event_count[j];
439
-              dir ? --e_steps[j] : ++e_steps[j];
440
-            }
432
+        // Step mixing steppers proportionally
433
+        bool dir = motor_direction(E_AXIS);
434
+        MIXING_STEPPERS_LOOP(j) {
435
+          counter_m[j] += current_block->steps[E_AXIS];
436
+          if (counter_m[j] > 0) {
437
+            counter_m[j] -= current_block->mix_event_count[j];
438
+            dir ? --e_steps[j] : ++e_steps[j];
441 439
           }
440
+        }
442 441
 
443
-        #endif // MIXING_EXTRUDER
444
-
445
-      #endif // ADVANCE or LIN_ADVANCE
446
-
447
-      #define _COUNTER(AXIS) counter_## AXIS
448
-      #define _APPLY_STEP(AXIS) AXIS ##_APPLY_STEP
449
-      #define _INVERT_STEP_PIN(AXIS) INVERT_## AXIS ##_STEP_PIN
442
+      #endif // MIXING_EXTRUDER
450 443
 
451
-      // Advance the Bresenham counter; start a pulse if the axis needs a step
452
-      #define PULSE_START(AXIS) \
453
-        _COUNTER(AXIS) += current_block->steps[_AXIS(AXIS)]; \
454
-        if (_COUNTER(AXIS) > 0) { _APPLY_STEP(AXIS)(!_INVERT_STEP_PIN(AXIS),0); }
444
+    #endif // ADVANCE or LIN_ADVANCE
455 445
 
456
-      // Stop an active pulse, reset the Bresenham counter, update the position
457
-      #define PULSE_STOP(AXIS) \
458
-        if (_COUNTER(AXIS) > 0) { \
459
-          _COUNTER(AXIS) -= current_block->step_event_count; \
460
-          count_position[_AXIS(AXIS)] += count_direction[_AXIS(AXIS)]; \
461
-          _APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS),0); \
462
-        }
446
+    #define _COUNTER(AXIS) counter_## AXIS
447
+    #define _APPLY_STEP(AXIS) AXIS ##_APPLY_STEP
448
+    #define _INVERT_STEP_PIN(AXIS) INVERT_## AXIS ##_STEP_PIN
463 449
 
464
-      // If a minimum pulse time was specified get the CPU clock
465
-      #if MINIMUM_STEPPER_PULSE > 0
466
-        static uint32_t pulse_start;
467
-        pulse_start = TCNT0;
468
-      #endif
450
+    // Advance the Bresenham counter; start a pulse if the axis needs a step
451
+    #define PULSE_START(AXIS) \
452
+      _COUNTER(AXIS) += current_block->steps[_AXIS(AXIS)]; \
453
+      if (_COUNTER(AXIS) > 0) { _APPLY_STEP(AXIS)(!_INVERT_STEP_PIN(AXIS),0); }
469 454
 
470
-      #if HAS_X_STEP
471
-        PULSE_START(X);
472
-      #endif
473
-      #if HAS_Y_STEP
474
-        PULSE_START(Y);
475
-      #endif
476
-      #if HAS_Z_STEP
477
-        PULSE_START(Z);
478
-      #endif
455
+    // Stop an active pulse, reset the Bresenham counter, update the position
456
+    #define PULSE_STOP(AXIS) \
457
+      if (_COUNTER(AXIS) > 0) { \
458
+        _COUNTER(AXIS) -= current_block->step_event_count; \
459
+        count_position[_AXIS(AXIS)] += count_direction[_AXIS(AXIS)]; \
460
+        _APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS),0); \
461
+      }
479 462
 
480
-      // For non-advance use linear interpolation for E also
481
-      #if DISABLED(ADVANCE) && DISABLED(LIN_ADVANCE)
482
-        #if ENABLED(MIXING_EXTRUDER)
483
-          // Keep updating the single E axis
484
-          counter_E += current_block->steps[E_AXIS];
485
-          // Tick the counters used for this mix
486
-          MIXING_STEPPERS_LOOP(j) {
487
-            // Step mixing steppers (proportionally)
488
-            counter_m[j] += current_block->steps[E_AXIS];
489
-            // Step when the counter goes over zero
490
-            if (counter_m[j] > 0) En_STEP_WRITE(j, !INVERT_E_STEP_PIN);
491
-          }
492
-        #else // !MIXING_EXTRUDER
493
-          PULSE_START(E);
494
-        #endif
495
-      #endif // !ADVANCE && !LIN_ADVANCE
463
+    // If a minimum pulse time was specified get the CPU clock
464
+    #if MINIMUM_STEPPER_PULSE > 0
465
+      static uint32_t pulse_start;
466
+      pulse_start = TCNT0;
467
+    #endif
496 468
 
497
-      // For a minimum pulse time wait before stopping pulses
498
-      #if MINIMUM_STEPPER_PULSE > 0
499
-        #define CYCLES_EATEN_BY_CODE 10
500
-        while ((uint32_t)(TCNT0 - pulse_start) < (MINIMUM_STEPPER_PULSE * (F_CPU / 1000000UL)) - CYCLES_EATEN_BY_CODE) { /* nada */ }
501
-      #endif
469
+    #if HAS_X_STEP
470
+      PULSE_START(X);
471
+    #endif
472
+    #if HAS_Y_STEP
473
+      PULSE_START(Y);
474
+    #endif
475
+    #if HAS_Z_STEP
476
+      PULSE_START(Z);
477
+    #endif
502 478
 
503
-      #if HAS_X_STEP
504
-        PULSE_STOP(X);
505
-      #endif
506
-      #if HAS_Y_STEP
507
-        PULSE_STOP(Y);
508
-      #endif
509
-      #if HAS_Z_STEP
510
-        PULSE_STOP(Z);
479
+    // For non-advance use linear interpolation for E also
480
+    #if DISABLED(ADVANCE) && DISABLED(LIN_ADVANCE)
481
+      #if ENABLED(MIXING_EXTRUDER)
482
+        // Keep updating the single E axis
483
+        counter_E += current_block->steps[E_AXIS];
484
+        // Tick the counters used for this mix
485
+        MIXING_STEPPERS_LOOP(j) {
486
+          // Step mixing steppers (proportionally)
487
+          counter_m[j] += current_block->steps[E_AXIS];
488
+          // Step when the counter goes over zero
489
+          if (counter_m[j] > 0) En_STEP_WRITE(j, !INVERT_E_STEP_PIN);
490
+        }
491
+      #else // !MIXING_EXTRUDER
492
+        PULSE_START(E);
511 493
       #endif
494
+    #endif // !ADVANCE && !LIN_ADVANCE
512 495
 
513
-      #if DISABLED(ADVANCE) && DISABLED(LIN_ADVANCE)
514
-        #if ENABLED(MIXING_EXTRUDER)
515
-          // Always step the single E axis
516
-          if (counter_E > 0) {
517
-            counter_E -= current_block->step_event_count;
518
-            count_position[E_AXIS] += count_direction[E_AXIS];
519
-          }
520
-          MIXING_STEPPERS_LOOP(j) {
521
-            if (counter_m[j] > 0) {
522
-              counter_m[j] -= current_block->mix_event_count[j];
523
-              En_STEP_WRITE(j, INVERT_E_STEP_PIN);
524
-            }
525
-          }
526
-        #else // !MIXING_EXTRUDER
527
-          PULSE_STOP(E);
528
-        #endif
529
-      #endif // !ADVANCE && !LIN_ADVANCE
530
-
531
-      if (++step_events_completed >= current_block->step_event_count) {
532
-        all_steps_done = true;
533
-        break;
534
-      }
535
-    }
536
-
537
-    #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
538
-      // If we have esteps to execute, fire the next advance_isr "now"
539
-      if (e_steps[TOOL_E_INDEX]) OCR0A = TCNT0 + 2;
496
+    // For a minimum pulse time wait before stopping pulses
497
+    #if MINIMUM_STEPPER_PULSE > 0
498
+      #define CYCLES_EATEN_BY_CODE 10
499
+      while ((uint32_t)(TCNT0 - pulse_start) < (MINIMUM_STEPPER_PULSE * (F_CPU / 1000000UL)) - CYCLES_EATEN_BY_CODE) { /* nada */ }
540 500
     #endif
541 501
 
542
-    // Calculate new timer value
543
-    uint16_t timer, step_rate;
544
-    if (step_events_completed <= (uint32_t)current_block->accelerate_until) {
502
+    #if HAS_X_STEP
503
+      PULSE_STOP(X);
504
+    #endif
505
+    #if HAS_Y_STEP
506
+      PULSE_STOP(Y);
507
+    #endif
508
+    #if HAS_Z_STEP
509
+      PULSE_STOP(Z);
510
+    #endif
545 511
 
546
-      MultiU24X32toH16(acc_step_rate, acceleration_time, current_block->acceleration_rate);
547
-      acc_step_rate += current_block->initial_rate;
512
+    #if DISABLED(ADVANCE) && DISABLED(LIN_ADVANCE)
513
+      #if ENABLED(MIXING_EXTRUDER)
514
+        // Always step the single E axis
515
+        if (counter_E > 0) {
516
+          counter_E -= current_block->step_event_count;
517
+          count_position[E_AXIS] += count_direction[E_AXIS];
518
+        }
519
+        MIXING_STEPPERS_LOOP(j) {
520
+          if (counter_m[j] > 0) {
521
+            counter_m[j] -= current_block->mix_event_count[j];
522
+            En_STEP_WRITE(j, INVERT_E_STEP_PIN);
523
+          }
524
+        }
525
+      #else // !MIXING_EXTRUDER
526
+        PULSE_STOP(E);
527
+      #endif
528
+    #endif // !ADVANCE && !LIN_ADVANCE
548 529
 
549
-      // upper limit
550
-      NOMORE(acc_step_rate, current_block->nominal_rate);
530
+    if (++step_events_completed >= current_block->step_event_count) {
531
+      all_steps_done = true;
532
+      break;
533
+    }
534
+  }
551 535
 
552
-      // step_rate to timer interval
553
-      timer = calc_timer(acc_step_rate);
554
-      OCR1A = timer;
555
-      acceleration_time += timer;
536
+  #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
537
+    // If we have esteps to execute, fire the next advance_isr "now"
538
+    if (e_steps[TOOL_E_INDEX]) OCR0A = TCNT0 + 2;
539
+  #endif
556 540
 
557
-      #if ENABLED(LIN_ADVANCE)
541
+  // Calculate new timer value
542
+  uint16_t timer, step_rate;
543
+  if (step_events_completed <= (uint32_t)current_block->accelerate_until) {
558 544
 
559
-        if (current_block->use_advance_lead)
560
-          current_estep_rate[TOOL_E_INDEX] = ((uint32_t)acc_step_rate * current_block->e_speed_multiplier8) >> 8;
545
+    MultiU24X32toH16(acc_step_rate, acceleration_time, current_block->acceleration_rate);
546
+    acc_step_rate += current_block->initial_rate;
561 547
 
562
-        if (current_block->use_advance_lead) {
563
-          #if ENABLED(MIXING_EXTRUDER)
564
-            MIXING_STEPPERS_LOOP(j)
565
-              current_estep_rate[j] = ((uint32_t)acc_step_rate * current_block->e_speed_multiplier8 * current_block->step_event_count / current_block->mix_event_count[j]) >> 8;
566
-          #else
567
-            current_estep_rate[TOOL_E_INDEX] = ((uint32_t)acc_step_rate * current_block->e_speed_multiplier8) >> 8;
568
-          #endif
569
-        }
548
+    // upper limit
549
+    NOMORE(acc_step_rate, current_block->nominal_rate);
570 550
 
571
-      #elif ENABLED(ADVANCE)
551
+    // step_rate to timer interval
552
+    timer = calc_timer(acc_step_rate);
553
+    OCR1A = timer;
554
+    acceleration_time += timer;
572 555
 
573
-        advance += advance_rate * step_loops;
574
-        //NOLESS(advance, current_block->advance);
556
+    #if ENABLED(LIN_ADVANCE)
575 557
 
576
-        long advance_whole = advance >> 8,
577
-             advance_factor = advance_whole - old_advance;
558
+      if (current_block->use_advance_lead)
559
+        current_estep_rate[TOOL_E_INDEX] = ((uint32_t)acc_step_rate * current_block->e_speed_multiplier8) >> 8;
578 560
 
579
-        // Do E steps + advance steps
561
+      if (current_block->use_advance_lead) {
580 562
         #if ENABLED(MIXING_EXTRUDER)
581
-          // ...for mixing steppers proportionally
582 563
           MIXING_STEPPERS_LOOP(j)
583
-            e_steps[j] += advance_factor * current_block->step_event_count / current_block->mix_event_count[j];
564
+            current_estep_rate[j] = ((uint32_t)acc_step_rate * current_block->e_speed_multiplier8 * current_block->step_event_count / current_block->mix_event_count[j]) >> 8;
584 565
         #else
585
-          // ...for the active extruder
586
-          e_steps[TOOL_E_INDEX] += advance_factor;
566
+          current_estep_rate[TOOL_E_INDEX] = ((uint32_t)acc_step_rate * current_block->e_speed_multiplier8) >> 8;
587 567
         #endif
568
+      }
588 569
 
589
-        old_advance = advance_whole;
570
+    #elif ENABLED(ADVANCE)
590 571
 
591
-      #endif // ADVANCE or LIN_ADVANCE
572
+      advance += advance_rate * step_loops;
573
+      //NOLESS(advance, current_block->advance);
592 574
 
593
-      #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
594
-        eISR_Rate = (timer >> 2) * step_loops / abs(e_steps[TOOL_E_INDEX]);
595
-      #endif
596
-    }
597
-    else if (step_events_completed > (uint32_t)current_block->decelerate_after) {
598
-      MultiU24X32toH16(step_rate, deceleration_time, current_block->acceleration_rate);
575
+      long advance_whole = advance >> 8,
576
+           advance_factor = advance_whole - old_advance;
599 577
 
600
-      if (step_rate < acc_step_rate) { // Still decelerating?
601
-        step_rate = acc_step_rate - step_rate;
602
-        NOLESS(step_rate, current_block->final_rate);
603
-      }
604
-      else
605
-        step_rate = current_block->final_rate;
578
+      // Do E steps + advance steps
579
+      #if ENABLED(MIXING_EXTRUDER)
580
+        // ...for mixing steppers proportionally
581
+        MIXING_STEPPERS_LOOP(j)
582
+          e_steps[j] += advance_factor * current_block->step_event_count / current_block->mix_event_count[j];
583
+      #else
584
+        // ...for the active extruder
585
+        e_steps[TOOL_E_INDEX] += advance_factor;
586
+      #endif
606 587
 
607
-      // step_rate to timer interval
608
-      timer = calc_timer(step_rate);
609
-      OCR1A = timer;
610
-      deceleration_time += timer;
588
+      old_advance = advance_whole;
611 589
 
612
-      #if ENABLED(LIN_ADVANCE)
590
+    #endif // ADVANCE or LIN_ADVANCE
613 591
 
614
-        if (current_block->use_advance_lead) {
615
-          #if ENABLED(MIXING_EXTRUDER)
616
-            MIXING_STEPPERS_LOOP(j)
617
-              current_estep_rate[j] = ((uint32_t)step_rate * current_block->e_speed_multiplier8 * current_block->step_event_count / current_block->mix_event_count[j]) >> 8;
618
-          #else
619
-            current_estep_rate[TOOL_E_INDEX] = ((uint32_t)step_rate * current_block->e_speed_multiplier8) >> 8;
620
-          #endif
621
-        }
592
+    #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
593
+      eISR_Rate = (timer >> 2) * step_loops / abs(e_steps[TOOL_E_INDEX]);
594
+    #endif
595
+  }
596
+  else if (step_events_completed > (uint32_t)current_block->decelerate_after) {
597
+    MultiU24X32toH16(step_rate, deceleration_time, current_block->acceleration_rate);
622 598
 
623
-      #elif ENABLED(ADVANCE)
599
+    if (step_rate < acc_step_rate) { // Still decelerating?
600
+      step_rate = acc_step_rate - step_rate;
601
+      NOLESS(step_rate, current_block->final_rate);
602
+    }
603
+    else
604
+      step_rate = current_block->final_rate;
624 605
 
625
-        advance -= advance_rate * step_loops;
626
-        NOLESS(advance, final_advance);
606
+    // step_rate to timer interval
607
+    timer = calc_timer(step_rate);
608
+    OCR1A = timer;
609
+    deceleration_time += timer;
627 610
 
628
-        // Do E steps + advance steps
629
-        long advance_whole = advance >> 8,
630
-             advance_factor = advance_whole - old_advance;
611
+    #if ENABLED(LIN_ADVANCE)
631 612
 
613
+      if (current_block->use_advance_lead) {
632 614
         #if ENABLED(MIXING_EXTRUDER)
633 615
           MIXING_STEPPERS_LOOP(j)
634
-            e_steps[j] += advance_factor * current_block->step_event_count / current_block->mix_event_count[j];
616
+            current_estep_rate[j] = ((uint32_t)step_rate * current_block->e_speed_multiplier8 * current_block->step_event_count / current_block->mix_event_count[j]) >> 8;
635 617
         #else
636
-          e_steps[TOOL_E_INDEX] += advance_factor;
618
+          current_estep_rate[TOOL_E_INDEX] = ((uint32_t)step_rate * current_block->e_speed_multiplier8) >> 8;
637 619
         #endif
620
+      }
621
+
622
+    #elif ENABLED(ADVANCE)
638 623
 
639
-        old_advance = advance_whole;
624
+      advance -= advance_rate * step_loops;
625
+      NOLESS(advance, final_advance);
640 626
 
641
-      #endif // ADVANCE or LIN_ADVANCE
627
+      // Do E steps + advance steps
628
+      long advance_whole = advance >> 8,
629
+           advance_factor = advance_whole - old_advance;
642 630
 
643
-      #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
644
-        eISR_Rate = (timer >> 2) * step_loops / abs(e_steps[TOOL_E_INDEX]);
631
+      #if ENABLED(MIXING_EXTRUDER)
632
+        MIXING_STEPPERS_LOOP(j)
633
+          e_steps[j] += advance_factor * current_block->step_event_count / current_block->mix_event_count[j];
634
+      #else
635
+        e_steps[TOOL_E_INDEX] += advance_factor;
645 636
       #endif
646
-    }
647
-    else {
648 637
 
649
-      #if ENABLED(LIN_ADVANCE)
638
+      old_advance = advance_whole;
650 639
 
651
-        if (current_block->use_advance_lead)
652
-          current_estep_rate[TOOL_E_INDEX] = final_estep_rate;
640
+    #endif // ADVANCE or LIN_ADVANCE
653 641
 
654
-        eISR_Rate = (OCR1A_nominal >> 2) * step_loops_nominal / abs(e_steps[TOOL_E_INDEX]);
642
+    #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
643
+      eISR_Rate = (timer >> 2) * step_loops / abs(e_steps[TOOL_E_INDEX]);
644
+    #endif
645
+  }
646
+  else {
655 647
 
656
-      #endif
648
+    #if ENABLED(LIN_ADVANCE)
657 649
 
658
-      OCR1A = OCR1A_nominal;
659
-      // ensure we're running at the correct step rate, even if we just came off an acceleration
660
-      step_loops = step_loops_nominal;
661
-    }
650
+      if (current_block->use_advance_lead)
651
+        current_estep_rate[TOOL_E_INDEX] = final_estep_rate;
662 652
 
663
-    NOLESS(OCR1A, TCNT1 + 16);
653
+      eISR_Rate = (OCR1A_nominal >> 2) * step_loops_nominal / abs(e_steps[TOOL_E_INDEX]);
664 654
 
665
-    // If current block is finished, reset pointer
666
-    if (all_steps_done) {
667
-      current_block = NULL;
668
-      planner.discard_current_block();
669
-    }
655
+    #endif
656
+
657
+    OCR1A = OCR1A_nominal;
658
+    // ensure we're running at the correct step rate, even if we just came off an acceleration
659
+    step_loops = step_loops_nominal;
660
+  }
661
+
662
+  NOLESS(OCR1A, TCNT1 + 16);
663
+
664
+  // If current block is finished, reset pointer
665
+  if (all_steps_done) {
666
+    current_block = NULL;
667
+    planner.discard_current_block();
670 668
   }
671 669
 }
672 670
 

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