Increase resolution of wave factor.

This commit is contained in:
Marek Bel 2018-03-22 19:53:58 +01:00
parent 3d299cc412
commit 397e7d4791
5 changed files with 31 additions and 31 deletions

View File

@ -574,11 +574,11 @@ void dcode_2130()
}
else if (strncmp(strchr_pointer + 7, "wave", 4) == 0)
{
uint8_t fac200 = atoi(strchr_pointer + 11) & 0xff;
if (fac200 < TMC2130_WAVE_FAC200_MIN) fac200 = 0;
if (fac200 > TMC2130_WAVE_FAC200_MAX) fac200 = TMC2130_WAVE_FAC200_MAX;
tmc2130_set_wave(axis, 247, fac200);
tmc2130_wave_fac[axis] = fac200;
uint16_t fac1000 = atoi(strchr_pointer + 11) & 0xffff;
if (fac1000 < TMC2130_WAVE_FAC1000_MIN) fac1000 = 0;
if (fac1000 > TMC2130_WAVE_FAC1000_MAX) fac1000 = TMC2130_WAVE_FAC1000_MAX;
tmc2130_set_wave(axis, 247, fac1000);
tmc2130_wave_fac[axis] = fac1000;
}
}
else if (strchr_pointer[1+5] == '@')

View File

