M350 for E axis (8, 16, 32, 64, 128 microsteps)

This commit is contained in:
Robert Pelnar 2018-02-15 15:40:49 +01:00
parent 79caf3d9c6
commit 57499dc6a0
6 changed files with 103 additions and 40 deletions

View file

@ -446,6 +446,11 @@ void dcode_10()
calibration_status_store(CALIBRATION_STATUS_LIVE_ADJUST);
}
void dcode_12()
{//Time
LOG("D12 - Time\n");
}
#include "tmc2130.h"
#include "Marlin.h"
#include "planner.h"
@ -495,7 +500,8 @@ void dcode_2130()
}
else if (strchr_pointer[1+5] == '?')
{
if (strcmp(strchr_pointer + 7, "step") == 0) printf_P(PSTR("%c step=%d\n"), ch_axis, tmc2130_rd_MSCNT(axis) >> tmc2130_mres[axis]);
if (strcmp(strchr_pointer + 7, "mres") == 0) printf_P(PSTR("%c mres=%d\n"), ch_axis, tmc2130_mres[axis]);
else if (strcmp(strchr_pointer + 7, "step") == 0) printf_P(PSTR("%c step=%d\n"), ch_axis, tmc2130_rd_MSCNT(axis) >> tmc2130_mres[axis]);
else if (strcmp(strchr_pointer + 7, "mscnt") == 0) printf_P(PSTR("%c MSCNT=%d\n"), ch_axis, tmc2130_rd_MSCNT(axis));
else if (strcmp(strchr_pointer + 7, "mscuract") == 0)
{
@ -519,6 +525,21 @@ void dcode_2130()
uint16_t res = tmc2130_get_res(axis);
tmc2130_goto_step(axis, step & (4*res - 1), 2, 1000, res);
}
else if (strncmp(strchr_pointer + 7, "mres", 4) == 0)
{
uint8_t mres = strchr_pointer[11] - '0';
if ((mres >= 0) && (mres <= 8))
{
st_synchronize();
uint16_t res = tmc2130_get_res(axis);
uint16_t res_new = tmc2130_mres2usteps(mres);
tmc2130_set_res(axis, res_new);
if (res_new > res)
axis_steps_per_unit[axis] *= (res_new / res);
else
axis_steps_per_unit[axis] /= (res / res_new);
}
}
else if (strncmp(strchr_pointer + 7, "wave", 4) == 0)
{
uint8_t fac200 = atoi(strchr_pointer + 11) & 0xfe;

View file

@ -6195,12 +6195,38 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp
case 350: // M350 Set microstepping mode. Warning: Steps per unit remains unchanged. S code sets stepping mode for all drivers.
{
#ifdef TMC2130
if(code_seen('E'))
{
uint16_t res_new = code_value();
if ((res_new == 8) || (res_new == 16) || (res_new == 32) || (res_new == 64) || (res_new == 128))
{
st_synchronize();
uint8_t axis = E_AXIS;
uint16_t res = tmc2130_get_res(axis);
tmc2130_set_res(axis, res_new);
if (res_new > res)
{
uint16_t fac = (res_new / res);
axis_steps_per_unit[axis] *= fac;
position[E_AXIS] *= fac;
}
else
{
uint16_t fac = (res / res_new);
axis_steps_per_unit[axis] /= fac;
position[E_AXIS] /= fac;
}
}
}
#else //TMC2130
#if defined(X_MS1_PIN) && X_MS1_PIN > -1
if(code_seen('S')) for(int i=0;i<=4;i++) microstep_mode(i,code_value());
for(int i=0;i<NUM_AXIS;i++) if(code_seen(axis_codes[i])) microstep_mode(i,(uint8_t)code_value());
if(code_seen('B')) microstep_mode(4,code_value());
microstep_readings();
#endif
#endif //TMC2130
}
break;
case 351: // M351 Toggle MS1 MS2 pins directly, S# determines MS1 or MS2, X# sets the pin high/low.

View file

@ -148,6 +148,8 @@ extern float max_jerk[NUM_AXIS];
extern float mintravelfeedrate;
extern unsigned long axis_steps_per_sqr_second[NUM_AXIS];
extern long position[NUM_AXIS];
#ifdef AUTOTEMP
extern bool autotemp_enabled;
extern float autotemp_max;

View file

@ -1433,6 +1433,9 @@ void microstep_init()
#endif
}
#ifndef TMC2130
void microstep_ms(uint8_t driver, int8_t ms1, int8_t ms2)
{
if(ms1 > -1) switch(driver)
@ -1490,3 +1493,4 @@ void microstep_readings()
SERIAL_PROTOCOLLN( digitalRead(E1_MS2_PIN));
#endif
}
#endif //TMC2130

View file

@ -698,6 +698,15 @@ uint16_t tmc2130_get_res(uint8_t axis)
return tmc2130_mres2usteps(tmc2130_mres[axis]);
}
void tmc2130_set_res(uint8_t axis, uint16_t res)
{
tmc2130_mres[axis] = tmc2130_usteps2mres(res);
// uint32_t u = micros();
tmc2130_setup_chopper(axis, tmc2130_mres[axis], tmc2130_current_h[axis], tmc2130_current_r[axis]);
// u = micros() - u;
// printf_P(PSTR("tmc2130_setup_chopper %c %lu us"), "XYZE"[axis], u);
}
uint8_t tmc2130_get_pwr(uint8_t axis)
{
switch (axis)

View file

@ -107,6 +107,7 @@ struct
#pragma pack(pop)
extern uint16_t tmc2130_get_res(uint8_t axis);
extern void tmc2130_set_res(uint8_t axis, uint16_t res);
extern uint8_t tmc2130_get_pwr(uint8_t axis);
extern void tmc2130_set_pwr(uint8_t axis, uint8_t pwr);
extern uint8_t tmc2130_get_inv(uint8_t axis);