Browse Source

First draft of Unified Stepper / E Advance ISR

Sebastianv650 7 years ago
parent
commit
84c685f8b5

+ 1
- 8
Marlin/Configuration_adv.h View File

547
  *
547
  *
548
  * Assumption: advance = k * (delta velocity)
548
  * Assumption: advance = k * (delta velocity)
549
  * K=0 means advance disabled.
549
  * K=0 means advance disabled.
550
- * To get a rough start value for calibration, measure your "free filament length"
551
- * between the hobbed bolt and the nozzle (in cm). Use the formula below that fits
552
- * your setup, where L is the "free filament length":
553
- *
554
- * Filament diameter           |   1.75mm  |    3.0mm   |
555
- * ----------------------------|-----------|------------|
556
- * Stiff filament (PLA)        | K=47*L/10 | K=139*L/10 |
557
- * Softer filament (ABS, nGen) | K=88*L/10 | K=260*L/10 |
550
+ * See Marlin documentation for calibration instructions.
558
  */
551
  */
559
 //#define LIN_ADVANCE
552
 //#define LIN_ADVANCE
560
 
553
 

+ 1
- 8
Marlin/example_configurations/Cartesio/Configuration_adv.h View File

547
  *
547
  *
548
  * Assumption: advance = k * (delta velocity)
548
  * Assumption: advance = k * (delta velocity)
549
  * K=0 means advance disabled.
549
  * K=0 means advance disabled.
550
- * To get a rough start value for calibration, measure your "free filament length"
551
- * between the hobbed bolt and the nozzle (in cm). Use the formula below that fits
552
- * your setup, where L is the "free filament length":
553
- *
554
- * Filament diameter           |   1.75mm  |    3.0mm   |
555
- * ----------------------------|-----------|------------|
556
- * Stiff filament (PLA)        | K=47*L/10 | K=139*L/10 |
557
- * Softer filament (ABS, nGen) | K=88*L/10 | K=260*L/10 |
550
+ * See Marlin documentation for calibration instructions.
558
  */
551
  */
559
 //#define LIN_ADVANCE
552
 //#define LIN_ADVANCE
560
 
553
 

+ 1
- 8
Marlin/example_configurations/Felix/Configuration_adv.h View File

547
  *
547
  *
548
  * Assumption: advance = k * (delta velocity)
548
  * Assumption: advance = k * (delta velocity)
549
  * K=0 means advance disabled.
549
  * K=0 means advance disabled.
550
- * To get a rough start value for calibration, measure your "free filament length"
551
- * between the hobbed bolt and the nozzle (in cm). Use the formula below that fits
552
- * your setup, where L is the "free filament length":
553
- *
554
- * Filament diameter           |   1.75mm  |    3.0mm   |
555
- * ----------------------------|-----------|------------|
556
- * Stiff filament (PLA)        | K=47*L/10 | K=139*L/10 |
557
- * Softer filament (ABS, nGen) | K=88*L/10 | K=260*L/10 |
550
+ * See Marlin documentation for calibration instructions.
558
  */
551
  */
559
 //#define LIN_ADVANCE
552
 //#define LIN_ADVANCE
560
 
553
 

+ 1
- 8
Marlin/example_configurations/Hephestos/Configuration_adv.h View File

547
  *
547
  *
548
  * Assumption: advance = k * (delta velocity)
548
  * Assumption: advance = k * (delta velocity)
549
  * K=0 means advance disabled.
549
  * K=0 means advance disabled.
550
- * To get a rough start value for calibration, measure your "free filament length"
551
- * between the hobbed bolt and the nozzle (in cm). Use the formula below that fits
552
- * your setup, where L is the "free filament length":
553
- *
554
- * Filament diameter           |   1.75mm  |    3.0mm   |
555
- * ----------------------------|-----------|------------|
556
- * Stiff filament (PLA)        | K=47*L/10 | K=139*L/10 |
557
- * Softer filament (ABS, nGen) | K=88*L/10 | K=260*L/10 |
550
+ * See Marlin documentation for calibration instructions.
558
  */
551
  */
559
 //#define LIN_ADVANCE
552
 //#define LIN_ADVANCE
560
 
553
 

+ 1
- 8
Marlin/example_configurations/Hephestos_2/Configuration_adv.h View File

530
  *
530
  *
531
  * Assumption: advance = k * (delta velocity)
531
  * Assumption: advance = k * (delta velocity)
532
  * K=0 means advance disabled.
