MOTOR_STEP_C_ATY.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /**
  2. * @file MOTOR_STEP_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 functions of close loop stepper motor control for C platform
  20. * Based on position feedback from encoder (e.g. MT6816)
  21. *
  22. * @version
  23. * - 1_00_260109 > ATY
  24. * -# Preliminary version
  25. ********************************************************************************
  26. */
  27. #ifndef __MOTOR_STEP_C_ATY_H
  28. #define __MOTOR_STEP_C_ATY_H
  29. #include "INCLUDE_ATY.h"
  30. /******************************* For user *************************************/
  31. /******************************************************************************/
  32. struct MOTOR_STEP_C_ATY_Dev{
  33. uint8_t (*enSet)(uint8_t en);
  34. uint8_t (*dirSet)(uint8_t dir);
  35. void (*pwmSet)(float frequency, float dutycycle);
  36. void (*pwmSetCount)(float frequency, float dutycycle, uint16_t step);
  37. uint8_t mode;
  38. uint8_t enable;
  39. uint8_t direction;
  40. uint16_t stepCount;
  41. float frequency; // Hz
  42. float dutyCycle; // 0-100f
  43. float speed; // rpm
  44. uint8_t autoPower;
  45. uint8_t forbidReverseCorrection;
  46. /* if used for flow control, fix over steps may lead
  47. no effect or bad effect, set this to 1 to forbid motor
  48. reverse */
  49. uint8_t positionFixFlag;
  50. float startAngle;
  51. float targetAngle;
  52. uint8_t angleLock;
  53. uint16_t cycleSpace; // in ms
  54. uint16_t fullSteps; // steps per revolution, 360 / 1.8 degree = 200 steps
  55. uint8_t microstepping; // 1/8 = 8, 1/16, 1/32, 1/64, 1/128, 1/256
  56. uint8_t lock;
  57. };
  58. #define MOTOR_STEP_C_MODE_POST_MOTION 0x00 // post-Motion Correction
  59. #define MOTOR_STEP_C_MODE_NOCOUNT 0x01 // continuous mode - run continuously
  60. #define MOTOR_STEP_C_MODE_POSITION_CC 0x02 // position Closed-Loop Control
  61. #define MOTOR_STEP_C_MODE_ANGLE_LOCK 0x03 // angle lock
  62. uint8_t MSC_Cycle(struct MOTOR_STEP_C_ATY_Dev* dev,
  63. uint8_t mode, uint8_t enable, uint8_t direction,
  64. uint16_t stepCount,
  65. float frequency, float dutyCycle, float speed,
  66. float currentAngle, float targetAngle);
  67. #endif /* __MOTOR_STEP_C_ATY_H */
  68. /******************************** End Of File *********************************/