Merge pull request #2789 from wavexx/MK3_TMC2130_DEDGE

Use/enable TMC2130 DEDGE support in MK3/MK3S
This commit is contained in:
DRracer 2021-01-29 11:13:09 +01:00 committed by GitHub
commit 42311db5f1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 244 additions and 127 deletions

View file

@ -129,11 +129,15 @@ void sm4_set_dir_bits(uint8_t dir_bits)
void sm4_do_step(uint8_t axes_mask) void sm4_do_step(uint8_t axes_mask)
{ {
#if ((MOTHERBOARD == BOARD_RAMBO_MINI_1_0) || (MOTHERBOARD == BOARD_RAMBO_MINI_1_3) || (MOTHERBOARD == BOARD_EINSY_1_0a)) #if ((MOTHERBOARD == BOARD_RAMBO_MINI_1_0) || (MOTHERBOARD == BOARD_RAMBO_MINI_1_3) || (MOTHERBOARD == BOARD_EINSY_1_0a))
#ifdef TMC2130_DEDGE_STEPPING
PINC = (axes_mask & 0x0f); // toggle step signals by mask
#else
register uint8_t portC = PORTC & 0xf0; register uint8_t portC = PORTC & 0xf0;
PORTC = portC | (axes_mask & 0x0f); //set step signals by mask PORTC = portC | (axes_mask & 0x0f); //set step signals by mask
asm("nop"); asm("nop");
PORTC = portC; //set step signals to zero PORTC = portC; //set step signals to zero
asm("nop"); asm("nop");
#endif
#endif //((MOTHERBOARD == BOARD_RAMBO_MINI_1_0) || (MOTHERBOARD == BOARD_RAMBO_MINI_1_3) || (MOTHERBOARD == BOARD_EINSY_1_0a)) #endif //((MOTHERBOARD == BOARD_RAMBO_MINI_1_0) || (MOTHERBOARD == BOARD_RAMBO_MINI_1_3) || (MOTHERBOARD == BOARD_EINSY_1_0a))
} }

View file