532
  * K=0 means advance disabled.
533
- * To get a rough start value for calibration, measure your "free filament length"
534
- * between the hobbed bolt and the nozzle (in cm). Use the formula below that fits
535
- * your setup, where L is the "free filament length":
536
- *
537
- * Filament diameter           |   1.75mm  |    3.0mm   |
538
- * ----------------------------|-----------|------------|
539
- * Stiff filament (PLA)        | K=47*L/10 | K=139*L/10 |
540
- * Softer filament (ABS, nGen) | K=88*L/10 | K=260*L/10 |
533
+ * See Marlin documentation for calibration instructions.
541
  */
534
  */
542
 //#define LIN_ADVANCE
535
 //#define LIN_ADVANCE
543
 
536
 

+ 1
- 8
Marlin/example_configurations/K8200/Configuration_adv.h View File

560
  *
560
  *
561
  * Assumption: advance = k * (delta velocity)
561
  * Assumption: advance = k * (delta velocity)
562
  * K=0 means advance disabled.
562
  * K=0 means advance disabled.
563
- * To get a rough start value for calibration, measure your "free filament length"
564
- * between the hobbed bolt and the nozzle (in cm). Use the formula below that fits
565
- * your setup, where L is the "free filament length":
566
- *
567
- * Filament diameter           |   1.75mm  |    3.0mm   |
568
- * ----------------------------|-----------|------------|
569
- * Stiff filament (PLA)        | K=47*L/10 | K=139*L/10 |
570
- * Softer filament (ABS, nGen) | K=88*L/10 | K=260*L/10 |
563
+ * See Marlin documentation for calibration instructions.
571
  */
564
  */
572
 //#define LIN_ADVANCE
565
 //#define LIN_ADVANCE
573
 
566
 

+ 1
- 8
Marlin/example_configurations/K8400/Configuration_adv.h View File

547
  *
547
  *
548
  * Assumption: advance = k * (delta velocity)
548
  * Assumption: advance = k * (delta velocity)
549
  * K=0 means advance disabled.
549
  * K=0 means advance disabled.
550
- * To get a rough start value for calibration, measure your "free filament length"
551
- * between the hobbed bolt and the nozzle (in cm). Use the formula below that fits
552
- * your setup, where L is the "free filament length":
553
- *
554
- * Filament diameter           |   1.75mm  |    3.0mm   |
555
- * ----------------------------|-----------|------------|
556
- * Stiff filament (PLA)        | K=47*L/10 | K=139*L/10 |
557
- * Softer filament (ABS, nGen) | K=88*L/10 | K=260*L/10 |
550
+ * See Marlin documentation for calibration instructions.
558
  */
551
  */
559
 //#define LIN_ADVANCE
552
 //#define LIN_ADVANCE
560
 
553
 

+ 1
- 8
Marlin/example_configurations/RigidBot/Configuration_adv.h View File

547
  *
547
  *
548
  * Assumption: advance = k * (delta velocity)
548
  * Assumption: advance = k * (delta velocity)
549
  * K=0 means advance disabled.
549
  * K=0 means advance disabled.
550
- * To get a rough start value for calibration, measure your "free filament length"
551
- * between the hobbed bolt and the nozzle (in cm). Use the formula below that fits
552
- * your setup, where L is the "free filament length":
553
- *
554
- * Filament diameter           |   1.75mm  |    3.0mm   |
555
- * ----------------------------|-----------|------------|
556
- * Stiff filament (PLA)        | K=47*L/10 | K=139*L/10 |
557
- * Softer filament (ABS, nGen) | K=88*L/10 | K=260*L/10 |
550
+ * See Marlin documentation for calibration instructions.
558
  */
551
  */
559
 //#define LIN_ADVANCE
552
 //#define LIN_ADVANCE
560
 
553
 

+ 1
- 8
Marlin/example_configurations/SCARA/Configuration_adv.h View File

547
  *
547
  *
548
  * Assumption: advance = k * (delta velocity)
548
  * Assumption: advance = k * (delta velocity)
549
  * K=0 means advance disabled.
549
  * K=0 means advance disabled.
550
- * To get a rough start value for calibration, measure your "free filament length"
551
- * between the hobbed bolt and the nozzle (in cm). Use the formula below that fits
552
- * your setup, where L is the "free filament length":
553
- *
554
- * Filament diameter           |   1.75mm  |    3.0mm   |
555
- * ----------------------------|-----------|------------|
556
- * Stiff filament (PLA)        | K=47*L/10 | K=139*L/10 |
557
- * Softer filament (ABS, nGen) | K=88*L/10 | K=260*L/10 |
550
+ * See Marlin documentation for calibration instructions.
558
  */
