Merge pull request #6309 from thinkyhead/rc_fix_minimum_pulse

Fix MINIMUM_STEPPER_PULSE calculations
This commit is contained in:
Scott Lahteine 2017-04-11 11:54:26 -05:00 committed by GitHub
commit 944218f7da
7 changed files with 297 additions and 210 deletions

View File

@ -60,36 +60,36 @@ void manage_inactivity(bool ignore_stepper_queue = false);
#endif #endif
#if HAS_X2_ENABLE #if HAS_X2_ENABLE
#define enable_x() do{ X_ENABLE_WRITE( X_ENABLE_ON); X2_ENABLE_WRITE( X_ENABLE_ON); }while(0) #define enable_X() do{ X_ENABLE_WRITE( X_ENABLE_ON); X2_ENABLE_WRITE( X_ENABLE_ON); }while(0)
#define disable_x() do{ X_ENABLE_WRITE(!X_ENABLE_ON); X2_ENABLE_WRITE(!X_ENABLE_ON); axis_known_position[X_AXIS] = false; }while(0) #define disable_X() do{ X_ENABLE_WRITE(!X_ENABLE_ON); X2_ENABLE_WRITE(!X_ENABLE_ON); axis_known_position[X_AXIS] = false; }while(0)
#elif HAS_X_ENABLE #elif HAS_X_ENABLE
#define enable_x() X_ENABLE_WRITE( X_ENABLE_ON) #define enable_X() X_ENABLE_WRITE( X_ENABLE_ON)
#define disable_x() do{ X_ENABLE_WRITE(!X_ENABLE_ON); axis_known_position[X_AXIS] = false; }while(0) #define disable_X() do{ X_ENABLE_WRITE(!X_ENABLE_ON); axis_known_position[X_AXIS] = false; }while(0)
#else #else
#define enable_x() NOOP #define enable_X() NOOP
#define disable_x() NOOP #define disable_X() NOOP
#endif #endif
#if HAS_Y2_ENABLE #if HAS_Y2_ENABLE
#define enable_y() do{ Y_ENABLE_WRITE( Y_ENABLE_ON); Y2_ENABLE_WRITE(Y_ENABLE_ON); }while(0) #define enable_Y() do{ Y_ENABLE_WRITE( Y_ENABLE_ON); Y2_ENABLE_WRITE(Y_ENABLE_ON); }while(0)
#define disable_y() do{ Y_ENABLE_WRITE(!Y_ENABLE_ON); Y2_ENABLE_WRITE(!Y_ENABLE_ON); axis_known_position[Y_AXIS] = false; }while(0) #define disable_Y() do{ Y_ENABLE_WRITE(!Y_ENABLE_ON); Y2_ENABLE_WRITE(!Y_ENABLE_ON); axis_known_position[Y_AXIS] = false; }while(0)
#elif HAS_Y_ENABLE #elif HAS_Y_ENABLE
#define enable_y() Y_ENABLE_WRITE( Y_ENABLE_ON) #define enable_Y() Y_ENABLE_WRITE( Y_ENABLE_ON)
#define disable_y() do{ Y_ENABLE_WRITE(!Y_ENABLE_ON); axis_known_position[Y_AXIS] = false; }while(0) #define disable_Y() do{ Y_ENABLE_WRITE(!Y_ENABLE_ON); axis_known_position[Y_AXIS] = false; }while(0)
#else #else
#define enable_y() NOOP #define enable_Y() NOOP
#define disable_y() NOOP #define disable_Y() NOOP
#endif #endif
#if HAS_Z2_ENABLE #if HAS_Z2_ENABLE
#define enable_z() do{ Z_ENABLE_WRITE( Z_ENABLE_ON); Z2_ENABLE_WRITE(Z_ENABLE_ON); }while(0) #define enable_Z() do{ Z_ENABLE_WRITE( Z_ENABLE_ON); Z2_ENABLE_WRITE(Z_ENABLE_ON); }while(0)
#define disable_z() do{ Z_ENABLE_WRITE(!Z_ENABLE_ON); Z2_ENABLE_WRITE(!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; }while(0) #define disable_Z() do{ Z_ENABLE_WRITE(!Z_ENABLE_ON); Z2_ENABLE_WRITE(!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; }while(0)
#elif HAS_Z_ENABLE #elif HAS_Z_ENABLE
#define enable_z() Z_ENABLE_WRITE( Z_ENABLE_ON) #define enable_Z() Z_ENABLE_WRITE( Z_ENABLE_ON)
#define disable_z() do{ Z_ENABLE_WRITE(!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; }while(0) #define disable_Z() do{ Z_ENABLE_WRITE(!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; }while(0)
#else #else
#define enable_z() NOOP #define enable_Z() NOOP
#define disable_z() NOOP #define disable_Z() NOOP
#endif #endif
#if ENABLED(MIXING_EXTRUDER) #if ENABLED(MIXING_EXTRUDER)
@ -98,64 +98,64 @@ void manage_inactivity(bool ignore_stepper_queue = false);
* Mixing steppers synchronize their enable (and direction) together * Mixing steppers synchronize their enable (and direction) together
*/ */
#if MIXING_STEPPERS > 3 #if MIXING_STEPPERS > 3
#define enable_e0() { E0_ENABLE_WRITE( E_ENABLE_ON); E1_ENABLE_WRITE( E_ENABLE_ON); E2_ENABLE_WRITE( E_ENABLE_ON); E3_ENABLE_WRITE( E_ENABLE_ON); } #define enable_E0() { E0_ENABLE_WRITE( E_ENABLE_ON); E1_ENABLE_WRITE( E_ENABLE_ON); E2_ENABLE_WRITE( E_ENABLE_ON); E3_ENABLE_WRITE( E_ENABLE_ON); }
#define disable_e0() { E0_ENABLE_WRITE(!E_ENABLE_ON); E1_ENABLE_WRITE(!E_ENABLE_ON); E2_ENABLE_WRITE(!E_ENABLE_ON); E3_ENABLE_WRITE(!E_ENABLE_ON); } #define disable_E0() { E0_ENABLE_WRITE(!E_ENABLE_ON); E1_ENABLE_WRITE(!E_ENABLE_ON); E2_ENABLE_WRITE(!E_ENABLE_ON); E3_ENABLE_WRITE(!E_ENABLE_ON); }
#elif MIXING_STEPPERS > 2 #elif MIXING_STEPPERS > 2
#define enable_e0() { E0_ENABLE_WRITE( E_ENABLE_ON); E1_ENABLE_WRITE( E_ENABLE_ON); E2_ENABLE_WRITE( E_ENABLE_ON); } #define enable_E0() { E0_ENABLE_WRITE( E_ENABLE_ON); E1_ENABLE_WRITE( E_ENABLE_ON); E2_ENABLE_WRITE( E_ENABLE_ON); }
#define disable_e0() { E0_ENABLE_WRITE(!E_ENABLE_ON); E1_ENABLE_WRITE(!E_ENABLE_ON); E2_ENABLE_WRITE(!E_ENABLE_ON); } #define disable_E0() { E0_ENABLE_WRITE(!E_ENABLE_ON); E1_ENABLE_WRITE(!E_ENABLE_ON); E2_ENABLE_WRITE(!E_ENABLE_ON); }
#else #else
#define enable_e0() { E0_ENABLE_WRITE( E_ENABLE_ON); E1_ENABLE_WRITE( E_ENABLE_ON); } #define enable_E0() { E0_ENABLE_WRITE( E_ENABLE_ON); E1_ENABLE_WRITE( E_ENABLE_ON); }
#define disable_e0() { E0_ENABLE_WRITE(!E_ENABLE_ON); E1_ENABLE_WRITE(!E_ENABLE_ON); } #define disable_E0() { E0_ENABLE_WRITE(!E_ENABLE_ON); E1_ENABLE_WRITE(!E_ENABLE_ON); }
#endif #endif
#define enable_e1() NOOP #define enable_E1() NOOP
#define disable_e1() NOOP #define disable_E1() NOOP
#define enable_e2() NOOP #define enable_E2() NOOP
#define disable_e2() NOOP #define disable_E2() NOOP
#define enable_e3() NOOP #define enable_E3() NOOP
#define disable_e3() NOOP #define disable_E3() NOOP
#define enable_e4() NOOP #define enable_E4() NOOP
#define disable_e4() NOOP #define disable_E4() NOOP
#else // !MIXING_EXTRUDER #else // !MIXING_EXTRUDER
#if HAS_E0_ENABLE #if HAS_E0_ENABLE
#define enable_e0() E0_ENABLE_WRITE( E_ENABLE_ON) #define enable_E0() E0_ENABLE_WRITE( E_ENABLE_ON)
#define disable_e0() E0_ENABLE_WRITE(!E_ENABLE_ON) #define disable_E0() E0_ENABLE_WRITE(!E_ENABLE_ON)
#else #else
#define enable_e0() NOOP #define enable_E0() NOOP
#define disable_e0() NOOP #define disable_E0() NOOP
#endif #endif
#if E_STEPPERS > 1 && HAS_E1_ENABLE #if E_STEPPERS > 1 && HAS_E1_ENABLE
#define enable_e1() E1_ENABLE_WRITE( E_ENABLE_ON) #define enable_E1() E1_ENABLE_WRITE( E_ENABLE_ON)
#define disable_e1() E1_ENABLE_WRITE(!E_ENABLE_ON) #define disable_E1() E1_ENABLE_WRITE(!E_ENABLE_ON)
#else #else
#define enable_e1() NOOP #define enable_E1() NOOP
#define disable_e1() NOOP #define disable_E1() NOOP
#endif #endif
#if E_STEPPERS > 2 && HAS_E2_ENABLE #if E_STEPPERS > 2 && HAS_E2_ENABLE
#define enable_e2() E2_ENABLE_WRITE( E_ENABLE_ON) #define enable_E2() E2_ENABLE_WRITE( E_ENABLE_ON)
#define disable_e2() E2_ENABLE_WRITE(!E_ENABLE_ON) #define disable_E2() E2_ENABLE_WRITE(!E_ENABLE_ON)
#else #else
#define enable_e2() NOOP #define enable_E2() NOOP
#define disable_e2() NOOP #define disable_E2() NOOP
#endif #endif
#if E_STEPPERS > 3 && HAS_E3_ENABLE #if E_STEPPERS > 3 && HAS_E3_ENABLE
#define enable_e3() E3_ENABLE_WRITE( E_ENABLE_ON) #define enable_E3() E3_ENABLE_WRITE( E_ENABLE_ON)
#define disable_e3() E3_ENABLE_WRITE(!E_ENABLE_ON) #define disable_E3() E3_ENABLE_WRITE(!E_ENABLE_ON)
#else #else
#define enable_e3() NOOP #define enable_E3() NOOP
#define disable_e3() NOOP #define disable_E3() NOOP
#endif #endif
#if E_STEPPERS > 4 && HAS_E4_ENABLE #if E_STEPPERS > 4 && HAS_E4_ENABLE
#define enable_e4() E4_ENABLE_WRITE( E_ENABLE_ON) #define enable_E4() E4_ENABLE_WRITE( E_ENABLE_ON)
#define disable_e4() E4_ENABLE_WRITE(!E_ENABLE_ON) #define disable_E4() E4_ENABLE_WRITE(!E_ENABLE_ON)
#else #else
#define enable_e4() NOOP #define enable_E4() NOOP
#define disable_e4() NOOP #define disable_E4() NOOP
#endif #endif
#endif // !MIXING_EXTRUDER #endif // !MIXING_EXTRUDER

