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.h 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. stepper.h - stepper motor driver: executes motion plans of planner.c using the stepper motors
  3. Part of Grbl
  4. Copyright (c) 2009-2011 Simen Svale Skogsrud
  5. Grbl is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. Grbl is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with Grbl. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef stepper_h
  17. #define stepper_h
  18. #include "planner.h"
  19. #include "stepper_indirection.h"
  20. #ifdef HAVE_TMCDRIVER
  21. #include <SPI.h>
  22. #include <TMC26XStepper.h>
  23. #endif
  24. #if EXTRUDERS > 3
  25. #define WRITE_E_STEP(v) { if(current_block->active_extruder == 3) { E3_STEP_WRITE(v); } else { if(current_block->active_extruder == 2) { E2_STEP_WRITE(v); } else { if(current_block->active_extruder == 1) { E1_STEP_WRITE(v); } else { E0_STEP_WRITE(v); }}}}
  26. #define NORM_E_DIR() { if(current_block->active_extruder == 3) { E3_DIR_WRITE( !INVERT_E3_DIR); } else { if(current_block->active_extruder == 2) { E2_DIR_WRITE(!INVERT_E2_DIR); } else { if(current_block->active_extruder == 1) { E1_DIR_WRITE(!INVERT_E1_DIR); } else { E0_DIR_WRITE(!INVERT_E0_DIR); }}}}
  27. #define REV_E_DIR() { if(current_block->active_extruder == 3) { E3_DIR_WRITE(INVERT_E3_DIR); } else { if(current_block->active_extruder == 2) { E2_DIR_WRITE(INVERT_E2_DIR); } else { if(current_block->active_extruder == 1) { E1_DIR_WRITE(INVERT_E1_DIR); } else { E0_DIR_WRITE(INVERT_E0_DIR); }}}}
  28. #elif EXTRUDERS > 2
  29. #define WRITE_E_STEP(v) { if(current_block->active_extruder == 2) { E2_STEP_WRITE(v); } else { if(current_block->active_extruder == 1) { E1_STEP_WRITE(v); } else { E0_STEP_WRITE(v); }}}
  30. #define NORM_E_DIR() { if(current_block->active_extruder == 2) { E2_DIR_WRITE(!INVERT_E2_DIR); } else { if(current_block->active_extruder == 1) { E1_DIR_WRITE(!INVERT_E1_DIR); } else { E0_DIR_WRITE(!INVERT_E0_DIR); }}}
  31. #define REV_E_DIR() { if(current_block->active_extruder == 2) { E2_DIR_WRITE(INVERT_E2_DIR); } else { if(current_block->active_extruder == 1) { E1_DIR_WRITE(INVERT_E1_DIR); } else { E0_DIR_WRITE(INVERT_E0_DIR); }}}
  32. #elif EXTRUDERS > 1
  33. #ifndef DUAL_X_CARRIAGE
  34. #define WRITE_E_STEP(v) { if(current_block->active_extruder == 1) { E1_STEP_WRITE(v); } else { E0_STEP_WRITE(v); }}
  35. #define NORM_E_DIR() { if(current_block->active_extruder == 1) { E1_DIR_WRITE(!INVERT_E1_DIR); } else { E0_DIR_WRITE(!INVERT_E0_DIR); }}
  36. #define REV_E_DIR() { if(current_block->active_extruder == 1) { E1_DIR_WRITE(INVERT_E1_DIR); } else { E0_DIR_WRITE(INVERT_E0_DIR); }}
  37. #else
  38. extern bool extruder_duplication_enabled;
  39. #define WRITE_E_STEP(v) { if(extruder_duplication_enabled) { E0_STEP_WRITE(v); E1_STEP_WRITE(v); } else if(current_block->active_extruder == 1) { E1_STEP_WRITE(v); } else { E0_STEP_WRITE(v); }}
  40. #define NORM_E_DIR() { if(extruder_duplication_enabled) { E0_DIR_WRITE(!INVERT_E0_DIR); E1_DIR_WRITE(!INVERT_E1_DIR); } else if(current_block->active_extruder == 1) { E1_DIR_WRITE(!INVERT_E1_DIR); } else { E0_DIR_WRITE(!INVERT_E0_DIR); }}
  41. #define REV_E_DIR() { if(extruder_duplication_enabled) { E0_DIR_WRITE(INVERT_E0_DIR); E1_DIR_WRITE(INVERT_E1_DIR); } else if(current_block->active_extruder == 1) { E1_DIR_WRITE(INVERT_E1_DIR); } else { E0_DIR_WRITE(INVERT_E0_DIR); }}
  42. #endif
  43. #else
  44. #define WRITE_E_STEP(v) E0_STEP_WRITE(v)
  45. #define NORM_E_DIR() E0_DIR_WRITE(!INVERT_E0_DIR)
  46. #define REV_E_DIR() E0_DIR_WRITE(INVERT_E0_DIR)
  47. #endif
  48. #ifdef ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED
  49. extern bool abort_on_endstop_hit;
  50. #endif
  51. // Initialize and start the stepper motor subsystem
  52. void st_init();
  53. // Block until all buffered steps are executed
  54. void st_synchronize();
  55. // Set current position in steps
  56. void st_set_position(const long &x, const long &y, const long &z, const long &e);
  57. void st_set_e_position(const long &e);
  58. // Get current position in steps
  59. long st_get_position(uint8_t axis);
  60. #ifdef ENABLE_AUTO_BED_LEVELING
  61. // Get current position in mm
  62. float st_get_position_mm(uint8_t axis);
  63. #endif //ENABLE_AUTO_BED_LEVELING
  64. // The stepper subsystem goes to sleep when it runs out of things to execute. Call this
  65. // to notify the subsystem that it is time to go to work.
  66. void st_wake_up();
  67. void checkHitEndstops(); //call from somewhere to create an serial error message with the locations the endstops where hit, in case they were triggered
  68. void endstops_hit_on_purpose(); //avoid creation of the message, i.e. after homing and before a routine call of checkHitEndstops();
  69. void enable_endstops(bool check); // Enable/disable endstop checking
  70. void checkStepperErrors(); //Print errors detected by the stepper
  71. void finishAndDisableSteppers();
  72. extern block_t *current_block; // A pointer to the block currently being traced
  73. void quickStop();
  74. void digitalPotWrite(int address, int value);
  75. void microstep_ms(uint8_t driver, int8_t ms1, int8_t ms2);
  76. void microstep_mode(uint8_t driver, uint8_t stepping);
  77. void digipot_init();
  78. void digipot_current(uint8_t driver, int current);
  79. void microstep_init();
  80. void microstep_readings();
  81. #ifdef BABYSTEPPING
  82. void babystep(const uint8_t axis,const bool direction); // perform a short step with a single stepper motor, outside of any convention
  83. #endif
  84. #ifdef HAVE_TMCDRIVER
  85. void tmc_init();
  86. #ifdef X_IS_TMC
  87. extern TMC26XStepper stepperX;
  88. #endif
  89. #ifdef X2_IS_TMC
  90. extern TMC26XStepper stepperX2;
  91. #endif
  92. #ifdef Y_IS_TMC
  93. extern TMC26XStepper stepperY;
  94. #endif
  95. #ifdef Y2_IS_TMC
  96. extern TMC26XStepper stepperY2;
  97. #endif
  98. #ifdef Z_IS_TMC
  99. extern TMC26XStepper stepperZ;
  100. #endif
  101. #ifdef Z2_IS_TMC
  102. extern TMC26XStepper stepperZ2;
  103. #endif
  104. #ifdef E0_IS_TMC
  105. extern TMC26XStepper stepperE0;
  106. #endif
  107. #ifdef E1_IS_TMC
  108. extern TMC26XStepper stepperE1;
  109. #endif
  110. #ifdef E2_IS_TMC
  111. extern TMC26XStepper stepperE2;
  112. #endif
  113. #ifdef E3_IS_TMC
  114. extern TMC26XStepper stepperE3;
  115. #endif
  116. #endif
  117. #endif