MOTOR_STEP_ATY.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /**
  2. * @file MOTOR_STEP_ATY.h
  3. *
  4. * @param Project DEVICE_GENERAL_ATY_LIB
  5. *
  6. * @author ATY
  7. *
  8. * @copyright
  9. * - Copyright 2017 - 2023 MZ-ATY
  10. * - This code follows:
  11. * - MZ-ATY Various Contents Joint Statement -
  12. * <a href="https://mengze.top/MZ-ATY_VCJS">
  13. * https://mengze.top/MZ-ATY_VCJS</a>
  14. * - CC 4.0 BY-NC-SA -
  15. * <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">
  16. * https://creativecommons.org/licenses/by-nc-sa/4.0/</a>
  17. * - Your use will be deemed to have accepted the terms of this statement.
  18. *
  19. * @brief Familiar functions of SteppingMotor control
  20. *
  21. * @version
  22. * - 1_01_221231 > ATY
  23. * -# Preliminary version, first Release
  24. * - 1_02_230408 > ATY
  25. * -# Add State Machine and so
  26. * - 1_03_230426 > ATY
  27. * -# Change name "SteppingMotor_ATY" to "MOTOR_STEP_ATY"
  28. ********************************************************************************
  29. */
  30. #ifndef __MOTOR_STEP_ATY_H
  31. #define __MOTOR_STEP_ATY_H
  32. #include "INCLUDE_ATY.h"
  33. #include "HW_GPIO_ATY.h"
  34. #include "HW_PWM_ATY.h"
  35. /******************************* For user *************************************/
  36. // #define __DEBUG_MOTOR_STEP_ATY
  37. #define Motor_Channel 2
  38. /******************************************************************************/
  39. extern uint8_t motorEn;
  40. extern uint8_t motorDir;
  41. extern uint32_t motorSoftSpeed;
  42. extern uint32_t motorSpeed;
  43. extern uint32_t motorSoftTime;
  44. extern uint32_t motorTime;
  45. extern uint32_t motorStartCounter;
  46. extern uint32_t motorStopCounter; // for stall detection or driver error(TMC2209)
  47. extern uint8_t motorSetState; // 0: stop, 1: start hold, 2: start soft, 3: run speed, 4: change dir, 5: stop state, soft set 0 after use
  48. #define MOTOR_EN_SET_ENABLE \
  49. do{GPIO_SET_L(MOTOR_EN_PORT, MOTOR_EN_PIN); motorEn = 1;}while(0)
  50. #define MOTOR_EN_SET_DISABLE \
  51. do{GPIO_SET_H(MOTOR_EN_PORT, MOTOR_EN_PIN); motorEn = 0;}while(0)
  52. #define MOTOR_DIR_OUT 0
  53. #define MOTOR_DIR_IN 1
  54. #define MOTOR_DIR_SET_IN \
  55. do{GPIO_SET_H(MOTOR_DIR_PORT, MOTOR_DIR_PIN); motorDir = MOTOR_DIR_IN;}while(0)
  56. #define MOTOR_DIR_SET_OUT \
  57. do{GPIO_SET_L(MOTOR_DIR_PORT, MOTOR_DIR_PIN); motorDir = MOTOR_DIR_OUT;}while(0)
  58. #define MOTOR_STEP_SET_H \
  59. (GPIO_SET_H(MOTOR_STEP_PORT, MOTOR_STEP_PIN))
  60. #define MOTOR_STEP_SET_L \
  61. (GPIO_SET_L(MOTOR_STEP_PORT, MOTOR_STEP_PIN))
  62. #define MOTOR_DIAG_GET_H (GPIO_GET_H(MOTOR_DIAG_PORT, MOTOR_DIAG_PIN))
  63. #define MOTOR_DIAG_GET_L (GPIO_GET_L(MOTOR_DIAG_PORT, MOTOR_DIAG_PIN))
  64. #define MOTOR_PARAM_SET(dir, softSpeed, speed, softTime, time, setState) \
  65. do \
  66. { \
  67. motorDir = dir; \
  68. motorSoftSpeed = softSpeed; \
  69. motorSpeed = speed; \
  70. motorSoftTime = softTime; \
  71. motorTime = time; \
  72. motorSetState = setState; \
  73. } while(0)
  74. void MotorStart(uint8_t dir, uint32_t speed);
  75. void MotorStartSpeed(uint32_t speed);
  76. void MotorStop(void);
  77. void MotorStateMachine_Step(void);
  78. #endif /* __MOTOR_STEP_ATY_H */
  79. /******************************** End Of File *********************************/