View File

@ -6489,9 +6489,9 @@ inline void gcode_M18_M84() {
} }
else { else {
stepper.synchronize(); stepper.synchronize();
if (code_seen('X')) disable_x(); if (code_seen('X')) disable_X();
if (code_seen('Y')) disable_y(); if (code_seen('Y')) disable_Y();
if (code_seen('Z')) disable_z(); if (code_seen('Z')) disable_Z();
#if ((E0_ENABLE_PIN != X_ENABLE_PIN) && (E1_ENABLE_PIN != Y_ENABLE_PIN)) // Only enable on boards that have seperate ENABLE_PINS #if ((E0_ENABLE_PIN != X_ENABLE_PIN) && (E1_ENABLE_PIN != Y_ENABLE_PIN)) // Only enable on boards that have seperate ENABLE_PINS
if (code_seen('E')) disable_e_steppers(); if (code_seen('E')) disable_e_steppers();
#endif #endif
@ -10888,28 +10888,28 @@ void calculate_volumetric_multipliers() {
} }
void enable_all_steppers() { void enable_all_steppers() {
enable_x(); enable_X();
enable_y(); enable_Y();
enable_z(); enable_Z();
enable_e0(); enable_E0();
enable_e1(); enable_E1();
enable_e2(); enable_E2();
enable_e3(); enable_E3();
enable_e4(); enable_E4();
} }
void disable_e_steppers() { void disable_e_steppers() {
disable_e0(); disable_E0();
disable_e1(); disable_E1();
disable_e2(); disable_E2();
disable_e3(); disable_E3();
disable_e4(); disable_E4();
} }
void disable_all_steppers() { void disable_all_steppers() {
disable_x(); disable_X();
disable_y(); disable_Y();
disable_z(); disable_Z();
disable_e_steppers(); disable_e_steppers();
} }
@ -11011,13 +11011,13 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) {
if (M600_TEST && stepper_inactive_time && ELAPSED(ms, previous_cmd_ms + stepper_inactive_time) if (M600_TEST && stepper_inactive_time && ELAPSED(ms, previous_cmd_ms + stepper_inactive_time)
&& !ignore_stepper_queue && !planner.blocks_queued()) { && !ignore_stepper_queue && !planner.blocks_queued()) {
#if ENABLED(DISABLE_INACTIVE_X) #if ENABLED(DISABLE_INACTIVE_X)
disable_x(); disable_X();
#endif #endif
#if ENABLED(DISABLE_INACTIVE_Y) #if ENABLED(DISABLE_INACTIVE_Y)
disable_y(); disable_Y();
#endif #endif
#if ENABLED(DISABLE_INACTIVE_Z) #if ENABLED(DISABLE_INACTIVE_Z)
disable_z(); disable_Z();
#endif #endif
#if ENABLED(DISABLE_INACTIVE_E) #if ENABLED(DISABLE_INACTIVE_E)
disable_e_steppers(); disable_e_steppers();
@ -11080,32 +11080,32 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) {
bool oldstatus; bool oldstatus;
#if ENABLED(SWITCHING_EXTRUDER) #if ENABLED(SWITCHING_EXTRUDER)
oldstatus = E0_ENABLE_READ; oldstatus = E0_ENABLE_READ;
enable_e0(); enable_E0();
#else // !SWITCHING_EXTRUDER #else // !SWITCHING_EXTRUDER
switch (active_extruder) { switch (active_extruder) {
case 0: case 0:
oldstatus = E0_ENABLE_READ; oldstatus = E0_ENABLE_READ;
enable_e0(); enable_E0();
break; break;
#if E_STEPPERS > 1 #if E_STEPPERS > 1
case 1: case 1:
oldstatus = E1_ENABLE_READ; oldstatus = E1_ENABLE_READ;
enable_e1(); enable_E1();
break; break;
#if E_STEPPERS > 2 #if E_STEPPERS > 2
case 2: case 2:
oldstatus = E2_ENABLE_READ; oldstatus = E2_ENABLE_READ;
enable_e2(); enable_E2();
break; break;
#if E_STEPPERS > 3 #if E_STEPPERS > 3
case 3: case 3:
oldstatus = E3_ENABLE_READ; oldstatus = E3_ENABLE_READ;
enable_e3(); enable_E3();
break; break;
#if E_STEPPERS > 4 #if E_STEPPERS > 4
case 4: case 4:
oldstatus = E4_ENABLE_READ; oldstatus = E4_ENABLE_READ;
enable_e4(); enable_E4();
break; break;
#endif // E_STEPPERS > 4 #endif // E_STEPPERS > 4
#endif // E_STEPPERS > 3 #endif // E_STEPPERS > 3

View File

@ -36,8 +36,49 @@
#define CRITICAL_SECTION_END SREG = _sreg; #define CRITICAL_SECTION_END SREG = _sreg;
#endif #endif
// Clock speed factor // Clock speed factors
#define CYCLES_PER_MICROSECOND (F_CPU / 1000000UL) // 16 or 20 #define CYCLES_PER_MICROSECOND (F_CPU / 1000000L) // 16 or 20
#define INT0_PRESCALER 8
// Highly granular delays for step pulses, etc.
#define DELAY_0_NOP NOOP
#define DELAY_1_NOP __asm__("nop\n\t")
#define DELAY_2_NOP DELAY_1_NOP; DELAY_1_NOP
#define DELAY_3_NOP DELAY_1_NOP; DELAY_2_NOP
#define DELAY_4_NOP DELAY_1_NOP; DELAY_3_NOP
#define DELAY_5_NOP DELAY_1_NOP; DELAY_4_NOP
#define DELAY_NOPS(X) \
switch (X) { \
case 20: DELAY_1_NOP; case 19: DELAY_1_NOP; \
case 18: DELAY_1_NOP; case 17: DELAY_1_NOP; \
case 16: DELAY_1_NOP; case 15: DELAY_1_NOP; \
case 14: DELAY_1_NOP; case 13: DELAY_1_NOP; \
case 12: DELAY_1_NOP; case 11: DELAY_1_NOP; \
case 10: DELAY_1_NOP; case 9: DELAY_1_NOP; \
case 8: DELAY_1_NOP; case 7: DELAY_1_NOP; \
case 6: DELAY_1_NOP; case 5: DELAY_1_NOP; \
case 4: DELAY_1_NOP; case 3: DELAY_1_NOP; \
case 2: DELAY_1_NOP; case 1: DELAY_1_NOP; \
}
#define DELAY_10_NOP DELAY_5_NOP; DELAY_5_NOP
#define DELAY_20_NOP DELAY_10_NOP; DELAY_10_NOP
#if CYCLES_PER_MICROSECOND == 16
#define DELAY_1US DELAY_10_NOP; DELAY_5_NOP; DELAY_1_NOP
#else
#define DELAY_1US DELAY_20_NOP
#endif
#define DELAY_2US DELAY_1US; DELAY_1US
#define DELAY_3US DELAY_1US; DELAY_2US
#define DELAY_4US DELAY_1US; DELAY_3US
#define DELAY_5US DELAY_1US; DELAY_4US
#define DELAY_6US DELAY_1US; DELAY_5US
#define DELAY_7US DELAY_1US; DELAY_6US
#define DELAY_8US DELAY_1US; DELAY_7US
#define DELAY_9US DELAY_1US; DELAY_8US
#define DELAY_10US DELAY_1US; DELAY_9US
// Remove compiler warning on an unused variable // Remove compiler warning on an unused variable
#define UNUSED(x) (void) (x) #define UNUSED(x) (void) (x)

View File

@ -441,13 +441,13 @@ void Planner::check_axes_activity() {
} }
} }
#if ENABLED(DISABLE_X) #if ENABLED(DISABLE_X)
if (!axis_active[X_AXIS]) disable_x(); if (!axis_active[X_AXIS]) disable_X();
#endif #endif
#if ENABLED(DISABLE_Y) #if ENABLED(DISABLE_Y)
if (!axis_active[Y_AXIS]) disable_y(); if (!axis_active[Y_AXIS]) disable_Y();
#endif #endif
#if ENABLED(DISABLE_Z) #if ENABLED(DISABLE_Z)
if (!axis_active[Z_AXIS]) disable_z(); if (!axis_active[Z_AXIS]) disable_Z();
#endif #endif
#if ENABLED(DISABLE_E) #if ENABLED(DISABLE_E)
if (!axis_active[E_AXIS]) disable_e_steppers(); if (!axis_active[E_AXIS]) disable_e_steppers();
@ -832,29 +832,29 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
//enable active axes //enable active axes
#if CORE_IS_XY #if CORE_IS_XY
if (block->steps[A_AXIS] || block->steps[B_AXIS]) { if (block->steps[A_AXIS] || block->steps[B_AXIS]) {
enable_x(); enable_X();
enable_y(); enable_Y();
} }
#if DISABLED(Z_LATE_ENABLE) #if DISABLED(Z_LATE_ENABLE)
if (block->steps[Z_AXIS]) enable_z(); if (block->steps[Z_AXIS]) enable_Z();
#endif #endif
#elif CORE_IS_XZ #elif CORE_IS_XZ
if (block->steps[A_AXIS] || block->steps[C_AXIS]) { if (block->steps[A_AXIS] || block->steps[C_AXIS]) {
enable_x(); enable_X();
enable_z(); enable_Z();
} }
if (block->steps[Y_AXIS]) enable_y(); if (block->steps[Y_AXIS]) enable_Y();
#elif CORE_IS_YZ #elif CORE_IS_YZ
if (block->steps[B_AXIS] || block->steps[C_AXIS]) { if (block->steps[B_AXIS] || block->steps[C_AXIS]) {
enable_y(); enable_Y();
enable_z(); enable_Z();
} }
if (block->steps[X_AXIS]) enable_x(); if (block->steps[X_AXIS]) enable_X();
#else #else
if (block->steps[X_AXIS]) enable_x(); if (block->steps[X_AXIS]) enable_X();
if (block->steps[Y_AXIS]) enable_y(); if (block->steps[Y_AXIS]) enable_Y();
#if DISABLED(Z_LATE_ENABLE) #if DISABLED(Z_LATE_ENABLE)
if (block->steps[Z_AXIS]) enable_z(); if (block->steps[Z_AXIS]) enable_Z();
#endif #endif
#endif #endif
@ -868,22 +868,22 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
switch(extruder) { switch(extruder) {
case 0: case 0:
enable_e0(); enable_E0();
#if ENABLED(DUAL_X_CARRIAGE) #if ENABLED(DUAL_X_CARRIAGE)
if (extruder_duplication_enabled) { if (extruder_duplication_enabled) {
enable_e1(); enable_E1();
g_uc_extruder_last_move[1] = (BLOCK_BUFFER_SIZE) * 2; g_uc_extruder_last_move[1] = (BLOCK_BUFFER_SIZE) * 2;
} }
#endif #endif
g_uc_extruder_last_move[0] = (BLOCK_BUFFER_SIZE) * 2; g_uc_extruder_last_move[0] = (BLOCK_BUFFER_SIZE) * 2;
#if EXTRUDERS > 1 #if EXTRUDERS > 1
if (g_uc_extruder_last_move[1] == 0) disable_e1(); if (g_uc_extruder_last_move[1] == 0) disable_E1();
#if EXTRUDERS > 2 #if EXTRUDERS > 2
if (g_uc_extruder_last_move[2] == 0) disable_e2(); if (g_uc_extruder_last_move[2] == 0) disable_E2();
#if EXTRUDERS > 3 #if EXTRUDERS > 3
if (g_uc_extruder_last_move[3] == 0) disable_e3(); if (g_uc_extruder_last_move[3] == 0) disable_E3();
#if EXTRUDERS > 4 #if EXTRUDERS > 4
if (g_uc_extruder_last_move[4] == 0) disable_e4(); if (g_uc_extruder_last_move[4] == 0) disable_E4();
#endif // EXTRUDERS > 4 #endif // EXTRUDERS > 4
#endif // EXTRUDERS > 3 #endif // EXTRUDERS > 3
#endif // EXTRUDERS > 2 #endif // EXTRUDERS > 2
@ -891,51 +891,51 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
break; break;
#if EXTRUDERS > 1 #if EXTRUDERS > 1
case 1: case 1:
enable_e1(); enable_E1();
g_uc_extruder_last_move[1] = (BLOCK_BUFFER_SIZE) * 2; g_uc_extruder_last_move[1] = (BLOCK_BUFFER_SIZE) * 2;
if (g_uc_extruder_last_move[0] == 0) disable_e0(); if (g_uc_extruder_last_move[0] == 0) disable_E0();
#if EXTRUDERS > 2 #if EXTRUDERS > 2
if (g_uc_extruder_last_move[2] == 0) disable_e2(); if (g_uc_extruder_last_move[2] == 0) disable_E2();
#if EXTRUDERS > 3 #if EXTRUDERS > 3
if (g_uc_extruder_last_move[3] == 0) disable_e3(); if (g_uc_extruder_last_move[3] == 0) disable_E3();
#if EXTRUDERS > 4 #if EXTRUDERS > 4
if (g_uc_extruder_last_move[4] == 0) disable_e4(); if (g_uc_extruder_last_move[4] == 0) disable_E4();
#endif // EXTRUDERS > 4 #endif // EXTRUDERS > 4
#endif // EXTRUDERS > 3 #endif // EXTRUDERS > 3
#endif // EXTRUDERS > 2 #endif // EXTRUDERS > 2
break; break;
#if EXTRUDERS > 2 #if EXTRUDERS > 2
case 2: case 2:
enable_e2(); enable_E2();
g_uc_extruder_last_move[2] = (BLOCK_BUFFER_SIZE) * 2; g_uc_extruder_last_move[2] = (BLOCK_BUFFER_SIZE) * 2;
if (g_uc_extruder_last_move[0] == 0) disable_e0(); if (g_uc_extruder_last_move[0] == 0) disable_E0();
if (g_uc_extruder_last_move[1] == 0) disable_e1(); if (g_uc_extruder_last_move[1] == 0) disable_E1();
#if EXTRUDERS > 3 #if EXTRUDERS > 3
if (g_uc_extruder_last_move[3] == 0) disable_e3(); if (g_uc_extruder_last_move[3] == 0) disable_E3();
#if EXTRUDERS > 4 #if EXTRUDERS > 4
if (g_uc_extruder_last_move[4] == 0) disable_e4(); if (g_uc_extruder_last_move[4] == 0) disable_E4();
#endif #endif
#endif #endif
break; break;
#if EXTRUDERS > 3 #if EXTRUDERS > 3
case 3: case 3:
enable_e3(); enable_E3();
g_uc_extruder_last_move[3] = (BLOCK_BUFFER_SIZE) * 2; g_uc_extruder_last_move[3] = (BLOCK_BUFFER_SIZE) * 2;
if (g_uc_extruder_last_move[0] == 0) disable_e0(); if (g_uc_extruder_last_move[0] == 0) disable_E0();
if (g_uc_extruder_last_move[1] == 0) disable_e1(); if (g_uc_extruder_last_move[1] == 0) disable_E1();
if (g_uc_extruder_last_move[2] == 0) disable_e2(); if (g_uc_extruder_last_move[2] == 0) disable_E2();
#if EXTRUDERS > 4 #if EXTRUDERS > 4
if (g_uc_extruder_last_move[4] == 0) disable_e4(); if (g_uc_extruder_last_move[4] == 0) disable_E4();
#endif #endif
break; break;
#if EXTRUDERS > 4 #if EXTRUDERS > 4
case 4: case 4:
enable_e4(); enable_E4();
g_uc_extruder_last_move[4] = (BLOCK_BUFFER_SIZE) * 2; g_uc_extruder_last_move[4] = (BLOCK_BUFFER_SIZE) * 2;
if (g_uc_extruder_last_move[0] == 0) disable_e0(); if (g_uc_extruder_last_move[0] == 0) disable_E0();
if (g_uc_extruder_last_move[1] == 0) disable_e1(); if (g_uc_extruder_last_move[1] == 0) disable_E1();
if (g_uc_extruder_last_move[2] == 0) disable_e2(); if (g_uc_extruder_last_move[2] == 0) disable_E2();
if (g_uc_extruder_last_move[3] == 0) disable_e3(); if (g_uc_extruder_last_move[3] == 0) disable_E3();
break; break;
#endif // EXTRUDERS > 4 #endif // EXTRUDERS > 4
#endif // EXTRUDERS > 3 #endif // EXTRUDERS > 3
@ -943,11 +943,11 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
#endif // EXTRUDERS > 1 #endif // EXTRUDERS > 1
} }
#else #else
enable_e0(); enable_E0();
enable_e1(); enable_E1();
enable_e2(); enable_E2();
enable_e3(); enable_E3();
enable_e4(); enable_E4();
#endif #endif
} }