@ -58,7 +58,7 @@ uint8_t tmc2130_home_origin[2] = {0, 0};
uint8_t tmc2130_home_bsteps[2] = {48, 48};
uint8_t tmc2130_home_fsteps[2] = {48, 48};
uint8_t tmc2130_wave_fac[4] = {0, 0, 0, 0};
uint16_t tmc2130_wave_fac[4] = {0, 0, 0, 0};
bool tmc2130_sg_stop_on_crash = true;
uint8_t tmc2130_sg_diag_mask = 0x00;
@ -821,14 +821,14 @@ void tmc2130_get_wave(uint8_t axis, uint8_t* data, FILE* stream)
tmc2130_setup_chopper(axis, tmc2130_mres[axis], tmc2130_current_h[axis], tmc2130_current_r[axis]);
}
void tmc2130_set_wave(uint8_t axis, uint8_t amp, uint8_t fac200)
void tmc2130_set_wave(uint8_t axis, uint8_t amp, uint16_t fac1000)
{
// TMC2130 wave compression algorithm
// optimized for minimal memory requirements
printf_P(PSTR("tmc2130_set_wave %d %d\n"), axis, fac200);
if (fac200 < TMC2130_WAVE_FAC200_MIN) fac200 = 0;
if (fac200 > TMC2130_WAVE_FAC200_MAX) fac200 = TMC2130_WAVE_FAC200_MAX;
float fac = (float)fac200/200; //correction factor
printf_P(PSTR("tmc2130_set_wave %d %d\n"), axis, fac1000);
if (fac1000 < TMC2130_WAVE_FAC1000_MIN) fac1000 = 0;
if (fac1000 > TMC2130_WAVE_FAC1000_MAX) fac1000 = TMC2130_WAVE_FAC1000_MAX;
float fac = (float)fac1000/1000; //correction factor
uint8_t vA = 0; //value of currentA
uint8_t va = 0; //previous vA
uint8_t d0 = 0; //delta0

View File

@ -23,16 +23,16 @@ extern uint32_t tmc2130_sg_meassure_val;
#define TMC2130_MODE_NORMAL 0
#define TMC2130_MODE_SILENT 1
#define TMC2130_WAVE_FAC200_MIN 180
#define TMC2130_WAVE_FAC200_MAX 250
#define TMC2130_WAVE_FAC200_STP 1
#define TMC2130_WAVE_FAC1000_MIN 900
#define TMC2130_WAVE_FAC1000_MAX 1250
#define TMC2130_WAVE_FAC1000_STP 1
extern uint8_t tmc2130_home_enabled;
extern uint8_t tmc2130_home_origin[2];
extern uint8_t tmc2130_home_bsteps[2];
extern uint8_t tmc2130_home_fsteps[2];
extern uint8_t tmc2130_wave_fac[4];
extern uint16_t tmc2130_wave_fac[4];
//initialize tmc2130
@ -117,7 +117,7 @@ extern void tmc2130_do_step(uint8_t axis);
extern void tmc2130_do_steps(uint8_t axis, uint16_t steps, uint8_t dir, uint16_t delay_us);
extern void tmc2130_goto_step(uint8_t axis, uint8_t step, uint8_t dir, uint16_t delay_us, uint16_t microstep_resolution);
extern void tmc2130_get_wave(uint8_t axis, uint8_t* data, FILE* stream);
extern void tmc2130_set_wave(uint8_t axis, uint8_t amp, uint8_t fac200);
extern void tmc2130_set_wave(uint8_t axis, uint8_t amp, uint16_t fac1000);
extern bool tmc2130_home_calibrate(uint8_t axis);

View File

@ -240,7 +240,7 @@ static void menu_action_setlang(unsigned char lang);
static void menu_action_sdfile(const char* filename, char* longFilename);
static void menu_action_sddirectory(const char* filename, char* longFilename);
static void menu_action_setting_edit_bool(const char* pstr, bool* ptr);
static void menu_action_setting_edit_wfac(const char* pstr, uint8_t* ptr, uint8_t minValue, uint8_t maxValue);
static void menu_action_setting_edit_wfac(const char* pstr, uint16_t* ptr, uint16_t minValue, uint16_t maxValue);
static void menu_action_setting_edit_mres(const char* pstr, uint8_t* ptr, uint8_t minValue, uint8_t maxValue);
static void menu_action_setting_edit_byte3(const char* pstr, uint8_t* ptr, uint8_t minValue, uint8_t maxValue);
static void menu_action_setting_edit_int3(const char* pstr, int* ptr, int minValue, int maxValue);
@ -1525,7 +1525,7 @@ static void lcd_menu_extruder_info()
lcd.print(itostr3(pat9125_b));
// Display LASER shutter time from Filament sensor
/* Shutter register is an index of LASER shutter time. It is automatically controlled by the chips internal
/* Shutter register is an index of LASER shutter time. It is automatically controlled by the chip<EFBFBD>s internal
auto-exposure algorithm. When the chip is tracking on a good reflection surface, the Shutter is small.
When the chip is tracking on a poor reflection surface, the Shutter is large. Value ranges from 0 to
46. */
@ -4108,10 +4108,10 @@ static void lcd_ustep_linearity_menu_save()
static void lcd_ustep_linearity_menu_back()
{
bool changed = false;
if (tmc2130_wave_fac[X_AXIS] < TMC2130_WAVE_FAC200_MIN) tmc2130_wave_fac[X_AXIS] = 0;
if (tmc2130_wave_fac[Y_AXIS] < TMC2130_WAVE_FAC200_MIN) tmc2130_wave_fac[Y_AXIS] = 0;
if (tmc2130_wave_fac[Z_AXIS] < TMC2130_WAVE_FAC200_MIN) tmc2130_wave_fac[Z_AXIS] = 0;
if (tmc2130_wave_fac[E_AXIS] < TMC2130_WAVE_FAC200_MIN) tmc2130_wave_fac[E_AXIS] = 0;
if (tmc2130_wave_fac[X_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[X_AXIS] = 0;
if (tmc2130_wave_fac[Y_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[Y_AXIS] = 0;
if (tmc2130_wave_fac[Z_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[Z_AXIS] = 0;
if (tmc2130_wave_fac[E_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[E_AXIS] = 0;
changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_X_FAC) != tmc2130_wave_fac[X_AXIS]);
changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_Y_FAC) != tmc2130_wave_fac[Y_AXIS]);
changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_Z_FAC) != tmc2130_wave_fac[Z_AXIS]);
@ -4145,10 +4145,10 @@ static void lcd_ustep_linearity_menu()
MENU_ITEM(back, PSTR("Experimental"), lcd_ustep_linearity_menu_back);
MENU_ITEM(function, PSTR("Reset correction"), lcd_ustep_linearity_menu_reset);
MENU_ITEM(function, PSTR("Recomended config"), lcd_ustep_linearity_menu_recomended);
MENU_ITEM_EDIT(wfac, PSTR("X-correction"), &tmc2130_wave_fac[X_AXIS], TMC2130_WAVE_FAC200_MIN-TMC2130_WAVE_FAC200_STP, TMC2130_WAVE_FAC200_MAX);
MENU_ITEM_EDIT(wfac, PSTR("Y-correction"), &tmc2130_wave_fac[Y_AXIS], TMC2130_WAVE_FAC200_MIN-TMC2130_WAVE_FAC200_STP, TMC2130_WAVE_FAC200_MAX);
MENU_ITEM_EDIT(wfac, PSTR("Z-correction"), &tmc2130_wave_fac[Z_AXIS], TMC2130_WAVE_FAC200_MIN-TMC2130_WAVE_FAC200_STP, TMC2130_WAVE_FAC200_MAX);
MENU_ITEM_EDIT(wfac, PSTR("E-correction"), &tmc2130_wave_fac[E_AXIS], TMC2130_WAVE_FAC200_MIN-TMC2130_WAVE_FAC200_STP, TMC2130_WAVE_FAC200_MAX);
MENU_ITEM_EDIT(wfac, PSTR("X-correction"), &tmc2130_wave_fac[X_AXIS], TMC2130_WAVE_FAC1000_MIN-TMC2130_WAVE_FAC1000_STP, TMC2130_WAVE_FAC1000_MAX);
MENU_ITEM_EDIT(wfac, PSTR("Y-correction"), &tmc2130_wave_fac[Y_AXIS], TMC2130_WAVE_FAC1000_MIN-TMC2130_WAVE_FAC1000_STP, TMC2130_WAVE_FAC1000_MAX);
MENU_ITEM_EDIT(wfac, PSTR("Z-correction"), &tmc2130_wave_fac[Z_AXIS], TMC2130_WAVE_FAC1000_MIN-TMC2130_WAVE_FAC1000_STP, TMC2130_WAVE_FAC1000_MAX);
MENU_ITEM_EDIT(wfac, PSTR("E-correction"), &tmc2130_wave_fac[E_AXIS], TMC2130_WAVE_FAC1000_MIN-TMC2130_WAVE_FAC1000_STP, TMC2130_WAVE_FAC1000_MAX);
END_MENU();
}
@ -5844,9 +5844,9 @@ char *mres_to_str3(const uint8_t &x)
extern char conv[8];
// Convert tmc2130 wfac to string
char *wfac_to_str5(const uint8_t &x)
char *wfac_to_str5(const uint16_t &x)
{
if (x>=TMC2130_WAVE_FAC200_MIN) return ftostr43(((float)(x & 0xff))/200);
if (x>=TMC2130_WAVE_FAC1000_MIN) return ftostr43(((float)(x & 0xffff))/1000);
conv[0] = ' ';
conv[1] = ' ';
conv[2] = 'O';
@ -5856,7 +5856,7 @@ char *wfac_to_str5(const uint8_t &x)
return conv;
}
menu_edit_type(uint8_t, wfac, wfac_to_str5, 1)
menu_edit_type(uint16_t, wfac, wfac_to_str5, 1)
menu_edit_type(uint8_t, mres, mres_to_str3, 1)
menu_edit_type(uint8_t, byte3, itostr3, 1)
menu_edit_type(int, int3, itostr3, 1)

View File

@ -1146,7 +1146,7 @@ static void lcd_implementation_drawmenu_setting_edit_generic_P(uint8_t row, cons
}
extern char *wfac_to_str5(const uint8_t &x);
extern char *wfac_to_str5(const uint16_t &x);
extern char *mres_to_str3(const uint8_t &x);
#define lcd_implementation_drawmenu_setting_edit_wfac_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', wfac_to_str5(*(data)))