MOTOR_DC_ATY.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /**
  2. * @file MOTOR_DC_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 DCMotor control
  20. *
  21. * @version
  22. * - 1_01_230426 > ATY
  23. * -# Preliminary version, first Release
  24. ********************************************************************************
  25. */
  26. #ifndef __MOTOR_DC_ATY_H
  27. #define __MOTOR_DC_ATY_H
  28. #include "INCLUDE_ATY.h"
  29. #include "HW_GPIO_ATY.h"
  30. #include "HW_PWM_ATY.h"
  31. /******************************* For user *************************************/
  32. // #define __DEBUG_MOTOR_DC_ATY
  33. // #define Motor_Channel 2
  34. /******************************************************************************/
  35. extern uint8_t motorEn;
  36. extern uint8_t motorDir;
  37. extern uint32_t motorSoftSpeed;
  38. extern uint32_t motorSpeed;
  39. extern uint32_t motorSoftTime;
  40. extern uint32_t motorTime;
  41. extern uint32_t motorStartCounter;
  42. extern uint32_t motorStopCounter; // for stall detection or driver error(TMC2209)
  43. 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
  44. #define MOTOR_STANDBY \
  45. do{GPIO_SET_L(MOTOR_A_PORT, MOTOR_A_PIN); GPIO_SET_L(MOTOR_B_PORT, MOTOR_B_PIN); motorEn = 0;}while(0)
  46. #define MOTOR_STOP \
  47. do{GPIO_SET_H(MOTOR_A_PORT, MOTOR_A_PIN); GPIO_SET_H(MOTOR_B_PORT, MOTOR_B_PIN); motorEn = 0;}while(0)
  48. #define MOTOR_IN \
  49. do{GPIO_SET_L(MOTOR_A_PORT, MOTOR_A_PIN); GPIO_SET_H(MOTOR_B_PORT, MOTOR_B_PIN); motorEn = 1;}while(0)
  50. #define MOTOR_OUT \
  51. do{GPIO_SET_H(MOTOR_A_PORT, MOTOR_A_PIN); GPIO_SET_L(MOTOR_B_PORT, MOTOR_B_PIN); motorEn = 1;}while(0)
  52. /*
  53. #define MOTOR_EN_SET_ENABLE \
  54. do{GPIO_SET_L(MOTOR_EN_PORT, MOTOR_EN_PIN); motorEn = 1;}while(0)
  55. #define MOTOR_EN_SET_DISABLE \
  56. do{GPIO_SET_H(MOTOR_EN_PORT, MOTOR_EN_PIN); motorEn = 0;}while(0)
  57. */
  58. #define MOTOR_DIR_OUT 2
  59. #define MOTOR_DIR_IN 1
  60. /*
  61. #define MOTOR_DIR_SET_IN \
  62. do{GPIO_SET_H(MOTOR_DIR_PORT, MOTOR_DIR_PIN); motorDir = MOTOR_DIR_IN;}while(0)
  63. #define MOTOR_DIR_SET_OUT \
  64. do{GPIO_SET_L(MOTOR_DIR_PORT, MOTOR_DIR_PIN); motorDir = MOTOR_DIR_OUT;}while(0)
  65. #define MOTOR_STEP_SET_H \
  66. (GPIO_SET_H(MOTOR_STEP_PORT, MOTOR_STEP_PIN))
  67. #define MOTOR_STEP_SET_L \
  68. (GPIO_SET_L(MOTOR_STEP_PORT, MOTOR_STEP_PIN))
  69. */
  70. #define MOTOR_PARAM_SET(dir, softSpeed, speed, softTime, time, setState) \
  71. do \
  72. { \
  73. motorDir = dir; \
  74. motorSoftSpeed = softSpeed; \
  75. motorSpeed = speed; \
  76. motorSoftTime = softTime; \
  77. motorTime = time; \
  78. motorSetState = setState; \
  79. } while(0)
  80. void MotorStart(uint8_t dir, uint32_t speed);
  81. void MotorStartSpeed(uint32_t speed);
  82. void MotorStop(void);
  83. void MotorStateMachine_DC(void);
  84. #endif /* __MOTOR_DC_ATY_H */
  85. /******************************** End Of File *********************************/