TMC2130 stallguard SW homing improvement - steps delta instead of delay (loop count), new function tmc2130_home_restart, always enable endstops durring homing.
This commit is contained in:
parent
76477edf63
commit
cd48d5b4ff
@ -1985,55 +1985,43 @@ inline void gcode_M900() {
|
||||
}
|
||||
#endif // LIN_ADVANCE
|
||||
|
||||
void homeaxis(int axis) {
|
||||
void homeaxis(int axis)
|
||||
{
|
||||
bool endstops_enabled = enable_endstops(true); //RP: endstops should be allways enabled durring homming
|
||||
#define HOMEAXIS_DO(LETTER) \
|
||||
((LETTER##_MIN_PIN > -1 && LETTER##_HOME_DIR==-1) || (LETTER##_MAX_PIN > -1 && LETTER##_HOME_DIR==1))
|
||||
|
||||
if (axis==X_AXIS ? HOMEAXIS_DO(X) :
|
||||
axis==Y_AXIS ? HOMEAXIS_DO(Y) :
|
||||
0) {
|
||||
if ((axis==X_AXIS)?HOMEAXIS_DO(X):(axis==Y_AXIS)?HOMEAXIS_DO(Y):0)
|
||||
{
|
||||
int axis_home_dir = home_dir(axis);
|
||||
|
||||
#ifdef HAVE_TMC2130_DRIVERS
|
||||
tmc2130_home_enter(X_AXIS_MASK << axis);
|
||||
#endif
|
||||
|
||||
current_position[axis] = 0;
|
||||
plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
|
||||
|
||||
destination[axis] = 1.5 * max_length(axis) * axis_home_dir;
|
||||
feedrate = homing_feedrate[axis];
|
||||
plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder);
|
||||
|
||||
#ifdef HAVE_TMC2130_DRIVERS
|
||||
sg_homing_delay = 0;
|
||||
tmc2130_axis_stalled[axis] = false;
|
||||
tmc2130_home_restart(axis);
|
||||
#endif
|
||||
st_synchronize();
|
||||
|
||||
current_position[axis] = 0;
|
||||
plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
|
||||
destination[axis] = -home_retract_mm(axis) * axis_home_dir;
|
||||
plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder);
|
||||
|
||||
#ifdef HAVE_TMC2130_DRIVERS
|
||||
sg_homing_delay = 0;
|
||||
tmc2130_axis_stalled[axis] = false;
|
||||
tmc2130_home_restart(axis);
|
||||
#endif
|
||||
st_synchronize();
|
||||
|
||||
destination[axis] = 2*home_retract_mm(axis) * axis_home_dir;
|
||||
#ifdef HAVE_TMC2130_DRIVERS
|
||||
if (tmc2130_didLastHomingStall())
|
||||
feedrate = homing_feedrate[axis];
|
||||
else
|
||||
#endif
|
||||
feedrate = homing_feedrate[axis];
|
||||
#else
|
||||
feedrate = homing_feedrate[axis] / 2;
|
||||
#endif
|
||||
plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder);
|
||||
|
||||
#ifdef HAVE_TMC2130_DRIVERS
|
||||
sg_homing_delay = 0;
|
||||
tmc2130_axis_stalled[axis] = false;
|
||||
tmc2130_home_restart(axis);
|
||||
#endif
|
||||
st_synchronize();
|
||||
axis_is_at_home(axis);
|
||||
@ -2041,29 +2029,24 @@ void homeaxis(int axis) {
|
||||
feedrate = 0.0;
|
||||
endstops_hit_on_purpose();
|
||||
axis_known_position[axis] = true;
|
||||
|
||||
#ifdef HAVE_TMC2130_DRIVERS
|
||||
tmc2130_home_exit();
|
||||
#endif
|
||||
}
|
||||
else if (axis==Z_AXIS ? HOMEAXIS_DO(Z) :
|
||||
0) {
|
||||
else if ((axis==Z_AXIS)?HOMEAXIS_DO(Z):0)
|
||||
{
|
||||
int axis_home_dir = home_dir(axis);
|
||||
|
||||
current_position[axis] = 0;
|
||||
plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
|
||||
|
||||
destination[axis] = 1.5 * max_length(axis) * axis_home_dir;
|
||||
feedrate = homing_feedrate[axis];
|
||||
plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder);
|
||||
st_synchronize();
|
||||
|
||||
current_position[axis] = 0;
|
||||
plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
|
||||
destination[axis] = -home_retract_mm(axis) * axis_home_dir;
|
||||
plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder);
|
||||
st_synchronize();
|
||||
|
||||
destination[axis] = 2*home_retract_mm(axis) * axis_home_dir;
|
||||
feedrate = homing_feedrate[axis]/2 ;
|
||||
plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder);
|
||||
@ -2074,7 +2057,9 @@ void homeaxis(int axis) {
|
||||
endstops_hit_on_purpose();
|
||||
axis_known_position[axis] = true;
|
||||
}
|
||||
enable_endstops(endstops_enabled);
|
||||
}
|
||||
|
||||
/**/
|
||||
void home_xy()
|
||||
{
|
||||
@ -5996,11 +5981,29 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
MYSERIAL.print("fsensor_enable()");
|
||||
fsensor_enable();
|
||||
break;
|
||||
case 4:
|
||||
MYSERIAL.print("fsensor_disable()");
|
||||
fsensor_disable();
|
||||
break;
|
||||
case 5:
|
||||
{
|
||||
/* MYSERIAL.print("tmc2130_rd_MSCNT(0)=");
|
||||
int val = tmc2130_rd_MSCNT(tmc2130_cs[0]);
|
||||
MYSERIAL.println(val);*/
|
||||
homeaxis(0);
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
{
|
||||
/* MYSERIAL.print("tmc2130_rd_MSCNT(1)=");
|
||||
int val = tmc2130_rd_MSCNT(tmc2130_cs[1]);
|
||||
MYSERIAL.println(val);*/
|
||||
homeaxis(1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ int pat9125_update()
|
||||
int iDY = ucYL | ((ucXYH << 8) & 0xf00);
|
||||
if (iDX & 0x800) iDX -= 4096;
|
||||
if (iDY & 0x800) iDY -= 4096;
|
||||
// pat9125_x += iDX;
|
||||
pat9125_x += iDX;
|
||||
pat9125_y += iDY;
|
||||
return 1;
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
#ifndef SWSPI_H
|
||||
#define SWSPI_H
|
||||
|
||||
|
||||
//#define SWSPI_RPI
|
||||
#define SWSPI_AVR
|
||||
|
||||
@ -14,18 +13,18 @@
|
||||
#endif //SWSPI_RPI
|
||||
|
||||
#ifdef SWSPI_AVR
|
||||
#if (MOTHERBOARD == BOARD_EINY_0_3a)
|
||||
//#if MOTHERBOARD == BOARD_EINY_0_3a
|
||||
#define SWSPI_MISO 16 //RX2
|
||||
#define SWSPI_MOSI 16 //RX2
|
||||
#define SWSPI_SCK 17 //TX2
|
||||
#define SWSPI_CS 20 //SDA
|
||||
#endif //(MOTHERBOARD == BOARD_EINY_0_3a)
|
||||
#if (MOTHERBOARD == BOARD_EINY_0_4a)
|
||||
//#endif //(MOTHERBOARD == 299)
|
||||
/*#if MOTHERBOARD == BOARD_EINY_0_4a
|
||||
#define SWSPI_MISO 62 //PK0
|
||||
#define SWSPI_MOSI 62 //PK0
|
||||
#define SWSPI_SCK 21 //SCL
|
||||
#define SWSPI_CS 20 //SDA
|
||||
#endif //(MOTHERBOARD == BOARD_EINY_0_4a)
|
||||
#endif //(MOTHERBOARD == BOARD_EINY_0_4a)*/
|
||||
#endif //SWSPI_AVR
|
||||
|
||||
#define SWSPI_POL 1 //polarity
|
||||
|
@ -8,6 +8,7 @@
|
||||
//externals for debuging
|
||||
extern float current_position[4];
|
||||
extern void st_get_position_xy(long &x, long &y);
|
||||
extern long st_get_position(uint8_t axis);
|
||||
|
||||
//chipselect pins
|
||||
uint8_t tmc2130_cs[4] = { X_TMC2130_CS, Y_TMC2130_CS, Z_TMC2130_CS, E0_TMC2130_CS };
|
||||
@ -32,8 +33,9 @@ uint8_t tmc2130_pwm_auto[2] = {TMC2130_PWM_AUTO_XY, TMC2130_PWM_AUTO_XY};
|
||||
uint8_t tmc2130_pwm_freq[2] = {TMC2130_PWM_FREQ_XY, TMC2130_PWM_FREQ_XY};
|
||||
|
||||
|
||||
uint32_t tmc2131_axis_sg_pos[2] = {0, 0};
|
||||
|
||||
uint8_t sg_homing_axes_mask = 0x00;
|
||||
uint8_t sg_homing_delay = 0;
|
||||
uint8_t sg_thrs_x = TMC2130_SG_THRS_X;
|
||||
uint8_t sg_thrs_y = TMC2130_SG_THRS_Y;
|
||||
|
||||
@ -74,6 +76,7 @@ bool skip_debug_msg = false;
|
||||
|
||||
|
||||
uint16_t tmc2130_rd_TSTEP(uint8_t cs);
|
||||
uint16_t tmc2130_rd_MSCNT(uint8_t cs);
|
||||
uint16_t tmc2130_rd_DRV_STATUS(uint8_t chipselect);
|
||||
|
||||
void tmc2130_wr_CHOPCONF(uint8_t cs, uint8_t toff = 3, uint8_t hstrt = 4, uint8_t hend = 1, uint8_t fd3 = 0, uint8_t disfdcc = 0, uint8_t rndtf = 0, uint8_t chm = 0, uint8_t tbl = 2, uint8_t vsense = 0, uint8_t vhighfs = 0, uint8_t vhighchm = 0, uint8_t sync = 0, uint8_t mres = 0b0100, uint8_t intpol = 1, uint8_t dedge = 0, uint8_t diss2g = 0);
|
||||
@ -146,7 +149,11 @@ bool tmc2130_update_sg()
|
||||
if (sg_homing_axes_mask == 0) return false;
|
||||
#ifdef TMC2130_DEBUG
|
||||
MYSERIAL.print("tmc2130_update_sg mask=0x");
|
||||
MYSERIAL.println((int)sg_homing_axes_mask, 16);
|
||||
MYSERIAL.print((int)sg_homing_axes_mask, 16);
|
||||
MYSERIAL.print(" stalledX=");
|
||||
MYSERIAL.print((int)tmc2130_axis_stalled[0]);
|
||||
MYSERIAL.print(" stalledY=");
|
||||
MYSERIAL.println((int)tmc2130_axis_stalled[1]);
|
||||
#endif //TMC2130_DEBUG
|
||||
for (uint8_t axis = X_AXIS; axis <= Y_AXIS; axis++) //only X and Y axes
|
||||
{
|
||||
@ -159,15 +166,19 @@ bool tmc2130_update_sg()
|
||||
uint16_t tstep = tmc2130_rd_TSTEP(cs);
|
||||
if (tstep < TMC2130_TCOOLTHRS)
|
||||
{
|
||||
if(sg_homing_delay < TMC2130_SG_DELAY) // wait for a few tens microsteps until stallGuard is used //todo: read out microsteps directly, instead of delay counter
|
||||
sg_homing_delay++;
|
||||
else
|
||||
long pos = st_get_position(axis);
|
||||
if (abs(pos - tmc2131_axis_sg_pos[axis]) > TMC2130_SG_DELTA)
|
||||
{
|
||||
uint16_t sg = tmc2130_rd_DRV_STATUS(cs) & 0x3ff;
|
||||
if (sg==0)
|
||||
if (sg == 0)
|
||||
{
|
||||
|
||||
tmc2130_axis_stalled[axis] = true;
|
||||
tmc2130_LastHomingStalled = true;
|
||||
#ifdef TMC2130_DEBUG
|
||||
MYSERIAL.print("tmc2130_update_sg AXIS STALLED ");
|
||||
MYSERIAL.println((int)axis);
|
||||
#endif //TMC2130_DEBUG
|
||||
}
|
||||
// else
|
||||
// tmc2130_axis_stalled[axis] = false;
|
||||
@ -233,7 +244,7 @@ void tmc2130_home_enter(uint8_t axes_mask)
|
||||
{
|
||||
uint8_t cs = tmc2130_cs[axis];
|
||||
sg_homing_axes_mask |= mask;
|
||||
sg_homing_delay = 0;
|
||||
tmc2131_axis_sg_pos[axis] = st_get_position(axis);
|
||||
tmc2130_axis_stalled[axis] = false;
|
||||
//Configuration to spreadCycle
|
||||
tmc2130_wr(cs, TMC2130_REG_GCONF, 0x00000000);
|
||||
@ -266,12 +277,19 @@ void tmc2130_home_exit()
|
||||
else
|
||||
tmc2130_wr(tmc2130_cs[axis], TMC2130_REG_GCONF, 0x00000000);
|
||||
}
|
||||
tmc2130_axis_stalled[axis] = false;
|
||||
}
|
||||
sg_homing_axes_mask = 0x00;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void tmc2130_home_restart(uint8_t axis)
|
||||
{
|
||||
tmc2131_axis_sg_pos[axis] = st_get_position(axis);
|
||||
tmc2130_axis_stalled[axis] = false;
|
||||
}
|
||||
|
||||
uint8_t tmc2130_didLastHomingStall()
|
||||
{
|
||||
uint8_t ret = tmc2130_LastHomingStalled;
|
||||
@ -353,6 +371,13 @@ uint16_t tmc2130_rd_TSTEP(uint8_t cs)
|
||||
return val32 & 0xffff;
|
||||
}
|
||||
|
||||
uint16_t tmc2130_rd_MSCNT(uint8_t cs)
|
||||
{
|
||||
uint32_t val32 = 0;
|
||||
tmc2130_rd(cs, TMC2130_REG_MSCNT, &val32);
|
||||
return val32 & 0x3ff;
|
||||
}
|
||||
|
||||
uint16_t tmc2130_rd_DRV_STATUS(uint8_t cs)
|
||||
{
|
||||
uint32_t val32 = 0;
|
||||
|
@ -1,6 +1,8 @@
|
||||
#ifndef TMC2130_H
|
||||
#define TMC2130_H
|
||||
|
||||
extern uint8_t tmc2130_cs[4];
|
||||
|
||||
//mode
|
||||
extern uint8_t tmc2130_mode;
|
||||
//holding and running currents
|
||||
@ -12,8 +14,6 @@ extern uint8_t tmc2130_axis_stalled[2];
|
||||
extern uint8_t sg_thrs_x;
|
||||
extern uint8_t sg_thrs_y;
|
||||
|
||||
extern uint8_t sg_homing_delay;
|
||||
|
||||
#define TMC2130_MODE_NORMAL 0
|
||||
#define TMC2130_MODE_SILENT 1
|
||||
|
||||
@ -24,9 +24,11 @@ extern bool tmc2130_update_sg();
|
||||
//temperature watching (called from )
|
||||
extern void tmc2130_check_overtemp();
|
||||
//enter homing (called from homeaxis before homing starts)
|
||||
extern void tmc2130_home_enter(uint8_t axis);
|
||||
extern void tmc2130_home_enter(uint8_t axes_mask);
|
||||
//exit homing (called from homeaxis after homing ends)
|
||||
extern void tmc2130_home_exit();
|
||||
//restart homing (called from homeaxis befor move)
|
||||
extern void tmc2130_home_restart(uint8_t axis);
|
||||
//
|
||||
extern uint8_t tmc2130_didLastHomingStall();
|
||||
|
||||
@ -43,4 +45,7 @@ extern void tmc2130_set_pwm_ampl(uint8_t axis, uint8_t pwm_ampl);
|
||||
extern void tmc2130_set_pwm_grad(uint8_t axis, uint8_t pwm_ampl);
|
||||
|
||||
|
||||
extern uint16_t tmc2130_rd_MSCNT(uint8_t cs);
|
||||
|
||||
|
||||
#endif //TMC2130_H
|
@ -131,13 +131,13 @@ const bool Z_MIN_ENDSTOP_INVERTING = false; // set to true to invert the logic o
|
||||
#define TMC2130_SG_HOMING_SW 1 // stallguard "software" homing
|
||||
#define TMC2130_SG_THRS_X 30 // stallguard sensitivity for X axis
|
||||
#define TMC2130_SG_THRS_Y 30 // stallguard sensitivity for Y axis
|
||||
#define TMC2130_SG_DELAY 10 // stallguard delay (temporary solution)
|
||||
#define TMC2130_SG_DELTA 128 // stallguard delta [usteps] (minimum usteps before stallguard readed)
|
||||
|
||||
//new settings is possible for vsense = 1
|
||||
//new settings is possible for vsense = 1, running current value > 31 set vsense to zero and shift both currents by 1 bit right
|
||||
#define TMC2130_CURRENTS_H {3, 3, 5, 8} // default holding currents for all axes
|
||||
#define TMC2130_CURRENTS_R {13, 13, 20, 20} // default running currents for all axes
|
||||
|
||||
#define TMC2130_DEBUG
|
||||
//#define TMC2130_DEBUG
|
||||
//#define TMC2130_DEBUG_WR
|
||||
//#define TMC2130_DEBUG_RD
|
||||
|
||||
|
@ -131,11 +131,11 @@ const bool Z_MIN_ENDSTOP_INVERTING = false; // set to true to invert the logic o
|
||||
#define TMC2130_SG_HOMING_SW 1 // stallguard "software" homing
|
||||
#define TMC2130_SG_THRS_X 40 // stallguard sensitivity for X axis
|
||||
#define TMC2130_SG_THRS_Y 40 // stallguard sensitivity for Y axis
|
||||
#define TMC2130_SG_DELAY 10 // stallguard delay (temporary solution)
|
||||
#define TMC2130_SG_DELTA 128 // stallguard delta [usteps] (minimum usteps before stallguard readed)
|
||||
|
||||
//new settings is possible for vsense = 1
|
||||
#define TMC2130_CURRENTS_H {15, 15, 20, 28} // default holding currents for all axes
|
||||
#define TMC2130_CURRENTS_R {15, 15, 40, 28} // default running currents for all axes
|
||||
//new settings is possible for vsense = 1, running current value > 31 set vsense to zero and shift both currents by 1 bit right
|
||||
#define TMC2130_CURRENTS_H {3, 3, 5, 8} // default holding currents for all axes
|
||||
#define TMC2130_CURRENTS_R {13, 13, 20, 20} // default running currents for all axes
|
||||
|
||||
//#define TMC2130_DEBUG
|
||||
//#define TMC2130_DEBUG_WR
|
||||
|
Loading…
Reference in New Issue
Block a user