551
  */
559
 //#define LIN_ADVANCE
552
 //#define LIN_ADVANCE
560
 
553
 

+ 1
- 8
Marlin/example_configurations/TAZ4/Configuration_adv.h View File

555
  *
555
  *
556
  * Assumption: advance = k * (delta velocity)
556
  * Assumption: advance = k * (delta velocity)
557
  * K=0 means advance disabled.
557
  * K=0 means advance disabled.
558
- * To get a rough start value for calibration, measure your "free filament length"
559
- * between the hobbed bolt and the nozzle (in cm). Use the formula below that fits
560
- * your setup, where L is the "free filament length":
561
- *
562
- * Filament diameter           |   1.75mm  |    3.0mm   |
563
- * ----------------------------|-----------|------------|
564
- * Stiff filament (PLA)        | K=47*L/10 | K=139*L/10 |
565
- * Softer filament (ABS, nGen) | K=88*L/10 | K=260*L/10 |
558
+ * See Marlin documentation for calibration instructions.
566
  */
559
  */
567
 //#define LIN_ADVANCE
560
 //#define LIN_ADVANCE
568
 
561
 

+ 1
- 8
Marlin/example_configurations/WITBOX/Configuration_adv.h View File

547
  *
547
  *
548
  * Assumption: advance = k * (delta velocity)
548
  * Assumption: advance = k * (delta velocity)
549
  * K=0 means advance disabled.
549
  * K=0 means advance disabled.
550
- * To get a rough start value for calibration, measure your "free filament length"
551
- * between the hobbed bolt and the nozzle (in cm). Use the formula below that fits
552
- * your setup, where L is the "free filament length":
553
- *
554
- * Filament diameter           |   1.75mm  |    3.0mm   |
555
- * ----------------------------|-----------|------------|
556
- * Stiff filament (PLA)        | K=47*L/10 | K=139*L/10 |
557
- * Softer filament (ABS, nGen) | K=88*L/10 | K=260*L/10 |
550
+ * See Marlin documentation for calibration instructions.
558
  */
551
  */
559
 //#define LIN_ADVANCE
552
 //#define LIN_ADVANCE
560
 
553
 

+ 1
- 8
Marlin/example_configurations/delta/biv2.5/Configuration_adv.h View File

549
  *
549
  *
550
  * Assumption: advance = k * (delta velocity)
550
  * Assumption: advance = k * (delta velocity)
551
  * K=0 means advance disabled.
551
  * K=0 means advance disabled.
552
- * To get a rough start value for calibration, measure your "free filament length"
553
- * between the hobbed bolt and the nozzle (in cm). Use the formula below that fits
554
- * your setup, where L is the "free filament length":
555
- *
556
- * Filament diameter           |   1.75mm  |    3.0mm   |
557
- * ----------------------------|-----------|------------|
558
- * Stiff filament (PLA)        | K=47*L/10 | K=139*L/10 |
559
- * Softer filament (ABS, nGen) | K=88*L/10 | K=260*L/10 |
552
+ * See Marlin documentation for calibration instructions.
560
  */
553
  */
561
 //#define LIN_ADVANCE
554
 //#define LIN_ADVANCE
562
 
555
 

+ 1
- 8
Marlin/example_configurations/delta/generic/Configuration_adv.h View File

549
  *
549
  *
550
  * Assumption: advance = k * (delta velocity)
550
  * Assumption: advance = k * (delta velocity)
551
  * K=0 means advance disabled.
551
  * K=0 means advance disabled.
552
- * To get a rough start value for calibration, measure your "free filament length"
553
- * between the hobbed bolt and the nozzle (in cm). Use the formula below that fits
554
- * your setup, where L is the "free filament length":
555
- *
556
- * Filament diameter           |   1.75mm  |    3.0mm   |
557
- * ----------------------------|-----------|------------|
558
- * Stiff filament (PLA)        | K=47*L/10 | K=139*L/10 |
559
- * Softer filament (ABS, nGen) | K=88*L/10 | K=260*L/10 |
552
+ * See Marlin documentation for calibration instructions.
560
  */
553
  */
561
 //#define LIN_ADVANCE
554
 //#define LIN_ADVANCE
