My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

stepper_indirection.cpp 6.7KB

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