My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

M919.cpp 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #include "../../../inc/MarlinConfig.h"
  23. #if HAS_TRINAMIC_CONFIG
  24. #if AXIS_COLLISION('I')
  25. #error "M919 parameter 'I' collision with axis name."
  26. #endif
  27. #include "../../gcode.h"
  28. #include "../../../feature/tmc_util.h"
  29. #include "../../../module/stepper/indirection.h"
  30. #define DEBUG_OUT ENABLED(MARLIN_DEV_MODE)
  31. #include "../../../core/debug_out.h"
  32. template<typename TMC>
  33. static void tmc_print_chopper_time(TMC &st) {
  34. st.printLabel();
  35. SERIAL_ECHOLNPGM(" chopper .toff: ", st.toff(),
  36. " .hend: ", st.hysteresis_end(),
  37. " .hstrt: ", st.hysteresis_start());
  38. }
  39. /**
  40. * M919: Set TMC stepper driver chopper times
  41. *
  42. * Parameters:
  43. * XYZ...E - Selected axes
  44. * I[index] - Axis sub-index (Omit for all XYZ steppers, 1 for X2, Y2, Z2; 2 for Z3; 3 for Z4)
  45. * T[index] - Extruder index (Zero-based. Omit for all extruders.)
  46. * O - time-off [ 1..15]
  47. * P - hysteresis_end [-3..12]
  48. * S - hysteresis_start [ 1...8]
  49. *
  50. * With no parameters report chopper times for all axes
  51. */
  52. void GcodeSuite::M919() {
  53. bool err = false;
  54. int8_t toff = int8_t(parser.intval('O', -127));
  55. if (toff != -127) {
  56. if (WITHIN(toff, 1, 15))
  57. DEBUG_ECHOLNPGM(".toff: ", toff);
  58. else {
  59. SERIAL_ECHOLNPGM("?O out of range (1..15)");
  60. err = true;
  61. }
  62. }
  63. int8_t hend = int8_t(parser.intval('P', -127));
  64. if (hend != -127) {
  65. if (WITHIN(hend, -3, 12))
  66. DEBUG_ECHOLNPGM(".hend: ", hend);
  67. else {
  68. SERIAL_ECHOLNPGM("?P out of range (-3..12)");
  69. err = true;
  70. }
  71. }
  72. int8_t hstrt = int8_t(parser.intval('S', -127));
  73. if (hstrt != -127) {
  74. if (WITHIN(hstrt, 1, 8))
  75. DEBUG_ECHOLNPGM(".hstrt: ", hstrt);
  76. else {
  77. SERIAL_ECHOLNPGM("?S out of range (1..8)");
  78. err = true;
  79. }
  80. }
  81. if (err) return;
  82. #if AXIS_IS_TMC(X2) || AXIS_IS_TMC(Y2) || AXIS_IS_TMC(Z2) || AXIS_IS_TMC(Z3) || AXIS_IS_TMC(Z4)
  83. const int8_t index = parser.byteval('I');
  84. #elif AXIS_IS_TMC(X) || AXIS_IS_TMC(Y) || AXIS_IS_TMC(Z)
  85. constexpr int8_t index = -1;
  86. #endif
  87. auto make_chopper_timing = [](chopper_timing_t bct, const int8_t toff, const int8_t hend, const int8_t hstrt) {
  88. chopper_timing_t uct = bct;
  89. if (toff != -127) uct.toff = toff;
  90. if (hend != -127) uct.hend = hend;
  91. if (hstrt != -127) uct.hstrt = hstrt;
  92. return uct;
  93. };
  94. #define TMC_SET_CHOPPER_TIME(Q) stepper##Q.set_chopper_times(make_chopper_timing(CHOPPER_TIMING_##Q, toff, hend, hstrt))
  95. #if AXIS_IS_TMC(E0) || AXIS_IS_TMC(E1) || AXIS_IS_TMC(E2) || AXIS_IS_TMC(E3) || AXIS_IS_TMC(E4) || AXIS_IS_TMC(E5) || AXIS_IS_TMC(E6) || AXIS_IS_TMC(E7)
  96. #define HAS_E_CHOPPER 1
  97. int8_t eindex = -1;
  98. #endif
  99. bool report = true;
  100. LOOP_LOGICAL_AXES(i) if (parser.seen_test(AXIS_CHAR(i))) {
  101. report = false;
  102. // Get the chopper timing for the specified axis and index
  103. switch (i) {
  104. default: // A specified axis isn't Trinamic
  105. SERIAL_ECHOLNPGM("?Axis ", AS_CHAR(AXIS_CHAR(i)), " has no TMC drivers.");
  106. break;
  107. #if AXIS_IS_TMC(X) || AXIS_IS_TMC(X2)
  108. case X_AXIS:
  109. #if AXIS_IS_TMC(X)
  110. if (index <= 0) TMC_SET_CHOPPER_TIME(X);
  111. #endif
  112. #if AXIS_IS_TMC(X2)
  113. if (index < 0 || index == 1) TMC_SET_CHOPPER_TIME(X2);
  114. #endif
  115. break;
  116. #endif
  117. #if AXIS_IS_TMC(Y) || AXIS_IS_TMC(Y2)
  118. case Y_AXIS:
  119. #if AXIS_IS_TMC(Y)
  120. if (index <= 0) TMC_SET_CHOPPER_TIME(Y);
  121. #endif
  122. #if AXIS_IS_TMC(Y2)
  123. if (index < 0 || index == 1) TMC_SET_CHOPPER_TIME(Y2);
  124. #endif
  125. break;
  126. #endif
  127. #if AXIS_IS_TMC(Z) || AXIS_IS_TMC(Z2) || AXIS_IS_TMC(Z3) || AXIS_IS_TMC(Z4)
  128. case Z_AXIS:
  129. #if AXIS_IS_TMC(Z)
  130. if (index <= 0) TMC_SET_CHOPPER_TIME(Z);
  131. #endif
  132. #if AXIS_IS_TMC(Z2)
  133. if (index < 0 || index == 1) TMC_SET_CHOPPER_TIME(Z2);
  134. #endif
  135. #if AXIS_IS_TMC(Z3)
  136. if (index < 0 || index == 2) TMC_SET_CHOPPER_TIME(Z3);
  137. #endif
  138. #if AXIS_IS_TMC(Z4)
  139. if (index < 0 || index == 3) TMC_SET_CHOPPER_TIME(Z4);
  140. #endif
  141. break;
  142. #endif
  143. #if AXIS_IS_TMC(I)
  144. case I_AXIS: TMC_SET_CHOPPER_TIME(I); break;
  145. #endif
  146. #if AXIS_IS_TMC(J)
  147. case J_AXIS: TMC_SET_CHOPPER_TIME(J); break;
  148. #endif
  149. #if AXIS_IS_TMC(K)
  150. case K_AXIS: TMC_SET_CHOPPER_TIME(K); break;
  151. #endif
  152. #if AXIS_IS_TMC(U)
  153. case U_AXIS: TMC_SET_CHOPPER_TIME(U); break;
  154. #endif
  155. #if AXIS_IS_TMC(V)
  156. case V_AXIS: TMC_SET_CHOPPER_TIME(V); break;
  157. #endif
  158. #if AXIS_IS_TMC(W)
  159. case W_AXIS: TMC_SET_CHOPPER_TIME(W); break;
  160. #endif
  161. #if HAS_E_CHOPPER
  162. case E_AXIS: {
  163. #if AXIS_IS_TMC(E0)
  164. if (eindex <= 0) TMC_SET_CHOPPER_TIME(E0);
  165. #endif
  166. #if AXIS_IS_TMC(E1)
  167. if (eindex < 0 || eindex == 1) TMC_SET_CHOPPER_TIME(E1);
  168. #endif
  169. #if AXIS_IS_TMC(E2)
  170. if (eindex < 0 || eindex == 2) TMC_SET_CHOPPER_TIME(E2);
  171. #endif
  172. #if AXIS_IS_TMC(E3)
  173. if (eindex < 0 || eindex == 3) TMC_SET_CHOPPER_TIME(E3);
  174. #endif
  175. #if AXIS_IS_TMC(E4)
  176. if (eindex < 0 || eindex == 4) TMC_SET_CHOPPER_TIME(E4);
  177. #endif
  178. #if AXIS_IS_TMC(E5)
  179. if (eindex < 0 || eindex == 5) TMC_SET_CHOPPER_TIME(E5);
  180. #endif
  181. #if AXIS_IS_TMC(E6)
  182. if (eindex < 0 || eindex == 6) TMC_SET_CHOPPER_TIME(E6);
  183. #endif
  184. #if AXIS_IS_TMC(E7)
  185. if (eindex < 0 || eindex == 7) TMC_SET_CHOPPER_TIME(E7);
  186. #endif
  187. } break;
  188. #endif
  189. }
  190. }
  191. if (report) {
  192. #define TMC_SAY_CHOPPER_TIME(Q) tmc_print_chopper_time(stepper##Q)
  193. #if AXIS_IS_TMC(X)
  194. TMC_SAY_CHOPPER_TIME(X);
  195. #endif
  196. #if AXIS_IS_TMC(X2)
  197. TMC_SAY_CHOPPER_TIME(X2);
  198. #endif
  199. #if AXIS_IS_TMC(Y)
  200. TMC_SAY_CHOPPER_TIME(Y);
  201. #endif
  202. #if AXIS_IS_TMC(Y2)
  203. TMC_SAY_CHOPPER_TIME(Y2);
  204. #endif
  205. #if AXIS_IS_TMC(Z)
  206. TMC_SAY_CHOPPER_TIME(Z);
  207. #endif
  208. #if AXIS_IS_TMC(Z2)
  209. TMC_SAY_CHOPPER_TIME(Z2);
  210. #endif
  211. #if AXIS_IS_TMC(Z3)
  212. TMC_SAY_CHOPPER_TIME(Z3);
  213. #endif
  214. #if AXIS_IS_TMC(Z4)
  215. TMC_SAY_CHOPPER_TIME(Z4);
  216. #endif
  217. #if AXIS_IS_TMC(I)
  218. TMC_SAY_CHOPPER_TIME(I);
  219. #endif
  220. #if AXIS_IS_TMC(J)
  221. TMC_SAY_CHOPPER_TIME(J);
  222. #endif
  223. #if AXIS_IS_TMC(K)
  224. TMC_SAY_CHOPPER_TIME(K);
  225. #endif
  226. #if AXIS_IS_TMC(U)
  227. TMC_SAY_CHOPPER_TIME(U);
  228. #endif
  229. #if AXIS_IS_TMC(V)
  230. TMC_SAY_CHOPPER_TIME(V);
  231. #endif
  232. #if AXIS_IS_TMC(W)
  233. TMC_SAY_CHOPPER_TIME(W);
  234. #endif
  235. #if AXIS_IS_TMC(E0)
  236. TMC_SAY_CHOPPER_TIME(E0);
  237. #endif
  238. #if AXIS_IS_TMC(E1)
  239. TMC_SAY_CHOPPER_TIME(E1);
  240. #endif
  241. #if AXIS_IS_TMC(E2)
  242. TMC_SAY_CHOPPER_TIME(E2);
  243. #endif
  244. #if AXIS_IS_TMC(E3)
  245. TMC_SAY_CHOPPER_TIME(E3);
  246. #endif
  247. #if AXIS_IS_TMC(E4)
  248. TMC_SAY_CHOPPER_TIME(E4);
  249. #endif
  250. #if AXIS_IS_TMC(E5)
  251. TMC_SAY_CHOPPER_TIME(E5);
  252. #endif
  253. #if AXIS_IS_TMC(E6)
  254. TMC_SAY_CHOPPER_TIME(E6);
  255. #endif
  256. #if AXIS_IS_TMC(E7)
  257. TMC_SAY_CHOPPER_TIME(E7);
  258. #endif
  259. }
  260. }
  261. #endif // HAS_TRINAMIC_CONFIG