View File

@ -82,7 +82,7 @@
// Say which 16 bit timers can be used and in what order // Say which 16 bit timers can be used and in what order
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
//#define _useTimer1 //#define _useTimer1 // Timer 1 is used by the stepper ISR
#define _useTimer3 #define _useTimer3
#define _useTimer4 #define _useTimer4
#if !HAS_MOTOR_CURRENT_PWM #if !HAS_MOTOR_CURRENT_PWM

View File

@ -428,7 +428,7 @@ void Stepper::isr() {
#if ENABLED(Z_LATE_ENABLE) #if ENABLED(Z_LATE_ENABLE)
if (current_block->steps[Z_AXIS] > 0) { if (current_block->steps[Z_AXIS] > 0) {
enable_z(); enable_Z();
_NEXT_ISR(2000); // Run at slow speed - 1 KHz _NEXT_ISR(2000); // Run at slow speed - 1 KHz
_ENABLE_ISRs(); // re-enable ISRs _ENABLE_ISRs(); // re-enable ISRs
return; return;
@ -460,7 +460,7 @@ void Stepper::isr() {
// Take multiple steps per interrupt (For high speed moves) // Take multiple steps per interrupt (For high speed moves)
bool all_steps_done = false; bool all_steps_done = false;
for (int8_t i = 0; i < step_loops; i++) { for (uint8_t i = step_loops; i--;) {
#if ENABLED(LIN_ADVANCE) #if ENABLED(LIN_ADVANCE)
counter_E += current_block->steps[E_AXIS]; counter_E += current_block->steps[E_AXIS];
@ -530,10 +530,34 @@ void Stepper::isr() {
_APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS),0); \ _APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS),0); \
} }
#define CYCLES_EATEN_BY_CODE 240 #if HAS_X_STEP
#define _COUNT_STEPPERS_1 1
#else
#define _COUNT_STEPPERS_1 0
#endif
#if HAS_Y_STEP
#define _COUNT_STEPPERS_2 _COUNT_STEPPERS_1 + 1
#else
#define _COUNT_STEPPERS_2 _COUNT_STEPPERS_1
#endif
#if HAS_Z_STEP
#define _COUNT_STEPPERS_3 _COUNT_STEPPERS_2 + 1
#else
#define _COUNT_STEPPERS_3 _COUNT_STEPPERS_2
#endif
#if DISABLED(ADVANCE) && DISABLED(LIN_ADVANCE)
#define _COUNT_STEPPERS_4 _COUNT_STEPPERS_3 + 1
#else
#define _COUNT_STEPPERS_4 _COUNT_STEPPERS_3
#endif
// If a minimum pulse time was specified get the CPU clock #define CYCLES_EATEN_XYZE ((_COUNT_STEPPERS_4) * 5)
#if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_CODE #define EXTRA_CYCLES_XYZE (STEP_PULSE_CYCLES - (CYCLES_EATEN_XYZE))
// If a minimum pulse time was specified get the timer 0 value
// which increments every 4µs on 16MHz and every 3.2µs on 20MHz.
// Two or 3 counts of TCNT0 should be a sufficient delay.
#if EXTRA_CYCLES_XYZE > 20
uint32_t pulse_start = TCNT0; uint32_t pulse_start = TCNT0;
#endif #endif
@ -564,9 +588,12 @@ void Stepper::isr() {
#endif #endif
#endif // !ADVANCE && !LIN_ADVANCE #endif // !ADVANCE && !LIN_ADVANCE
// For a minimum pulse time wait before stopping pulses // For minimum pulse time wait before stopping pulses
#if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_CODE #if EXTRA_CYCLES_XYZE > 20
while ((uint32_t)(TCNT0 - pulse_start) < STEP_PULSE_CYCLES - CYCLES_EATEN_BY_CODE) { /* nada */ } while (EXTRA_CYCLES_XYZE > (uint32_t)(TCNT0 - pulse_start) * (INT0_PRESCALER)) { /* nada */ }
pulse_start = TCNT0;
#elif EXTRA_CYCLES_XYZE > 0
DELAY_NOPS(EXTRA_CYCLES_XYZE);
#endif #endif
#if HAS_X_STEP #if HAS_X_STEP
@ -601,7 +628,15 @@ void Stepper::isr() {
all_steps_done = true; all_steps_done = true;
break; break;
} }
}
// For minimum pulse time wait before stopping pulses
#if EXTRA_CYCLES_XYZE > 20
if (i) while (EXTRA_CYCLES_XYZE > (uint32_t)(TCNT0 - pulse_start) * (INT0_PRESCALER)) { /* nada */ }
#elif EXTRA_CYCLES_XYZE > 0
if (i) DELAY_NOPS(EXTRA_CYCLES_XYZE);
#endif
} // steps_loop
#if ENABLED(LIN_ADVANCE) #if ENABLED(LIN_ADVANCE)
if (current_block->use_advance_lead) { if (current_block->use_advance_lead) {
@ -765,6 +800,9 @@ void Stepper::isr() {
#if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE) #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
#define CYCLES_EATEN_E (E_STEPPERS * 5)
#define EXTRA_CYCLES_E (STEP_PULSE_CYCLES - (CYCLES_EATEN_E))
// Timer interrupt for E. e_steps is set in the main routine; // Timer interrupt for E. e_steps is set in the main routine;
void Stepper::advance_isr() { void Stepper::advance_isr() {
@ -794,12 +832,10 @@ void Stepper::isr() {
#endif #endif
#endif #endif
#define CYCLES_EATEN_BY_E 60
// Step all E steppers that have steps // Step all E steppers that have steps
for (uint8_t i = 0; i < step_loops; i++) { for (uint8_t i = step_loops; i--;) {
#if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_E #if EXTRA_CYCLES_E > 20
uint32_t pulse_start = TCNT0; uint32_t pulse_start = TCNT0;
#endif #endif
@ -814,9 +850,12 @@ void Stepper::isr() {
#endif #endif
#endif #endif
// For a minimum pulse time wait before stopping pulses // For minimum pulse time wait before stopping pulses
#if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_E #if EXTRA_CYCLES_E > 20
while ((uint32_t)(TCNT0 - pulse_start) < STEP_PULSE_CYCLES - CYCLES_EATEN_BY_E) { /* nada */ } while (EXTRA_CYCLES_E > (uint32_t)(TCNT0 - pulse_start) * (INT0_PRESCALER)) { /* nada */ }
pulse_start = TCNT0;
#elif EXTRA_CYCLES_E > 0
DELAY_NOPS(EXTRA_CYCLES_E);
#endif #endif
STOP_E_PULSE(0); STOP_E_PULSE(0);
@ -829,8 +868,15 @@ void Stepper::isr() {
#endif #endif
#endif #endif
#endif #endif
}
// For minimum pulse time wait before looping
#if EXTRA_CYCLES_E > 20
if (i) while (EXTRA_CYCLES_E > (uint32_t)(TCNT0 - pulse_start) * (INT0_PRESCALER)) { /* nada */ }
#elif EXTRA_CYCLES_E > 0
if (i) DELAY_NOPS(EXTRA_CYCLES_E);
#endif
} // steps_loop
} }
void Stepper::advance_isr_scheduler() { void Stepper::advance_isr_scheduler() {
@ -986,14 +1032,14 @@ void Stepper::init() {
#define _STEP_INIT(AXIS) AXIS ##_STEP_INIT #define _STEP_INIT(AXIS) AXIS ##_STEP_INIT
#define _WRITE_STEP(AXIS, HIGHLOW) AXIS ##_STEP_WRITE(HIGHLOW) #define _WRITE_STEP(AXIS, HIGHLOW) AXIS ##_STEP_WRITE(HIGHLOW)
#define _DISABLE(axis) disable_## axis() #define _DISABLE(AXIS) disable_## AXIS()
#define AXIS_INIT(axis, AXIS, PIN) \ #define AXIS_INIT(AXIS, PIN) \
_STEP_INIT(AXIS); \ _STEP_INIT(AXIS); \
_WRITE_STEP(AXIS, _INVERT_STEP_PIN(PIN)); \ _WRITE_STEP(AXIS, _INVERT_STEP_PIN(PIN)); \
_DISABLE(axis) _DISABLE(AXIS)
#define E_AXIS_INIT(NUM) AXIS_INIT(e## NUM, E## NUM, E) #define E_AXIS_INIT(NUM) AXIS_INIT(E## NUM, E)
// Init Step Pins // Init Step Pins
#if HAS_X_STEP #if HAS_X_STEP
@ -1001,7 +1047,7 @@ void Stepper::init() {
X2_STEP_INIT; X2_STEP_INIT;
X2_STEP_WRITE(INVERT_X_STEP_PIN); X2_STEP_WRITE(INVERT_X_STEP_PIN);
#endif #endif
AXIS_INIT(x, X, X); AXIS_INIT(X, X);
#endif #endif
#if HAS_Y_STEP #if HAS_Y_STEP
@ -1009,7 +1055,7 @@ void Stepper::init() {
Y2_STEP_INIT; Y2_STEP_INIT;
Y2_STEP_WRITE(INVERT_Y_STEP_PIN); Y2_STEP_WRITE(INVERT_Y_STEP_PIN);
#endif #endif
AXIS_INIT(y, Y, Y); AXIS_INIT(Y, Y);
#endif #endif
#if HAS_Z_STEP #if HAS_Z_STEP
@ -1017,7 +1063,7 @@ void Stepper::init() {
Z2_STEP_INIT; Z2_STEP_INIT;
Z2_STEP_WRITE(INVERT_Z_STEP_PIN); Z2_STEP_WRITE(INVERT_Z_STEP_PIN);
#endif #endif
AXIS_INIT(z, Z, Z); AXIS_INIT(Z, Z);
#endif #endif
#if HAS_E0_STEP #if HAS_E0_STEP
@ -1056,15 +1102,11 @@ void Stepper::init() {
ENABLE_STEPPER_DRIVER_INTERRUPT(); ENABLE_STEPPER_DRIVER_INTERRUPT();
#if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE) #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
ZERO(e_steps);
for (int i = 0; i < E_STEPPERS; i++) {
e_steps[i] = 0;
#if ENABLED(LIN_ADVANCE) #if ENABLED(LIN_ADVANCE)
current_adv_steps[i] = 0; ZERO(current_adv_steps);
#endif #endif
} #endif // ADVANCE || LIN_ADVANCE
#endif // ADVANCE or LIN_ADVANCE
endstops.enable(true); // Start with endstops active. After homing they can be disabled endstops.enable(true); // Start with endstops active. After homing they can be disabled
sei(); sei();
@ -1235,29 +1277,40 @@ void Stepper::report_positions() {
#if ENABLED(BABYSTEPPING) #if ENABLED(BABYSTEPPING)
#define CYCLES_EATEN_BY_BABYSTEP 60 #if ENABLED(DELTA)
#define CYCLES_EATEN_BABYSTEP (2 * 15)
#else
#define CYCLES_EATEN_BABYSTEP 0
#endif
#define EXTRA_CYCLES_BABYSTEP (STEP_PULSE_CYCLES - (CYCLES_EATEN_BABYSTEP))
#define _ENABLE(axis) enable_## axis() #define _ENABLE(AXIS) enable_## AXIS()
#define _READ_DIR(AXIS) AXIS ##_DIR_READ #define _READ_DIR(AXIS) AXIS ##_DIR_READ
#define _INVERT_DIR(AXIS) INVERT_## AXIS ##_DIR #define _INVERT_DIR(AXIS) INVERT_## AXIS ##_DIR
#define _APPLY_DIR(AXIS, INVERT) AXIS ##_APPLY_DIR(INVERT, true) #define _APPLY_DIR(AXIS, INVERT) AXIS ##_APPLY_DIR(INVERT, true)
#if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_BABYSTEP #if EXTRA_CYCLES_BABYSTEP > 20
#define _SAVE_START (pulse_start = TCNT0) #define _SAVE_START (pulse_start = TCNT0)
#define _PULSE_WAIT while ((uint32_t)(TCNT0 - pulse_start) < STEP_PULSE_CYCLES - CYCLES_EATEN_BY_BABYSTEP) { /* nada */ } #define _PULSE_WAIT while (EXTRA_CYCLES_BABYSTEP > (uint32_t)(TCNT0 - pulse_start) * (INT0_PRESCALER)) { /* nada */ }
#else #else
#define _SAVE_START NOOP #define _SAVE_START NOOP
#if EXTRA_CYCLES_BABYSTEP > 0
#define _PULSE_WAIT DELAY_NOPS(EXTRA_CYCLES_BABYSTEP)
#elif STEP_PULSE_CYCLES > 0
#define _PULSE_WAIT NOOP #define _PULSE_WAIT NOOP
#elif ENABLED(DELTA)
#define _PULSE_WAIT delayMicroseconds(2);
#else
#define _PULSE_WAIT delayMicroseconds(4);
#endif
#endif #endif
#define START_BABYSTEP_AXIS(AXIS, INVERT) { \ #define BABYSTEP_AXIS(AXIS, INVERT) { \
old_dir = _READ_DIR(AXIS); \ const uint8_t old_dir = _READ_DIR(AXIS); \
_ENABLE(AXIS); \
_SAVE_START; \ _SAVE_START; \
_APPLY_DIR(AXIS, _INVERT_DIR(AXIS)^direction^INVERT); \ _APPLY_DIR(AXIS, _INVERT_DIR(AXIS)^direction^INVERT); \
_APPLY_STEP(AXIS)(!_INVERT_STEP_PIN(AXIS), true); \ _APPLY_STEP(AXIS)(!_INVERT_STEP_PIN(AXIS), true); \
}
#define STOP_BABYSTEP_AXIS(AXIS) { \
_PULSE_WAIT; \ _PULSE_WAIT; \
_APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS), true); \ _APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS), true); \
_APPLY_DIR(AXIS, old_dir); \ _APPLY_DIR(AXIS, old_dir); \
@ -1268,60 +1321,60 @@ void Stepper::report_positions() {
void Stepper::babystep(const AxisEnum axis, const bool direction) { void Stepper::babystep(const AxisEnum axis, const bool direction) {
cli(); cli();
uint8_t old_dir; uint8_t old_dir;
#if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_BABYSTEP
#if EXTRA_CYCLES_BABYSTEP > 20
uint32_t pulse_start; uint32_t pulse_start;
#endif #endif
switch (axis) { switch (axis) {
#if ENABLED(BABYSTEP_XY)
case X_AXIS: case X_AXIS:
_ENABLE(x); BABYSTEP_AXIS(X, false);
START_BABYSTEP_AXIS(X, false);
STOP_BABYSTEP_AXIS(X);
break; break;
case Y_AXIS: case Y_AXIS:
_ENABLE(y); BABYSTEP_AXIS(Y, false);
START_BABYSTEP_AXIS(Y, false);
STOP_BABYSTEP_AXIS(Y);
break; break;
#endif
case Z_AXIS: { case Z_AXIS: {
#if DISABLED(DELTA) #if DISABLED(DELTA)
_ENABLE(z); BABYSTEP_AXIS(Z, BABYSTEP_INVERT_Z);
START_BABYSTEP_AXIS(Z, BABYSTEP_INVERT_Z);
STOP_BABYSTEP_AXIS(Z);
#else // DELTA #else // DELTA
bool z_direction = direction ^ BABYSTEP_INVERT_Z; bool z_direction = direction ^ BABYSTEP_INVERT_Z;
enable_x(); enable_X();
enable_y(); enable_Y();
enable_z(); enable_Z();
uint8_t old_x_dir_pin = X_DIR_READ, uint8_t old_x_dir_pin = X_DIR_READ,
old_y_dir_pin = Y_DIR_READ, old_y_dir_pin = Y_DIR_READ,
old_z_dir_pin = Z_DIR_READ; old_z_dir_pin = Z_DIR_READ;
//setup new step
X_DIR_WRITE(INVERT_X_DIR ^ z_direction); X_DIR_WRITE(INVERT_X_DIR ^ z_direction);
Y_DIR_WRITE(INVERT_Y_DIR ^ z_direction); Y_DIR_WRITE(INVERT_Y_DIR ^ z_direction);
Z_DIR_WRITE(INVERT_Z_DIR ^ z_direction); Z_DIR_WRITE(INVERT_Z_DIR ^ z_direction);
//perform step
#if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_BABYSTEP _SAVE_START;
pulse_start = TCNT0;
#endif
X_STEP_WRITE(!INVERT_X_STEP_PIN); X_STEP_WRITE(!INVERT_X_STEP_PIN);
Y_STEP_WRITE(!INVERT_Y_STEP_PIN); Y_STEP_WRITE(!INVERT_Y_STEP_PIN);
Z_STEP_WRITE(!INVERT_Z_STEP_PIN); Z_STEP_WRITE(!INVERT_Z_STEP_PIN);
#if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_BABYSTEP
while ((uint32_t)(TCNT0 - pulse_start) < STEP_PULSE_CYCLES - CYCLES_EATEN_BY_BABYSTEP) { /* nada */ } _PULSE_WAIT;
#endif
X_STEP_WRITE(INVERT_X_STEP_PIN); X_STEP_WRITE(INVERT_X_STEP_PIN);
Y_STEP_WRITE(INVERT_Y_STEP_PIN); Y_STEP_WRITE(INVERT_Y_STEP_PIN);
Z_STEP_WRITE(INVERT_Z_STEP_PIN); Z_STEP_WRITE(INVERT_Z_STEP_PIN);
//get old pin state back.
// Restore direction bits
X_DIR_WRITE(old_x_dir_pin); X_DIR_WRITE(old_x_dir_pin);
Y_DIR_WRITE(old_y_dir_pin); Y_DIR_WRITE(old_y_dir_pin);
Z_DIR_WRITE(old_z_dir_pin); Z_DIR_WRITE(old_z_dir_pin);

View File

@ -43,13 +43,6 @@
//set optimization so ARDUINO optimizes this file //set optimization so ARDUINO optimizes this file
#pragma GCC optimize (3) #pragma GCC optimize (3)
#define DELAY_0_NOP NOOP
#define DELAY_1_NOP __asm__("nop\n\t")
#define DELAY_2_NOP __asm__("nop\n\t" "nop\n\t")
#define DELAY_3_NOP __asm__("nop\n\t" "nop\n\t" "nop\n\t")
#define DELAY_4_NOP __asm__("nop\n\t" "nop\n\t" "nop\n\t" "nop\n\t")
// If you want you can define your own set of delays in Configuration.h // If you want you can define your own set of delays in Configuration.h
//#define ST7920_DELAY_1 DELAY_0_NOP //#define ST7920_DELAY_1 DELAY_0_NOP
//#define ST7920_DELAY_2 DELAY_0_NOP //#define ST7920_DELAY_2 DELAY_0_NOP