stepper.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. #if EXTRUDERS > 2
  20. #define WRITE_E_STEP(v) { if(current_block->active_extruder == 2) { WRITE(E2_STEP_PIN, v); } else { if(current_block->active_extruder == 1) { WRITE(E1_STEP_PIN, v); } else { WRITE(E0_STEP_PIN, v); }}}
  21. #define NORM_E_DIR() { if(current_block->active_extruder == 2) { WRITE(E2_DIR_PIN, !INVERT_E2_DIR); } else { if(current_block->active_extruder == 1) { WRITE(E1_DIR_PIN, !INVERT_E1_DIR); } else { WRITE(E0_DIR_PIN, !INVERT_E0_DIR); }}}
  22. #define REV_E_DIR() { if(current_block->active_extruder == 2) { WRITE(E2_DIR_PIN, INVERT_E2_DIR); } else { if(current_block->active_extruder == 1) { WRITE(E1_DIR_PIN, INVERT_E1_DIR); } else { WRITE(E0_DIR_PIN, INVERT_E0_DIR); }}}
  23. #elif EXTRUDERS > 1
  24. #define WRITE_E_STEP(v) { if(current_block->active_extruder == 1) { WRITE(E1_STEP_PIN, v); } else { WRITE(E0_STEP_PIN, v); }}
  25. #define NORM_E_DIR() { if(current_block->active_extruder == 1) { WRITE(E1_DIR_PIN, !INVERT_E1_DIR); } else { WRITE(E0_DIR_PIN, !INVERT_E0_DIR); }}
  26. #define REV_E_DIR() { if(current_block->active_extruder == 1) { WRITE(E1_DIR_PIN, INVERT_E1_DIR); } else { WRITE(E0_DIR_PIN, INVERT_E0_DIR); }}
  27. #else
  28. #define WRITE_E_STEP(v) WRITE(E0_STEP_PIN, v)
  29. #define NORM_E_DIR() WRITE(E0_DIR_PIN, !INVERT_E0_DIR)
  30. #define REV_E_DIR() WRITE(E0_DIR_PIN, INVERT_E0_DIR)
  31. #endif
  32. #ifdef ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED
  33. extern bool abort_on_endstop_hit;
  34. #endif
  35. // Initialize and start the stepper motor subsystem
  36. void st_init();
  37. // Block until all buffered steps are executed
  38. void st_synchronize();
  39. // Set current position in steps
  40. void st_set_position(const long &x, const long &y, const long &z, const long &e);
  41. void st_set_e_position(const long &e);
  42. // Get current position in steps
  43. long st_get_position(uint8_t axis);
  44. // Get current x and y position in steps
  45. void st_get_position_xy(long &x, long &y);
  46. // Get current position in mm
  47. float st_get_position_mm(uint8_t axis);
  48. // The stepper subsystem goes to sleep when it runs out of things to execute. Call this
  49. // to notify the subsystem that it is time to go to work.
  50. void st_wake_up();
  51. void checkHitEndstops(); //call from somewhere to create an serial error message with the locations the endstops where hit, in case they were triggered
  52. bool endstops_hit_on_purpose(); //avoid creation of the message, i.e. after homing and before a routine call of checkHitEndstops();
  53. bool endstop_z_hit_on_purpose();
  54. bool enable_endstops(bool check); // Enable/disable endstop checking. Return the old value.
  55. bool enable_z_endstop(bool check);
  56. void checkStepperErrors(); //Print errors detected by the stepper
  57. void finishAndDisableSteppers();
  58. extern block_t *current_block; // A pointer to the block currently being traced
  59. void quickStop();
  60. void digitalPotWrite(int address, int value);
  61. void microstep_ms(uint8_t driver, int8_t ms1, int8_t ms2);
  62. void microstep_mode(uint8_t driver, uint8_t stepping);
  63. void digipot_init();
  64. void digipot_current(uint8_t driver, int current);
  65. void microstep_init();
  66. void microstep_readings();
  67. static void check_fans();
  68. #ifdef HAVE_TMC2130_DRIVERS
  69. void tmc2130_check_overtemp();
  70. void tmc2130_write(uint8_t chipselect, uint8_t address, uint8_t wval1, uint8_t wval2, uint8_t wval3, uint8_t wval4);
  71. uint8_t tmc2130_read8(uint8_t chipselect, uint8_t address);
  72. uint16_t tmc2130_readSG(uint8_t chipselect);
  73. uint16_t tmc2130_readTStep(uint8_t chipselect);
  74. void tmc2130_PWMconf(uint8_t cs, uint8_t PWMgrad, uint8_t PWMampl);
  75. void st_setSGHoming(uint8_t axis);
  76. void st_resetSGflags();
  77. uint8_t st_didLastHomingStall();
  78. #endif
  79. #ifdef BABYSTEPPING
  80. void babystep(const uint8_t axis,const bool direction); // perform a short step with a single stepper motor, outside of any convention
  81. #endif
  82. #endif