562
 
555
 

+ 1
- 8
Marlin/example_configurations/delta/kossel_mini/Configuration_adv.h View File

549
  *
549
  *
550
  * Assumption: advance = k * (delta velocity)
550
  * Assumption: advance = k * (delta velocity)
551
  * K=0 means advance disabled.
551
  * K=0 means advance disabled.
552
- * To get a rough start value for calibration, measure your "free filament length"
553
- * between the hobbed bolt and the nozzle (in cm). Use the formula below that fits
554
- * your setup, where L is the "free filament length":
555
- *
556
- * Filament diameter           |   1.75mm  |    3.0mm   |
557
- * ----------------------------|-----------|------------|
558
- * Stiff filament (PLA)        | K=47*L/10 | K=139*L/10 |
559
- * Softer filament (ABS, nGen) | K=88*L/10 | K=260*L/10 |
552
+ * See Marlin documentation for calibration instructions.
560
  */
553
  */
561
 //#define LIN_ADVANCE
554
 //#define LIN_ADVANCE
562
 
555
 

+ 1
- 8
Marlin/example_configurations/delta/kossel_pro/Configuration_adv.h View File

554
  *
554
  *
555
  * Assumption: advance = k * (delta velocity)
555
  * Assumption: advance = k * (delta velocity)
556
  * K=0 means advance disabled.
556
  * K=0 means advance disabled.
557
- * To get a rough start value for calibration, measure your "free filament length"
558
- * between the hobbed bolt and the nozzle (in cm). Use the formula below that fits
559
- * your setup, where L is the "free filament length":
560
- *
561
- * Filament diameter           |   1.75mm  |    3.0mm   |
562
- * ----------------------------|-----------|------------|
563
- * Stiff filament (PLA)        | K=47*L/10 | K=139*L/10 |
564
- * Softer filament (ABS, nGen) | K=88*L/10 | K=260*L/10 |
557
+ * See Marlin documentation for calibration instructions.
565
  */
558
  */
566
 //#define LIN_ADVANCE
559
 //#define LIN_ADVANCE
567
 
560
 

+ 1
- 8
Marlin/example_configurations/delta/kossel_xl/Configuration_adv.h View File

549
  *
549
  *
550
  * Assumption: advance = k * (delta velocity)
550
  * Assumption: advance = k * (delta velocity)
551
  * K=0 means advance disabled.
551
  * K=0 means advance disabled.
552
- * To get a rough start value for calibration, measure your "free filament length"
553
- * between the hobbed bolt and the nozzle (in cm). Use the formula below that fits
554
- * your setup, where L is the "free filament length":
555
- *
556
- * Filament diameter           |   1.75mm  |    3.0mm   |
557
- * ----------------------------|-----------|------------|
558
- * Stiff filament (PLA)        | K=47*L/10 | K=139*L/10 |
559
- * Softer filament (ABS, nGen) | K=88*L/10 | K=260*L/10 |
552
+ * See Marlin documentation for calibration instructions.
560
  */
553
  */
561
 //#define LIN_ADVANCE
554
 //#define LIN_ADVANCE
562
 
555
 

+ 1
- 8
Marlin/example_configurations/makibox/Configuration_adv.h View File

547
  *
547
  *
548
  * Assumption: advance = k * (delta velocity)
548
  * Assumption: advance = k * (delta velocity)
549
  * K=0 means advance disabled.
549
  * K=0 means advance disabled.
550
- * To get a rough start value for calibration, measure your "free filament length"
551
- * between the hobbed bolt and the nozzle (in cm). Use the formula below that fits
552
- * your setup, where L is the "free filament length":
553
- *
554
- * Filament diameter           |   1.75mm  |    3.0mm   |
555
- * ----------------------------|-----------|------------|
556
- * Stiff filament (PLA)        | K=47*L/10 | K=139*L/10 |
557
- * Softer filament (ABS, nGen) | K=88*L/10 | K=260*L/10 |
550
+ * See Marlin documentation for calibration instructions.
558
  */
551
  */
559
 //#define LIN_ADVANCE
552
 //#define LIN_ADVANCE
560
 
553
 

+ 1
- 8
Marlin/example_configurations/tvrrug/Round2/Configuration_adv.h View File

547
  *
547
  *
548
  * Assumption: advance = k * (delta velocity)
548
  * Assumption: advance = k * (delta velocity)
549
  * K=0 means advance disabled.
