Linearity correction - TMC codes for calibration object, variable stored as uint8, range from 1.03 to 1.20

This commit is contained in:
Robert Pelnar 2018-04-03 12:30:35 +02:00
parent baade7db61
commit 92997204a1
9 changed files with 69 additions and 44 deletions

View file

@ -159,10 +159,10 @@
// TMC2130 uStep linearity correction
// Linearity correction factor (XYZE)
#define EEPROM_TMC2130_WAVE_X_FAC (EEPROM_TMC2130_HOME_ENABLED - 2) // uint16
#define EEPROM_TMC2130_WAVE_Y_FAC (EEPROM_TMC2130_WAVE_X_FAC - 2) // uint16
#define EEPROM_TMC2130_WAVE_Z_FAC (EEPROM_TMC2130_WAVE_Y_FAC - 2) // uint16
#define EEPROM_TMC2130_WAVE_E_FAC (EEPROM_TMC2130_WAVE_Z_FAC - 2) // uint16
#define EEPROM_TMC2130_WAVE_X_FAC (EEPROM_TMC2130_HOME_ENABLED - 1) // uint8
#define EEPROM_TMC2130_WAVE_Y_FAC (EEPROM_TMC2130_WAVE_X_FAC - 1) // uint8
#define EEPROM_TMC2130_WAVE_Z_FAC (EEPROM_TMC2130_WAVE_Y_FAC - 1) // uint8
#define EEPROM_TMC2130_WAVE_E_FAC (EEPROM_TMC2130_WAVE_Z_FAC - 1) // uint8
////////////////////////////////////////

View file

@ -465,6 +465,7 @@ void dcode_10()
void dcode_12()
{//Time
LOG("D12 - Time\n");
}
@ -590,7 +591,7 @@ void dcode_2130()
}
else if (strncmp(strchr_pointer + 7, "wave", 4) == 0)
{
uint16_t fac1000 = atoi(strchr_pointer + 11) & 0xffff;
uint8_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);

View file

