Implement double-edge stepping
Introduce new wrapper macros to tick the stepper pins. Default to the original raising-edge stepping mode. When using the TMC double-edge stepping mode (aka half-wave or square-wave mode) the _LO macros become no-ops.
This commit is contained in:
parent
6017600714
commit
6ceca9bf85
2 changed files with 100 additions and 44 deletions
|
@ -48,6 +48,50 @@ int fsensor_counter; //counter for e-steps
|
|||
uint16_t SP_min = 0x21FF;
|
||||
#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_DEDGE_STEPPING
|
||||
#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 ============================
|
||||
//===========================================================================
|
||||
|
@ -300,9 +344,9 @@ FORCE_INLINE void stepper_next_block()
|
|||
_delay_us(100);
|
||||
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);
|
||||
WRITE_NC(X_STEP_PIN, INVERT_X_STEP_PIN);
|
||||
STEP_NC_LO(X_AXIS);
|
||||
_delay_us(900);
|
||||
}
|
||||
}
|
||||
|
@ -323,9 +367,9 @@ FORCE_INLINE void stepper_next_block()
|
|||
_delay_us(100);
|
||||
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);
|
||||
WRITE_NC(Y_STEP_PIN, INVERT_Y_STEP_PIN);
|
||||
STEP_NC_LO(Y_AXIS);
|
||||
_delay_us(900);
|
||||
}
|
||||
}
|
||||
|
@ -607,44 +651,44 @@ FORCE_INLINE void stepper_tick_lowres()
|
|||
// Step in X axis
|
||||
counter_x.lo += current_block->steps_x.lo;
|
||||
if (counter_x.lo > 0) {
|
||||
WRITE_NC(X_STEP_PIN, !INVERT_X_STEP_PIN);
|
||||
STEP_NC_HI(X_AXIS);
|
||||
#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
|
||||
counter_x.lo -= current_block->step_event_count.lo;
|
||||
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
|
||||
WRITE_NC(DEBUG_XSTEP_DUP_PIN,INVERT_X_STEP_PIN);
|
||||
STEP_NC_LO(X_DUP_AXIS);
|
||||
#endif //DEBUG_XSTEP_DUP_PIN
|
||||
}
|
||||
// Step in Y axis
|
||||
counter_y.lo += current_block->steps_y.lo;
|
||||
if (counter_y.lo > 0) {
|
||||
WRITE_NC(Y_STEP_PIN, !INVERT_Y_STEP_PIN);
|
||||
STEP_NC_HI(Y_AXIS);
|
||||
#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
|
||||
counter_y.lo -= current_block->step_event_count.lo;
|
||||
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
|
||||
WRITE_NC(DEBUG_YSTEP_DUP_PIN,INVERT_Y_STEP_PIN);
|
||||
STEP_NC_LO(Y_DUP_AXIS);
|
||||
#endif //DEBUG_YSTEP_DUP_PIN
|
||||
}
|
||||
// Step in Z axis
|
||||
counter_z.lo += current_block->steps_z.lo;
|
||||
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;
|
||||
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
|
||||
counter_e.lo += current_block->steps_e.lo;
|
||||
if (counter_e.lo > 0) {
|
||||
#ifndef LIN_ADVANCE
|
||||
WRITE(E0_STEP_PIN, !INVERT_E_STEP_PIN);
|
||||
STEP_NC_HI(E_AXIS);
|
||||
#endif /* LIN_ADVANCE */
|
||||
counter_e.lo -= current_block->step_event_count.lo;
|
||||
count_position[E_AXIS] += count_direction[E_AXIS];
|
||||
|
@ -654,7 +698,7 @@ FORCE_INLINE void stepper_tick_lowres()
|
|||
#ifdef FILAMENT_SENSOR
|
||||
fsensor_counter += count_direction[E_AXIS];
|
||||
#endif //FILAMENT_SENSOR
|
||||
WRITE(E0_STEP_PIN, INVERT_E_STEP_PIN);
|
||||
STEP_NC_LO(E_AXIS);
|
||||
#endif
|
||||
}
|
||||
if(++ step_events_completed.lo >= current_block->step_event_count.lo)
|
||||
|
@ -669,44 +713,44 @@ FORCE_INLINE void stepper_tick_highres()
|
|||
// Step in X axis
|
||||
counter_x.wide += current_block->steps_x.wide;
|
||||
if (counter_x.wide > 0) {
|
||||
WRITE_NC(X_STEP_PIN, !INVERT_X_STEP_PIN);
|
||||
STEP_NC_HI(X_AXIS);
|
||||
#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
|
||||
counter_x.wide -= current_block->step_event_count.wide;
|
||||
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
|
||||
WRITE_NC(DEBUG_XSTEP_DUP_PIN,INVERT_X_STEP_PIN);
|
||||
STEP_NC_LO(X_DUP_AXIS);
|
||||
#endif //DEBUG_XSTEP_DUP_PIN
|
||||
}
|
||||
// Step in Y axis
|
||||
counter_y.wide += current_block->steps_y.wide;
|
||||
if (counter_y.wide > 0) {
|
||||
WRITE_NC(Y_STEP_PIN, !INVERT_Y_STEP_PIN);
|
||||
STEP_NC_HI(Y_AXIS);
|
||||
#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
|
||||
counter_y.wide -= current_block->step_event_count.wide;
|
||||
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
|
||||
WRITE_NC(DEBUG_YSTEP_DUP_PIN,INVERT_Y_STEP_PIN);
|
||||
STEP_NC_LO(Y_DUP_AXIS);
|
||||
#endif //DEBUG_YSTEP_DUP_PIN
|
||||
}
|
||||
// Step in Z axis
|
||||
counter_z.wide += current_block->steps_z.wide;
|
||||
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;
|
||||
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
|
||||
counter_e.wide += current_block->steps_e.wide;
|
||||
if (counter_e.wide > 0) {
|
||||
#ifndef LIN_ADVANCE
|
||||
WRITE(E0_STEP_PIN, !INVERT_E_STEP_PIN);
|
||||
STEP_NC_HI(E_AXIS);
|
||||
#endif /* LIN_ADVANCE */
|
||||
counter_e.wide -= current_block->step_event_count.wide;
|
||||
count_position[E_AXIS]+=count_direction[E_AXIS];
|
||||
|
@ -716,7 +760,7 @@ FORCE_INLINE void stepper_tick_highres()
|
|||
#ifdef FILAMENT_SENSOR
|
||||
fsensor_counter += count_direction[E_AXIS];
|
||||
#endif //FILAMENT_SENSOR
|
||||
WRITE(E0_STEP_PIN, INVERT_E_STEP_PIN);
|
||||
STEP_NC_LO(E_AXIS);
|
||||
#endif
|
||||
}
|
||||
if(++ step_events_completed.wide >= current_block->step_event_count.wide)
|
||||
|
@ -997,9 +1041,9 @@ FORCE_INLINE void advance_isr_scheduler() {
|
|||
bool rev = (e_steps < 0);
|
||||
do
|
||||
{
|
||||
WRITE_NC(E0_STEP_PIN, !INVERT_E_STEP_PIN);
|
||||
STEP_NC_HI(E_AXIS);
|
||||
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)
|
||||
fsensor_counter += (rev? -1: 1);
|
||||
#endif
|
||||
|
@ -1385,14 +1429,14 @@ void babystep(const uint8_t axis,const bool direction)
|
|||
WRITE(X_DIR_PIN,(INVERT_X_DIR)^direction);
|
||||
|
||||
//perform step
|
||||
WRITE(X_STEP_PIN, !INVERT_X_STEP_PIN);
|
||||
STEP_NC_HI(X_AXIS);
|
||||
#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
|
||||
delayMicroseconds(1);
|
||||
WRITE(X_STEP_PIN, INVERT_X_STEP_PIN);
|
||||
STEP_NC_LO(X_AXIS);
|
||||
#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
|
||||
|
||||
//get old pin state back.
|
||||
|
@ -1408,14 +1452,14 @@ void babystep(const uint8_t axis,const bool direction)
|
|||
WRITE(Y_DIR_PIN,(INVERT_Y_DIR)^direction);
|
||||
|
||||
//perform step
|
||||
WRITE(Y_STEP_PIN, !INVERT_Y_STEP_PIN);
|
||||
STEP_NC_HI(Y_AXIS);
|
||||
#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
|
||||
delayMicroseconds(1);
|
||||
WRITE(Y_STEP_PIN, INVERT_Y_STEP_PIN);
|
||||
STEP_NC_LO(Y_AXIS);
|
||||
#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
|
||||
|
||||
//get old pin state back.
|
||||
|
@ -1434,14 +1478,14 @@ void babystep(const uint8_t axis,const bool direction)
|
|||
WRITE(Z2_DIR_PIN,(INVERT_Z_DIR)^direction^BABYSTEP_INVERT_Z);
|
||||
#endif
|
||||
//perform step
|
||||
WRITE(Z_STEP_PIN, !INVERT_Z_STEP_PIN);
|
||||
STEP_NC_HI(Z_AXIS);
|
||||
#ifdef Z_DUAL_STEPPER_DRIVERS
|
||||
WRITE(Z2_STEP_PIN, !INVERT_Z_STEP_PIN);
|
||||
STEP_NC_HI(Z2_AXIS);
|
||||
#endif
|
||||
delayMicroseconds(1);
|
||||
WRITE(Z_STEP_PIN, INVERT_Z_STEP_PIN);
|
||||
STEP_NC_LO(Z_AXIS);
|
||||
#ifdef Z_DUAL_STEPPER_DRIVERS
|
||||
WRITE(Z2_STEP_PIN, INVERT_Z_STEP_PIN);
|
||||
STEP_NC_LO(Z2_AXIS);
|
||||
#endif
|
||||
|
||||
//get old pin state back.
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
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 hstrt = tmc2130_chopper_config[axis].hstr; //initial 4, modified to 5
|
||||
uint8_t hend = tmc2130_chopper_config[axis].hend; //original value = 1
|
||||
|
@ -464,12 +469,12 @@ void tmc2130_setup_chopper(uint8_t axis, uint8_t mres, uint8_t current_h, uint8_
|
|||
// DBG(_n(" toff=%hhd, hstr=%hhd, hend=%hhd, tbl=%hhd\n"), toff, hstrt, hend, tbl);
|
||||
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));
|
||||
}
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
@ -706,10 +711,17 @@ static uint8_t tmc2130_rx(uint8_t axis, uint8_t addr, uint32_t* rval)
|
|||
#define _SET_DIR_Z(dir) { WRITE(Z_DIR_PIN, dir?INVERT_Z_DIR:!INVERT_Z_DIR); asm("nop"); }
|
||||
#define _SET_DIR_E(dir) { WRITE(E0_DIR_PIN, dir?INVERT_E0_DIR:!INVERT_E0_DIR); asm("nop"); }
|
||||
|
||||
#ifdef TMC2130_DEDGE_STEPPING
|
||||
#define _DO_STEP_X { TOGGLE(X_STEP_PIN); asm("nop"); }
|
||||
#define _DO_STEP_Y { TOGGLE(Y_STEP_PIN); asm("nop"); }
|
||||
#define _DO_STEP_Z { TOGGLE(Z_STEP_PIN); asm("nop"); }
|
||||
#define _DO_STEP_E { TOGGLE(E0_STEP_PIN); asm("nop"); }
|
||||
#else
|
||||
#define _DO_STEP_X { WRITE(X_STEP_PIN, !INVERT_X_STEP_PIN); asm("nop"); WRITE(X_STEP_PIN, INVERT_X_STEP_PIN); asm("nop"); }
|
||||
#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_Z { WRITE(Z_STEP_PIN, !INVERT_Z_STEP_PIN); asm("nop"); WRITE(Z_STEP_PIN, INVERT_Z_STEP_PIN); asm("nop"); }
|
||||
#define _DO_STEP_E { WRITE(E0_STEP_PIN, !INVERT_E_STEP_PIN); asm("nop"); WRITE(E0_STEP_PIN, INVERT_E_STEP_PIN); asm("nop"); }
|
||||
#endif
|
||||
|
||||
|
||||
uint16_t tmc2130_get_res(uint8_t axis)
|
||||
|
|
Loading…
Reference in a new issue