Browse Source

Fix TMC gcode commands

teemuatlut 7 years ago
parent
commit
9d923c6c03

+ 0
- 50
Marlin/src/feature/tmc_util.cpp View File

@@ -35,56 +35,6 @@
35 35
 bool report_tmc_status = false;
36 36
 char extended_axis_codes[11][3] = { "X", "X2", "Y", "Y2", "Z", "Z2", "E0", "E1", "E2", "E3", "E4" };
37 37
 
38
-template<typename TMC>
39
-void tmc_get_current(TMC &st, const char name[]) {
40
-  SERIAL_ECHO(name);
41
-  SERIAL_ECHOPGM(" axis driver current: ");
42
-  SERIAL_ECHOLN(st.getCurrent());
43
-}
44
-template<typename TMC>
45
-void tmc_set_current(TMC &st, const char name[], const int mA) {
46
-  st.setCurrent(mA, R_SENSE, HOLD_MULTIPLIER);
47
-  tmc_get_current(st, name);
48
-}
49
-
50
-template<typename TMC>
51
-void tmc_report_otpw(TMC &st, const char name[]) {
52
-  SERIAL_ECHO(name);
53
-  SERIAL_ECHOPGM(" axis temperature prewarn triggered: ");
54
-  serialprintPGM(st.getOTPW() ? PSTR("true") : PSTR("false"));
55
-  SERIAL_EOL();
56
-}
57
-template<typename TMC>
58
-void tmc_clear_otpw(TMC &st, const char name[]) {
59
-  st.clear_otpw();
60
-  SERIAL_ECHO(name);
61
-  SERIAL_ECHOLNPGM(" prewarn flag cleared");
62
-}
63
-
64
-template<typename TMC>
65
-void tmc_get_pwmthrs(TMC &st, const char name[], const uint16_t spmm) {
66
-  SERIAL_ECHO(name);
67
-  SERIAL_ECHOPGM(" stealthChop max speed set to ");
68
-  SERIAL_ECHOLN(12650000UL * st.microsteps() / (256 * st.TPWMTHRS() * spmm));
69
-}
70
-template<typename TMC>
71
-void tmc_set_pwmthrs(TMC &st, const char name[], const int32_t thrs, const uint32_t spmm) {
72
-  st.TPWMTHRS(12650000UL * st.microsteps() / (256 * thrs * spmm));
73
-  tmc_get_pwmthrs(st, name, spmm);
74
-}
75
-
76
-template<typename TMC>
77
-void tmc_get_sgt(TMC &st, const char name[]) {
78
-  SERIAL_ECHO(name);
79
-  SERIAL_ECHOPGM(" driver homing sensitivity set to ");
80
-  MYSERIAL.println(st.sgt(), DEC);
81
-}
82
-template<typename TMC>
83
-void tmc_set_sgt(TMC &st, const char name[], const int8_t sgt_val) {
84
-  st.sgt(sgt_val);
85
-  tmc_get_sgt(st, name);
86
-}
87
-
88 38
 /*
89 39
  * Check for over temperature or short to ground error flags.
90 40
  * Report and log warning of overtemperature condition.

+ 39
- 8
Marlin/src/feature/tmc_util.h View File

@@ -29,27 +29,58 @@
29 29
 
30 30
 extern bool report_tmc_status;
31 31
 extern char extended_axis_codes[11][3];
32
+
32 33
 enum TMC_AxisEnum {
33 34
   TMC_X, TMC_X2, TMC_Y, TMC_Y2, TMC_Z, TMC_Z2,
34 35
   TMC_E0, TMC_E1, TMC_E2, TMC_E3, TMC_E4
35 36
 };
36 37
 
37 38
 template<typename TMC>
38
-void tmc_get_current(TMC &st, const char name[]);
39
+void tmc_get_current(TMC &st, const char name[]) {
40
+  SERIAL_ECHO(name);
41
+  SERIAL_ECHOPGM(" axis driver current: ");
42
+  SERIAL_ECHOLN(st.getCurrent());
43
+}
39 44
 template<typename TMC>
40
-void tmc_set_current(TMC &st, const char name[], const int mA);
45
+void tmc_set_current(TMC &st, const char name[], const int mA) {
46
+  st.setCurrent(mA, R_SENSE, HOLD_MULTIPLIER);
47
+  tmc_get_current(st, name);
48
+}
41 49
 template<typename TMC>
42
-void tmc_report_otpw(TMC &st, const char name[]);
50
+void tmc_report_otpw(TMC &st, const char name[]) {
51
+  SERIAL_ECHO(name);
52
+  SERIAL_ECHOPGM(" axis temperature prewarn triggered: ");
53
+  serialprintPGM(st.getOTPW() ? PSTR("true") : PSTR("false"));
54
+  SERIAL_EOL();
55
+}
43 56
 template<typename TMC>
44
-void tmc_clear_otpw(TMC &st, const char name[]);
57
+void tmc_clear_otpw(TMC &st, const char name[]) {
58
+  st.clear_otpw();
59
+  SERIAL_ECHO(name);
60
+  SERIAL_ECHOLNPGM(" prewarn flag cleared");
61
+}
45 62
 template<typename TMC>
46
-void tmc_get_pwmthrs(TMC &st, const char name[], const uint16_t spmm);
63
+void tmc_get_pwmthrs(TMC &st, const char name[], const uint16_t spmm) {
64
+  SERIAL_ECHO(name);
65
+  SERIAL_ECHOPGM(" stealthChop max speed set to ");
66
+  SERIAL_ECHOLN(12650000UL * st.microsteps() / (256 * st.TPWMTHRS() * spmm));
67
+}
47 68
 template<typename TMC>
48
-void tmc_set_pwmthrs(TMC &st, const char name[], const int32_t thrs, const uint32_t spmm);
69
+void tmc_set_pwmthrs(TMC &st, const char name[], const int32_t thrs, const uint32_t spmm) {
70
+  st.TPWMTHRS(12650000UL * st.microsteps() / (256 * thrs * spmm));
71
+  tmc_get_pwmthrs(st, name, spmm);
72
+}
49 73
 template<typename TMC>
50
-void tmc_get_sgt(TMC &st, const char name[]);
74
+void tmc_get_sgt(TMC &st, const char name[]) {
75
+  SERIAL_ECHO(name);
76
+  SERIAL_ECHOPGM(" driver homing sensitivity set to ");
77
+  MYSERIAL.println(st.sgt(), DEC);
78
+}
51 79
 template<typename TMC>
52
-void tmc_set_sgt(TMC &st, const char name[], const int8_t sgt_val);
80
+void tmc_set_sgt(TMC &st, const char name[], const int8_t sgt_val) {
81
+  st.sgt(sgt_val);
82
+  tmc_get_sgt(st, name);
83
+}
53 84
 
54 85
 void _M122();
55 86
 void monitor_tmc_driver();

+ 1
- 1
Marlin/src/gcode/feature/trinamic/M122.cpp View File

@@ -334,6 +334,6 @@ void _M122() {
334 334
 }
335 335
 
336 336
 // We need to call M122 from monitor_tmc_driver() as well but GcodeSuite::M122 is private.
337
-inline void GcodeSuite::M122() { _M122(); }
337
+void GcodeSuite::M122() { _M122(); }
338 338
 
339 339
 #endif // TMC_DEBUG

+ 1
- 1
Marlin/src/gcode/feature/trinamic/M906.cpp View File

@@ -33,7 +33,7 @@
33 33
  * M906: Set motor current in milliamps using axis codes X, Y, Z, E
34 34
  * Report driver currents when no axis specified
35 35
  */
