From 0f21ccee3c776b66b5a753371df3905f1d92571d Mon Sep 17 00:00:00 2001 From: Harpalyke <33022534+Harpalyke@users.noreply.github.com> Date: Tue, 19 Mar 2019 20:28:31 +0000 Subject: [PATCH] Adding the microstepping resolution for all axis to the eprom config which is persisted during M500 for Mk3 and Mk3S --- Firmware/ConfigurationStore.cpp | 24 ++++++++++++++++++- Firmware/ConfigurationStore.h | 1 + Firmware/Marlin_main.cpp | 17 ++++--------- .../variants/1_75mm_MK3-EINSy10a-E3Dv6full.h | 2 +- .../variants/1_75mm_MK3S-EINSy10a-E3Dv6full.h | 2 +- 5 files changed, 31 insertions(+), 15 deletions(-) diff --git a/Firmware/ConfigurationStore.cpp b/Firmware/ConfigurationStore.cpp index 39a74430..f2df8fc6 100644 --- a/Firmware/ConfigurationStore.cpp +++ b/Firmware/ConfigurationStore.cpp @@ -11,6 +11,11 @@ #include "mesh_bed_leveling.h" #endif +#ifdef TMC2130 +#include "tmc2130.h" +#endif + + M500_conf cs; //! @brief Write data to EEPROM @@ -86,6 +91,7 @@ void Config_PrintSettings(uint8_t level) #ifdef TMC2130 printf_P(PSTR( "%SSteps per unit:\n%S M92 X%.2f Y%.2f Z%.2f E%.2f\n" + "%SUStep resolution: \n%S M350 X%d Y%d Z%d E%d\n" "%SMaximum feedrates - normal (mm/s):\n%S M203 X%.2f Y%.2f Z%.2f E%.2f\n" "%SMaximum feedrates - stealth (mm/s):\n%S M203 X%.2f Y%.2f Z%.2f E%.2f\n" "%SMaximum acceleration - normal (mm/s2):\n%S M201 X%lu Y%lu Z%lu E%lu\n" @@ -95,6 +101,7 @@ void Config_PrintSettings(uint8_t level) "%SHome offset (mm):\n%S M206 X%.2f Y%.2f Z%.2f\n" ), echomagic, echomagic, cs.axis_steps_per_unit[X_AXIS], cs.axis_steps_per_unit[Y_AXIS], cs.axis_steps_per_unit[Z_AXIS], cs.axis_steps_per_unit[E_AXIS], + echomagic, echomagic, cs.axis_ustep_resolution[X_AXIS], cs.axis_ustep_resolution[Y_AXIS], cs.axis_ustep_resolution[Z_AXIS], cs.axis_ustep_resolution[E_AXIS], echomagic, echomagic, cs.max_feedrate_normal[X_AXIS], cs.max_feedrate_normal[Y_AXIS], cs.max_feedrate_normal[Z_AXIS], cs.max_feedrate_normal[E_AXIS], echomagic, echomagic, cs.max_feedrate_silent[X_AXIS], cs.max_feedrate_silent[Y_AXIS], cs.max_feedrate_silent[Z_AXIS], cs.max_feedrate_silent[E_AXIS], echomagic, echomagic, cs.max_acceleration_units_per_sq_second_normal[X_AXIS], cs.max_acceleration_units_per_sq_second_normal[Y_AXIS], cs.max_acceleration_units_per_sq_second_normal[Z_AXIS], cs.max_acceleration_units_per_sq_second_normal[E_AXIS], @@ -177,7 +184,7 @@ static_assert (false, "zprobe_zoffset was not initialized in printers in field t "0.0, if this is not acceptable, increment EEPROM_VERSION to force use default_conf"); #endif -static_assert (sizeof(M500_conf) == 188, "sizeof(M500_conf) has changed, ensure that EEPROM_VERSION has been incremented, " +static_assert (sizeof(M500_conf) == 192, "sizeof(M500_conf) has changed, ensure that EEPROM_VERSION has been incremented, " "or if you added members in the end of struct, ensure that historically uninitialized values will be initialized." "If this is caused by change to more then 8bit processor, decide whether make this struct packed to save EEPROM," "leave as it is to keep fast code, or reorder struct members to pack more tightly."); @@ -220,6 +227,11 @@ static const M500_conf default_conf PROGMEM = }, DEFAULT_MAX_FEEDRATE_SILENT, DEFAULT_MAX_ACCELERATION_SILENT, +#ifdef TMC2130 + { TMC2130_USTEPS_XY, TMC2130_USTEPS_XY, TMC2130_USTEPS_Z, TMC2130_USTEPS_E }, +#else // TMC2130 + {16,16,16,16}, +#endif }; //! @brief Read M500 configuration @@ -269,6 +281,16 @@ bool Config_RetrieveSettings() if (cs.max_acceleration_units_per_sq_second_silent[j] > SILENT_MAX_ACCEL_XY) cs.max_acceleration_units_per_sq_second_silent[j] = SILENT_MAX_ACCEL_XY; } + + if(cs.axis_ustep_resolution[X_AXIS] == 0xff){ cs.axis_ustep_resolution[X_AXIS] = TMC2130_USTEPS_XY; } + if(cs.axis_ustep_resolution[Y_AXIS] == 0xff){ cs.axis_ustep_resolution[Y_AXIS] = TMC2130_USTEPS_XY; } + if(cs.axis_ustep_resolution[Z_AXIS] == 0xff){ cs.axis_ustep_resolution[Z_AXIS] = TMC2130_USTEPS_Z; } + if(cs.axis_ustep_resolution[E_AXIS] == 0xff){ cs.axis_ustep_resolution[E_AXIS] = TMC2130_USTEPS_E; } + + tmc2130_set_res(X_AXIS, cs.axis_ustep_resolution[X_AXIS]); + tmc2130_set_res(Y_AXIS, cs.axis_ustep_resolution[Y_AXIS]); + tmc2130_set_res(Z_AXIS, cs.axis_ustep_resolution[Z_AXIS]); + tmc2130_set_res(E_AXIS, cs.axis_ustep_resolution[E_AXIS]); #endif //TMC2130 reset_acceleration_rates(); diff --git a/Firmware/ConfigurationStore.h b/Firmware/ConfigurationStore.h index aa201369..b9dca368 100644 --- a/Firmware/ConfigurationStore.h +++ b/Firmware/ConfigurationStore.h @@ -37,6 +37,7 @@ typedef struct float filament_size[1]; //!< cross-sectional area of filament (in millimeters), typically around 1.75 or 2.85, 0 disables the volumetric calculations for the extruder. float max_feedrate_silent[4]; //!< max speeds for silent mode unsigned long max_acceleration_units_per_sq_second_silent[4]; + unsigned char axis_ustep_resolution[4]; } M500_conf; extern M500_conf cs; diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 7be151f9..deb60182 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -1250,18 +1250,10 @@ void setup() #endif //TMC2130_LINEARITY_CORRECTION #ifdef TMC2130_VARIABLE_RESOLUTION - tmc2130_mres[X_AXIS] = eeprom_read_byte((uint8_t*)EEPROM_TMC2130_X_MRES); - tmc2130_mres[Y_AXIS] = eeprom_read_byte((uint8_t*)EEPROM_TMC2130_Y_MRES); - tmc2130_mres[Z_AXIS] = eeprom_read_byte((uint8_t*)EEPROM_TMC2130_Z_MRES); - tmc2130_mres[E_AXIS] = eeprom_read_byte((uint8_t*)EEPROM_TMC2130_E_MRES); - if (tmc2130_mres[X_AXIS] == 0xff) tmc2130_mres[X_AXIS] = tmc2130_usteps2mres(TMC2130_USTEPS_XY); - if (tmc2130_mres[Y_AXIS] == 0xff) tmc2130_mres[Y_AXIS] = tmc2130_usteps2mres(TMC2130_USTEPS_XY); - if (tmc2130_mres[Z_AXIS] == 0xff) tmc2130_mres[Z_AXIS] = tmc2130_usteps2mres(TMC2130_USTEPS_Z); - if (tmc2130_mres[E_AXIS] == 0xff) tmc2130_mres[E_AXIS] = tmc2130_usteps2mres(TMC2130_USTEPS_E); - eeprom_update_byte((uint8_t*)EEPROM_TMC2130_X_MRES, tmc2130_mres[X_AXIS]); - eeprom_update_byte((uint8_t*)EEPROM_TMC2130_Y_MRES, tmc2130_mres[Y_AXIS]); - eeprom_update_byte((uint8_t*)EEPROM_TMC2130_Z_MRES, tmc2130_mres[Z_AXIS]); - eeprom_update_byte((uint8_t*)EEPROM_TMC2130_E_MRES, tmc2130_mres[E_AXIS]); + tmc2130_mres[X_AXIS] = tmc2130_usteps2mres(cs.axis_ustep_resolution[X_AXIS]); + tmc2130_mres[Y_AXIS] = tmc2130_usteps2mres(cs.axis_ustep_resolution[Y_AXIS]); + tmc2130_mres[Z_AXIS] = tmc2130_usteps2mres(cs.axis_ustep_resolution[Z_AXIS]); + tmc2130_mres[E_AXIS] = tmc2130_usteps2mres(cs.axis_ustep_resolution[E_AXIS]); #else //TMC2130_VARIABLE_RESOLUTION tmc2130_mres[X_AXIS] = tmc2130_usteps2mres(TMC2130_USTEPS_XY); tmc2130_mres[Y_AXIS] = tmc2130_usteps2mres(TMC2130_USTEPS_XY); @@ -6882,6 +6874,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) 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 fac = (res_new / res); diff --git a/Firmware/variants/1_75mm_MK3-EINSy10a-E3Dv6full.h b/Firmware/variants/1_75mm_MK3-EINSy10a-E3Dv6full.h index 4a1fe53c..7ddc76b3 100644 --- a/Firmware/variants/1_75mm_MK3-EINSy10a-E3Dv6full.h +++ b/Firmware/variants/1_75mm_MK3-EINSy10a-E3Dv6full.h @@ -190,7 +190,7 @@ #define LINEARITY_CORRECTION #define TMC2130_LINEARITY_CORRECTION #define TMC2130_LINEARITY_CORRECTION_XYZ -//#define TMC2130_VARIABLE_RESOLUTION +#define TMC2130_VARIABLE_RESOLUTION diff --git a/Firmware/variants/1_75mm_MK3S-EINSy10a-E3Dv6full.h b/Firmware/variants/1_75mm_MK3S-EINSy10a-E3Dv6full.h index 1c0c6d28..2cf180a1 100644 --- a/Firmware/variants/1_75mm_MK3S-EINSy10a-E3Dv6full.h +++ b/Firmware/variants/1_75mm_MK3S-EINSy10a-E3Dv6full.h @@ -190,7 +190,7 @@ #define LINEARITY_CORRECTION #define TMC2130_LINEARITY_CORRECTION #define TMC2130_LINEARITY_CORRECTION_XYZ -//#define TMC2130_VARIABLE_RESOLUTION +#define TMC2130_VARIABLE_RESOLUTION