My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

stepper_indirection.cpp 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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.c - stepper motor driver indirection
  24. to allow some stepper functions to be done via SPI/I2c instead of direct pin manipulation
  25. Part of Marlin
  26. Copyright (c) 2015 Dominik Wenger
  27. Marlin is free software: you can redistribute it and/or modify
  28. it under the terms of the GNU General Public License as published by
  29. the Free Software Foundation, either version 3 of the License, or
  30. (at your option) any later version.
  31. Marlin is distributed in the hope that it will be useful,
  32. but WITHOUT ANY WARRANTY; without even the implied warranty of
  33. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  34. GNU General Public License for more details.
  35. You should have received a copy of the GNU General Public License
  36. along with Marlin. If not, see <http://www.gnu.org/licenses/>.
  37. */
  38. #include "stepper_indirection.h"
  39. #include "Configuration.h"
  40. #if ENABLED(HAVE_TMCDRIVER)
  41. #include <SPI.h>
  42. #include <TMC26XStepper.h>
  43. #endif
  44. // Stepper objects of TMC steppers used
  45. #if ENABLED(X_IS_TMC)
  46. TMC26XStepper stepperX(200, X_ENABLE_PIN, X_STEP_PIN, X_DIR_PIN, X_MAX_CURRENT, X_SENSE_RESISTOR);
  47. #endif
  48. #if ENABLED(X2_IS_TMC)
  49. TMC26XStepper stepperX2(200, X2_ENABLE_PIN, X2_STEP_PIN, X2_DIR_PIN, X2_MAX_CURRENT, X2_SENSE_RESISTOR);
  50. #endif
  51. #if ENABLED(Y_IS_TMC)
  52. TMC26XStepper stepperY(200, Y_ENABLE_PIN, Y_STEP_PIN, Y_DIR_PIN, Y_MAX_CURRENT, Y_SENSE_RESISTOR);
  53. #endif
  54. #if ENABLED(Y2_IS_TMC)
  55. TMC26XStepper stepperY2(200, Y2_ENABLE_PIN, Y2_STEP_PIN, Y2_DIR_PIN, Y2_MAX_CURRENT, Y2_SENSE_RESISTOR);
  56. #endif
  57. #if ENABLED(Z_IS_TMC)
  58. TMC26XStepper stepperZ(200, Z_ENABLE_PIN, Z_STEP_PIN, Z_DIR_PIN, Z_MAX_CURRENT, Z_SENSE_RESISTOR);
  59. #endif
  60. #if ENABLED(Z2_IS_TMC)
  61. TMC26XStepper stepperZ2(200, Z2_ENABLE_PIN, Z2_STEP_PIN, Z2_DIR_PIN, Z2_MAX_CURRENT, Z2_SENSE_RESISTOR);
  62. #endif
  63. #if ENABLED(E0_IS_TMC)
  64. TMC26XStepper stepperE0(200, E0_ENABLE_PIN, E0_STEP_PIN, E0_DIR_PIN, E0_MAX_CURRENT, E0_SENSE_RESISTOR);
  65. #endif
  66. #if ENABLED(E1_IS_TMC)
  67. TMC26XStepper stepperE1(200, E1_ENABLE_PIN, E1_STEP_PIN, E1_DIR_PIN, E1_MAX_CURRENT, E1_SENSE_RESISTOR);
  68. #endif
  69. #if ENABLED(E2_IS_TMC)
  70. TMC26XStepper stepperE2(200, E2_ENABLE_PIN, E2_STEP_PIN, E2_DIR_PIN, E2_MAX_CURRENT, E2_SENSE_RESISTOR);
  71. #endif
  72. #if ENABLED(E3_IS_TMC)
  73. TMC26XStepper stepperE3(200, E3_ENABLE_PIN, E3_STEP_PIN, E3_DIR_PIN, E3_MAX_CURRENT, E3_SENSE_RESISTOR);
  74. #endif
  75. #if ENABLED(HAVE_TMCDRIVER)
  76. void tmc_init() {
  77. #if ENABLED(X_IS_TMC)
  78. stepperX.setMicrosteps(X_MICROSTEPS);
  79. stepperX.start();
  80. #endif
  81. #if ENABLED(X2_IS_TMC)
  82. stepperX2.setMicrosteps(X2_MICROSTEPS);
  83. stepperX2.start();
  84. #endif
  85. #if ENABLED(Y_IS_TMC)
  86. stepperY.setMicrosteps(Y_MICROSTEPS);
  87. stepperY.start();
  88. #endif
  89. #if ENABLED(Y2_IS_TMC)
  90. stepperY2.setMicrosteps(Y2_MICROSTEPS);
  91. stepperY2.start();
  92. #endif
  93. #if ENABLED(Z_IS_TMC)
  94. stepperZ.setMicrosteps(Z_MICROSTEPS);
  95. stepperZ.start();
  96. #endif
  97. #if ENABLED(Z2_IS_TMC)
  98. stepperZ2.setMicrosteps(Z2_MICROSTEPS);
  99. stepperZ2.start();
  100. #endif
  101. #if ENABLED(E0_IS_TMC)
  102. stepperE0.setMicrosteps(E0_MICROSTEPS);
  103. stepperE0.start();
  104. #endif
  105. #if ENABLED(E1_IS_TMC)
  106. stepperE1.setMicrosteps(E1_MICROSTEPS);
  107. stepperE1.start();
  108. #endif
  109. #if ENABLED(E2_IS_TMC)
  110. stepperE2.setMicrosteps(E2_MICROSTEPS);
  111. stepperE2.start();
  112. #endif
  113. #if ENABLED(E3_IS_TMC)
  114. stepperE3.setMicrosteps(E3_MICROSTEPS);
  115. stepperE3.start();
  116. #endif
  117. }
  118. #endif
  119. // L6470 Driver objects and inits
  120. #if ENABLED(HAVE_L6470DRIVER)
  121. #include <SPI.h>
  122. #include <L6470.h>
  123. #endif
  124. // L6470 Stepper objects
  125. #if ENABLED(X_IS_L6470)
  126. L6470 stepperX(X_ENABLE_PIN);
  127. #endif
  128. #if ENABLED(X2_IS_L6470)
  129. L6470 stepperX2(X2_ENABLE_PIN);
  130. #endif
  131. #if ENABLED(Y_IS_L6470)
  132. L6470 stepperY(Y_ENABLE_PIN);
  133. #endif
  134. #if ENABLED(Y2_IS_L6470)
  135. L6470 stepperY2(Y2_ENABLE_PIN);
  136. #endif
  137. #if ENABLED(Z_IS_L6470)
  138. L6470 stepperZ(Z_ENABLE_PIN);
  139. #endif
  140. #if ENABLED(Z2_IS_L6470)
  141. L6470 stepperZ2(Z2_ENABLE_PIN);
  142. #endif
  143. #if ENABLED(E0_IS_L6470)
  144. L6470 stepperE0(E0_ENABLE_PIN);
  145. #endif
  146. #if ENABLED(E1_IS_L6470)
  147. L6470 stepperE1(E1_ENABLE_PIN);
  148. #endif
  149. #if ENABLED(E2_IS_L6470)
  150. L6470 stepperE2(E2_ENABLE_PIN);
  151. #endif
  152. #if ENABLED(E3_IS_L6470)
  153. L6470 stepperE3(E3_ENABLE_PIN);
  154. #endif
  155. // init routine
  156. #if ENABLED(HAVE_L6470DRIVER)
  157. void L6470_init() {
  158. #if ENABLED(X_IS_L6470)
  159. stepperX.init(X_K_VAL);
  160. stepperX.softFree();
  161. stepperX.setMicroSteps(X_MICROSTEPS);
  162. stepperX.setOverCurrent(X_OVERCURRENT); //set overcurrent protection
  163. stepperX.setStallCurrent(X_STALLCURRENT);
  164. #endif
  165. #if ENABLED(X2_IS_L6470)
  166. stepperX2.init(X2_K_VAL);
  167. stepperX2.softFree();
  168. stepperX2.setMicroSteps(X2_MICROSTEPS);
  169. stepperX2.setOverCurrent(X2_OVERCURRENT); //set overcurrent protection
  170. stepperX2.setStallCurrent(X2_STALLCURRENT);
  171. #endif
  172. #if ENABLED(Y_IS_L6470)
  173. stepperY.init(Y_K_VAL);
  174. stepperY.softFree();
  175. stepperY.setMicroSteps(Y_MICROSTEPS);
  176. stepperY.setOverCurrent(Y_OVERCURRENT); //set overcurrent protection
  177. stepperY.setStallCurrent(Y_STALLCURRENT);
  178. #endif
  179. #if ENABLED(Y2_IS_L6470)
  180. stepperY2.init(Y2_K_VAL);
  181. stepperY2.softFree();
  182. stepperY2.setMicroSteps(Y2_MICROSTEPS);
  183. stepperY2.setOverCurrent(Y2_OVERCURRENT); //set overcurrent protection
  184. stepperY2.setStallCurrent(Y2_STALLCURRENT);
  185. #endif
  186. #if ENABLED(Z_IS_L6470)
  187. stepperZ.init(Z_K_VAL);
  188. stepperZ.softFree();
  189. stepperZ.setMicroSteps(Z_MICROSTEPS);
  190. stepperZ.setOverCurrent(Z_OVERCURRENT); //set overcurrent protection
  191. stepperZ.setStallCurrent(Z_STALLCURRENT);
  192. #endif
  193. #if ENABLED(Z2_IS_L6470)
  194. stepperZ2.init(Z2_K_VAL);
  195. stepperZ2.softFree();
  196. stepperZ2.setMicroSteps(Z2_MICROSTEPS);
  197. stepperZ2.setOverCurrent(Z2_OVERCURRENT); //set overcurrent protection
  198. stepperZ2.setStallCurrent(Z2_STALLCURRENT);
  199. #endif
  200. #if ENABLED(E0_IS_L6470)
  201. stepperE0.init(E0_K_VAL);
  202. stepperE0.softFree();
  203. stepperE0.setMicroSteps(E0_MICROSTEPS);
  204. stepperE0.setOverCurrent(E0_OVERCURRENT); //set overcurrent protection
  205. stepperE0.setStallCurrent(E0_STALLCURRENT);
  206. #endif
  207. #if ENABLED(E1_IS_L6470)
  208. stepperE1.init(E1_K_VAL);
  209. stepperE1.softFree();
  210. stepperE1.setMicroSteps(E1_MICROSTEPS);
  211. stepperE1.setOverCurrent(E1_OVERCURRENT); //set overcurrent protection
  212. stepperE1.setStallCurrent(E1_STALLCURRENT);
  213. #endif
  214. #if ENABLED(E2_IS_L6470)
  215. stepperE2.init(E2_K_VAL);
  216. stepperE2.softFree();
  217. stepperE2.setMicroSteps(E2_MICROSTEPS);
  218. stepperE2.setOverCurrent(E2_OVERCURRENT); //set overcurrent protection
  219. stepperE2.setStallCurrent(E2_STALLCURRENT);
  220. #endif
  221. #if ENABLED(E3_IS_L6470)
  222. stepperE3.init(E3_K_VAL);
  223. stepperE3.softFree();
  224. stepperE3.setMicroSteps(E3_MICROSTEPS);
  225. stepperE3.setOverCurrent(E3_OVERCURRENT); //set overcurrent protection
  226. stepperE3.setStallCurrent(E3_STALLCURRENT);
  227. #endif
  228. }
  229. #endif