@ -48,6 +48,62 @@ int fsensor_counter; //counter for e-steps
uint16_t SP_min = 0x21FF; uint16_t SP_min = 0x21FF;
#endif //DEBUG_STACK_MONITOR #endif //DEBUG_STACK_MONITOR
/*
* Stepping macros
*/
#define _STEP_PIN_X_AXIS X_STEP_PIN
#define _STEP_PIN_Y_AXIS Y_STEP_PIN
#define _STEP_PIN_Z_AXIS Z_STEP_PIN
#define _STEP_PIN_E_AXIS E0_STEP_PIN
#ifdef DEBUG_XSTEP_DUP_PIN
#define _STEP_PIN_X_DUP_AXIS DEBUG_XSTEP_DUP_PIN
#endif
#ifdef DEBUG_YSTEP_DUP_PIN
#define _STEP_PIN_Y_DUP_AXIS DEBUG_YSTEP_DUP_PIN
#endif
#ifdef Y_DUAL_STEPPER_DRIVERS
#error Y_DUAL_STEPPER_DRIVERS not fully implemented
#define _STEP_PIN_Y2_AXIS Y2_STEP_PIN
#endif
#ifdef Z_DUAL_STEPPER_DRIVERS
#error Z_DUAL_STEPPER_DRIVERS not fully implemented
#define _STEP_PIN_Z2_AXIS Z2_STEP_PIN
#endif
#ifdef TMC2130
#define STEPPER_MINIMUM_PULSE TMC2130_MINIMUM_PULSE
#define STEPPER_SET_DIR_DELAY TMC2130_SET_DIR_DELAY
#define STEPPER_MINIMUM_DELAY TMC2130_MINIMUM_DELAY
#else
#define STEPPER_MINIMUM_PULSE 2
#define STEPPER_SET_DIR_DELAY 100
#define STEPPER_MINIMUM_DELAY delayMicroseconds(STEPPER_MINIMUM_PULSE)
#endif
#ifdef TMC2130_DEDGE_STEPPING
static_assert(TMC2130_MINIMUM_DELAY 1, // this will fail to compile when non-empty
"DEDGE implies/requires an empty TMC2130_MINIMUM_DELAY");
#define STEP_NC_HI(axis) TOGGLE(_STEP_PIN_##axis)
#define STEP_NC_LO(axis) //NOP
#else
#define _STEP_HI_X_AXIS !INVERT_X_STEP_PIN
#define _STEP_LO_X_AXIS INVERT_X_STEP_PIN
#define _STEP_HI_Y_AXIS !INVERT_Y_STEP_PIN
#define _STEP_LO_Y_AXIS INVERT_Y_STEP_PIN
#define _STEP_HI_Z_AXIS !INVERT_Z_STEP_PIN
#define _STEP_LO_Z_AXIS INVERT_Z_STEP_PIN
#define _STEP_HI_E_AXIS !INVERT_E_STEP_PIN
#define _STEP_LO_E_AXIS INVERT_E_STEP_PIN
#define STEP_NC_HI(axis) WRITE_NC(_STEP_PIN_##axis, _STEP_HI_##axis)
#define STEP_NC_LO(axis) WRITE_NC(_STEP_PIN_##axis, _STEP_LO_##axis)
#endif //TMC2130_DEDGE_STEPPING
//=========================================================================== //===========================================================================
//=============================public variables ============================ //=============================public variables ============================
//=========================================================================== //===========================================================================
@ -296,13 +352,13 @@ FORCE_INLINE void stepper_next_block()
WRITE_NC(X_DIR_PIN, INVERT_X_DIR); WRITE_NC(X_DIR_PIN, INVERT_X_DIR);
else else
WRITE_NC(X_DIR_PIN, !INVERT_X_DIR); WRITE_NC(X_DIR_PIN, !INVERT_X_DIR);
_delay_us(100); delayMicroseconds(STEPPER_SET_DIR_DELAY);
for (uint8_t i = 0; i < st_backlash_x; i++) for (uint8_t i = 0; i < st_backlash_x; i++)
{ {
WRITE_NC(X_STEP_PIN, !INVERT_X_STEP_PIN); STEP_NC_HI(X_AXIS);
_delay_us(100); STEPPER_MINIMUM_DELAY;
WRITE_NC(X_STEP_PIN, INVERT_X_STEP_PIN); STEP_NC_LO(X_AXIS);
_delay_us(900); _delay_us(900); // hard-coded jerk! *bad*
} }
} }
last_dir_bits &= ~1; last_dir_bits &= ~1;
@ -319,13 +375,13 @@ FORCE_INLINE void stepper_next_block()
WRITE_NC(Y_DIR_PIN, INVERT_Y_DIR); WRITE_NC(Y_DIR_PIN, INVERT_Y_DIR);
else else
WRITE_NC(Y_DIR_PIN, !INVERT_Y_DIR); WRITE_NC(Y_DIR_PIN, !INVERT_Y_DIR);
_delay_us(100); delayMicroseconds(STEPPER_SET_DIR_DELAY);
for (uint8_t i = 0; i < st_backlash_y; i++) for (uint8_t i = 0; i < st_backlash_y; i++)
{ {
WRITE_NC(Y_STEP_PIN, !INVERT_Y_STEP_PIN); STEP_NC_HI(Y_AXIS);
_delay_us(100); STEPPER_MINIMUM_DELAY;
WRITE_NC(Y_STEP_PIN, INVERT_Y_STEP_PIN); STEP_NC_LO(Y_AXIS);
_delay_us(900); _delay_us(900); // hard-coded jerk! *bad*
} }
} }
last_dir_bits &= ~2; last_dir_bits &= ~2;
@ -603,44 +659,44 @@ FORCE_INLINE void stepper_tick_lowres()
// Step in X axis // Step in X axis
counter_x.lo += current_block->steps_x.lo; counter_x.lo += current_block->steps_x.lo;
if (counter_x.lo > 0) { if (counter_x.lo > 0) {
WRITE_NC(X_STEP_PIN, !INVERT_X_STEP_PIN); STEP_NC_HI(X_AXIS);
#ifdef DEBUG_XSTEP_DUP_PIN #ifdef DEBUG_XSTEP_DUP_PIN
WRITE_NC(DEBUG_XSTEP_DUP_PIN,!INVERT_X_STEP_PIN); STEP_NC_HI(X_DUP_AXIS);
#endif //DEBUG_XSTEP_DUP_PIN #endif //DEBUG_XSTEP_DUP_PIN
counter_x.lo -= current_block->step_event_count.lo; counter_x.lo -= current_block->step_event_count.lo;
count_position[X_AXIS]+=count_direction[X_AXIS]; count_position[X_AXIS]+=count_direction[X_AXIS];
WRITE_NC(X_STEP_PIN, INVERT_X_STEP_PIN); STEP_NC_LO(X_AXIS);
#ifdef DEBUG_XSTEP_DUP_PIN #ifdef DEBUG_XSTEP_DUP_PIN
WRITE_NC(DEBUG_XSTEP_DUP_PIN,INVERT_X_STEP_PIN); STEP_NC_LO(X_DUP_AXIS);
#endif //DEBUG_XSTEP_DUP_PIN #endif //DEBUG_XSTEP_DUP_PIN
} }
// Step in Y axis // Step in Y axis
counter_y.lo += current_block->steps_y.lo; counter_y.lo += current_block->steps_y.lo;
if (counter_y.lo > 0) { if (counter_y.lo > 0) {
WRITE_NC(Y_STEP_PIN, !INVERT_Y_STEP_PIN); STEP_NC_HI(Y_AXIS);
#ifdef DEBUG_YSTEP_DUP_PIN #ifdef DEBUG_YSTEP_DUP_PIN
WRITE_NC(DEBUG_YSTEP_DUP_PIN,!INVERT_Y_STEP_PIN); STEP_NC_HI(Y_DUP_AXIS);
#endif //DEBUG_YSTEP_DUP_PIN #endif //DEBUG_YSTEP_DUP_PIN
counter_y.lo -= current_block->step_event_count.lo; counter_y.lo -= current_block->step_event_count.lo;
count_position[Y_AXIS]+=count_direction[Y_AXIS]; count_position[Y_AXIS]+=count_direction[Y_AXIS];
WRITE_NC(Y_STEP_PIN, INVERT_Y_STEP_PIN); STEP_NC_LO(Y_AXIS);
#ifdef DEBUG_YSTEP_DUP_PIN #ifdef DEBUG_YSTEP_DUP_PIN
WRITE_NC(DEBUG_YSTEP_DUP_PIN,INVERT_Y_STEP_PIN); STEP_NC_LO(Y_DUP_AXIS);
#endif //DEBUG_YSTEP_DUP_PIN #endif //DEBUG_YSTEP_DUP_PIN
} }
// Step in Z axis // Step in Z axis
counter_z.lo += current_block->steps_z.lo; counter_z.lo += current_block->steps_z.lo;
if (counter_z.lo > 0) { if (counter_z.lo > 0) {
WRITE_NC(Z_STEP_PIN, !INVERT_Z_STEP_PIN); STEP_NC_HI(Z_AXIS);
counter_z.lo -= current_block->step_event_count.lo; counter_z.lo -= current_block->step_event_count.lo;
count_position[Z_AXIS]+=count_direction[Z_AXIS]; count_position[Z_AXIS]+=count_direction[Z_AXIS];
WRITE_NC(Z_STEP_PIN, INVERT_Z_STEP_PIN); STEP_NC_LO(Z_AXIS);
} }
// Step in E axis // Step in E axis
counter_e.lo += current_block->steps_e.lo; counter_e.lo += current_block->steps_e.lo;
if (counter_e.lo > 0) { if (counter_e.lo > 0) {
#ifndef LIN_ADVANCE #ifndef LIN_ADVANCE
WRITE(E0_STEP_PIN, !INVERT_E_STEP_PIN); STEP_NC_HI(E_AXIS);
#endif /* LIN_ADVANCE */ #endif /* LIN_ADVANCE */
counter_e.lo -= current_block->step_event_count.lo; counter_e.lo -= current_block->step_event_count.lo;
count_position[E_AXIS] += count_direction[E_AXIS]; count_position[E_AXIS] += count_direction[E_AXIS];
@ -650,7 +706,7 @@ FORCE_INLINE void stepper_tick_lowres()
#ifdef FILAMENT_SENSOR #ifdef FILAMENT_SENSOR
fsensor_counter += count_direction[E_AXIS]; fsensor_counter += count_direction[E_AXIS];
#endif //FILAMENT_SENSOR #endif //FILAMENT_SENSOR
WRITE(E0_STEP_PIN, INVERT_E_STEP_PIN); STEP_NC_LO(E_AXIS);
#endif #endif
} }
if(++ step_events_completed.lo >= current_block->step_event_count.lo) if(++ step_events_completed.lo >= current_block->step_event_count.lo)
@ -665,44 +721,44 @@ FORCE_INLINE void stepper_tick_highres()
// Step in X axis // Step in X axis
counter_x.wide += current_block->steps_x.wide; counter_x.wide += current_block->steps_x.wide;
if (counter_x.wide > 0) { if (counter_x.wide > 0) {
WRITE_NC(X_STEP_PIN, !INVERT_X_STEP_PIN); STEP_NC_HI(X_AXIS);
#ifdef DEBUG_XSTEP_DUP_PIN #ifdef DEBUG_XSTEP_DUP_PIN
WRITE_NC(DEBUG_XSTEP_DUP_PIN,!INVERT_X_STEP_PIN); STEP_NC_HI(X_DUP_AXIS);
#endif //DEBUG_XSTEP_DUP_PIN #endif //DEBUG_XSTEP_DUP_PIN
counter_x.wide -= current_block->step_event_count.wide; counter_x.wide -= current_block->step_event_count.wide;
count_position[X_AXIS]+=count_direction[X_AXIS]; count_position[X_AXIS]+=count_direction[X_AXIS];
WRITE_NC(X_STEP_PIN, INVERT_X_STEP_PIN); STEP_NC_LO(X_AXIS);
#ifdef DEBUG_XSTEP_DUP_PIN #ifdef DEBUG_XSTEP_DUP_PIN
WRITE_NC(DEBUG_XSTEP_DUP_PIN,INVERT_X_STEP_PIN); STEP_NC_LO(X_DUP_AXIS);
#endif //DEBUG_XSTEP_DUP_PIN #endif //DEBUG_XSTEP_DUP_PIN
} }
// Step in Y axis // Step in Y axis
counter_y.wide += current_block->steps_y.wide; counter_y.wide += current_block->steps_y.wide;
if (counter_y.wide > 0) { if (counter_y.wide > 0) {
WRITE_NC(Y_STEP_PIN, !INVERT_Y_STEP_PIN); STEP_NC_HI(Y_AXIS);
#ifdef DEBUG_YSTEP_DUP_PIN #ifdef DEBUG_YSTEP_DUP_PIN
WRITE_NC(DEBUG_YSTEP_DUP_PIN,!INVERT_Y_STEP_PIN); STEP_NC_HI(Y_DUP_AXIS);
#endif //DEBUG_YSTEP_DUP_PIN #endif //DEBUG_YSTEP_DUP_PIN
counter_y.wide -= current_block->step_event_count.wide; counter_y.wide -= current_block->step_event_count.wide;
count_position[Y_AXIS]+=count_direction[Y_AXIS]; count_position[Y_AXIS]+=count_direction[Y_AXIS];
WRITE_NC(Y_STEP_PIN, INVERT_Y_STEP_PIN); STEP_NC_LO(Y_AXIS);
#ifdef DEBUG_YSTEP_DUP_PIN #ifdef DEBUG_YSTEP_DUP_PIN
WRITE_NC(DEBUG_YSTEP_DUP_PIN,INVERT_Y_STEP_PIN); STEP_NC_LO(Y_DUP_AXIS);
#endif //DEBUG_YSTEP_DUP_PIN #endif //DEBUG_YSTEP_DUP_PIN
} }
// Step in Z axis // Step in Z axis
counter_z.wide += current_block->steps_z.wide; counter_z.wide += current_block->steps_z.wide;
if (counter_z.wide > 0) { if (counter_z.wide > 0) {
WRITE_NC(Z_STEP_PIN, !INVERT_Z_STEP_PIN); STEP_NC_HI(Z_AXIS);
counter_z.wide -= current_block->step_event_count.wide; counter_z.wide -= current_block->step_event_count.wide;
count_position[Z_AXIS]+=count_direction[Z_AXIS]; count_position[Z_AXIS]+=count_direction[Z_AXIS];
WRITE_NC(Z_STEP_PIN, INVERT_Z_STEP_PIN); STEP_NC_LO(Z_AXIS);
} }
// Step in E axis // Step in E axis
counter_e.wide += current_block->steps_e.wide; counter_e.wide += current_block->steps_e.wide;
if (counter_e.wide > 0) { if (counter_e.wide > 0) {
#ifndef LIN_ADVANCE #ifndef LIN_ADVANCE
WRITE(E0_STEP_PIN, !INVERT_E_STEP_PIN); STEP_NC_HI(E_AXIS);
#endif /* LIN_ADVANCE */ #endif /* LIN_ADVANCE */
counter_e.wide -= current_block->step_event_count.wide; counter_e.wide -= current_block->step_event_count.wide;
count_position[E_AXIS]+=count_direction[E_AXIS]; count_position[E_AXIS]+=count_direction[E_AXIS];
@ -712,7 +768,7 @@ FORCE_INLINE void stepper_tick_highres()
#ifdef FILAMENT_SENSOR #ifdef FILAMENT_SENSOR
fsensor_counter += count_direction[E_AXIS]; fsensor_counter += count_direction[E_AXIS];
#endif //FILAMENT_SENSOR #endif //FILAMENT_SENSOR
WRITE(E0_STEP_PIN, INVERT_E_STEP_PIN); STEP_NC_LO(E_AXIS);
#endif #endif
} }
if(++ step_events_completed.wide >= current_block->step_event_count.wide) if(++ step_events_completed.wide >= current_block->step_event_count.wide)
@ -1014,9 +1070,9 @@ FORCE_INLINE void advance_isr_scheduler() {
bool rev = (e_steps < 0); bool rev = (e_steps < 0);
do do
{ {
WRITE_NC(E0_STEP_PIN, !INVERT_E_STEP_PIN); STEP_NC_HI(E_AXIS);
e_steps += (rev? 1: -1); e_steps += (rev? 1: -1);
WRITE_NC(E0_STEP_PIN, INVERT_E_STEP_PIN); STEP_NC_LO(E_AXIS);
#if defined(FILAMENT_SENSOR) && defined(PAT9125) #if defined(FILAMENT_SENSOR) && defined(PAT9125)
fsensor_counter += (rev? -1: 1); fsensor_counter += (rev? -1: 1);
#endif #endif
@ -1389,89 +1445,106 @@ void quickStop()
#ifdef BABYSTEPPING #ifdef BABYSTEPPING
void babystep(const uint8_t axis,const bool direction) void babystep(const uint8_t axis,const bool direction)
{ {
//MUST ONLY BE CALLED BY A ISR, it depends on that no other ISR interrupts this // MUST ONLY BE CALLED BY A ISR as stepper pins are manipulated directly.
//store initial pin states // note: when switching direction no delay is inserted at the end when the
switch(axis) // original is restored. We assume enough time passes as the function
{ // returns and the stepper is manipulated again (to avoid dead times)
case X_AXIS: switch(axis)
{ {
enable_x(); case X_AXIS:
uint8_t old_x_dir_pin= READ(X_DIR_PIN); //if dualzstepper, both point to same direction. {
enable_x();
//setup new step uint8_t old_x_dir_pin = READ(X_DIR_PIN); //if dualzstepper, both point to same direction.
WRITE(X_DIR_PIN,(INVERT_X_DIR)^direction); uint8_t new_x_dir_pin = (INVERT_X_DIR)^direction;
//perform step //setup new step
WRITE(X_STEP_PIN, !INVERT_X_STEP_PIN); if (new_x_dir_pin != old_x_dir_pin) {
WRITE_NC(X_DIR_PIN, new_x_dir_pin);
delayMicroseconds(STEPPER_SET_DIR_DELAY);
}
//perform step
STEP_NC_HI(X_AXIS);
#ifdef DEBUG_XSTEP_DUP_PIN #ifdef DEBUG_XSTEP_DUP_PIN
WRITE(DEBUG_XSTEP_DUP_PIN,!INVERT_X_STEP_PIN); STEP_NC_HI(X_DUP_AXIS);
#endif //DEBUG_XSTEP_DUP_PIN #endif
delayMicroseconds(1); STEPPER_MINIMUM_DELAY;
WRITE(X_STEP_PIN, INVERT_X_STEP_PIN); STEP_NC_LO(X_AXIS);
#ifdef DEBUG_XSTEP_DUP_PIN #ifdef DEBUG_XSTEP_DUP_PIN
WRITE(DEBUG_XSTEP_DUP_PIN,INVERT_X_STEP_PIN); STEP_NC_LO(X_DUP_AXIS);
#endif //DEBUG_XSTEP_DUP_PIN #endif
//get old pin state back. //get old pin state back.
WRITE(X_DIR_PIN,old_x_dir_pin); WRITE_NC(X_DIR_PIN, old_x_dir_pin);
} }
break; break;
case Y_AXIS:
{ case Y_AXIS:
enable_y(); {
uint8_t old_y_dir_pin= READ(Y_DIR_PIN); //if dualzstepper, both point to same direction. enable_y();
uint8_t old_y_dir_pin = READ(Y_DIR_PIN); //if dualzstepper, both point to same direction.
//setup new step uint8_t new_y_dir_pin = (INVERT_Y_DIR)^direction;
WRITE(Y_DIR_PIN,(INVERT_Y_DIR)^direction);
//setup new step
//perform step if (new_y_dir_pin != old_y_dir_pin) {
WRITE(Y_STEP_PIN, !INVERT_Y_STEP_PIN); WRITE_NC(Y_DIR_PIN, new_y_dir_pin);
delayMicroseconds(STEPPER_SET_DIR_DELAY);
}
//perform step
STEP_NC_HI(Y_AXIS);
#ifdef DEBUG_YSTEP_DUP_PIN #ifdef DEBUG_YSTEP_DUP_PIN
WRITE(DEBUG_YSTEP_DUP_PIN,!INVERT_Y_STEP_PIN); STEP_NC_HI(Y_DUP_AXIS);
#endif //DEBUG_YSTEP_DUP_PIN #endif
delayMicroseconds(1); STEPPER_MINIMUM_DELAY;
WRITE(Y_STEP_PIN, INVERT_Y_STEP_PIN); STEP_NC_LO(Y_AXIS);
#ifdef DEBUG_YSTEP_DUP_PIN #ifdef DEBUG_YSTEP_DUP_PIN
WRITE(DEBUG_YSTEP_DUP_PIN,INVERT_Y_STEP_PIN); STEP_NC_LO(Y_DUP_AXIS);
#endif //DEBUG_YSTEP_DUP_PIN #endif
//get old pin state back. //get old pin state back.
WRITE(Y_DIR_PIN,old_y_dir_pin); WRITE_NC(Y_DIR_PIN, old_y_dir_pin);
}
break;
} case Z_AXIS:
break; {
enable_z();
case Z_AXIS: uint8_t old_z_dir_pin = READ(Z_DIR_PIN); //if dualzstepper, both point to same direction.
{ uint8_t new_z_dir_pin = (INVERT_Z_DIR)^direction^BABYSTEP_INVERT_Z;
enable_z();
uint8_t old_z_dir_pin= READ(Z_DIR_PIN); //if dualzstepper, both point to same direction.
//setup new step
WRITE(Z_DIR_PIN,(INVERT_Z_DIR)^direction^BABYSTEP_INVERT_Z);
#ifdef Z_DUAL_STEPPER_DRIVERS
WRITE(Z2_DIR_PIN,(INVERT_Z_DIR)^direction^BABYSTEP_INVERT_Z);
#endif
//perform step
WRITE(Z_STEP_PIN, !INVERT_Z_STEP_PIN);
#ifdef Z_DUAL_STEPPER_DRIVERS
WRITE(Z2_STEP_PIN, !INVERT_Z_STEP_PIN);
#endif
delayMicroseconds(1);
WRITE(Z_STEP_PIN, INVERT_Z_STEP_PIN);
#ifdef Z_DUAL_STEPPER_DRIVERS
WRITE(Z2_STEP_PIN, INVERT_Z_STEP_PIN);
#endif
//get old pin state back. //setup new step
WRITE(Z_DIR_PIN,old_z_dir_pin); if (new_z_dir_pin != old_z_dir_pin) {
#ifdef Z_DUAL_STEPPER_DRIVERS WRITE_NC(Z_DIR_PIN, new_z_dir_pin);
WRITE(Z2_DIR_PIN,old_z_dir_pin); #ifdef Z_DUAL_STEPPER_DRIVERS
#endif WRITE_NC(Z2_DIR_PIN, new_z_dir_pin);
#endif
delayMicroseconds(STEPPER_SET_DIR_DELAY);
}
} //perform step
break; STEP_NC_HI(Z_AXIS);
#ifdef Z_DUAL_STEPPER_DRIVERS
default: break; STEP_NC_HI(Z2_AXIS);
} #endif
STEPPER_MINIMUM_DELAY;
STEP_NC_LO(Z_AXIS);
#ifdef Z_DUAL_STEPPER_DRIVERS
STEP_NC_LO(Z2_AXIS);
#endif
//get old pin state back.
if (new_z_dir_pin != old_z_dir_pin) {
WRITE_NC(Z_DIR_PIN, old_z_dir_pin);
#ifdef Z_DUAL_STEPPER_DRIVERS
WRITE_NC(Z2_DIR_PIN, old_z_dir_pin);
#endif
}
}
break;
default: break;
}
} }
#endif //BABYSTEPPING #endif //BABYSTEPPING

View file

@ -428,6 +428,11 @@ void tmc2130_check_overtemp()
void tmc2130_setup_chopper(uint8_t axis, uint8_t mres, uint8_t current_h, uint8_t current_r) void tmc2130_setup_chopper(uint8_t axis, uint8_t mres, uint8_t current_h, uint8_t current_r)
{ {
uint8_t intpol = (mres != 0); // intpol to 256 only if microsteps aren't 256 uint8_t intpol = (mres != 0); // intpol to 256 only if microsteps aren't 256
#ifdef TMC2130_DEDGE_STEPPING
uint8_t dedge = 1;
#else
uint8_t dedge = 0;
#endif
uint8_t toff = tmc2130_chopper_config[axis].toff; // toff = 3 (fchop = 27.778kHz) uint8_t toff = tmc2130_chopper_config[axis].toff; // toff = 3 (fchop = 27.778kHz)
uint8_t hstrt = tmc2130_chopper_config[axis].hstr; //initial 4, modified to 5 uint8_t hstrt = tmc2130_chopper_config[axis].hstr; //initial 4, modified to 5
uint8_t hend = tmc2130_chopper_config[axis].hend; //original value = 1 uint8_t hend = tmc2130_chopper_config[axis].hend; //original value = 1
@ -437,6 +442,9 @@ void tmc2130_setup_chopper(uint8_t axis, uint8_t mres, uint8_t current_h, uint8_
uint8_t tbl = tmc2130_chopper_config[axis].tbl; //blanking time, original value = 2 uint8_t tbl = tmc2130_chopper_config[axis].tbl; //blanking time, original value = 2
if (axis == E_AXIS) if (axis == E_AXIS)
{ {
#if defined(TMC2130_INTPOL_E) && (TMC2130_INTPOL_E == 0)
intpol = 0;
#endif
#ifdef TMC2130_CNSTOFF_E #ifdef TMC2130_CNSTOFF_E
// fd = 0 (slow decay only) // fd = 0 (slow decay only)
hstrt = 0; //fd0..2 hstrt = 0; //fd0..2
@ -447,16 +455,26 @@ void tmc2130_setup_chopper(uint8_t axis, uint8_t mres, uint8_t current_h, uint8_
// toff = TMC2130_TOFF_E; // toff = 3-5 // toff = TMC2130_TOFF_E; // toff = 3-5
// rndtf = 1; // rndtf = 1;
} }
#if defined(TMC2130_INTPOL_XY) && (TMC2130_INTPOL_XY == 0)
else if (axis == X_AXIS || axis == Y_AXIS) {
intpol = 0;
}
#endif
#if defined(TMC2130_INTPOL_Z) && (TMC2130_INTPOL_Z == 0)
else if (axis == Z_AXIS) {
intpol = 0;
}
#endif
// DBG(_n("tmc2130_setup_chopper(axis=%hhd, mres=%hhd, curh=%hhd, curr=%hhd\n"), axis, mres, current_h, current_r); // DBG(_n("tmc2130_setup_chopper(axis=%hhd, mres=%hhd, curh=%hhd, curr=%hhd\n"), axis, mres, current_h, current_r);
// DBG(_n(" toff=%hhd, hstr=%hhd, hend=%hhd, tbl=%hhd\n"), toff, hstrt, hend, tbl); // DBG(_n(" toff=%hhd, hstr=%hhd, hend=%hhd, tbl=%hhd\n"), toff, hstrt, hend, tbl);
if (current_r <= 31) if (current_r <= 31)
{ {
tmc2130_wr_CHOPCONF(axis, toff, hstrt, hend, fd3, 0, rndtf, chm, tbl, 1, 0, 0, 0, mres, intpol, 0, 0); tmc2130_wr_CHOPCONF(axis, toff, hstrt, hend, fd3, 0, rndtf, chm, tbl, 1, 0, 0, 0, mres, intpol, dedge, 0);
tmc2130_wr(axis, TMC2130_REG_IHOLD_IRUN, 0x000f0000 | ((current_r & 0x1f) << 8) | (current_h & 0x1f)); tmc2130_wr(axis, TMC2130_REG_IHOLD_IRUN, 0x000f0000 | ((current_r & 0x1f) << 8) | (current_h & 0x1f));
} }
else else
{ {
tmc2130_wr_CHOPCONF(axis, toff, hstrt, hend, fd3, 0, rndtf, chm, tbl, 0, 0, 0, 0, mres, intpol, 0, 0); tmc2130_wr_CHOPCONF(axis, toff, hstrt, hend, fd3, 0, rndtf, chm, tbl, 0, 0, 0, 0, mres, intpol, dedge, 0);
tmc2130_wr(axis, TMC2130_REG_IHOLD_IRUN, 0x000f0000 | (((current_r >> 1) & 0x1f) << 8) | ((current_h >> 1) & 0x1f)); tmc2130_wr(axis, TMC2130_REG_IHOLD_IRUN, 0x000f0000 | (((current_r >> 1) & 0x1f) << 8) | ((current_h >> 1) & 0x1f));
} }
} }
@ -678,25 +696,32 @@ static uint8_t tmc2130_rx(uint8_t axis, uint8_t addr, uint32_t* rval)
#define _GET_PWR_Z (READ(Z_ENABLE_PIN) == Z_ENABLE_ON) #define _GET_PWR_Z (READ(Z_ENABLE_PIN) == Z_ENABLE_ON)
#define _GET_PWR_E (READ(E0_ENABLE_PIN) == E_ENABLE_ON) #define _GET_PWR_E (READ(E0_ENABLE_PIN) == E_ENABLE_ON)
#define _SET_PWR_X(ena) { WRITE(X_ENABLE_PIN, ena?X_ENABLE_ON:!X_ENABLE_ON); asm("nop"); } #define _SET_PWR_X(ena) WRITE(X_ENABLE_PIN, ena?X_ENABLE_ON:!X_ENABLE_ON)
#define _SET_PWR_Y(ena) { WRITE(Y_ENABLE_PIN, ena?Y_ENABLE_ON:!Y_ENABLE_ON); asm("nop"); } #define _SET_PWR_Y(ena) WRITE(Y_ENABLE_PIN, ena?Y_ENABLE_ON:!Y_ENABLE_ON)
#define _SET_PWR_Z(ena) { WRITE(Z_ENABLE_PIN, ena?Z_ENABLE_ON:!Z_ENABLE_ON); asm("nop"); } #define _SET_PWR_Z(ena) WRITE(Z_ENABLE_PIN, ena?Z_ENABLE_ON:!Z_ENABLE_ON)
#define _SET_PWR_E(ena) { WRITE(E0_ENABLE_PIN, ena?E_ENABLE_ON:!E_ENABLE_ON); asm("nop"); } #define _SET_PWR_E(ena) WRITE(E0_ENABLE_PIN, ena?E_ENABLE_ON:!E_ENABLE_ON)
#define _GET_DIR_X (READ(X_DIR_PIN) == INVERT_X_DIR) #define _GET_DIR_X (READ(X_DIR_PIN) == INVERT_X_DIR)
#define _GET_DIR_Y (READ(Y_DIR_PIN) == INVERT_Y_DIR) #define _GET_DIR_Y (READ(Y_DIR_PIN) == INVERT_Y_DIR)
#define _GET_DIR_Z (READ(Z_DIR_PIN) == INVERT_Z_DIR) #define _GET_DIR_Z (READ(Z_DIR_PIN) == INVERT_Z_DIR)
#define _GET_DIR_E (READ(E0_DIR_PIN) == INVERT_E0_DIR) #define _GET_DIR_E (READ(E0_DIR_PIN) == INVERT_E0_DIR)
#define _SET_DIR_X(dir) { WRITE(X_DIR_PIN, dir?INVERT_X_DIR:!INVERT_X_DIR); asm("nop"); } #define _SET_DIR_X(dir) WRITE(X_DIR_PIN, dir?INVERT_X_DIR:!INVERT_X_DIR)
#define _SET_DIR_Y(dir) { WRITE(Y_DIR_PIN, dir?INVERT_Y_DIR:!INVERT_Y_DIR); asm("nop"); } #define _SET_DIR_Y(dir) WRITE(Y_DIR_PIN, dir?INVERT_Y_DIR:!INVERT_Y_DIR)
#define _SET_DIR_Z(dir) { WRITE(Z_DIR_PIN, dir?INVERT_Z_DIR:!INVERT_Z_DIR); asm("nop"); } #define _SET_DIR_Z(dir) WRITE(Z_DIR_PIN, dir?INVERT_Z_DIR:!INVERT_Z_DIR)
#define _SET_DIR_E(dir) { WRITE(E0_DIR_PIN, dir?INVERT_E0_DIR:!INVERT_E0_DIR); asm("nop"); } #define _SET_DIR_E(dir) WRITE(E0_DIR_PIN, dir?INVERT_E0_DIR:!INVERT_E0_DIR)
#define _DO_STEP_X { WRITE(X_STEP_PIN, !INVERT_X_STEP_PIN); asm("nop"); WRITE(X_STEP_PIN, INVERT_X_STEP_PIN); asm("nop"); } #ifdef TMC2130_DEDGE_STEPPING
#define _DO_STEP_Y { WRITE(Y_STEP_PIN, !INVERT_Y_STEP_PIN); asm("nop"); WRITE(Y_STEP_PIN, INVERT_Y_STEP_PIN); asm("nop"); } #define _DO_STEP_X TOGGLE(X_STEP_PIN)
#define _DO_STEP_Z { WRITE(Z_STEP_PIN, !INVERT_Z_STEP_PIN); asm("nop"); WRITE(Z_STEP_PIN, INVERT_Z_STEP_PIN); asm("nop"); } #define _DO_STEP_Y TOGGLE(Y_STEP_PIN)
#define _DO_STEP_E { WRITE(E0_STEP_PIN, !INVERT_E_STEP_PIN); asm("nop"); WRITE(E0_STEP_PIN, INVERT_E_STEP_PIN); asm("nop"); } #define _DO_STEP_Z TOGGLE(Z_STEP_PIN)
#define _DO_STEP_E TOGGLE(E0_STEP_PIN)
#else
#define _DO_STEP_X { WRITE(X_STEP_PIN, !INVERT_X_STEP_PIN); TMC2130_MINIMUM_DELAY; WRITE(X_STEP_PIN, INVERT_X_STEP_PIN); }
#define _DO_STEP_Y { WRITE(Y_STEP_PIN, !INVERT_Y_STEP_PIN); TMC2130_MINIMUM_DELAY; WRITE(Y_STEP_PIN, INVERT_Y_STEP_PIN); }
#define _DO_STEP_Z { WRITE(Z_STEP_PIN, !INVERT_Z_STEP_PIN); TMC2130_MINIMUM_DELAY; WRITE(Z_STEP_PIN, INVERT_Z_STEP_PIN); }
#define _DO_STEP_E { WRITE(E0_STEP_PIN, !INVERT_E_STEP_PIN); TMC2130_MINIMUM_DELAY; WRITE(E0_STEP_PIN, INVERT_E_STEP_PIN); }
#endif
uint16_t tmc2130_get_res(uint8_t axis) uint16_t tmc2130_get_res(uint8_t axis)
@ -737,6 +762,7 @@ void tmc2130_set_pwr(uint8_t axis, uint8_t pwr)
case Z_AXIS: _SET_PWR_Z(pwr); break; case Z_AXIS: _SET_PWR_Z(pwr); break;
case E_AXIS: _SET_PWR_E(pwr); break; case E_AXIS: _SET_PWR_E(pwr); break;
} }
delayMicroseconds(TMC2130_SET_PWR_DELAY);
} }
uint8_t tmc2130_get_inv(uint8_t axis) uint8_t tmc2130_get_inv(uint8_t axis)
@ -773,6 +799,7 @@ void tmc2130_set_dir(uint8_t axis, uint8_t dir)
case Z_AXIS: _SET_DIR_Z(dir); break; case Z_AXIS: _SET_DIR_Z(dir); break;
case E_AXIS: _SET_DIR_E(dir); break; case E_AXIS: _SET_DIR_E(dir); break;
} }
delayMicroseconds(TMC2130_SET_DIR_DELAY);
} }
void tmc2130_do_step(uint8_t axis) void tmc2130_do_step(uint8_t axis)
@ -788,8 +815,8 @@ void tmc2130_do_step(uint8_t axis)
void tmc2130_do_steps(uint8_t axis, uint16_t steps, uint8_t dir, uint16_t delay_us) void tmc2130_do_steps(uint8_t axis, uint16_t steps, uint8_t dir, uint16_t delay_us)
{ {
tmc2130_set_dir(axis, dir); if (tmc2130_get_dir(axis) != dir)
delayMicroseconds(100); tmc2130_set_dir(axis, dir);
while (steps--) while (steps--)
{ {
tmc2130_do_step(axis); tmc2130_do_step(axis);
@ -820,7 +847,6 @@ void tmc2130_goto_step(uint8_t axis, uint8_t step, uint8_t dir, uint16_t delay_u
cnt = steps; cnt = steps;
} }
tmc2130_set_dir(axis, dir); tmc2130_set_dir(axis, dir);
delayMicroseconds(100);
mscnt = tmc2130_rd_MSCNT(axis); mscnt = tmc2130_rd_MSCNT(axis);
while ((cnt--) && ((mscnt >> shift) != step)) while ((cnt--) && ((mscnt >> shift) != step))
{ {

View file

@ -29,6 +29,18 @@ extern uint8_t tmc2130_sg_homing_axes_mask;
#define TMC2130_WAVE_FAC1000_MAX 200 #define TMC2130_WAVE_FAC1000_MAX 200
#define TMC2130_WAVE_FAC1000_STP 1 #define TMC2130_WAVE_FAC1000_STP 1
#define TMC2130_MINIMUM_PULSE 0 // minimum pulse width in uS
#define TMC2130_SET_DIR_DELAY 20 // minimum delay after setting direction in uS
#define TMC2130_SET_PWR_DELAY 0 // minimum delay after changing pwr mode in uS
#ifdef TMC2130_DEDGE_STEPPING
#define TMC2130_MINIMUM_DELAY //NOP
#elif TMC2130_MINIMUM_PULSE == 0
#define TMC2130_MINIMUM_DELAY asm("nop")
#else
#define TMC2130_MINIMUM_DELAY delayMicroseconds(TMC2130_MINIMUM_PULSE)
#endif
extern uint8_t tmc2130_home_enabled; extern uint8_t tmc2130_home_enabled;
extern uint8_t tmc2130_home_origin[2]; extern uint8_t tmc2130_home_origin[2];
extern uint8_t tmc2130_home_bsteps[2]; extern uint8_t tmc2130_home_bsteps[2];

View file

@ -268,6 +268,7 @@
#define TMC2130_CURRENTS_R_HOME {8, 10, 20, 18} // homing running currents for all axes #define TMC2130_CURRENTS_R_HOME {8, 10, 20, 18} // homing running currents for all axes
#define TMC2130_STEALTH_Z #define TMC2130_STEALTH_Z
#define TMC2130_DEDGE_STEPPING
//#define TMC2130_SERVICE_CODES_M910_M918 //#define TMC2130_SERVICE_CODES_M910_M918

View file

@ -270,6 +270,7 @@
#define TMC2130_CURRENTS_R_HOME {8, 10, 20, 18} // homing running currents for all axes #define TMC2130_CURRENTS_R_HOME {8, 10, 20, 18} // homing running currents for all axes
#define TMC2130_STEALTH_Z #define TMC2130_STEALTH_Z
#define TMC2130_DEDGE_STEPPING
//#define TMC2130_SERVICE_CODES_M910_M918 //#define TMC2130_SERVICE_CODES_M910_M918