|
@@ -95,7 +95,7 @@ volatile uint32_t Stepper::step_events_completed = 0; // The number of step even
|
95
|
95
|
volatile unsigned char Stepper::eISR_Rate = 200; // Keep the ISR at a low rate until needed
|
96
|
96
|
|
97
|
97
|
#if ENABLED(LIN_ADVANCE)
|
98
|
|
- volatile long Stepper::e_steps[E_STEPPERS];
|
|
98
|
+ volatile int Stepper::e_steps[E_STEPPERS];
|
99
|
99
|
int Stepper::extruder_advance_k = LIN_ADVANCE_K,
|
100
|
100
|
Stepper::final_estep_rate,
|
101
|
101
|
Stepper::current_estep_rate[E_STEPPERS],
|
|
@@ -311,8 +311,20 @@ void Stepper::set_directions() {
|
311
|
311
|
#endif // !ADVANCE && !LIN_ADVANCE
|
312
|
312
|
}
|
313
|
313
|
|
314
|
|
-// "The Stepper Driver Interrupt" - This timer interrupt is the workhorse.
|
315
|
|
-// It pops blocks from the block_buffer and executes them by pulsing the stepper pins appropriately.
|
|
314
|
+/**
|
|
315
|
+ * Stepper Driver Interrupt
|
|
316
|
+ *
|
|
317
|
+ * Directly pulses the stepper motors at high frequency.
|
|
318
|
+ * Timer 1 runs at a base frequency of 2MHz, with this ISR using OCR1A compare mode.
|
|
319
|
+ *
|
|
320
|
+ * OCR1A Frequency
|
|
321
|
+ * 1 2 MHz
|
|
322
|
+ * 50 40 KHz
|
|
323
|
+ * 100 20 KHz - capped max rate
|
|
324
|
+ * 200 10 KHz - nominal max rate
|
|
325
|
+ * 2000 1 KHz - sleep rate
|
|
326
|
+ * 4000 500 Hz - init rate
|
|
327
|
+ */
|
316
|
328
|
ISR(TIMER1_COMPA_vect) { Stepper::isr(); }
|
317
|
329
|
|
318
|
330
|
void Stepper::isr() {
|
|
@@ -323,7 +335,7 @@ void Stepper::isr() {
|
323
|
335
|
if ((cleaning_buffer_counter == 1) && (SD_FINISHED_STEPPERRELEASE)) enqueue_and_echo_commands_P(PSTR(SD_FINISHED_RELEASECOMMAND));
|
324
|
336
|
#endif
|
325
|
337
|
cleaning_buffer_counter--;
|
326
|
|
- OCR1A = 200;
|
|
338
|
+ OCR1A = 200; // Run at max speed - 10 KHz
|
327
|
339
|
return;
|
328
|
340
|
}
|
329
|
341
|
|
|
@@ -348,7 +360,7 @@ void Stepper::isr() {
|
348
|
360
|
#if ENABLED(Z_LATE_ENABLE)
|
349
|
361
|
if (current_block->steps[Z_AXIS] > 0) {
|
350
|
362
|
enable_z();
|
351
|
|
- OCR1A = 2000; //1ms wait
|
|
363
|
+ OCR1A = 2000; // Run at slow speed - 1 KHz
|
352
|
364
|
return;
|
353
|
365
|
}
|
354
|
366
|
#endif
|
|
@@ -358,7 +370,7 @@ void Stepper::isr() {
|
358
|
370
|
// #endif
|
359
|
371
|
}
|
360
|
372
|
else {
|
361
|
|
- OCR1A = 2000; // 1kHz.
|
|
373
|
+ OCR1A = 2000; // Run at slow speed - 1 KHz
|
362
|
374
|
return;
|
363
|
375
|
}
|
364
|
376
|
}
|
|
@@ -391,7 +403,7 @@ void Stepper::isr() {
|
391
|
403
|
|
392
|
404
|
#if ENABLED(MIXING_EXTRUDER)
|
393
|
405
|
// Step mixing steppers proportionally
|
394
|
|
- bool dir = motor_direction(E_AXIS);
|
|
406
|
+ const bool dir = motor_direction(E_AXIS);
|
395
|
407
|
MIXING_STEPPERS_LOOP(j) {
|
396
|
408
|
counter_m[j] += current_block->steps[E_AXIS];
|
397
|
409
|
if (counter_m[j] > 0) {
|
|
@@ -401,22 +413,6 @@ void Stepper::isr() {
|
401
|
413
|
}
|
402
|
414
|
#endif
|
403
|
415
|
|
404
|
|
- if (current_block->use_advance_lead) {
|
405
|
|
- int delta_adv_steps = (((long)extruder_advance_k * current_estep_rate[TOOL_E_INDEX]) >> 9) - current_adv_steps[TOOL_E_INDEX];
|
406
|
|
- #if ENABLED(MIXING_EXTRUDER)
|
407
|
|
- // Mixing extruders apply advance lead proportionally
|
408
|
|
- MIXING_STEPPERS_LOOP(j) {
|
409
|
|
- int steps = delta_adv_steps * current_block->step_event_count / current_block->mix_event_count[j];
|
410
|
|
- e_steps[j] += steps;
|
411
|
|
- current_adv_steps[j] += steps;
|
412
|
|
- }
|
413
|
|
- #else
|
414
|
|
- // For most extruders, advance the single E stepper
|
415
|
|
- e_steps[TOOL_E_INDEX] += delta_adv_steps;
|
416
|
|
- current_adv_steps[TOOL_E_INDEX] += delta_adv_steps;
|
417
|
|
- #endif
|
418
|
|
- }
|
419
|
|
-
|
420
|
416
|
#elif ENABLED(ADVANCE)
|
421
|
417
|
|
422
|
418
|
// Always count the unified E axis
|
|
@@ -432,7 +428,7 @@ void Stepper::isr() {
|
432
|
428
|
#if ENABLED(MIXING_EXTRUDER)
|
433
|
429
|
|
434
|
430
|
// Step mixing steppers proportionally
|
435
|
|
- bool dir = motor_direction(E_AXIS);
|
|
431
|
+ const bool dir = motor_direction(E_AXIS);
|
436
|
432
|
MIXING_STEPPERS_LOOP(j) {
|
437
|
433
|
counter_m[j] += current_block->steps[E_AXIS];
|
438
|
434
|
if (counter_m[j] > 0) {
|
|
@@ -536,6 +532,21 @@ void Stepper::isr() {
|
536
|
532
|
}
|
537
|
533
|
}
|
538
|
534
|
|
|
535
|
+ #if ENABLED(LIN_ADVANCE)
|
|
536
|
+ if (current_block->use_advance_lead) {
|
|
537
|
+ int delta_adv_steps = (((long)extruder_advance_k * current_estep_rate[TOOL_E_INDEX]) >> 9) - current_adv_steps[TOOL_E_INDEX];
|
|
538
|
+ current_adv_steps[TOOL_E_INDEX] += delta_adv_steps;
|
|
539
|
+ #if ENABLED(MIXING_EXTRUDER)
|
|
540
|
+ // Mixing extruders apply advance lead proportionally
|
|
541
|
+ MIXING_STEPPERS_LOOP(j)
|
|
542
|
+ e_steps[j] += delta_adv_steps * current_block->step_event_count / current_block->mix_event_count[j];
|
|
543
|
+ #else
|
|
544
|
+ // For most extruders, advance the single E stepper
|
|
545
|
+ e_steps[TOOL_E_INDEX] += delta_adv_steps;
|
|
546
|
+ #endif
|
|
547
|
+ }
|
|
548
|
+ #endif
|
|
549
|
+
|
539
|
550
|
#if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
|
540
|
551
|
// If we have esteps to execute, fire the next advance_isr "now"
|
541
|
552
|
if (e_steps[TOOL_E_INDEX]) OCR0A = TCNT0 + 2;
|
|
@@ -593,7 +604,7 @@ void Stepper::isr() {
|
593
|
604
|
#endif // ADVANCE or LIN_ADVANCE
|
594
|
605
|
|
595
|
606
|
#if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
|
596
|
|
- eISR_Rate = (timer >> 2) * step_loops / abs(e_steps[TOOL_E_INDEX]);
|
|
607
|
+ eISR_Rate = (timer >> 3) * step_loops / abs(e_steps[TOOL_E_INDEX]); //>> 3 is divide by 8. Reason: Timer 0 runs at 16/8=2MHz, Timer 1 at 16/64=0.25MHz. ==> 2/0.25=8.
|
597
|
608
|
#endif
|
598
|
609
|
}
|
599
|
610
|
else if (step_events_completed > (uint32_t)current_block->decelerate_after) {
|
|
@@ -643,7 +654,7 @@ void Stepper::isr() {
|
643
|
654
|
#endif // ADVANCE or LIN_ADVANCE
|
644
|
655
|
|
645
|
656
|
#if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
|
646
|
|
- eISR_Rate = (timer >> 2) * step_loops / abs(e_steps[TOOL_E_INDEX]);
|
|
657
|
+ eISR_Rate = (timer >> 3) * step_loops / abs(e_steps[TOOL_E_INDEX]);
|
647
|
658
|
#endif
|
648
|
659
|
}
|
649
|
660
|
else {
|
|
@@ -653,7 +664,7 @@ void Stepper::isr() {
|
653
|
664
|
if (current_block->use_advance_lead)
|
654
|
665
|
current_estep_rate[TOOL_E_INDEX] = final_estep_rate;
|
655
|
666
|
|
656
|
|
- eISR_Rate = (OCR1A_nominal >> 2) * step_loops_nominal / abs(e_steps[TOOL_E_INDEX]);
|
|
667
|
+ eISR_Rate = (OCR1A_nominal >> 3) * step_loops_nominal / abs(e_steps[TOOL_E_INDEX]);
|
657
|
668
|
|
658
|
669
|
#endif
|
659
|
670
|
|
|
@@ -904,6 +915,7 @@ void Stepper::init() {
|
904
|
915
|
// output mode = 00 (disconnected)
|
905
|
916
|
TCCR1A &= ~(3 << COM1A0);
|
906
|
917
|
TCCR1A &= ~(3 << COM1B0);
|
|
918
|
+
|
907
|
919
|
// Set the timer pre-scaler
|
908
|
920
|
// Generally we use a divider of 8, resulting in a 2MHz timer
|
909
|
921
|
// frequency on a 16MHz MCU. If you are going to change this, be
|
|
@@ -911,6 +923,7 @@ void Stepper::init() {
|
911
|
923
|
// create_speed_lookuptable.py
|
912
|
924
|
TCCR1B = (TCCR1B & ~(0x07 << CS10)) | (2 << CS10);
|
913
|
925
|
|
|
926
|
+ // Init Stepper ISR to 122 Hz for quick starting
|
914
|
927
|
OCR1A = 0x4000;
|
915
|
928
|
TCNT1 = 0;
|
916
|
929
|
ENABLE_STEPPER_DRIVER_INTERRUPT();
|