36
-inline void GcodeSuite::M906() {
36
+void GcodeSuite::M906() {
37 37
   uint16_t values[XYZE];
38 38
   LOOP_XYZE(i)
39 39
     values[i] = parser.intval(axis_codes[i]);

+ 22
- 13
Marlin/src/gcode/feature/trinamic/M911-M915.cpp View File

@@ -28,12 +28,13 @@
28 28
 #include "../../../feature/tmc_util.h"
29 29
 #include "../../../module/stepper_indirection.h"
30 30
 #include "../../../module/planner.h"
31
+#include "../../queue.h"
31 32
 
32 33
 /**
33 34
  * M911: Report TMC stepper driver overtemperature pre-warn flag
34 35
  * The flag is held by the library and persist until manually cleared by M912
35 36
  */
36
-inline void GcodeSuite::M911() {
37
+void GcodeSuite::M911() {
37 38
   #if ENABLED(X_IS_TMC2130) || (ENABLED(X_IS_TMC2208) && PIN_EXISTS(X_SERIAL_RX)) || ENABLED(IS_TRAMS)
38 39
     tmc_report_otpw(stepperX, extended_axis_codes[TMC_X]);
39 40
   #endif
@@ -51,7 +52,7 @@ inline void GcodeSuite::M911() {
51 52
 /**
52 53
  * M912: Clear TMC stepper driver overtemperature pre-warn flag held by the library
53 54
  */
54
-inline void GcodeSuite::M912() {
55
+void GcodeSuite::M912() {
55 56
   const bool clearX = parser.seen(axis_codes[X_AXIS]), clearY = parser.seen(axis_codes[Y_AXIS]), clearZ = parser.seen(axis_codes[Z_AXIS]), clearE = parser.seen(axis_codes[E_AXIS]),
56 57
            clearAll = (!clearX && !clearY && !clearZ && !clearE) || (clearX && clearY && clearZ && clearE);
57 58
   #if ENABLED(X_IS_TMC2130) || ENABLED(IS_TRAMS) || (ENABLED(X_IS_TMC2208) && PIN_EXISTS(X_SERIAL_RX))
@@ -78,7 +79,7 @@ inline void GcodeSuite::M912() {
78 79
  * M913: Set HYBRID_THRESHOLD speed.
79 80
  */
80 81
 #if ENABLED(HYBRID_THRESHOLD)
81
-  inline void GcodeSuite::M913() {
82
+  void GcodeSuite::M913() {
82 83
     uint16_t values[XYZE];
83 84
     LOOP_XYZE(i)
84 85
       values[i] = parser.intval(axis_codes[i]);
@@ -137,7 +138,7 @@ inline void GcodeSuite::M912() {
137 138
  * M914: Set SENSORLESS_HOMING sensitivity.
138 139
  */
139 140
 #if ENABLED(SENSORLESS_HOMING)
140
-  inline void GcodeSuite::M914() {
141
+  void GcodeSuite::M914() {
141 142
     #if ENABLED(X_IS_TMC2130) || ENABLED(IS_TRAMS)
142 143
       if (parser.seen(axis_codes[X_AXIS])) tmc_set_sgt(stepperX, extended_axis_codes[TMC_X], parser.value_int());
143 144
       else tmc_get_sgt(stepperX, extended_axis_codes[TMC_X]);
@@ -160,8 +161,8 @@ inline void GcodeSuite::M912() {
160 161
 /**
161 162
  * TMC Z axis calibration routine
162 163
  */
163
-#if ENABLED(TMC_Z_CALIBRATION) && (Z_IS_TRINAMIC || Z2_IS_TRINAMIC)
164
-  inline void GcodeSuite::M915() {
164
+#if ENABLED(TMC_Z_CALIBRATION)
165
+  void GcodeSuite::M915() {
165 166
     uint16_t _rms = parser.seenval('S') ? parser.value_int() : CALIBRATION_CURRENT;
166 167
     uint16_t _z = parser.seenval('Z') ? parser.value_int() : CALIBRATION_EXTRA_HEIGHT;
167 168
 
@@ -170,25 +171,33 @@ inline void GcodeSuite::M912() {
170 171
       return;
171 172
     }
172 173
 
173
-    uint16_t Z_current_1 = stepperZ.getCurrent();
174
-    uint16_t Z2_current_1 = stepperZ.getCurrent();
174
+    #if Z_IS_TRINAMIC
175
+      uint16_t Z_current_1 = stepperZ.getCurrent();
176
+      stepperZ.setCurrent(_rms, R_SENSE, HOLD_MULTIPLIER);
177
+    #endif
178
+    #if Z2_IS_TRINAMIC
179
+      uint16_t Z2_current_1 = stepperZ2.getCurrent();
180
+      stepperZ2.setCurrent(_rms, R_SENSE, HOLD_MULTIPLIER);
181
+    #endif
175 182
 
176
-    stepperZ.setCurrent(_rms, R_SENSE, HOLD_MULTIPLIER);
177
-    stepperZ2.setCurrent(_rms, R_SENSE, HOLD_MULTIPLIER);
178 183
     SERIAL_ECHOPAIR("\nCalibration current: Z", _rms);
179 184
 
180 185
     soft_endstops_enabled = false;
181 186
 
182 187
     do_blocking_move_to_z(Z_MAX_POS+_z);
183 188
 
184
-    stepperZ.setCurrent(Z_current_1, R_SENSE, HOLD_MULTIPLIER);
185
-    stepperZ2.setCurrent(Z2_current_1, R_SENSE, HOLD_MULTIPLIER);
189
+    #if Z_IS_TRINAMIC
190
+      stepperZ.setCurrent(Z_current_1, R_SENSE, HOLD_MULTIPLIER);
191
+    #endif
192
+    #if Z2_IS_TRINAMIC
193
+      stepperZ2.setCurrent(Z2_current_1, R_SENSE, HOLD_MULTIPLIER);
194
+    #endif
186 195
 
187 196
     do_blocking_move_to_z(Z_MAX_POS);
188 197
     soft_endstops_enabled = true;
189 198
 
190 199
     SERIAL_ECHOLNPGM("\nHoming Z because we lost steps");
191
-    home_z_safely();
200
+    enqueue_and_echo_commands_P(PSTR("G28 Z"));
192 201
   }
193 202
 #endif
194 203
 

+ 7
- 2
Marlin/src/gcode/gcode.cpp View File

@@ -659,8 +659,10 @@ void GcodeSuite::process_parsed_command() {
659 659
         #endif
660 660
       #endif
661 661
 
662
-      #if HAVE_TRINAMIC
663
-        case 122: M122(); break;
662
+      #if HAS_TRINAMIC
663
+        #if ENABLED(TMC_DEBUG)
664
+          case 122: M122(); break;
665
+        #endif
664 666
         case 906: M906(); break;    // M906: Set motor current in milliamps using axis codes X, Y, Z, E
665 667
         case 911: M911(); break;    // M911: Report TMC2130 prewarn triggered flags
666 668
         case 912: M912(); break;    // M912: Clear TMC2130 prewarn triggered flags
@@ -670,6 +672,9 @@ void GcodeSuite::process_parsed_command() {
670 672
         #if ENABLED(SENSORLESS_HOMING)
671 673
           case 914: M914(); break;  // M914: Set SENSORLESS_HOMING sensitivity.
672 674
         #endif
675
+        #if ENABLED(TMC_Z_CALIBRATION)
676
+          case 915: M915(); break;  // M915: TMC Z axis calibration.
677
+        #endif
673 678
       #endif
674 679
 
675 680
       #if HAS_MICROSTEPS

+ 6
- 0
Marlin/src/inc/SanityCheck.h View File

@@ -1491,6 +1491,12 @@ static_assert(1 >= 0
1491 1491
   #error "Enable STEALTHCHOP to use HYBRID_THRESHOLD."
1492 1492
 #endif
1493 1493
 
1494
+#include "../feature/tmc_macros.h"
1495
+
1496
+#if ENABLED(TMC_Z_CALIBRATION) && !Z_IS_TRINAMIC && !Z2_IS_TRINAMIC
1497
+  #error "TMC_Z_CALIBRATION requires at least one TMC driver on Z axis"
1498
+#endif
1499
+
1494 1500
 /**
1495 1501
  * Make sure HAVE_L6470DRIVER is warranted
1496 1502
  */

Loading…
Cancel
Save