549
  * K=0 means advance disabled.
550
- * To get a rough start value for calibration, measure your "free filament length"
551
- * between the hobbed bolt and the nozzle (in cm). Use the formula below that fits
552
- * your setup, where L is the "free filament length":
553
- *
554
- * Filament diameter           |   1.75mm  |    3.0mm   |
555
- * ----------------------------|-----------|------------|
556
- * Stiff filament (PLA)        | K=47*L/10 | K=139*L/10 |
557
- * Softer filament (ABS, nGen) | K=88*L/10 | K=260*L/10 |
550
+ * See Marlin documentation for calibration instructions.
558
  */
551
  */
559
 //#define LIN_ADVANCE
552
 //#define LIN_ADVANCE
560
 
553
 

+ 78
- 52
Marlin/stepper.cpp View File

91
 
91
 
92
 #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
92
 #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
93
 
93
 
94
-  uint8_t Stepper::old_OCR0A = 0;
95
-  volatile uint8_t Stepper::eISR_Rate = 200; // Keep the ISR at a low rate until needed
94
+  uint16_t Stepper::nextMainISR = 0,
95
+           Stepper::nextAdvanceISR = 65535,
96
+           Stepper::eISR_Rate = 65535;
96
 
97
 
97
   #if ENABLED(LIN_ADVANCE)
98
   #if ENABLED(LIN_ADVANCE)
98
     volatile int Stepper::e_steps[E_STEPPERS];
99
     volatile int Stepper::e_steps[E_STEPPERS];
328
  *  2000     1 KHz - sleep rate
329
  *  2000     1 KHz - sleep rate
329
  *  4000   500  Hz - init rate
330
  *  4000   500  Hz - init rate
330
  */
331
  */
331
-ISR(TIMER1_COMPA_vect) { Stepper::isr(); }
332
+ISR(TIMER1_COMPA_vect) {
333
+  #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
334
+    Stepper::advance_isr_scheduler();
335
+  #else
336
+    Stepper::isr();
337
+  #endif
338
+}
332
 
339
 
333
 void Stepper::isr() {
340
 void Stepper::isr() {
334
-  //Disable Timer0 ISRs and enable global ISR again to capture UART events (incoming chars)
335
-  #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
336
-    CBI(TIMSK0, OCIE0A); //estepper ISR
341
+  #define _ENABLE_ISRs() cli(); SBI(TIMSK0, OCIE0B); ENABLE_STEPPER_DRIVER_INTERRUPT()
342
+
343
+  #if DISABLED(ADVANCE) && DISABLED(LIN_ADVANCE)
344
+    //Disable Timer0 ISRs and enable global ISR again to capture UART events (incoming chars)
345
+    CBI(TIMSK0, OCIE0B); //Temperature ISR
346
+    DISABLE_STEPPER_DRIVER_INTERRUPT();
347
+    sei();
337
   #endif
348
   #endif
338
-  CBI(TIMSK0, OCIE0B); //Temperature ISR
339
-  DISABLE_STEPPER_DRIVER_INTERRUPT();
340
-  sei();
341
 
349
 
342
   if (cleaning_buffer_counter) {
350
   if (cleaning_buffer_counter) {
343
     --cleaning_buffer_counter;
351
     --cleaning_buffer_counter;
346
     #ifdef SD_FINISHED_RELEASECOMMAND
354
     #ifdef SD_FINISHED_RELEASECOMMAND
347
       if (!cleaning_buffer_counter && (SD_FINISHED_STEPPERRELEASE)) enqueue_and_echo_commands_P(PSTR(SD_FINISHED_RELEASECOMMAND));
355
       if (!cleaning_buffer_counter && (SD_FINISHED_STEPPERRELEASE)) enqueue_and_echo_commands_P(PSTR(SD_FINISHED_RELEASECOMMAND));
348
     #endif
356
     #endif
349
-    OCR1A = 200; // Run at max speed - 10 KHz
350
-    //re-enable ISRs
351
-    #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
352
-      SBI(TIMSK0, OCIE0A);
353
-    #endif
354
-    SBI(TIMSK0, OCIE0B);
355
-    ENABLE_STEPPER_DRIVER_INTERRUPT();
357
+    _NEXT_ISR(200); // Run at max speed - 10 KHz
358
+    _ENABLE_ISRs(); // re-enable ISRs
356
     return;
359
     return;
357
   }
360
   }
358
 
361
 
381
       #if ENABLED(Z_LATE_ENABLE)
384
       #if ENABLED(Z_LATE_ENABLE)
382
         if (current_block->steps[Z_AXIS] > 0) {
385
         if (current_block->steps[Z_AXIS] > 0) {
383
           enable_z();
386
           enable_z();
384
-          OCR1A = 2000; // Run at slow speed - 1 KHz
385
-          #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
386
-            SBI(TIMSK0, OCIE0A);
387
-          #endif
388
-          SBI(TIMSK0, OCIE0B);
389
-          ENABLE_STEPPER_DRIVER_INTERRUPT();
387
+          _NEXT_ISR(2000); // Run at slow speed - 1 KHz
388
+          _ENABLE_ISRs(); // re-enable ISRs
390
           return;
389
           return;
391
         }
390
         }
392
       #endif
391
       #endif
396
       // #endif
395
       // #endif
397
     }
396
     }
