MOTOR_DC_ATY.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 - 2025 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. * - 1_01_240112 > ATY
  25. * -# add multy addr and channel
  26. * -# add lock
  27. ********************************************************************************
  28. */
  29. #ifndef __MOTOR_DC_ATY_H
  30. #define __MOTOR_DC_ATY_H
  31. #include "INCLUDE_ATY.h"
  32. /******************************* For user *************************************/
  33. /******************************************************************************/
  34. struct MOTOR_DC_ATY_Dev
  35. {
  36. uint8_t id;
  37. uint8_t motorEn;
  38. uint8_t motorDir;
  39. uint32_t motorSpeed;
  40. uint32_t motorSpeedCounter;
  41. uint32_t motorSoftSteps;
  42. uint32_t motorSteps;
  43. uint32_t motorStepCounter;
  44. 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, 10: scram motor
  45. float speedIncreaseStep;
  46. uint8_t lineProType;
  47. float lineProParam;
  48. void (*signalSet)(uint8_t pin, uint8_t level);
  49. uint8_t lock;
  50. uint8_t debugEnable;
  51. void (*LOG)(const char*, ...);
  52. };
  53. #define MOTOR_DC_PARAM_SET(en, dir, speed, softSteps, steps, setState, dev) \
  54. do \
  55. { \
  56. dev->motorEn = (uint8_t)en; \
  57. dev->motorDir = (uint8_t)dir; \
  58. dev->motorSpeed = (uint32_t)speed; \
  59. dev->motorSoftSteps = (uint32_t)softSteps; \
  60. dev->motorSteps = (uint32_t)steps; \
  61. dev->motorSetState = (uint8_t)setState; \
  62. } while(0)
  63. #define MOTOR_DC_PARAM_GET(en, dir, speed, softSteps, steps, setState, dev) \
  64. do \
  65. { \
  66. en = dev.motorEn; \
  67. dir = dev.motorDir; \
  68. speed = dev.motorSpeed; \
  69. softSteps = dev.motorSoftSteps; \
  70. steps = dev.motorSteps; \
  71. setState = dev.motorSetState; \
  72. } while(0)
  73. uint8_t MOTOR_DC_Start(uint8_t dir, uint32_t speed, struct MOTOR_DC_ATY_Dev* dev);
  74. uint8_t MOTOR_DC_Stop(struct MOTOR_DC_ATY_Dev* dev);
  75. void MOTOR_DC_StateMachine_PWM(struct MOTOR_DC_ATY_Dev* dev);
  76. void MOTOR_DC_StateMachine(struct MOTOR_DC_ATY_Dev* dev);
  77. #define MOTOR_DC_SET_REVERSE 4
  78. #define MOTOR_DC_SET_START_DIRECTLY 3
  79. #define MOTOR_DC_SET_START_SOFT 2
  80. #define MOTOR_DC_SET_STOP 0
  81. #define MOTOR_DC_SET_SCRAM 10
  82. #define MOTOR_DC_SET_FINISHED 5
  83. #define MOTOR_DC_SET_RUNNING 1
  84. /* for motor soft start */
  85. #define MOTOR_DC_S_PARAM_C 0.5 // 0-1
  86. #endif /* __MOTOR_DC_ATY_H */
  87. /******************************** End Of File *********************************/