stepper.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. #define ENABLE_STEPPER_DRIVER_INTERRUPT() TIMSK1 |= (1<<OCIE1A)
  20. #define DISABLE_STEPPER_DRIVER_INTERRUPT() TIMSK1 &= ~(1<<OCIE1A)
  21. #ifdef ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED
  22. extern bool abort_on_endstop_hit;
  23. #endif
  24. // Initialize and start the stepper motor subsystem
  25. void st_init();
  26. // Interrupt Service Routines
  27. void isr();
  28. // Block until all buffered steps are executed
  29. void st_synchronize();
  30. // Set current position in steps
  31. void st_set_position(const long &x, const long &y, const long &z, const long &e);
  32. void st_set_e_position(const long &e);
  33. // Get current position in steps
  34. long st_get_position(uint8_t axis);
  35. // Get current x and y position in steps
  36. void st_get_position_xy(long &x, long &y);
  37. // Get current position in mm
  38. float st_get_position_mm(uint8_t axis);
  39. // Call this function just before re-enabling the stepper driver interrupt and the global interrupts
  40. // to avoid a stepper timer overflow.
  41. void st_reset_timer();
  42. void checkHitEndstops(); //call from somewhere to create an serial error message with the locations the endstops where hit, in case they were triggered
  43. bool endstops_hit_on_purpose(); //avoid creation of the message, i.e. after homing and before a routine call of checkHitEndstops();
  44. bool endstop_z_hit_on_purpose();
  45. bool enable_endstops(bool check); // Enable/disable endstop checking. Return the old value.
  46. bool enable_z_endstop(bool check);
  47. void invert_z_endstop(bool endstop_invert);
  48. void checkStepperErrors(); //Print errors detected by the stepper
  49. extern block_t *current_block; // A pointer to the block currently being traced
  50. extern volatile long count_position[NUM_AXIS];
  51. void quickStop();
  52. #if defined(DIGIPOTSS_PIN) && DIGIPOTSS_PIN > -1
  53. void digitalPotWrite(int address, int value);
  54. #endif //defined(DIGIPOTSS_PIN) && DIGIPOTSS_PIN > -1
  55. void microstep_ms(uint8_t driver, int8_t ms1, int8_t ms2);
  56. void microstep_mode(uint8_t driver, uint8_t stepping);
  57. void st_current_init();
  58. void st_current_set(uint8_t driver, int current);
  59. void microstep_init();
  60. void microstep_readings();
  61. #ifdef BABYSTEPPING
  62. void babystep(const uint8_t axis,const bool direction); // perform a short step with a single stepper motor, outside of any convention
  63. #endif
  64. #if defined(FILAMENT_SENSOR) && defined(PAT9125)
  65. // reset the internal filament sensor state
  66. void st_reset_fsensor();
  67. #endif
  68. #endif