Merge pull request #57 from XPila/MK3
Soft homing + fixed homing in silent mode.
This commit is contained in:
commit
4fa5669298
@ -1526,6 +1526,9 @@ void homeaxis(int axis)
|
|||||||
#endif
|
#endif
|
||||||
plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder);
|
plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder);
|
||||||
st_synchronize();
|
st_synchronize();
|
||||||
|
/*
|
||||||
|
tmc2130_home_pause(axis);
|
||||||
|
|
||||||
current_position[axis] = 0;
|
current_position[axis] = 0;
|
||||||
plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
|
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;
|
destination[axis] = -home_retract_mm(axis) * axis_home_dir;
|
||||||
@ -1534,21 +1537,26 @@ void homeaxis(int axis)
|
|||||||
#endif
|
#endif
|
||||||
plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder);
|
plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder);
|
||||||
st_synchronize();
|
st_synchronize();
|
||||||
|
|
||||||
|
tmc2130_home_resume(axis);
|
||||||
|
|
||||||
destination[axis] = 2*home_retract_mm(axis) * axis_home_dir;
|
destination[axis] = 2*home_retract_mm(axis) * axis_home_dir;
|
||||||
#ifdef TMC2130
|
//#ifdef TMC2130
|
||||||
feedrate = homing_feedrate[axis];
|
// feedrate = homing_feedrate[axis];
|
||||||
#else
|
//#else
|
||||||
feedrate = homing_feedrate[axis] / 2;
|
feedrate = homing_feedrate[axis] / 2;
|
||||||
#endif
|
//#endif
|
||||||
#ifdef TMC2130
|
#ifdef TMC2130
|
||||||
tmc2130_home_restart(axis);
|
tmc2130_home_restart(axis);
|
||||||
#endif
|
#endif
|
||||||
plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder);
|
plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder);
|
||||||
st_synchronize();
|
st_synchronize();
|
||||||
|
*/
|
||||||
|
tmc2130_home_pause(axis);
|
||||||
|
|
||||||
current_position[axis] = 0;
|
current_position[axis] = 0;
|
||||||
plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
|
plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
|
||||||
destination[axis] = -0.16 * axis_home_dir;
|
destination[axis] = -0.32 * axis_home_dir;
|
||||||
plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder);
|
plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder);
|
||||||
st_synchronize();
|
st_synchronize();
|
||||||
|
|
||||||
@ -1558,6 +1566,8 @@ void homeaxis(int axis)
|
|||||||
|
|
||||||
endstops_hit_on_purpose();
|
endstops_hit_on_purpose();
|
||||||
axis_known_position[axis] = true;
|
axis_known_position[axis] = true;
|
||||||
|
|
||||||
|
|
||||||
#ifdef TMC2130
|
#ifdef TMC2130
|
||||||
tmc2130_home_exit();
|
tmc2130_home_exit();
|
||||||
// destination[axis] += 2;
|
// destination[axis] += 2;
|
||||||
@ -5462,15 +5472,15 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp
|
|||||||
|
|
||||||
case 916: // M916 Set sg_thrs
|
case 916: // M916 Set sg_thrs
|
||||||
{
|
{
|
||||||
if (code_seen('X')) tmc2131_axis_sg_thr[X_AXIS] = code_value();
|
if (code_seen('X')) tmc2130_axis_sg_thr[X_AXIS] = code_value();
|
||||||
if (code_seen('Y')) tmc2131_axis_sg_thr[Y_AXIS] = code_value();
|
if (code_seen('Y')) tmc2130_axis_sg_thr[Y_AXIS] = code_value();
|
||||||
if (code_seen('Z')) tmc2131_axis_sg_thr[Z_AXIS] = code_value();
|
if (code_seen('Z')) tmc2130_axis_sg_thr[Z_AXIS] = code_value();
|
||||||
MYSERIAL.print("tmc2131_axis_sg_thr[X]=");
|
MYSERIAL.print("tmc2130_axis_sg_thr[X]=");
|
||||||
MYSERIAL.print(tmc2131_axis_sg_thr[X_AXIS], DEC);
|
MYSERIAL.print(tmc2130_axis_sg_thr[X_AXIS], DEC);
|
||||||
MYSERIAL.print("tmc2131_axis_sg_thr[Y]=");
|
MYSERIAL.print("tmc2130_axis_sg_thr[Y]=");
|
||||||
MYSERIAL.print(tmc2131_axis_sg_thr[Y_AXIS], DEC);
|
MYSERIAL.print(tmc2130_axis_sg_thr[Y_AXIS], DEC);
|
||||||
MYSERIAL.print("tmc2131_axis_sg_thr[Z]=");
|
MYSERIAL.print("tmc2130_axis_sg_thr[Z]=");
|
||||||
MYSERIAL.print(tmc2131_axis_sg_thr[Z_AXIS], DEC);
|
MYSERIAL.print(tmc2130_axis_sg_thr[Z_AXIS], DEC);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -28,6 +28,10 @@ uint8_t tmc2130_current_r[4] = TMC2130_CURRENTS_R;
|
|||||||
//axis stalled flags
|
//axis stalled flags
|
||||||
uint8_t tmc2130_axis_stalled[4] = {0, 0, 0, 0};
|
uint8_t tmc2130_axis_stalled[4] = {0, 0, 0, 0};
|
||||||
|
|
||||||
|
//running currents for homing
|
||||||
|
uint8_t tmc2130_current_r_home[4] = {10, 10, 20, 10};
|
||||||
|
|
||||||
|
|
||||||
//pwm_ampl
|
//pwm_ampl
|
||||||
uint8_t tmc2130_pwm_ampl[2] = {TMC2130_PWM_AMPL_X, TMC2130_PWM_AMPL_Y};
|
uint8_t tmc2130_pwm_ampl[2] = {TMC2130_PWM_AMPL_X, TMC2130_PWM_AMPL_Y};
|
||||||
//pwm_grad
|
//pwm_grad
|
||||||
@ -37,11 +41,13 @@ uint8_t tmc2130_pwm_auto[2] = {TMC2130_PWM_AUTO_X, TMC2130_PWM_AUTO_Y};
|
|||||||
//pwm_freq
|
//pwm_freq
|
||||||
uint8_t tmc2130_pwm_freq[2] = {TMC2130_PWM_FREQ_X, TMC2130_PWM_FREQ_Y};
|
uint8_t tmc2130_pwm_freq[2] = {TMC2130_PWM_FREQ_X, TMC2130_PWM_FREQ_Y};
|
||||||
|
|
||||||
|
uint8_t tmc2130_mres[4] = {0, 0, 0, 0}; //will be filed at begin of init
|
||||||
|
|
||||||
uint8_t tmc2131_axis_sg_thr[4] = {TMC2130_SG_THRS_X, TMC2130_SG_THRS_Y, TMC2130_SG_THRS_Z, 0};
|
|
||||||
uint8_t tmc2131_axis_sg_thr_home[4] = {5, 5, TMC2130_SG_THRS_Z, 0};
|
|
||||||
|
|
||||||
uint32_t tmc2131_axis_sg_pos[4] = {0, 0, 0, 0};
|
uint8_t tmc2130_axis_sg_thr[4] = {TMC2130_SG_THRS_X, TMC2130_SG_THRS_Y, TMC2130_SG_THRS_Z, 0};
|
||||||
|
uint8_t tmc2130_axis_sg_thr_home[4] = {3, 3, TMC2130_SG_THRS_Z, 0};
|
||||||
|
|
||||||
|
uint32_t tmc2130_axis_sg_pos[4] = {0, 0, 0, 0};
|
||||||
|
|
||||||
uint8_t sg_homing_axes_mask = 0x00;
|
uint8_t sg_homing_axes_mask = 0x00;
|
||||||
|
|
||||||
@ -96,16 +102,23 @@ void tmc2130_wr_TPWMTHRS(uint8_t cs, uint32_t val32);
|
|||||||
void tmc2130_wr_THIGH(uint8_t cs, uint32_t val32);
|
void tmc2130_wr_THIGH(uint8_t cs, uint32_t val32);
|
||||||
|
|
||||||
uint8_t tmc2130_axis_by_cs(uint8_t cs);
|
uint8_t tmc2130_axis_by_cs(uint8_t cs);
|
||||||
uint8_t tmc2130_mres(uint16_t microstep_resolution);
|
uint8_t tmc2130_calc_mres(uint16_t microstep_resolution);
|
||||||
|
|
||||||
uint8_t tmc2130_wr(uint8_t cs, uint8_t addr, uint32_t wval);
|
uint8_t tmc2130_wr(uint8_t cs, uint8_t addr, uint32_t wval);
|
||||||
uint8_t tmc2130_rd(uint8_t cs, uint8_t addr, uint32_t* rval);
|
uint8_t tmc2130_rd(uint8_t cs, uint8_t addr, uint32_t* rval);
|
||||||
uint8_t tmc2130_txrx(uint8_t cs, uint8_t addr, uint32_t wval, uint32_t* rval);
|
uint8_t tmc2130_txrx(uint8_t cs, uint8_t addr, uint32_t wval, uint32_t* rval);
|
||||||
|
|
||||||
|
|
||||||
|
void tmc2130_setup_chopper(uint8_t axis, uint8_t mres, uint8_t current_h, uint8_t current_r);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void tmc2130_init()
|
void tmc2130_init()
|
||||||
{
|
{
|
||||||
|
tmc2130_mres[0] = tmc2130_calc_mres(TMC2130_USTEPS_XY);
|
||||||
|
tmc2130_mres[1] = tmc2130_calc_mres(TMC2130_USTEPS_XY);
|
||||||
|
tmc2130_mres[2] = tmc2130_calc_mres(TMC2130_USTEPS_Z);
|
||||||
|
tmc2130_mres[3] = tmc2130_calc_mres(TMC2130_USTEPS_E);
|
||||||
MYSERIAL.print("tmc2130_init mode=");
|
MYSERIAL.print("tmc2130_init mode=");
|
||||||
MYSERIAL.println(tmc2130_mode, DEC);
|
MYSERIAL.println(tmc2130_mode, DEC);
|
||||||
WRITE(X_TMC2130_CS, HIGH);
|
WRITE(X_TMC2130_CS, HIGH);
|
||||||
@ -123,8 +136,7 @@ void tmc2130_init()
|
|||||||
SPI.begin();
|
SPI.begin();
|
||||||
for (int i = 0; i < 2; i++) // X Y axes
|
for (int i = 0; i < 2; i++) // X Y axes
|
||||||
{
|
{
|
||||||
uint8_t mres = tmc2130_mres(TMC2130_USTEPS_XY);
|
/* if (tmc2130_current_r[i] <= 31)
|
||||||
if (tmc2130_current_r[i] <= 31)
|
|
||||||
{
|
{
|
||||||
tmc2130_wr_CHOPCONF(tmc2130_cs[i], 3, 5, 1, 0, 0, 0, 0, 2, 1, 0, 0, 0, mres, TMC2130_INTPOL_XY, 0, 0);
|
tmc2130_wr_CHOPCONF(tmc2130_cs[i], 3, 5, 1, 0, 0, 0, 0, 2, 1, 0, 0, 0, mres, TMC2130_INTPOL_XY, 0, 0);
|
||||||
tmc2130_wr(tmc2130_cs[i], TMC2130_REG_IHOLD_IRUN, 0x000f0000 | ((tmc2130_current_r[i] & 0x1f) << 8) | (tmc2130_current_h[i] & 0x1f));
|
tmc2130_wr(tmc2130_cs[i], TMC2130_REG_IHOLD_IRUN, 0x000f0000 | ((tmc2130_current_r[i] & 0x1f) << 8) | (tmc2130_current_h[i] & 0x1f));
|
||||||
@ -133,11 +145,13 @@ void tmc2130_init()
|
|||||||
{
|
{
|
||||||
tmc2130_wr_CHOPCONF(tmc2130_cs[i], 3, 5, 1, 0, 0, 0, 0, 2, 0, 0, 0, 0, mres, TMC2130_INTPOL_XY, 0, 0);
|
tmc2130_wr_CHOPCONF(tmc2130_cs[i], 3, 5, 1, 0, 0, 0, 0, 2, 0, 0, 0, 0, mres, TMC2130_INTPOL_XY, 0, 0);
|
||||||
tmc2130_wr(tmc2130_cs[i], TMC2130_REG_IHOLD_IRUN, 0x000f0000 | (((tmc2130_current_r[i] >> 1) & 0x1f) << 8) | ((tmc2130_current_h[i] >> 1) & 0x1f));
|
tmc2130_wr(tmc2130_cs[i], TMC2130_REG_IHOLD_IRUN, 0x000f0000 | (((tmc2130_current_r[i] >> 1) & 0x1f) << 8) | ((tmc2130_current_h[i] >> 1) & 0x1f));
|
||||||
}
|
}*/
|
||||||
|
tmc2130_setup_chopper(i, tmc2130_mres[i], tmc2130_current_h[i], tmc2130_current_r[i]);
|
||||||
|
|
||||||
// tmc2130_wr_CHOPCONF(tmc2130_cs[i], 3, 5, 1, 0, 0, 0, 0, 2, 1, 0, 0, 0, mres, TMC2130_INTPOL_XY, 0, 0);
|
// tmc2130_wr_CHOPCONF(tmc2130_cs[i], 3, 5, 1, 0, 0, 0, 0, 2, 1, 0, 0, 0, mres, TMC2130_INTPOL_XY, 0, 0);
|
||||||
// tmc2130_wr(tmc2130_cs[i], TMC2130_REG_IHOLD_IRUN, 0x000f0000 | ((tmc2130_current_r[i] & 0x1f) << 8) | (tmc2130_current_h[i] & 0x1f));
|
// tmc2130_wr(tmc2130_cs[i], TMC2130_REG_IHOLD_IRUN, 0x000f0000 | ((tmc2130_current_r[i] & 0x1f) << 8) | (tmc2130_current_h[i] & 0x1f));
|
||||||
tmc2130_wr(tmc2130_cs[i], TMC2130_REG_TPOWERDOWN, 0x00000000);
|
tmc2130_wr(tmc2130_cs[i], TMC2130_REG_TPOWERDOWN, 0x00000000);
|
||||||
tmc2130_wr(tmc2130_cs[i], TMC2130_REG_COOLCONF, (((uint32_t)tmc2131_axis_sg_thr[i]) << 16) | ((uint32_t)1 << 24));
|
tmc2130_wr(tmc2130_cs[i], TMC2130_REG_COOLCONF, (((uint32_t)tmc2130_axis_sg_thr[i]) << 16) | ((uint32_t)1 << 24));
|
||||||
tmc2130_wr(tmc2130_cs[i], TMC2130_REG_TCOOLTHRS, (tmc2130_mode == TMC2130_MODE_SILENT)?0:TMC2130_TCOOLTHRS);
|
tmc2130_wr(tmc2130_cs[i], TMC2130_REG_TCOOLTHRS, (tmc2130_mode == TMC2130_MODE_SILENT)?0:TMC2130_TCOOLTHRS);
|
||||||
tmc2130_wr(tmc2130_cs[i], TMC2130_REG_GCONF, (tmc2130_mode == TMC2130_MODE_SILENT)?TMC2130_GCONF_SILENT:TMC2130_GCONF_SGSENS);
|
tmc2130_wr(tmc2130_cs[i], TMC2130_REG_GCONF, (tmc2130_mode == TMC2130_MODE_SILENT)?TMC2130_GCONF_SILENT:TMC2130_GCONF_SGSENS);
|
||||||
tmc2130_wr_PWMCONF(tmc2130_cs[i], tmc2130_pwm_ampl[i], tmc2130_pwm_grad[i], tmc2130_pwm_freq[i], tmc2130_pwm_auto[i], 0, 0);
|
tmc2130_wr_PWMCONF(tmc2130_cs[i], tmc2130_pwm_ampl[i], tmc2130_pwm_grad[i], tmc2130_pwm_freq[i], tmc2130_pwm_auto[i], 0, 0);
|
||||||
@ -146,8 +160,8 @@ void tmc2130_init()
|
|||||||
}
|
}
|
||||||
for (int i = 2; i < 3; i++) // Z axis
|
for (int i = 2; i < 3; i++) // Z axis
|
||||||
{
|
{
|
||||||
uint8_t mres = tmc2130_mres(TMC2130_USTEPS_Z);
|
// uint8_t mres = tmc2130_mres(TMC2130_USTEPS_Z);
|
||||||
if (tmc2130_current_r[i] <= 31)
|
/* if (tmc2130_current_r[i] <= 31)
|
||||||
{
|
{
|
||||||
tmc2130_wr_CHOPCONF(tmc2130_cs[i], 3, 5, 1, 0, 0, 0, 0, 2, 1, 0, 0, 0, mres, TMC2130_INTPOL_Z, 0, 0);
|
tmc2130_wr_CHOPCONF(tmc2130_cs[i], 3, 5, 1, 0, 0, 0, 0, 2, 1, 0, 0, 0, mres, TMC2130_INTPOL_Z, 0, 0);
|
||||||
tmc2130_wr(tmc2130_cs[i], TMC2130_REG_IHOLD_IRUN, 0x000f0000 | ((tmc2130_current_r[i] & 0x1f) << 8) | (tmc2130_current_h[i] & 0x1f));
|
tmc2130_wr(tmc2130_cs[i], TMC2130_REG_IHOLD_IRUN, 0x000f0000 | ((tmc2130_current_r[i] & 0x1f) << 8) | (tmc2130_current_h[i] & 0x1f));
|
||||||
@ -156,15 +170,20 @@ void tmc2130_init()
|
|||||||
{
|
{
|
||||||
tmc2130_wr_CHOPCONF(tmc2130_cs[i], 3, 5, 1, 0, 0, 0, 0, 2, 0, 0, 0, 0, mres, TMC2130_INTPOL_Z, 0, 0);
|
tmc2130_wr_CHOPCONF(tmc2130_cs[i], 3, 5, 1, 0, 0, 0, 0, 2, 0, 0, 0, 0, mres, TMC2130_INTPOL_Z, 0, 0);
|
||||||
tmc2130_wr(tmc2130_cs[i], TMC2130_REG_IHOLD_IRUN, 0x000f0000 | (((tmc2130_current_r[i] >> 1) & 0x1f) << 8) | ((tmc2130_current_h[i] >> 1) & 0x1f));
|
tmc2130_wr(tmc2130_cs[i], TMC2130_REG_IHOLD_IRUN, 0x000f0000 | (((tmc2130_current_r[i] >> 1) & 0x1f) << 8) | ((tmc2130_current_h[i] >> 1) & 0x1f));
|
||||||
}
|
}*/
|
||||||
|
tmc2130_setup_chopper(i, tmc2130_mres[i], tmc2130_current_h[i], tmc2130_current_r[i]);
|
||||||
|
|
||||||
tmc2130_wr(tmc2130_cs[i], TMC2130_REG_TPOWERDOWN, 0x00000000);
|
tmc2130_wr(tmc2130_cs[i], TMC2130_REG_TPOWERDOWN, 0x00000000);
|
||||||
tmc2130_wr(tmc2130_cs[i], TMC2130_REG_GCONF, TMC2130_GCONF_SGSENS);
|
tmc2130_wr(tmc2130_cs[i], TMC2130_REG_GCONF, TMC2130_GCONF_SGSENS);
|
||||||
}
|
}
|
||||||
for (int i = 3; i < 4; i++) // E axis
|
for (int i = 3; i < 4; i++) // E axis
|
||||||
{
|
{
|
||||||
uint8_t mres = tmc2130_mres(TMC2130_USTEPS_E);
|
// uint8_t mres = tmc2130_mres(TMC2130_USTEPS_E);
|
||||||
tmc2130_wr_CHOPCONF(tmc2130_cs[i], 3, 5, 1, 0, 0, 0, 0, 2, 1, 0, 0, 0, mres, TMC2130_INTPOL_E, 0, 0);
|
tmc2130_setup_chopper(i, tmc2130_mres[i], tmc2130_current_h[i], tmc2130_current_r[i]);
|
||||||
tmc2130_wr(tmc2130_cs[i], TMC2130_REG_IHOLD_IRUN, 0x000f0000 | ((tmc2130_current_r[i] & 0x1f) << 8) | (tmc2130_current_h[i] & 0x1f));
|
|
||||||
|
// tmc2130_wr_CHOPCONF(tmc2130_cs[i], 3, 5, 1, 0, 0, 0, 0, 2, 1, 0, 0, 0, mres, TMC2130_INTPOL_E, 0, 0);
|
||||||
|
// tmc2130_wr(tmc2130_cs[i], TMC2130_REG_IHOLD_IRUN, 0x000f0000 | ((tmc2130_current_r[i] & 0x1f) << 8) | (tmc2130_current_h[i] & 0x1f));
|
||||||
|
|
||||||
tmc2130_wr(tmc2130_cs[i], TMC2130_REG_TPOWERDOWN, 0x00000000);
|
tmc2130_wr(tmc2130_cs[i], TMC2130_REG_TPOWERDOWN, 0x00000000);
|
||||||
tmc2130_wr(tmc2130_cs[i], TMC2130_REG_GCONF, 0x00000000);
|
tmc2130_wr(tmc2130_cs[i], TMC2130_REG_GCONF, 0x00000000);
|
||||||
}
|
}
|
||||||
@ -209,7 +228,7 @@ void tmc2130_update_sg_axis(uint8_t axis)
|
|||||||
if (tstep < TMC2130_TCOOLTHRS)
|
if (tstep < TMC2130_TCOOLTHRS)
|
||||||
{
|
{
|
||||||
long pos = st_get_position(axis);
|
long pos = st_get_position(axis);
|
||||||
if (abs(pos - tmc2131_axis_sg_pos[axis]) > TMC2130_SG_DELTA)
|
if (abs(pos - tmc2130_axis_sg_pos[axis]) > TMC2130_SG_DELTA)
|
||||||
{
|
{
|
||||||
uint16_t sg = tmc2130_rd_DRV_STATUS(cs) & 0x3ff;
|
uint16_t sg = tmc2130_rd_DRV_STATUS(cs) & 0x3ff;
|
||||||
if (sg == 0)
|
if (sg == 0)
|
||||||
@ -250,7 +269,7 @@ bool tmc2130_update_sg()
|
|||||||
if (tstep < TMC2130_TCOOLTHRS)
|
if (tstep < TMC2130_TCOOLTHRS)
|
||||||
{
|
{
|
||||||
long pos = st_get_position(axis);
|
long pos = st_get_position(axis);
|
||||||
if (abs(pos - tmc2131_axis_sg_pos[axis]) > TMC2130_SG_DELTA)
|
if (abs(pos - tmc2130_axis_sg_pos[axis]) > TMC2130_SG_DELTA)
|
||||||
{
|
{
|
||||||
uint16_t sg = tmc2130_rd_DRV_STATUS(cs) & 0x3ff;
|
uint16_t sg = tmc2130_rd_DRV_STATUS(cs) & 0x3ff;
|
||||||
if (sg == 0)
|
if (sg == 0)
|
||||||
@ -285,13 +304,14 @@ void tmc2130_home_enter(uint8_t axes_mask)
|
|||||||
if (axes_mask & mask)
|
if (axes_mask & mask)
|
||||||
{
|
{
|
||||||
sg_homing_axes_mask |= mask;
|
sg_homing_axes_mask |= mask;
|
||||||
tmc2131_axis_sg_pos[axis] = st_get_position(axis);
|
tmc2130_axis_sg_pos[axis] = st_get_position(axis);
|
||||||
tmc2130_axis_stalled[axis] = false;
|
tmc2130_axis_stalled[axis] = false;
|
||||||
//Configuration to spreadCycle
|
//Configuration to spreadCycle
|
||||||
tmc2130_wr(cs, TMC2130_REG_GCONF, TMC2130_GCONF_NORMAL);
|
tmc2130_wr(cs, TMC2130_REG_GCONF, TMC2130_GCONF_NORMAL);
|
||||||
tmc2130_wr(cs, TMC2130_REG_COOLCONF, (((uint32_t)tmc2131_axis_sg_thr_home[axis]) << 16));
|
tmc2130_wr(cs, TMC2130_REG_COOLCONF, (((uint32_t)tmc2130_axis_sg_thr_home[axis]) << 16));
|
||||||
// tmc2130_wr(cs, TMC2130_REG_COOLCONF, (((uint32_t)tmc2131_axis_sg_thr[axis]) << 16) | ((uint32_t)1 << 24));
|
// tmc2130_wr(cs, TMC2130_REG_COOLCONF, (((uint32_t)tmc2130_axis_sg_thr[axis]) << 16) | ((uint32_t)1 << 24));
|
||||||
tmc2130_wr(cs, TMC2130_REG_TCOOLTHRS, TMC2130_TCOOLTHRS);
|
tmc2130_wr(cs, TMC2130_REG_TCOOLTHRS, TMC2130_TCOOLTHRS);
|
||||||
|
tmc2130_setup_chopper(axis, tmc2130_mres[axis], tmc2130_current_h[axis], tmc2130_current_r_home[axis]);
|
||||||
#ifndef TMC2130_SG_HOMING_SW_XY
|
#ifndef TMC2130_SG_HOMING_SW_XY
|
||||||
if (mask & (X_AXIS_MASK | Y_AXIS_MASK))
|
if (mask & (X_AXIS_MASK | Y_AXIS_MASK))
|
||||||
tmc2130_wr(cs, TMC2130_REG_GCONF, TMC2130_GCONF_SGSENS); //stallguard output DIAG1, DIAG1 = pushpull
|
tmc2130_wr(cs, TMC2130_REG_GCONF, TMC2130_GCONF_SGSENS); //stallguard output DIAG1, DIAG1 = pushpull
|
||||||
@ -326,7 +346,8 @@ void tmc2130_home_exit()
|
|||||||
#ifdef TMC2130_SG_HOMING_SW_XY
|
#ifdef TMC2130_SG_HOMING_SW_XY
|
||||||
tmc2130_wr(tmc2130_cs[axis], TMC2130_REG_GCONF, TMC2130_GCONF_NORMAL);
|
tmc2130_wr(tmc2130_cs[axis], TMC2130_REG_GCONF, TMC2130_GCONF_NORMAL);
|
||||||
#else //TMC2130_SG_HOMING_SW_XY
|
#else //TMC2130_SG_HOMING_SW_XY
|
||||||
tmc2130_wr(tmc2130_cs[axis], TMC2130_REG_COOLCONF, (((uint32_t)tmc2131_axis_sg_thr[axis]) << 16) | ((uint32_t)1 << 24));
|
tmc2130_setup_chopper(axis, tmc2130_mres[axis], tmc2130_current_h[axis], tmc2130_current_r[axis]);
|
||||||
|
tmc2130_wr(tmc2130_cs[axis], TMC2130_REG_COOLCONF, (((uint32_t)tmc2130_axis_sg_thr[axis]) << 16) | ((uint32_t)1 << 24));
|
||||||
tmc2130_wr(tmc2130_cs[axis], TMC2130_REG_GCONF, TMC2130_GCONF_SGSENS);
|
tmc2130_wr(tmc2130_cs[axis], TMC2130_REG_GCONF, TMC2130_GCONF_SGSENS);
|
||||||
#endif //TMC2130_SG_HOMING_SW_XY
|
#endif //TMC2130_SG_HOMING_SW_XY
|
||||||
}
|
}
|
||||||
@ -338,9 +359,25 @@ void tmc2130_home_exit()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tmc2130_home_pause(uint8_t axis)
|
||||||
|
{
|
||||||
|
if (tmc2130_mode == TMC2130_MODE_NORMAL)
|
||||||
|
{
|
||||||
|
tmc2130_wr(tmc2130_cs[axis], TMC2130_REG_GCONF, TMC2130_GCONF_NORMAL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void tmc2130_home_resume(uint8_t axis)
|
||||||
|
{
|
||||||
|
if (tmc2130_mode == TMC2130_MODE_NORMAL)
|
||||||
|
{
|
||||||
|
tmc2130_wr(tmc2130_cs[axis], TMC2130_REG_GCONF, TMC2130_GCONF_SGSENS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void tmc2130_home_restart(uint8_t axis)
|
void tmc2130_home_restart(uint8_t axis)
|
||||||
{
|
{
|
||||||
tmc2131_axis_sg_pos[axis] = st_get_position(axis);
|
tmc2130_axis_sg_pos[axis] = st_get_position(axis);
|
||||||
tmc2130_axis_stalled[axis] = false;
|
tmc2130_axis_stalled[axis] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -368,6 +405,22 @@ void tmc2130_check_overtemp()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tmc2130_setup_chopper(uint8_t axis, uint8_t mres, uint8_t current_h, uint8_t current_r)
|
||||||
|
{
|
||||||
|
uint8_t cs = tmc2130_cs[axis];
|
||||||
|
uint8_t intpol = 1;
|
||||||
|
if (current_r <= 31)
|
||||||
|
{
|
||||||
|
tmc2130_wr_CHOPCONF(cs, 3, 5, 1, 0, 0, 0, 0, 2, 1, 0, 0, 0, mres, intpol, 0, 0);
|
||||||
|
tmc2130_wr(cs, TMC2130_REG_IHOLD_IRUN, 0x000f0000 | ((current_r & 0x1f) << 8) | (current_h & 0x1f));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tmc2130_wr_CHOPCONF(cs, 3, 5, 1, 0, 0, 0, 0, 2, 0, 0, 0, 0, mres, intpol, 0, 0);
|
||||||
|
tmc2130_wr(cs, TMC2130_REG_IHOLD_IRUN, 0x000f0000 | (((current_r >> 1) & 0x1f) << 8) | ((current_h >> 1) & 0x1f));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void tmc2130_set_current_h(uint8_t axis, uint8_t current)
|
void tmc2130_set_current_h(uint8_t axis, uint8_t current)
|
||||||
{
|
{
|
||||||
MYSERIAL.print("tmc2130_set_current_h ");
|
MYSERIAL.print("tmc2130_set_current_h ");
|
||||||
@ -375,7 +428,7 @@ void tmc2130_set_current_h(uint8_t axis, uint8_t current)
|
|||||||
MYSERIAL.print(" ");
|
MYSERIAL.print(" ");
|
||||||
MYSERIAL.println((int)current);
|
MYSERIAL.println((int)current);
|
||||||
tmc2130_current_h[axis] = current;
|
tmc2130_current_h[axis] = current;
|
||||||
tmc2130_wr(tmc2130_cs[axis], TMC2130_REG_IHOLD_IRUN, 0x000f0000 | ((tmc2130_current_r[axis] & 0x1f) << 8) | (tmc2130_current_h[axis] & 0x1f));
|
tmc2130_setup_chopper(axis, tmc2130_mres[axis], tmc2130_current_h[axis], tmc2130_current_r[axis]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tmc2130_set_current_r(uint8_t axis, uint8_t current)
|
void tmc2130_set_current_r(uint8_t axis, uint8_t current)
|
||||||
@ -385,7 +438,7 @@ void tmc2130_set_current_r(uint8_t axis, uint8_t current)
|
|||||||
MYSERIAL.print(" ");
|
MYSERIAL.print(" ");
|
||||||
MYSERIAL.println((int)current);
|
MYSERIAL.println((int)current);
|
||||||
tmc2130_current_r[axis] = current;
|
tmc2130_current_r[axis] = current;
|
||||||
tmc2130_wr(tmc2130_cs[axis], TMC2130_REG_IHOLD_IRUN, 0x000f0000 | ((tmc2130_current_r[axis] & 0x1f) << 8) | (tmc2130_current_h[axis] & 0x1f));
|
tmc2130_setup_chopper(axis, tmc2130_mres[axis], tmc2130_current_h[axis], tmc2130_current_r[axis]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tmc2130_print_currents()
|
void tmc2130_print_currents()
|
||||||
@ -514,7 +567,7 @@ uint8_t tmc2130_axis_by_cs(uint8_t cs)
|
|||||||
}
|
}
|
||||||
#endif //TMC2130_DEBUG
|
#endif //TMC2130_DEBUG
|
||||||
|
|
||||||
uint8_t tmc2130_mres(uint16_t microstep_resolution)
|
uint8_t tmc2130_calc_mres(uint16_t microstep_resolution)
|
||||||
{
|
{
|
||||||
if (microstep_resolution == 256) return 0b0000;
|
if (microstep_resolution == 256) return 0b0000;
|
||||||
if (microstep_resolution == 128) return 0b0001;
|
if (microstep_resolution == 128) return 0b0001;
|
||||||
|
@ -11,7 +11,7 @@ extern uint8_t tmc2130_current_r[4];
|
|||||||
//flags for axis stall detection
|
//flags for axis stall detection
|
||||||
extern uint8_t tmc2130_axis_stalled[4];
|
extern uint8_t tmc2130_axis_stalled[4];
|
||||||
|
|
||||||
extern uint8_t tmc2131_axis_sg_thr[4];
|
extern uint8_t tmc2130_axis_sg_thr[4];
|
||||||
|
|
||||||
extern bool tmc2130_sg_stop_on_crash;
|
extern bool tmc2130_sg_stop_on_crash;
|
||||||
extern bool tmc2130_sg_crash;
|
extern bool tmc2130_sg_crash;
|
||||||
@ -50,5 +50,8 @@ extern void tmc2130_set_pwm_grad(uint8_t axis, uint8_t pwm_ampl);
|
|||||||
|
|
||||||
extern uint16_t tmc2130_rd_MSCNT(uint8_t cs);
|
extern uint16_t tmc2130_rd_MSCNT(uint8_t cs);
|
||||||
|
|
||||||
|
extern void tmc2130_home_pause(uint8_t axis);
|
||||||
|
extern void tmc2130_home_resume(uint8_t axis);
|
||||||
|
|
||||||
|
|
||||||
#endif //TMC2130_H
|
#endif //TMC2130_H
|
Loading…
Reference in New Issue
Block a user