| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- /**
- * @file TMC2209_ATY.h
- *
- * @param Project DEVICE_GENERAL_ATY_LIB
- *
- * @author ATY
- *
- * @copyright
- * - Copyright 2017 - 2026 MZ-ATY
- * - This code follows:
- * - MZ-ATY Various Contents Joint Statement -
- * <a href="https://mengze.top/MZ-ATY_VCJS">
- * https://mengze.top/MZ-ATY_VCJS</a>
- * - CC 4.0 BY-NC-SA -
- * <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">
- * https://creativecommons.org/licenses/by-nc-sa/4.0/</a>
- * - Your use will be deemed to have accepted the terms of this statement.
- *
- * @brief functions of SteppingMotor control
- *
- * @version
- * - 1_01_221231 > ATY
- * -# Preliminary version, first Release
- * - 1_02_230408 > ATY
- * -# Add State Machine and so
- * - 1_03_230426 > ATY
- * -# Change name "SteppingMotor_ATY" to "TMC2209_ATY"
- * - 1_01_240111 > ATY
- * -# add multy addr and channel
- * -# add lock
- ********************************************************************************
- */
- #ifndef __TMC2209_ATY_H
- #define __TMC2209_ATY_H
- #include "INCLUDE_ATY.h"
- /******************************* For user *************************************/
- /* set step pin vol level when motor is not enable */
- // #define STATIC_STEP_LEVEL 0
- /******************************************************************************/
- struct TMC2209_ATY_Dev
- {
- uint8_t id;
- uint8_t motorEn;
- uint8_t motorDir;
- uint8_t motorDiag;
- uint32_t motorSoftSpeed;
- uint32_t motorSpeed;
- uint32_t motorSpeedCounter;
- uint32_t motorSoftSteps;
- uint32_t motorSteps;
- uint32_t motorStepCounter;
- uint32_t motorStopCounter; // delay for stall detection or driver error(TMC2209)
- 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
- float speedIncreaseStep;
- float lineProParam;
- uint8_t lineProType;
- void (*enSet)(uint8_t level);
- void (*dirSet)(uint8_t level);
- uint8_t (*diagGet)();
- void (*freqSet)(uint16_t freq);
- uint8_t lock;
- uint8_t debugEnable;
- void (*LOG)(const char*, ...);
- };
- #define TMC2209_PARAM_SET(dir, softSpeed, speed, softSteps, steps, setState, dev) \
- do \
- { \
- dev->motorDir = (uint8_t)dir; \
- dev->motorSoftSpeed = (uint32_t)softSpeed; \
- dev->motorSpeed = (uint32_t)speed; \
- dev->motorSoftSteps = (uint32_t)softSteps; \
- dev->motorSteps = (uint32_t)steps; \
- dev->motorSetState = (uint8_t)setState; \
- } while(0)
- #define TMC2209_PARAM_GET(dir, softSpeed, speed, softSteps, steps, setState, dev) \
- do \
- { \
- dir = dev.motorDir; \
- softSpeed = dev.motorSoftSpeed; \
- speed = dev.motorSpeed; \
- softSteps = dev.motorSoftSteps; \
- steps = dev.motorSteps; \
- setState = dev.motorSetState; \
- } while(0)
- uint8_t TMC2209_SetAble(uint8_t enable, struct TMC2209_ATY_Dev *dev);
- uint8_t TMC2209_SetDirection(uint8_t dir, struct TMC2209_ATY_Dev *dev);
- uint8_t TMC2209_GetDiagLevel(struct TMC2209_ATY_Dev *dev);
- void TMC2209_Start(uint8_t dir, uint32_t speed, struct TMC2209_ATY_Dev *dev);
- void TMC2209_Stop(struct TMC2209_ATY_Dev *dev);
- void TMC2209_StateMachine_PWM(struct TMC2209_ATY_Dev *dev);
- #define TMC2209_SET_REVERSE 4
- #define TMC2209_SET_START_DIRECTLY 3
- #define TMC2209_SET_START_SOFT 2
- #define TMC2209_SET_STOP 0
- #define TMC2209_SET_SCRAM 10
- #define TMC2209_SET_FINISHED 5
- #define TMC2209_SET_RUNNING 1
- /* for motor soft start */
- #define TMC2209_S_PARAM_C 0.5 // 0-1
- #endif /* __TMC2209_ATY_H */
- /******************************** End Of File *********************************/
|