My Marlin configs for Fabrikator Mini and CTC i3 Pro B
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

stepper_indirection.cpp 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. {
  57. #if ENABLED(X_IS_TMC)
  58. stepperX.setMicrosteps(X_MICROSTEPS);
  59. stepperX.start();
  60. #endif
  61. #if ENABLED(X2_IS_TMC)
  62. stepperX2.setMicrosteps(X2_MICROSTEPS);
  63. stepperX2.start();
  64. #endif
  65. #if ENABLED(Y_IS_TMC)
  66. stepperY.setMicrosteps(Y_MICROSTEPS);
  67. stepperY.start();
  68. #endif
  69. #if ENABLED(Y2_IS_TMC)
  70. stepperY2.setMicrosteps(Y2_MICROSTEPS);
  71. stepperY2.start();
  72. #endif
  73. #if ENABLED(Z_IS_TMC)
  74. stepperZ.setMicrosteps(Z_MICROSTEPS);
  75. stepperZ.start();
  76. #endif
  77. #if ENABLED(Z2_IS_TMC)
  78. stepperZ2.setMicrosteps(Z2_MICROSTEPS);
  79. stepperZ2.start();
  80. #endif
  81. #if ENABLED(E0_IS_TMC)
  82. stepperE0.setMicrosteps(E0_MICROSTEPS);
  83. stepperE0.start();
  84. #endif
  85. #if ENABLED(E1_IS_TMC)
  86. stepperE1.setMicrosteps(E1_MICROSTEPS);
  87. stepperE1.start();
  88. #endif
  89. #if ENABLED(E2_IS_TMC)
  90. stepperE2.setMicrosteps(E2_MICROSTEPS);
  91. stepperE2.start();
  92. #endif
  93. #if ENABLED(E3_IS_TMC)
  94. stepperE3.setMicrosteps(E3_MICROSTEPS);
  95. stepperE3.start();
  96. #endif
  97. }
  98. #endif
  99. // L6470 Driver objects and inits
  100. #if ENABLED(HAVE_L6470DRIVER)
  101. #include <SPI.h>
  102. #include <L6470.h>
  103. #endif
  104. // L6470 Stepper objects
  105. #if ENABLED(X_IS_L6470)
  106. L6470 stepperX(X_ENABLE_PIN);
  107. #endif
  108. #if ENABLED(X2_IS_L6470)
  109. L6470 stepperX2(X2_ENABLE_PIN);
  110. #endif
  111. #if ENABLED(Y_IS_L6470)
  112. L6470 stepperY(Y_ENABLE_PIN);
  113. #endif
  114. #if ENABLED(Y2_IS_L6470)
  115. L6470 stepperY2(Y2_ENABLE_PIN);
  116. #endif
  117. #if ENABLED(Z_IS_L6470)
  118. L6470 stepperZ(Z_ENABLE_PIN);
  119. #endif
  120. #if ENABLED(Z2_IS_L6470)
  121. L6470 stepperZ2(Z2_ENABLE_PIN);
  122. #endif
  123. #if ENABLED(E0_IS_L6470)
  124. L6470 stepperE0(E0_ENABLE_PIN);
  125. #endif
  126. #if ENABLED(E1_IS_L6470)
  127. L6470 stepperE1(E1_ENABLE_PIN);
  128. #endif
  129. #if ENABLED(E2_IS_L6470)
  130. L6470 stepperE2(E2_ENABLE_PIN);
  131. #endif
  132. #if ENABLED(E3_IS_L6470)
  133. L6470 stepperE3(E3_ENABLE_PIN);
  134. #endif
  135. // init routine
  136. #if ENABLED(HAVE_L6470DRIVER)
  137. void L6470_init()
  138. {
  139. #if ENABLED(X_IS_L6470)
  140. stepperX.init(X_K_VAL);
  141. stepperX.softFree();
  142. stepperX.setMicroSteps(X_MICROSTEPS);
  143. stepperX.setOverCurrent(X_OVERCURRENT); //set overcurrent protection
  144. stepperX.setStallCurrent(X_STALLCURRENT);
  145. #endif
  146. #if ENABLED(X2_IS_L6470)
  147. stepperX2.init(X2_K_VAL);
  148. stepperX2.softFree();
  149. stepperX2.setMicroSteps(X2_MICROSTEPS);
  150. stepperX2.setOverCurrent(X2_OVERCURRENT); //set overcurrent protection
  151. stepperX2.setStallCurrent(X2_STALLCURRENT);
  152. #endif
  153. #if ENABLED(Y_IS_L6470)
  154. stepperY.init(Y_K_VAL);
  155. stepperY.softFree();
  156. stepperY.setMicroSteps(Y_MICROSTEPS);
  157. stepperY.setOverCurrent(Y_OVERCURRENT); //set overcurrent protection
  158. stepperY.setStallCurrent(Y_STALLCURRENT);
  159. #endif
  160. #if ENABLED(Y2_IS_L6470)
  161. stepperY2.init(Y2_K_VAL);
  162. stepperY2.softFree();
  163. stepperY2.setMicroSteps(Y2_MICROSTEPS);
  164. stepperY2.setOverCurrent(Y2_OVERCURRENT); //set overcurrent protection
  165. stepperY2.setStallCurrent(Y2_STALLCURRENT);
  166. #endif
  167. #if ENABLED(Z_IS_L6470)
  168. stepperZ.init(Z_K_VAL);
  169. stepperZ.softFree();
  170. stepperZ.setMicroSteps(Z_MICROSTEPS);
  171. stepperZ.setOverCurrent(Z_OVERCURRENT); //set overcurrent protection
  172. stepperZ.setStallCurrent(Z_STALLCURRENT);
  173. #endif
  174. #if ENABLED(Z2_IS_L6470)
  175. stepperZ2.init(Z2_K_VAL);
  176. stepperZ2.softFree();
  177. stepperZ2.setMicroSteps(Z2_MICROSTEPS);
  178. stepperZ2.setOverCurrent(Z2_OVERCURRENT); //set overcurrent protection
  179. stepperZ2.setStallCurrent(Z2_STALLCURRENT);
  180. #endif
  181. #if ENABLED(E0_IS_L6470)
  182. stepperE0.init(E0_K_VAL);
  183. stepperE0.softFree();
  184. stepperE0.setMicroSteps(E0_MICROSTEPS);
  185. stepperE0.setOverCurrent(E0_OVERCURRENT); //set overcurrent protection
  186. stepperE0.setStallCurrent(E0_STALLCURRENT);
  187. #endif
  188. #if ENABLED(E1_IS_L6470)
  189. stepperE1.init(E1_K_VAL);
  190. stepperE1.softFree();
  191. stepperE1.setMicroSteps(E1_MICROSTEPS);
  192. stepperE1.setOverCurrent(E1_OVERCURRENT); //set overcurrent protection
  193. stepperE1.setStallCurrent(E1_STALLCURRENT);
  194. #endif
  195. #if ENABLED(E2_IS_L6470)
  196. stepperE2.init(E2_K_VAL);
  197. stepperE2.softFree();
  198. stepperE2.setMicroSteps(E2_MICROSTEPS);
  199. stepperE2.setOverCurrent(E2_OVERCURRENT); //set overcurrent protection
  200. stepperE2.setStallCurrent(E2_STALLCURRENT);
  201. #endif
  202. #if ENABLED(E3_IS_L6470)
  203. stepperE3.init(E3_K_VAL);
  204. stepperE3.softFree();
  205. stepperE3.setMicroSteps(E3_MICROSTEPS);
  206. stepperE3.setOverCurrent(E3_OVERCURRENT); //set overcurrent protection
  207. stepperE3.setStallCurrent(E3_STALLCURRENT);
  208. #endif
  209. }
  210. #endif