@ -57,6 +57,7 @@
#include "Timer.h"
#include <avr/wdt.h>
#include <avr/pgmspace.h>
#include "Dcodes.h"
@ -1077,15 +1078,15 @@ void setup()
#ifdef TMC2130_LINEARITY_CORRECTION
#ifdef EXPERIMENTAL_FEATURES
tmc2130_wave_fac[X_AXIS] = eeprom_read_word((uint16_t*)EEPROM_TMC2130_WAVE_X_FAC);
tmc2130_wave_fac[Y_AXIS] = eeprom_read_word((uint16_t*)EEPROM_TMC2130_WAVE_Y_FAC);
tmc2130_wave_fac[Z_AXIS] = eeprom_read_word((uint16_t*)EEPROM_TMC2130_WAVE_Z_FAC);
tmc2130_wave_fac[X_AXIS] = eeprom_read_word((uint8_t*)EEPROM_TMC2130_WAVE_X_FAC);
tmc2130_wave_fac[Y_AXIS] = eeprom_read_word((uint8_t*)EEPROM_TMC2130_WAVE_Y_FAC);
tmc2130_wave_fac[Z_AXIS] = eeprom_read_word((uint8_t*)EEPROM_TMC2130_WAVE_Z_FAC);
#endif //EXPERIMENTAL_FEATURES
tmc2130_wave_fac[E_AXIS] = eeprom_read_word((uint16_t*)EEPROM_TMC2130_WAVE_E_FAC);
if (tmc2130_wave_fac[X_AXIS] == 0xffff) tmc2130_wave_fac[X_AXIS] = 0;
if (tmc2130_wave_fac[Y_AXIS] == 0xffff) tmc2130_wave_fac[Y_AXIS] = 0;
if (tmc2130_wave_fac[Z_AXIS] == 0xffff) tmc2130_wave_fac[Z_AXIS] = 0;
if (tmc2130_wave_fac[E_AXIS] == 0xffff) tmc2130_wave_fac[E_AXIS] = 0;
if (tmc2130_wave_fac[X_AXIS] == 0xff) tmc2130_wave_fac[X_AXIS] = 0;
if (tmc2130_wave_fac[Y_AXIS] == 0xff) tmc2130_wave_fac[Y_AXIS] = 0;
if (tmc2130_wave_fac[Z_AXIS] == 0xff) tmc2130_wave_fac[Z_AXIS] = 0;
if (tmc2130_wave_fac[E_AXIS] == 0xff) tmc2130_wave_fac[E_AXIS] = 0;
#endif //TMC2130_LINEARITY_CORRECTION
#ifdef TMC2130_VARIABLE_RESOLUTION
@ -2543,19 +2544,36 @@ void process_commands()
lcd_setstatus(strchr_pointer + 5);
}
#ifdef TMC2130
else if(code_seen("CRASH_DETECTED"))
{
uint8_t mask = 0;
if (code_seen("X")) mask |= X_AXIS_MASK;
if (code_seen("Y")) mask |= Y_AXIS_MASK;
crashdet_detected(mask);
}
else if(code_seen("CRASH_RECOVER"))
crashdet_recover();
else if(code_seen("CRASH_CANCEL"))
crashdet_cancel();
#endif //TMC2130
//#ifdef TMC2130
else if (strncmp_P(CMDBUFFER_CURRENT_STRING, PSTR("CRASH_"), 6) == 0)
{
if(code_seen("CRASH_DETECTED"))
{
uint8_t mask = 0;
if (code_seen("X")) mask |= X_AXIS_MASK;
if (code_seen("Y")) mask |= Y_AXIS_MASK;
crashdet_detected(mask);
}
else if(code_seen("CRASH_RECOVER"))
crashdet_recover();
else if(code_seen("CRASH_CANCEL"))
crashdet_cancel();
}
else if (strncmp_P(CMDBUFFER_CURRENT_STRING, PSTR("TMC_"), 4) == 0)
{
if (strncmp_P(CMDBUFFER_CURRENT_STRING + 4, PSTR("SET_WAVE_E"), 10) == 0)
{
uint8_t fac = (uint8_t)strtol(CMDBUFFER_CURRENT_STRING + 14, NULL, 10);
tmc2130_set_wave(E_AXIS, 247, fac);
}
else if (strncmp_P(CMDBUFFER_CURRENT_STRING + 4, PSTR("SET_STEP_E"), 10) == 0)
{
uint8_t step = (uint8_t)strtol(CMDBUFFER_CURRENT_STRING + 14, NULL, 10);
uint16_t res = tmc2130_get_res(E_AXIS);
tmc2130_goto_step(E_AXIS, step & (4*res - 1), 2, 1000, res);
}
}
//#endif //TMC2130
else if(code_seen("PRUSA")){
if (code_seen("Ping")) { //PRUSA Ping

View file

@ -992,7 +992,11 @@ static void updateTemperaturesFromRawValues()
current_temperature_ambient = analog2tempAmbient(current_temperature_raw_ambient); //thermistor for ambient is NTCG104LH104JT1 (2000)
#endif
#ifdef DEBUG_HEATER_BED_SIM
current_temperature_bed = target_temperature_bed;
#else //DEBUG_HEATER_BED_SIM
current_temperature_bed = analog2tempBed(current_temperature_bed_raw);
#endif //DEBUG_HEATER_BED_SIM
#ifdef TEMP_SENSOR_1_AS_REDUNDANT
redundant_temperature = analog2temp(redundant_temperature_raw, 1);

View file

@ -63,7 +63,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};
uint16_t tmc2130_wave_fac[4] = {0, 0, 0, 0};
uint8_t tmc2130_wave_fac[4] = {0, 0, 0, 0};
bool tmc2130_sg_stop_on_crash = true;
uint8_t tmc2130_sg_diag_mask = 0x00;
@ -193,9 +193,9 @@ void tmc2130_init()
tmc2130_sg_cnt[3] = 0;
#ifdef TMC2130_LINEARITY_CORRECTION
tmc2130_set_wave(X_AXIS, 247, tmc2130_wave_fac[X_AXIS]);
tmc2130_set_wave(Y_AXIS, 247, tmc2130_wave_fac[Y_AXIS]);
tmc2130_set_wave(Z_AXIS, 247, tmc2130_wave_fac[Z_AXIS]);
// tmc2130_set_wave(X_AXIS, 247, tmc2130_wave_fac[X_AXIS]);
// tmc2130_set_wave(Y_AXIS, 247, tmc2130_wave_fac[Y_AXIS]);
// tmc2130_set_wave(Z_AXIS, 247, tmc2130_wave_fac[Z_AXIS]);
tmc2130_set_wave(E_AXIS, 247, tmc2130_wave_fac[E_AXIS]);
#endif //TMC2130_LINEARITY_CORRECTION
@ -892,14 +892,16 @@ 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, uint16_t fac1000)
void tmc2130_set_wave(uint8_t axis, uint8_t amp, uint8_t fac1000)
{
// TMC2130 wave compression algorithm
// optimized for minimal memory requirements
printf_P(PSTR("tmc2130_set_wave %d %d\n"), axis, fac1000);
printf_P(PSTR("tmc2130_set_wave %hhd %hhd\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
float fac = 0;
if (fac1000) fac = (float)((uint16_t)fac1000 + 1000) / 1000; //correction factor
printf_P(PSTR(" factor: %s\n"), ftostr43(fac));
uint8_t vA = 0; //value of currentA
uint8_t va = 0; //previous vA
uint8_t d0 = 0; //delta0

View file

@ -23,8 +23,8 @@ extern uint32_t tmc2130_sg_meassure_val;
#define TMC2130_MODE_NORMAL 0
#define TMC2130_MODE_SILENT 1
#define TMC2130_WAVE_FAC1000_MIN 900
#define TMC2130_WAVE_FAC1000_MAX 1250
#define TMC2130_WAVE_FAC1000_MIN 30
#define TMC2130_WAVE_FAC1000_MAX 200
#define TMC2130_WAVE_FAC1000_STP 1
extern uint8_t tmc2130_home_enabled;
@ -32,7 +32,7 @@ extern uint8_t tmc2130_home_origin[2];
extern uint8_t tmc2130_home_bsteps[2];
extern uint8_t tmc2130_home_fsteps[2];
extern uint16_t tmc2130_wave_fac[4];
extern uint8_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, uint16_t fac1000);
extern void tmc2130_set_wave(uint8_t axis, uint8_t amp, uint8_t fac1000);
extern bool tmc2130_home_calibrate(uint8_t axis);

View file

@ -242,7 +242,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, uint16_t* ptr, uint16_t minValue, uint16_t maxValue);
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_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);
@ -6114,20 +6114,20 @@ char *mres_to_str3(const uint8_t &x)
}
menu_edit_type(uint8_t, mres, mres_to_str3, 1)
// Convert tmc2130 wfac to string
char *wfac_to_str5(const uint16_t &x)
char *wfac_to_str5(const uint8_t &x)
{
if (x>=TMC2130_WAVE_FAC1000_MIN)
if (x >= TMC2130_WAVE_FAC1000_MIN)
{
conv[0] = '[';
ftostr43(((float)(x & 0xffff)/1000),1);
ftostr43(((float)((uint16_t)x + 1000) / 1000), 1);
}
else strcpy_P(conv,MSG_EXTRUDER_CORRECTION_OFF);
else strcpy_P(conv, MSG_EXTRUDER_CORRECTION_OFF);
conv[6] = ']';
conv[7] = ' ';
conv[8] = 0;
return conv;
}
menu_edit_type(uint16_t, wfac, wfac_to_str5, 1)
menu_edit_type(uint8_t, wfac, wfac_to_str5, 1)
#endif //TMC2130
menu_edit_type(uint8_t, byte3, itostr3, 1)

View file

@ -1145,7 +1145,7 @@ static void lcd_implementation_drawmenu_setting_edit_generic_P(uint8_t row, cons
}
extern char *wfac_to_str5(const uint16_t &x);
extern char *wfac_to_str5(const uint8_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)))

View file

@ -169,7 +169,7 @@ const bool Z_MIN_ENDSTOP_INVERTING = false; // set to true to invert the logic o
#endif /* DEBUG_BUILD */
//#define EXPERIMENTAL_FEATURES
//#define TMC2130_LINEARITY_CORRECTION
#define TMC2130_LINEARITY_CORRECTION
//#define TMC2130_VARIABLE_RESOLUTION