398
     else {
397
     else {
399
-      OCR1A = 2000; // Run at slow speed - 1 KHz
400
-      #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
401
-        SBI(TIMSK0, OCIE0A);
402
-      #endif
403
-      SBI(TIMSK0, OCIE0B);
404
-      ENABLE_STEPPER_DRIVER_INTERRUPT();
398
+      _NEXT_ISR(2000); // Run at slow speed - 1 KHz
399
+      _ENABLE_ISRs(); // re-enable ISRs
405
       return;
400
       return;
406
     }
401
     }
407
   }
402
   }
586
 
581
 
587
   #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
582
   #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
588
     // If we have esteps to execute, fire the next advance_isr "now"
583
     // If we have esteps to execute, fire the next advance_isr "now"
589
-    if (e_steps[TOOL_E_INDEX]) OCR0A = TCNT0 + 2;
584
+    if (e_steps[TOOL_E_INDEX]) nextAdvanceISR = 0;
590
   #endif
585
   #endif
591
 
586
 
592
   // Calculate new timer value
587
   // Calculate new timer value
600
 
595
 
601
     // step_rate to timer interval
596
     // step_rate to timer interval
602
     uint16_t timer = calc_timer(acc_step_rate);
597
     uint16_t timer = calc_timer(acc_step_rate);
603
-    OCR1A = timer;
598
+    _NEXT_ISR(timer);
604
     acceleration_time += timer;
599
     acceleration_time += timer;
605
 
600
 
606
     #if ENABLED(LIN_ADVANCE)
601
     #if ENABLED(LIN_ADVANCE)
637
     #endif // ADVANCE or LIN_ADVANCE
632
     #endif // ADVANCE or LIN_ADVANCE
638
 
633
 
639
     #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
634
     #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
640
-      eISR_Rate = (timer >> 3) * step_loops / abs(e_steps[TOOL_E_INDEX]); //>> 3 is divide by 8. Reason: Timer 1 runs at 16/8=2MHz, Timer 0 at 16/64=0.25MHz. ==> 2/0.25=8.
635
+      eISR_Rate = !e_steps[TOOL_E_INDEX] ? 65535 : timer * step_loops / abs(e_steps[TOOL_E_INDEX]);
641
     #endif
636
     #endif
642
   }
637
   }
643
   else if (step_events_completed > (uint32_t)current_block->decelerate_after) {
638
   else if (step_events_completed > (uint32_t)current_block->decelerate_after) {
653
 
648
 
654
     // step_rate to timer interval
649
     // step_rate to timer interval
655
     uint16_t timer = calc_timer(step_rate);
650
     uint16_t timer = calc_timer(step_rate);
656
-    OCR1A = timer;
651
+    _NEXT_ISR(timer);
657
     deceleration_time += timer;
652
     deceleration_time += timer;
658
 
653
 
659
     #if ENABLED(LIN_ADVANCE)
654
     #if ENABLED(LIN_ADVANCE)
688
     #endif // ADVANCE or LIN_ADVANCE
683
     #endif // ADVANCE or LIN_ADVANCE
689
 
684
 
690
     #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
685
     #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
691
-      eISR_Rate = (timer >> 3) * step_loops / abs(e_steps[TOOL_E_INDEX]);
686
+      eISR_Rate = !e_steps[TOOL_E_INDEX] ? 65535 : timer * step_loops / abs(e_steps[TOOL_E_INDEX]);
692
     #endif
687
     #endif
693
   }
688
   }
