stepper.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. #ifdef LIN_ADVANCE
  29. void advance_isr();
  30. void advance_isr_scheduler();
  31. void clear_current_adv_vars(); //Used to reset the built up pretension and remaining esteps on filament change.
  32. #endif
  33. // Block until all buffered steps are executed
  34. void st_synchronize();
  35. // Set current position in steps
  36. void st_set_position(const long &x, const long &y, const long &z, const long &e);
  37. void st_set_e_position(const long &e);
  38. // Get current position in steps
  39. long st_get_position(uint8_t axis);
  40. // Get current x and y position in steps
  41. void st_get_position_xy(long &x, long &y);
  42. // Get current position in mm
  43. float st_get_position_mm(uint8_t axis);
  44. // Call this function just before re-enabling the stepper driver interrupt and the global interrupts
  45. // to avoid a stepper timer overflow.
  46. FORCE_INLINE void st_reset_timer()
  47. {
  48. // Clear a possible pending interrupt on OCR1A overflow.
  49. TIFR1 |= 1 << OCF1A;
  50. // Reset the counter.
  51. TCNT1 = 0;
  52. // Wake up after 1ms from now.
  53. OCR1A = 2000;
  54. }
  55. void checkHitEndstops(); //call from somewhere to create an serial error message with the locations the endstops where hit, in case they were triggered
  56. bool endstops_hit_on_purpose(); //avoid creation of the message, i.e. after homing and before a routine call of checkHitEndstops();
  57. bool endstop_z_hit_on_purpose();
  58. bool enable_endstops(bool check); // Enable/disable endstop checking. Return the old value.
  59. bool enable_z_endstop(bool check);
  60. void invert_z_endstop(bool endstop_invert);
  61. void checkStepperErrors(); //Print errors detected by the stepper
  62. void finishAndDisableSteppers();
  63. extern block_t *current_block; // A pointer to the block currently being traced
  64. extern bool x_min_endstop;
  65. extern bool x_max_endstop;
  66. extern bool y_min_endstop;
  67. extern bool y_max_endstop;
  68. void quickStop();
  69. void digitalPotWrite(int address, int value);
  70. void microstep_ms(uint8_t driver, int8_t ms1, int8_t ms2);
  71. void microstep_mode(uint8_t driver, uint8_t stepping);
  72. void digipot_init();
  73. void digipot_current(uint8_t driver, int current);
  74. void microstep_init();
  75. void microstep_readings();
  76. #ifdef BABYSTEPPING
  77. void babystep(const uint8_t axis,const bool direction); // perform a short step with a single stepper motor, outside of any convention
  78. #endif
  79. #endif