|
@@ -345,13 +345,50 @@ ISR(TIMER1_COMPA_vect) {
|
345
|
345
|
void Stepper::isr() {
|
346
|
346
|
#define _ENABLE_ISRs() cli(); SBI(TIMSK0, OCIE0B); ENABLE_STEPPER_DRIVER_INTERRUPT()
|
347
|
347
|
|
|
348
|
+ uint16_t timer, remainder, ocr_val;
|
|
349
|
+
|
|
350
|
+ static uint32_t step_remaining = 0;
|
|
351
|
+
|
|
352
|
+ #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
|
+
|
348
|
355
|
#if DISABLED(ADVANCE) && DISABLED(LIN_ADVANCE)
|
349
|
|
- //Disable Timer0 ISRs and enable global ISR again to capture UART events (incoming chars)
|
350
|
|
- CBI(TIMSK0, OCIE0B); //Temperature ISR
|
|
356
|
+ // Disable Timer0 ISRs and enable global ISR again to capture UART events (incoming chars)
|
|
357
|
+ CBI(TIMSK0, OCIE0B); // Temperature ISR
|
351
|
358
|
DISABLE_STEPPER_DRIVER_INTERRUPT();
|
352
|
359
|
sei();
|
353
|
360
|
#endif
|
354
|
361
|
|
|
362
|
+ #define _SPLIT(L) (ocr_val = (uint16_t)L)
|
|
363
|
+ #if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
|
|
364
|
+ #define SPLIT(L) _SPLIT(L)
|
|
365
|
+ #else // sample endstops in between step pulses
|
|
366
|
+ #define SPLIT(L) do { \
|
|
367
|
+ _SPLIT(L); \
|
|
368
|
+ if (ENDSTOPS_ENABLED && L > ENDSTOP_NOMINAL_OCR_VAL) { \
|
|
369
|
+ 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
|
+ step_remaining = (uint16_t)L - ocr_val; \
|
|
372
|
+ } \
|
|
373
|
+ } while(0)
|
|
374
|
+
|
|
375
|
+ if (step_remaining && ENDSTOPS_ENABLED) { // Just check endstops - not yet time for a step
|
|
376
|
+ endstops.update();
|
|
377
|
+ ocr_val = step_remaining;
|
|
378
|
+ if (step_remaining > ENDSTOP_NOMINAL_OCR_VAL) {
|
|
379
|
+ step_remaining = step_remaining - ENDSTOP_NOMINAL_OCR_VAL;
|
|
380
|
+ ocr_val = ENDSTOP_NOMINAL_OCR_VAL;
|
|
381
|
+ }
|
|
382
|
+ else step_remaining = 0; // last one before the ISR that does the step
|
|
383
|
+ _NEXT_ISR(ocr_val); //
|
|
384
|
+
|
|
385
|
+ NOLESS(OCR1A, TCNT1 + 16);
|
|
386
|
+
|
|
387
|
+ _ENABLE_ISRs(); // re-enable ISRs
|
|
388
|
+ return;
|
|
389
|
+ }
|
|
390
|
+ # endif
|
|
391
|
+
|
355
|
392
|
if (cleaning_buffer_counter) {
|
356
|
393
|
--cleaning_buffer_counter;
|
357
|
394
|
current_block = NULL;
|
|
@@ -407,21 +444,16 @@ void Stepper::isr() {
|
407
|
444
|
}
|
408
|
445
|
|
409
|
446
|
// Update endstops state, if enabled
|
410
|
|
- if ((endstops.enabled
|
411
|
|
- #if HAS_BED_PROBE
|
412
|
|
- || endstops.z_probe_enabled
|
413
|
|
- #endif
|
414
|
|
- )
|
415
|
|
- #if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
|
416
|
|
- && e_hit
|
417
|
|
- #endif
|
418
|
|
- ) {
|
419
|
|
- endstops.update();
|
420
|
447
|
|
421
|
|
- #if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
|
|
448
|
+
|
|
449
|
+ #if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
|
|
450
|
+ if (ENDSTOPS_ENABLED && e_hit) {
|
|
451
|
+ endstops.update();
|
422
|
452
|
e_hit--;
|
423
|
|
- #endif
|
424
|
|
- }
|
|
453
|
+ }
|
|
454
|
+ #else
|
|
455
|
+ if (ENDSTOPS_ENABLED) endstops.update();
|
|
456
|
+ #endif
|
425
|
457
|
|
426
|
458
|
// Take multiple steps per interrupt (For high speed moves)
|
427
|
459
|
bool all_steps_done = false;
|
|
@@ -600,7 +632,10 @@ void Stepper::isr() {
|
600
|
632
|
|
601
|
633
|
// step_rate to timer interval
|
602
|
634
|
uint16_t timer = calc_timer(acc_step_rate);
|
603
|
|
- _NEXT_ISR(timer);
|
|
635
|
+
|
|
636
|
+ SPLIT(timer); // split step into multiple ISRs if larger than ENDSTOP_NOMINAL_OCR_VAL
|
|
637
|
+ _NEXT_ISR(ocr_val);
|
|
638
|
+
|
604
|
639
|
acceleration_time += timer;
|
605
|
640
|
|
606
|
641
|
#if ENABLED(LIN_ADVANCE)
|
|
@@ -653,7 +688,10 @@ void Stepper::isr() {
|
653
|
688
|
|
654
|
689
|
// step_rate to timer interval
|
655
|
690
|
uint16_t timer = calc_timer(step_rate);
|
656
|
|
- _NEXT_ISR(timer);
|
|
691
|
+
|
|
692
|
+ SPLIT(timer); // split step into multiple ISRs if larger than ENDSTOP_NOMINAL_OCR_VAL
|
|
693
|
+ _NEXT_ISR(ocr_val);
|
|
694
|
+
|
657
|
695
|
deceleration_time += timer;
|
658
|
696
|
|
659
|
697
|
#if ENABLED(LIN_ADVANCE)
|
|
@@ -702,7 +740,9 @@ void Stepper::isr() {
|
702
|
740
|
|
703
|
741
|
#endif
|
704
|
742
|
|
705
|
|
- _NEXT_ISR(OCR1A_nominal);
|
|
743
|
+ SPLIT(OCR1A_nominal); // split step into multiple ISRs if larger than ENDSTOP_NOMINAL_OCR_VAL
|
|
744
|
+ _NEXT_ISR(ocr_val);
|
|
745
|
+
|
706
|
746
|
// ensure we're running at the correct step rate, even if we just came off an acceleration
|
707
|
747
|
step_loops = step_loops_nominal;
|
708
|
748
|
}
|
|
@@ -726,9 +766,9 @@ void Stepper::isr() {
|
726
|
766
|
// Timer interrupt for E. e_steps is set in the main routine;
|
727
|
767
|
|
728
|
768
|
void Stepper::advance_isr() {
|
729
|
|
-
|
|
769
|
+
|
730
|
770
|
nextAdvanceISR = eISR_Rate;
|
731
|
|
-
|
|
771
|
+
|
732
|
772
|
#define SET_E_STEP_DIR(INDEX) \
|
733
|
773
|
if (e_steps[INDEX]) E## INDEX ##_DIR_WRITE(e_steps[INDEX] < 0 ? INVERT_E## INDEX ##_DIR : !INVERT_E## INDEX ##_DIR)
|
734
|
774
|
|
|
@@ -803,7 +843,7 @@ void Stepper::isr() {
|
803
|
843
|
|
804
|
844
|
// Run Advance stepping ISR if flagged
|
805
|
845
|
if (!nextAdvanceISR) advance_isr();
|
806
|
|
-
|
|
846
|
+
|
807
|
847
|
// Is the next advance ISR scheduled before the next main ISR?
|
808
|
848
|
if (nextAdvanceISR <= nextMainISR) {
|
809
|
849
|
// Set up the next interrupt
|
|
@@ -822,7 +862,7 @@ void Stepper::isr() {
|
822
|
862
|
// Will call Stepper::isr on the next interrupt
|
823
|
863
|
nextMainISR = 0;
|
824
|
864
|
}
|
825
|
|
-
|
|
865
|
+
|
826
|
866
|
// Don't run the ISR faster than possible
|
827
|
867
|
NOLESS(OCR1A, TCNT1 + 16);
|
828
|
868
|
|