MOTOR_STEP_SPEED_T_C_ATY.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /**
  2. * @file MOTOR_STEP_SPEED_T_C_ATY.h
  3. *
  4. * @param Project DEVICE_GENERAL_ATY_LIB
  5. *
  6. * @author ATY
  7. *
  8. * @copyright
  9. * - Copyright 2017 - 2026 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 Trapezoidal acceleration and deceleration control implementation for stepper motor
  20. *
  21. * @note import angle to use COMPENSATE
  22. *
  23. * @version
  24. * - 1_00_260119 > ATY
  25. * -# Initial version based on trapezoidal acceleration algorithm
  26. ********************************************************************************
  27. */
  28. #ifndef __MOTOR_STEP_SPEED_T_C_ATY_H
  29. #define __MOTOR_STEP_SPEED_T_C_ATY_H
  30. #include "INCLUDE_ATY.h"
  31. /******************************* For user *************************************/
  32. /******************************************************************************/
  33. /* Motion states */
  34. #define MSSTC_STATE_STANDBY 0 // Standby
  35. #define MSSTC_STATE_STOP 1 // Stopped
  36. #define MSSTC_STATE_ACCEL 2 // Accelerating
  37. #define MSSTC_STATE_DECEL 3 // Decelerating
  38. #define MSSTC_STATE_FULL 4 // Full speed
  39. #define MSSTC_STATE_COMPENSATE 5 // COMPENSATE
  40. #define MSSTC_MODE_DISTANCE_CLOSE 0
  41. #define MSSTC_MODE_DISTANCE_OPEN 1
  42. #define MSSTC_MODE_SPEED_OPEN 2
  43. /* Motor control device structure */
  44. struct MOTOR_STEP_SPEED_T_C_ATY_Dev{
  45. /* Hardware control functions */
  46. uint8_t (*enSet)(uint8_t en);
  47. uint8_t (*dirSet)(uint8_t dir);
  48. void (*start)(void);
  49. void (*stop)(void);
  50. void (*setTimerCompare)(uint32_t value);
  51. // MCU params
  52. uint32_t timerFreq; // Timer frequency in Hz
  53. // motor params
  54. uint32_t fullSteps; // steps per revolution, 360 / 1.8 degree = 200 steps
  55. uint32_t microstepping; // 1/8 = 8, 1/16, 1/32, 1/64, 1/128, 1/256
  56. uint8_t enable;
  57. uint8_t direction;
  58. uint32_t fullSpeed; // rad/sec / unitDiv
  59. uint32_t unitDivision; // 10 -> 0.1 rad, set 1 to ignore
  60. uint32_t acceleration; // rad/sec^2 / unitDiv, set 0 to disable acceleration
  61. uint32_t deceleration; // rad/sec^2 / unitDiv, set 0 to disable deceleration
  62. uint8_t mode;
  63. float angleLock;
  64. uint8_t powerOnlyRun;
  65. uint8_t turnBackAllowed;
  66. uint8_t runState;
  67. uint32_t stepCountCurrent; // current total step counter
  68. uint32_t accelSteps; // accelerate to fullSpeed steps
  69. uint32_t accelLimit; // max acceleration steps before deceleration
  70. uint32_t decelSteps; // decelerate to stop steps
  71. uint32_t decelStart; // Step position to start deceleration
  72. uint8_t lock;
  73. };
  74. uint8_t MSSTC_Move(struct MOTOR_STEP_SPEED_T_C_ATY_Dev* dev,
  75. uint32_t steps, float startAngle);
  76. void MSSTC_IRQHandler(struct MOTOR_STEP_SPEED_T_C_ATY_Dev* dev);
  77. void MSSTC_Scram(struct MOTOR_STEP_SPEED_T_C_ATY_Dev* dev);
  78. void MSSTC_Stop(struct MOTOR_STEP_SPEED_T_C_ATY_Dev* dev);
  79. uint8_t MSSTC_IsRunning(struct MOTOR_STEP_SPEED_T_C_ATY_Dev* dev);
  80. void MSSTC_UpdateFullSpeed(struct MOTOR_STEP_SPEED_T_C_ATY_Dev* dev);
  81. void MSSTC_UpdateAngle(struct MOTOR_STEP_SPEED_T_C_ATY_Dev* dev,
  82. uint32_t turn, float angle);
  83. #endif /* __MOTOR_STEP_SPEED_T_C_ATY_H */
  84. /******************************** End Of File *********************************/