| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- /**
- * @file MOTOR_STEP_ATY.h
- *
- * @param Project DEVICE_GENERAL_ATY_LIB
- *
- * @author ATY
- *
- * @copyright
- * - Copyright 2017 - 2023 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 Familiar 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 "MOTOR_STEP_ATY"
- ********************************************************************************
- */
- #ifndef __MOTOR_STEP_ATY_H
- #define __MOTOR_STEP_ATY_H
- #include "INCLUDE_ATY.h"
- #include "HW_GPIO_ATY.h"
- #include "HW_PWM_ATY.h"
- /******************************* For user *************************************/
- // #define __DEBUG_MOTOR_STEP_ATY
- #define Motor_Channel 2
- /******************************************************************************/
- extern uint8_t motorEn;
- extern uint8_t motorDir;
- extern uint32_t motorSoftSpeed;
- extern uint32_t motorSpeed;
- extern uint32_t motorSoftTime;
- extern uint32_t motorTime;
- extern uint32_t motorStartCounter;
- extern uint32_t motorStopCounter; // for stall detection or driver error(TMC2209)
- 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
- #define MOTOR_EN_SET_ENABLE \
- do{GPIO_SET_L(MOTOR_EN_PORT, MOTOR_EN_PIN); motorEn = 1;}while(0)
- #define MOTOR_EN_SET_DISABLE \
- do{GPIO_SET_H(MOTOR_EN_PORT, MOTOR_EN_PIN); motorEn = 0;}while(0)
- #define MOTOR_DIR_OUT 0
- #define MOTOR_DIR_IN 1
- #define MOTOR_DIR_SET_IN \
- do{ \
- if(MOTOR_DIR_IN) \
- GPIO_SET_H(MOTOR_DIR_PORT, MOTOR_DIR_PIN); \
- else \
- GPIO_SET_L(MOTOR_DIR_PORT, MOTOR_DIR_PIN); \
- motorDir = MOTOR_DIR_IN; \
- }while(0)
- #define MOTOR_DIR_SET_OUT \
- do{ \
- if(MOTOR_DIR_OUT) \
- GPIO_SET_H(MOTOR_DIR_PORT, MOTOR_DIR_PIN); \
- else \
- GPIO_SET_L(MOTOR_DIR_PORT, MOTOR_DIR_PIN); \
- motorDir = MOTOR_DIR_OUT; \
- }while(0)
- #define MOTOR_STEP_SET_H \
- (GPIO_SET_H(MOTOR_STEP_PORT, MOTOR_STEP_PIN))
- #define MOTOR_STEP_SET_L \
- (GPIO_SET_L(MOTOR_STEP_PORT, MOTOR_STEP_PIN))
- #define MOTOR_DIAG_GET_H (GPIO_GET_H(MOTOR_DIAG_PORT, MOTOR_DIAG_PIN))
- #define MOTOR_DIAG_GET_L (GPIO_GET_L(MOTOR_DIAG_PORT, MOTOR_DIAG_PIN))
- #define MOTOR_PARAM_SET(dir, softSpeed, speed, softTime, time, setState) \
- do \
- { \
- motorDir = (uint8_t)dir; \
- motorSoftSpeed = (uint32_t)softSpeed; \
- motorSpeed = (uint32_t)speed; \
- motorSoftTime = (uint32_t)softTime; \
- motorTime = (uint32_t)time; \
- motorSetState = (uint8_t)setState; \
- } while(0)
- void MotorStart(uint8_t dir, uint32_t speed);
- void MotorStartSpeed(uint32_t speed);
- void MotorStop(void);
- void MotorStateMachine_Step(void);
- #endif /* __MOTOR_STEP_ATY_H */
- /******************************** End Of File *********************************/
|