|
@@ -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
|
}
|
|
@@ -903,6 +915,7 @@ void Stepper::init() {
|
903
|
915
|
// output mode = 00 (disconnected)
|
904
|
916
|
TCCR1A &= ~(3 << COM1A0);
|
905
|
917
|
TCCR1A &= ~(3 << COM1B0);
|
|
918
|
+
|
906
|
919
|
// Set the timer pre-scaler
|
907
|
920
|
// Generally we use a divider of 8, resulting in a 2MHz timer
|
908
|
921
|
// frequency on a 16MHz MCU. If you are going to change this, be
|
|
@@ -910,6 +923,7 @@ void Stepper::init() {
|
910
|
923
|
// create_speed_lookuptable.py
|
911
|
924
|
TCCR1B = (TCCR1B & ~(0x07 << CS10)) | (2 << CS10);
|
912
|
925
|
|
|
926
|
+ // Init Stepper ISR to 122 Hz for quick starting
|
913
|
927
|
OCR1A = 0x4000;
|
914
|
928
|
TCNT1 = 0;
|
915
|
929
|
ENABLE_STEPPER_DRIVER_INTERRUPT();
|