694
   else {
689
   else {
698
       if (current_block->use_advance_lead)
693
       if (current_block->use_advance_lead)
699
         current_estep_rate[TOOL_E_INDEX] = final_estep_rate;
694
         current_estep_rate[TOOL_E_INDEX] = final_estep_rate;
700
 
695
 
701
-      eISR_Rate = (OCR1A_nominal >> 3) * step_loops_nominal / abs(e_steps[TOOL_E_INDEX]);
696
+      eISR_Rate = !e_steps[TOOL_E_INDEX] ? 65535 : OCR1A_nominal * step_loops_nominal / abs(e_steps[TOOL_E_INDEX]);
702
 
697
 
703
     #endif
698
     #endif
704
 
699
 
705
-    OCR1A = OCR1A_nominal;
700
+    _NEXT_ISR(OCR1A_nominal);
706
     // ensure we're running at the correct step rate, even if we just came off an acceleration
701
     // ensure we're running at the correct step rate, even if we just came off an acceleration
707
     step_loops = step_loops_nominal;
702
     step_loops = step_loops_nominal;
708
   }
703
   }
709
 
704
 
710
-  NOLESS(OCR1A, TCNT1 + 16);
705
+  #if DISABLED(ADVANCE) && DISABLED(LIN_ADVANCE)
706
+    NOLESS(OCR1A, TCNT1 + 16);
707
+  #endif
711
 
708
 
712
   // If current block is finished, reset pointer
709
   // If current block is finished, reset pointer
713
   if (all_steps_done) {
710
   if (all_steps_done) {
714
     current_block = NULL;
711
     current_block = NULL;
715
     planner.discard_current_block();
712
     planner.discard_current_block();
716
   }
713
   }
717
-  #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
718
-    SBI(TIMSK0, OCIE0A);
714
+  #if DISABLED(ADVANCE) && DISABLED(LIN_ADVANCE)
715
+    _ENABLE_ISRs(); // re-enable ISRs
719
   #endif
716
   #endif
720
-  SBI(TIMSK0, OCIE0B);
721
-  ENABLE_STEPPER_DRIVER_INTERRUPT();
722
 }
717
 }
723
 
718
 
724
 #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
719
 #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
725
 
720
 
726
   // Timer interrupt for E. e_steps is set in the main routine;
721
   // Timer interrupt for E. e_steps is set in the main routine;
727
-  // Timer 0 is shared with millies
728
-  ISR(TIMER0_COMPA_vect) { Stepper::advance_isr(); }
729
 
722
 
730
   void Stepper::advance_isr() {
723
   void Stepper::advance_isr() {
731
-
732
-    old_OCR0A += eISR_Rate;
733
-    OCR0A = old_OCR0A;
734
-
724
+    
725
+    nextAdvanceISR = eISR_Rate;
726
+    
735
     #define SET_E_STEP_DIR(INDEX) \
727
     #define SET_E_STEP_DIR(INDEX) \
736
       if (e_steps[INDEX]) E## INDEX ##_DIR_WRITE(e_steps[INDEX] < 0 ? INVERT_E## INDEX ##_DIR : !INVERT_E## INDEX ##_DIR)
728
       if (e_steps[INDEX]) E## INDEX ##_DIR_WRITE(e_steps[INDEX] < 0 ? INVERT_E## INDEX ##_DIR : !INVERT_E## INDEX ##_DIR)
737
 
729
 
795
 
787
 
796
   }
788
   }
797
 
789
 
790
+  void Stepper::advance_isr_scheduler() {
791
+    // Disable Timer0 ISRs and enable global ISR again to capture UART events (incoming chars)
792
+    CBI(TIMSK0, OCIE0B); // Temperature ISR
793
+    DISABLE_STEPPER_DRIVER_INTERRUPT();
794
+    sei();
795
+
796
+    // Run main stepping ISR if flagged
797
+    if (!nextMainISR) isr();
798
+
799
+    // Run Advance stepping ISR if flagged
800
+    if (!nextAdvanceISR) advance_isr();
801
+  
802
+    // Is the next advance ISR scheduled before the next main ISR?
803
+    if (nextAdvanceISR <= nextMainISR) {
804
+      // Set up the next interrupt
805
+      OCR1A = nextAdvanceISR;
806
+      // New interval for the next main ISR
807
+      if (nextMainISR) nextMainISR -= nextAdvanceISR;
808
+      // Will call Stepper::advance_isr on the next interrupt
809
+      nextAdvanceISR = 0;
810
+    }
811
+    else {
812
+      // The next main ISR comes first
813
+      OCR1A = nextMainISR;
814
+      // New interval for the next advance ISR, if any
815
+      if (nextAdvanceISR && nextAdvanceISR != 65535)
816
+        nextAdvanceISR -= nextMainISR;
817
+      // Will call Stepper::isr on the next interrupt
818
+      nextMainISR = 0;
819
+    }
820
+  
821
+    // Don't run the ISR faster than possible
822
+    NOLESS(OCR1A, TCNT1 + 16);
823
+
824
+    // Restore original ISR settings
825
+    cli();
826
+    SBI(TIMSK0, OCIE0B);
827
+    ENABLE_STEPPER_DRIVER_INTERRUPT();
828
+  }
829
+
798
 #endif // ADVANCE or LIN_ADVANCE
