Skip to content

Commit

Permalink
Run the advance_isr faster instead of doing multiple e-steps per inte…
Browse files Browse the repository at this point in the history
…rrupt
  • Loading branch information
thinkyhead committed May 6, 2016
1 parent ac3c862 commit fa7a232
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions Marlin/stepper.cpp
Original file line number Diff line number Diff line change
@@ -445,7 +445,19 @@ void Stepper::isr() {

void Stepper::advance_isr() {

old_OCR0A += 52; // ~10kHz interrupt (250000 / 26 = 9615kHz)
byte maxesteps = 0;
for (uint8_t i = 0; i < EXTRUDERS; i++)
if (abs(e_steps[i]) > maxesteps) maxesteps = abs(e_steps[i]);

if (maxesteps > 3)
old_OCR0A += 13; // ~19kHz (250000/13 = 19230 Hz)
else if (maxesteps > 2)
old_OCR0A += 17; // ~15kHz (250000/17 = 14705 Hz)
else if (maxesteps > 1)
old_OCR0A += 26; // ~10kHz (250000/26 = 9615 Hz)
else
old_OCR0A += 52; // ~5kHz (250000/26 = 4807 Hz)

OCR0A = old_OCR0A;

#define STEP_E_ONCE(INDEX) \
@@ -462,19 +474,17 @@ void Stepper::isr() {
E## INDEX ##_STEP_WRITE(!INVERT_E_STEP_PIN); \
}

// Step all E steppers that have steps, up to 4 steps per interrupt
for (unsigned char i = 0; i < 4; i++) {
STEP_E_ONCE(0);
#if EXTRUDERS > 1
STEP_E_ONCE(1);
#if EXTRUDERS > 2
STEP_E_ONCE(2);
#if EXTRUDERS > 3
STEP_E_ONCE(3);
#endif
// Step all E steppers that have steps
STEP_E_ONCE(0);
#if EXTRUDERS > 1
STEP_E_ONCE(1);
#if EXTRUDERS > 2
STEP_E_ONCE(2);
#if EXTRUDERS > 3
STEP_E_ONCE(3);
#endif
#endif
}
#endif

}

0 comments on commit fa7a232

Please sign in to comment.