Browse Source

Save/Load distinct TMC SG thresholds (#17741)

Neil van Geffen 4 years ago
parent
commit
7c3909bc3f
No account linked to committer's email address

+ 5
- 1
Marlin/Configuration_adv.h View File

@@ -2393,7 +2393,11 @@
2393 2393
     #define X_STALL_SENSITIVITY  8
2394 2394
     #define X2_STALL_SENSITIVITY X_STALL_SENSITIVITY
2395 2395
     #define Y_STALL_SENSITIVITY  8
2396
-    //#define Z_STALL_SENSITIVITY  8
2396
+    #define Y2_STALL_SENSITIVITY Y_STALL_SENSITIVITY
2397
+    #define Z_STALL_SENSITIVITY  8
2398
+    #define Z2_STALL_SENSITIVITY Z_STALL_SENSITIVITY
2399
+    #define Z3_STALL_SENSITIVITY Z_STALL_SENSITIVITY
2400
+    #define Z4_STALL_SENSITIVITY Z_STALL_SENSITIVITY
2397 2401
     //#define SPI_ENDSTOPS              // TMC2130 only
2398 2402
     //#define IMPROVE_HOMING_RELIABILITY
2399 2403
   #endif

+ 17
- 39
Marlin/src/module/configuration_store.cpp View File

@@ -37,7 +37,7 @@
37 37
  */
38 38
 
39 39
 // Change EEPROM version if the structure changes
40
-#define EEPROM_VERSION "V77"
40
+#define EEPROM_VERSION "V78"
41 41
 #define EEPROM_OFFSET 100
42 42
 
43 43
 // Check the integrity of data offsets.
@@ -135,7 +135,7 @@
135 135
 
136 136
 typedef struct { uint16_t X, Y, Z, X2, Y2, Z2, Z3, Z4, E0, E1, E2, E3, E4, E5, E6, E7; } tmc_stepper_current_t;
137 137
 typedef struct { uint32_t X, Y, Z, X2, Y2, Z2, Z3, Z4, E0, E1, E2, E3, E4, E5, E6, E7; } tmc_hybrid_threshold_t;
138
-typedef struct {  int16_t X, Y, Z, X2;                                                 } tmc_sgt_t;
138
+typedef struct {  int16_t X, Y, Z, X2, Y2, Z2, Z3, Z4;                                 } tmc_sgt_t;
139 139
 typedef struct {     bool X, Y, Z, X2, Y2, Z2, Z3, Z4, E0, E1, E2, E3, E4, E5, E6, E7; } tmc_stealth_enabled_t;
140 140
 
141 141
 // Limit an index to an array size
@@ -328,7 +328,7 @@ typedef struct SettingsDataStruct {
328 328
   //
329 329
   tmc_stepper_current_t tmc_stepper_current;            // M906 X Y Z X2 Y2 Z2 Z3 Z4 E0 E1 E2 E3 E4 E5
330 330
   tmc_hybrid_threshold_t tmc_hybrid_threshold;          // M913 X Y Z X2 Y2 Z2 Z3 Z4 E0 E1 E2 E3 E4 E5
331
-  tmc_sgt_t tmc_sgt;                                    // M914 X Y Z X2
331
+  tmc_sgt_t tmc_sgt;                                    // M914 X Y Z X2 Y2 Z2 Z3 Z4
332 332
   tmc_stealth_enabled_t tmc_stealth_enabled;            // M569 X Y Z X2 Y2 Z2 Z3 Z4 E0 E1 E2 E3 E4 E5
333 333
 
334 334
   //
@@ -1112,10 +1112,14 @@ void MarlinSettings::postprocess() {
1112 1112
     {
1113 1113
       tmc_sgt_t tmc_sgt{0};
1114 1114
       #if USE_SENSORLESS
1115
-        TERN_(X_SENSORLESS, tmc_sgt.X = stepperX.homing_threshold());
1115
+        TERN_(X_SENSORLESS,  tmc_sgt.X  = stepperX.homing_threshold());
1116 1116
         TERN_(X2_SENSORLESS, tmc_sgt.X2 = stepperX2.homing_threshold());
1117
-        TERN_(Y_SENSORLESS, tmc_sgt.Y = stepperY.homing_threshold());
1118
-        TERN_(Z_SENSORLESS, tmc_sgt.Z = stepperZ.homing_threshold());
1117
+        TERN_(Y_SENSORLESS,  tmc_sgt.Y  = stepperY.homing_threshold());
1118
+        TERN_(Y2_SENSORLESS, tmc_sgt.Y2 = stepperY2.homing_threshold());
1119
+        TERN_(Z_SENSORLESS,  tmc_sgt.Z  = stepperZ.homing_threshold());
1120
+        TERN_(Z2_SENSORLESS, tmc_sgt.Z2 = stepperZ2.homing_threshold());
1121
+        TERN_(Z3_SENSORLESS, tmc_sgt.Z3 = stepperZ3.homing_threshold());
1122
+        TERN_(Z4_SENSORLESS, tmc_sgt.Z4 = stepperZ4.homing_threshold());
1119 1123
       #endif
1120 1124
       EEPROM_WRITE(tmc_sgt);
1121 1125
     }
@@ -1929,9 +1933,6 @@ void MarlinSettings::postprocess() {
1929 1933
 
1930 1934
       //
1931 1935
       // TMC StallGuard threshold.
1932
-      // X and X2 use the same value
1933
-      // Y and Y2 use the same value
1934
-      // Z, Z2, Z3 and Z4 use the same value
1935 1936
       //
1936 1937
       {
1937 1938
         tmc_sgt_t tmc_sgt;
@@ -1939,37 +1940,14 @@ void MarlinSettings::postprocess() {
1939 1940
         EEPROM_READ(tmc_sgt);
1940 1941
         #if USE_SENSORLESS
1941 1942
           if (!validating) {
1942
-            #ifdef X_STALL_SENSITIVITY
1943
-              #if AXIS_HAS_STALLGUARD(X)
1944
-                stepperX.homing_threshold(tmc_sgt.X);
1945
-              #endif
1946
-              #if AXIS_HAS_STALLGUARD(X2) && !X2_SENSORLESS
1947
-                stepperX2.homing_threshold(tmc_sgt.X);
1948
-              #endif
1949
-            #endif
1943
+            TERN_(X_SENSORLESS,  stepperX.homing_threshold(tmc_sgt.X));
1950 1944
             TERN_(X2_SENSORLESS, stepperX2.homing_threshold(tmc_sgt.X2));
1951
-            #ifdef Y_STALL_SENSITIVITY
1952
-              #if AXIS_HAS_STALLGUARD(Y)
1953
-                stepperY.homing_threshold(tmc_sgt.Y);
1954
-              #endif
1955
-              #if AXIS_HAS_STALLGUARD(Y2)
1956
-                stepperY2.homing_threshold(tmc_sgt.Y);
1957
-              #endif
1958
-            #endif
1959
-            #ifdef Z_STALL_SENSITIVITY
1960
-              #if AXIS_HAS_STALLGUARD(Z)
1961
-                stepperZ.homing_threshold(tmc_sgt.Z);
1962
-              #endif
1963
-              #if AXIS_HAS_STALLGUARD(Z2)
1964
-                stepperZ2.homing_threshold(tmc_sgt.Z);
1965
-              #endif
1966
-              #if AXIS_HAS_STALLGUARD(Z3)
1967
-                stepperZ3.homing_threshold(tmc_sgt.Z);
1968
-              #endif
1969
-              #if AXIS_HAS_STALLGUARD(Z4)
1970
-                stepperZ4.homing_threshold(tmc_sgt.Z);
1971
-              #endif
1972
-            #endif
1945
+            TERN_(Y_SENSORLESS,  stepperY.homing_threshold(tmc_sgt.Y));
1946
+            TERN_(Y2_SENSORLESS, stepperY2.homing_threshold(tmc_sgt.Y2));
1947
+            TERN_(Z_SENSORLESS,  stepperZ.homing_threshold(tmc_sgt.Z));
1948
+            TERN_(Z2_SENSORLESS, stepperZ2.homing_threshold(tmc_sgt.Z2));
1949
+            TERN_(Z3_SENSORLESS, stepperZ3.homing_threshold(tmc_sgt.Z3));
1950
+            TERN_(Z4_SENSORLESS, stepperZ4.homing_threshold(tmc_sgt.Z4));
1973 1951
           }
1974 1952
         #endif
1975 1953
       }

+ 8
- 33
Marlin/src/module/stepper/trinamic.cpp View File

@@ -770,39 +770,14 @@ void reset_trinamic_drivers() {
770 770
   #endif
771 771
 
772 772
   #if USE_SENSORLESS
773
-    #if X_SENSORLESS
774
-      #if AXIS_HAS_STALLGUARD(X)
775
-        stepperX.homing_threshold(X_STALL_SENSITIVITY);
776
-      #endif
777
-      #if AXIS_HAS_STALLGUARD(X2) && !X2_SENSORLESS
778
-        stepperX2.homing_threshold(X_STALL_SENSITIVITY);
779
-      #endif
780
-    #endif
781
-    #if X2_SENSORLESS
782
-      stepperX2.homing_threshold(X2_STALL_SENSITIVITY);
783
-    #endif
784
-    #if Y_SENSORLESS
785
-      #if AXIS_HAS_STALLGUARD(Y)
786
-        stepperY.homing_threshold(Y_STALL_SENSITIVITY);
787
-      #endif
788
-      #if AXIS_HAS_STALLGUARD(Y2)
789
-        stepperY2.homing_threshold(Y_STALL_SENSITIVITY);
790
-      #endif
791
-    #endif
792
-    #if Z_SENSORLESS
793
-      #if AXIS_HAS_STALLGUARD(Z)
794
-        stepperZ.homing_threshold(Z_STALL_SENSITIVITY);
795
-      #endif
796
-      #if AXIS_HAS_STALLGUARD(Z2)
797
-        stepperZ2.homing_threshold(Z_STALL_SENSITIVITY);
798
-      #endif
799
-      #if AXIS_HAS_STALLGUARD(Z3)
800
-        stepperZ3.homing_threshold(Z_STALL_SENSITIVITY);
801
-      #endif
802
-      #if AXIS_HAS_STALLGUARD(Z4)
803
-        stepperZ4.homing_threshold(Z_STALL_SENSITIVITY);
804
-      #endif
805
-    #endif
773
+    TERN_(X_SENSORLESS,  stepperX.homing_threshold(X_STALL_SENSITIVITY));
774
+    TERN_(X2_SENSORLESS, stepperX2.homing_threshold(X2_STALL_SENSITIVITY));
775
+    TERN_(Y_SENSORLESS,  stepperY.homing_threshold(Y_STALL_SENSITIVITY));
776
+    TERN_(Y2_SENSORLESS, stepperY2.homing_threshold(Y2_STALL_SENSITIVITY));
777
+    TERN_(Z_SENSORLESS,  stepperZ.homing_threshold(Z_STALL_SENSITIVITY));
778
+    TERN_(Z2_SENSORLESS, stepperZ2.homing_threshold(Z2_STALL_SENSITIVITY));
779
+    TERN_(Z3_SENSORLESS, stepperZ3.homing_threshold(Z3_STALL_SENSITIVITY));
780
+    TERN_(Z4_SENSORLESS, stepperZ4.homing_threshold(Z4_STALL_SENSITIVITY));
806 781
   #endif
807 782
 
808 783
   #ifdef TMC_ADV

Loading…
Cancel
Save