830
 #endif // ADVANCE or LIN_ADVANCE
799
 
831
 
800
 void Stepper::init() {
832
 void Stepper::init() {
981
       #endif
1013
       #endif
982
     }
1014
     }
983
 
1015
 
984
-    #if defined(TCCR0A) && defined(WGM01)
985
-      CBI(TCCR0A, WGM01);
986
-      CBI(TCCR0A, WGM00);
987
-    #endif
988
-    SBI(TIMSK0, OCIE0A);
989
-
990
   #endif // ADVANCE or LIN_ADVANCE
1016
   #endif // ADVANCE or LIN_ADVANCE
991
 
1017
 
992
   endstops.enable(true); // Start with endstops active. After homing they can be disabled
1018
   endstops.enable(true); // Start with endstops active. After homing they can be disabled

+ 8
- 5
Marlin/stepper.h View File

105
     static volatile uint32_t step_events_completed; // The number of step events executed in the current block
105
     static volatile uint32_t step_events_completed; // The number of step events executed in the current block
106
 
106
 
107
     #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
107
     #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
108
-      static uint8_t old_OCR0A;
109
-      static volatile uint8_t eISR_Rate;
108
+      static uint16_t nextMainISR, nextAdvanceISR, eISR_Rate;
109
+      #define _NEXT_ISR(T) nextMainISR = T
110
       #if ENABLED(LIN_ADVANCE)
110
       #if ENABLED(LIN_ADVANCE)
111
         static volatile int e_steps[E_STEPPERS];
111
         static volatile int e_steps[E_STEPPERS];
112
         static int final_estep_rate;
112
         static int final_estep_rate;
119
         static long advance_rate, advance, final_advance;
119
         static long advance_rate, advance, final_advance;
120
         static long old_advance;
120
         static long old_advance;
121
       #endif
121
       #endif
122
+    #else
123
+      #define _NEXT_ISR(T) OCR1A = T
122
     #endif // ADVANCE or LIN_ADVANCE
124
     #endif // ADVANCE or LIN_ADVANCE
123
 
125
 
124
     static long acceleration_time, deceleration_time;
126
     static long acceleration_time, deceleration_time;
177
 
179
 
178
     #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
180
     #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
179
       static void advance_isr();
181
       static void advance_isr();
182
+      static void advance_isr_scheduler();
180
     #endif
183
     #endif
181
 
184
 
182
     //
185
     //
318
       return timer;
321
       return timer;
319
     }
322
     }
320
 
323
 
321
-    // Initializes the trapezoid generator from the current block. Called whenever a new
322
-    // block begins.
324
+    // Initialize the trapezoid generator from the current block.
325
+    // Called whenever a new block begins.
323
     static FORCE_INLINE void trapezoid_generator_reset() {
326
     static FORCE_INLINE void trapezoid_generator_reset() {
324
 
327
 
325
       static int8_t last_extruder = -1;
328
       static int8_t last_extruder = -1;
357
       step_loops_nominal = step_loops;
360
       step_loops_nominal = step_loops;
358
       acc_step_rate = current_block->initial_rate;
361
       acc_step_rate = current_block->initial_rate;
359
       acceleration_time = calc_timer(acc_step_rate);
362
       acceleration_time = calc_timer(acc_step_rate);
360
-      OCR1A = acceleration_time;
363
+      _NEXT_ISR(acceleration_time);
361
 
364
 
362
       #if ENABLED(LIN_ADVANCE)
365
       #if ENABLED(LIN_ADVANCE)
363
         if (current_block->use_advance_lead) {
366
         if (current_block->use_advance_lead) {

Loading…
Cancel
Save