M350 for all axis - MK3

This commit is contained in:
leptun 2019-07-29 09:41:33 +03:00
parent da7ce65bb4
commit 556b87edec
2 changed files with 27 additions and 20 deletions

View File

@ -7538,27 +7538,34 @@ Sigma_Exit:
case 350:
{
#ifdef TMC2130
if(code_seen('E'))
for (int i=0; i<NUM_AXIS; i++)
{
uint16_t res_new = code_value();
if ((res_new == 8) || (res_new == 16) || (res_new == 32) || (res_new == 64) || (res_new == 128))
if(code_seen(axis_codes[i]))
{
st_synchronize();
uint8_t axis = E_AXIS;
uint16_t res = tmc2130_get_res(axis);
tmc2130_set_res(axis, res_new);
cs.axis_ustep_resolution[axis] = res_new;
if (res_new > res)
uint16_t res_new = code_value();
bool res_valid = (res_new == 8) || (res_new == 16) || (res_new == 32); // resolutions valid for all axis
res_valid |= (i != E_AXIS) && ((res_new == 1) || (res_new == 2) || (res_new == 4)); // resolutions valid for X Y Z only
res_valid |= (i == E_AXIS) && ((res_new == 64) || (res_new == 128)); // resolutions valid for E only
if (res_valid)
{
uint16_t fac = (res_new / res);
cs.axis_steps_per_unit[axis] *= fac;
position[E_AXIS] *= fac;
}
else
{
uint16_t fac = (res / res_new);
cs.axis_steps_per_unit[axis] /= fac;
position[E_AXIS] /= fac;
st_synchronize();
uint16_t res = tmc2130_get_res(i);
tmc2130_set_res(i, res_new);
cs.axis_ustep_resolution[i] = res_new;
uint16_t fac;
if (res_new > res)
{
fac = (res_new / res);
cs.axis_steps_per_unit[i] *= fac;
position[i] *= fac;
}
else
{
fac = (res / res_new);
cs.axis_steps_per_unit[i] /= fac;
position[i] /= fac;
}
}
}
}

View File

@ -425,7 +425,7 @@ 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 = 1;
uint8_t intpol = (mres != 0); // intpol to 256 only if microsteps aren't 256
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
@ -598,7 +598,7 @@ void tmc2130_wr_THIGH(uint8_t axis, uint32_t val32)
uint8_t tmc2130_usteps2mres(uint16_t usteps)
{
uint8_t mres = 8; while (mres && (usteps >>= 1)) mres--;
uint8_t mres = 8; while (usteps >>= 1) mres--;
return mres;
}