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.

stepper_indirection.cpp 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 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 <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * stepper_indirection.cpp
  24. *
  25. * Stepper motor driver indirection to allow some stepper functions to
  26. * be done via SPI/I2c instead of direct pin manipulation.
  27. *
  28. * Part of Marlin
  29. *
  30. * Copyright (c) 2015 Dominik Wenger
  31. */
  32. #include "stepper_indirection.h"
  33. #include "MarlinConfig.h"
  34. //
  35. // TMC26X Driver objects and inits
  36. //
  37. #if ENABLED(HAVE_TMCDRIVER)
  38. #include <SPI.h>
  39. #include <TMC26XStepper.h>
  40. #define _TMC_DEFINE(ST) TMC26XStepper stepper##ST(200, ST##_ENABLE_PIN, ST##_STEP_PIN, ST##_DIR_PIN, ST##_MAX_CURRENT, ST##_SENSE_RESISTOR)
  41. #if ENABLED(X_IS_TMC)
  42. _TMC_DEFINE(X);
  43. #endif
  44. #if ENABLED(X2_IS_TMC)
  45. _TMC_DEFINE(X2);
  46. #endif
  47. #if ENABLED(Y_IS_TMC)
  48. _TMC_DEFINE(Y);
  49. #endif
  50. #if ENABLED(Y2_IS_TMC)
  51. _TMC_DEFINE(Y2);
  52. #endif
  53. #if ENABLED(Z_IS_TMC)
  54. _TMC_DEFINE(Z);
  55. #endif
  56. #if ENABLED(Z2_IS_TMC)
  57. _TMC_DEFINE(Z2);
  58. #endif
  59. #if ENABLED(E0_IS_TMC)
  60. _TMC_DEFINE(E0);
  61. #endif
  62. #if ENABLED(E1_IS_TMC)
  63. _TMC_DEFINE(E1);
  64. #endif
  65. #if ENABLED(E2_IS_TMC)
  66. _TMC_DEFINE(E2);
  67. #endif
  68. #if ENABLED(E3_IS_TMC)
  69. _TMC_DEFINE(E3);
  70. #endif
  71. #define _TMC_INIT(A) do{ \
  72. stepper##A.setMicrosteps(A##_MICROSTEPS); \
  73. stepper##A.start(); \
  74. }while(0)
  75. void tmc_init() {
  76. #if ENABLED(X_IS_TMC)
  77. _TMC_INIT(X);
  78. #endif
  79. #if ENABLED(X2_IS_TMC)
  80. _TMC_INIT(X2);
  81. #endif
  82. #if ENABLED(Y_IS_TMC)
  83. _TMC_INIT(Y);
  84. #endif
  85. #if ENABLED(Y2_IS_TMC)
  86. _TMC_INIT(Y2);
  87. #endif
  88. #if ENABLED(Z_IS_TMC)
  89. _TMC_INIT(Z);
  90. #endif
  91. #if ENABLED(Z2_IS_TMC)
  92. _TMC_INIT(Z2);
  93. #endif
  94. #if ENABLED(E0_IS_TMC)
  95. _TMC_INIT(E0);
  96. #endif
  97. #if ENABLED(E1_IS_TMC)
  98. _TMC_INIT(E1);
  99. #endif
  100. #if ENABLED(E2_IS_TMC)
  101. _TMC_INIT(E2);
  102. #endif
  103. #if ENABLED(E3_IS_TMC)
  104. _TMC_INIT(E3);
  105. #endif
  106. }
  107. #endif // HAVE_TMCDRIVER
  108. //
  109. // TMC2130 Driver objects and inits
  110. //
  111. #if ENABLED(HAVE_TMC2130)
  112. #include <SPI.h>
  113. #include <TMC2130Stepper.h>
  114. #define _TMC2130_DEFINE(ST) TMC2130Stepper stepper##ST(ST##_ENABLE_PIN, ST##_DIR_PIN, ST##_STEP_PIN, ST##_CHIP_SELECT)
  115. // Stepper objects of TMC2130 steppers used
  116. #if ENABLED(X_IS_TMC2130)
  117. _TMC2130_DEFINE(X);
  118. #endif
  119. #if ENABLED(X2_IS_TMC2130)
  120. _TMC2130_DEFINE(X2);
  121. #endif
  122. #if ENABLED(Y_IS_TMC2130)
  123. _TMC2130_DEFINE(Y);
  124. #endif
  125. #if ENABLED(Y2_IS_TMC2130)
  126. _TMC2130_DEFINE(Y2);
  127. #endif
  128. #if ENABLED(Z_IS_TMC2130)
  129. _TMC2130_DEFINE(Z);
  130. #endif
  131. #if ENABLED(Z2_IS_TMC2130)
  132. _TMC2130_DEFINE(Z2);
  133. #endif
  134. #if ENABLED(E0_IS_TMC2130)
  135. _TMC2130_DEFINE(E0);
  136. #endif
  137. #if ENABLED(E1_IS_TMC2130)
  138. _TMC2130_DEFINE(E1);
  139. #endif
  140. #if ENABLED(E2_IS_TMC2130)
  141. _TMC2130_DEFINE(E2);
  142. #endif
  143. #if ENABLED(E3_IS_TMC2130)
  144. _TMC2130_DEFINE(E3);
  145. #endif
  146. // Use internal reference voltage for current calculations. This is the default.
  147. // Following values from Trinamic's spreadsheet with values for a NEMA17 (42BYGHW609)
  148. void tmc2130_init(TMC2130Stepper &st, const uint16_t max_current, const uint16_t microsteps) {
  149. st.begin();
  150. st.setCurrent(st.getCurrent(), R_SENSE, HOLD_MULTIPLIER);
  151. st.microsteps(microsteps);
  152. st.blank_time(24);
  153. st.off_time(8);
  154. st.interpolate(INTERPOLATE);
  155. #if ENABLED(STEALTHCHOP)
  156. st.stealthChop(1);
  157. #endif
  158. #if ENABLED(SENSORLESS_HOMING)
  159. st.coolstep_min_speed(1048575);
  160. st.sg_stall_value(STALL_THRESHOLD);
  161. st.sg_filter(1);
  162. st.diag1_stall(1);
  163. st.diag1_active_high(1);
  164. #endif
  165. }
  166. #define _TMC2130_INIT(ST) tmc2130_init(stepper##ST, ST##_MAX_CURRENT, ST##_MICROSTEPS)
  167. void tmc2130_init() {
  168. delay(500); // Let power stabilize before configuring the steppers
  169. #if ENABLED(X_IS_TMC2130)
  170. _TMC2130_INIT(X);
  171. #endif
  172. #if ENABLED(X2_IS_TMC2130)
  173. _TMC2130_INIT(X2);
  174. #endif
  175. #if ENABLED(Y_IS_TMC2130)
  176. _TMC2130_INIT(Y);
  177. #endif
  178. #if ENABLED(Y2_IS_TMC2130)
  179. _TMC2130_INIT(Y2);
  180. #endif
  181. #if ENABLED(Z_IS_TMC2130)
  182. _TMC2130_INIT(Z);
  183. #endif
  184. #if ENABLED(Z2_IS_TMC2130)
  185. _TMC2130_INIT(Z2);
  186. #endif
  187. #if ENABLED(E0_IS_TMC2130)
  188. _TMC2130_INIT(E0);
  189. #endif
  190. #if ENABLED(E1_IS_TMC2130)
  191. _TMC2130_INIT(E1);
  192. #endif
  193. #if ENABLED(E2_IS_TMC2130)
  194. _TMC2130_INIT(E2);
  195. #endif
  196. #if ENABLED(E3_IS_TMC2130)
  197. _TMC2130_INIT(E3);
  198. #endif
  199. TMC2130_ADV()
  200. }
  201. #endif // HAVE_TMC2130
  202. //
  203. // L6470 Driver objects and inits
  204. //
  205. #if ENABLED(HAVE_L6470DRIVER)
  206. #include <SPI.h>
  207. #include <L6470.h>
  208. #define _L6470_DEFINE(ST) L6470 stepper##ST(ST##_ENABLE_PIN)
  209. // L6470 Stepper objects
  210. #if ENABLED(X_IS_L6470)
  211. _L6470_DEFINE(X);
  212. #endif
  213. #if ENABLED(X2_IS_L6470)
  214. _L6470_DEFINE(X2);
  215. #endif
  216. #if ENABLED(Y_IS_L6470)
  217. _L6470_DEFINE(Y);
  218. #endif
  219. #if ENABLED(Y2_IS_L6470)
  220. _L6470_DEFINE(Y2);
  221. #endif
  222. #if ENABLED(Z_IS_L6470)
  223. _L6470_DEFINE(Z);
  224. #endif
  225. #if ENABLED(Z2_IS_L6470)
  226. _L6470_DEFINE(Z2);
  227. #endif
  228. #if ENABLED(E0_IS_L6470)
  229. _L6470_DEFINE(E0);
  230. #endif
  231. #if ENABLED(E1_IS_L6470)
  232. _L6470_DEFINE(E1);
  233. #endif
  234. #if ENABLED(E2_IS_L6470)
  235. _L6470_DEFINE(E2);
  236. #endif
  237. #if ENABLED(E3_IS_L6470)
  238. _L6470_DEFINE(E3);
  239. #endif
  240. #define _L6470_INIT(A) do{ \
  241. stepper##A.init(A##_K_VAL); \
  242. stepper##A.softFree(); \
  243. stepper##A.setMicroSteps(A##_MICROSTEPS); \
  244. stepper##A.setOverCurrent(A##_OVERCURRENT); \
  245. stepper##A.setStallCurrent(A##_STALLCURRENT); \
  246. } while(0)
  247. void L6470_init() {
  248. #if ENABLED(X_IS_L6470)
  249. _L6470_INIT(X);
  250. #endif
  251. #if ENABLED(X2_IS_L6470)
  252. _L6470_INIT(X2);
  253. #endif
  254. #if ENABLED(Y_IS_L6470)
  255. _L6470_INIT(Y);
  256. #endif
  257. #if ENABLED(Y2_IS_L6470)
  258. _L6470_INIT(Y2);
  259. #endif
  260. #if ENABLED(Z_IS_L6470)
  261. _L6470_INIT(Z);
  262. #endif
  263. #if ENABLED(Z2_IS_L6470)
  264. _L6470_INIT(Z2);
  265. #endif
  266. #if ENABLED(E0_IS_L6470)
  267. _L6470_INIT(E0);
  268. #endif
  269. #if ENABLED(E1_IS_L6470)
  270. _L6470_INIT(E1);
  271. #endif
  272. #if ENABLED(E2_IS_L6470)
  273. _L6470_INIT(E2);
  274. #endif
  275. #if ENABLED(E3_IS_L6470)
  276. _L6470_INIT(E3);
  277. #endif
  278. }
  279. #endif // HAVE_L6470DRIVER