/** * @file MOTOR_STEP_SPEED_T_C_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 - * * https://mengze.top/MZ-ATY_VCJS * - CC 4.0 BY-NC-SA - * * https://creativecommons.org/licenses/by-nc-sa/4.0/ * - Your use will be deemed to have accepted the terms of this statement. * * @brief Trapezoidal acceleration and deceleration control implementation for stepper motor * * @note import angle to use COMPENSATE * * @version * - 1_00_260119 > ATY * -# Initial version based on trapezoidal acceleration algorithm ******************************************************************************** */ #ifndef __MOTOR_STEP_SPEED_T_C_ATY_H #define __MOTOR_STEP_SPEED_T_C_ATY_H #include "INCLUDE_ATY.h" /******************************* For user *************************************/ /******************************************************************************/ /* Motion states */ #define MSSTC_STATE_STANDBY 0 // Standby #define MSSTC_STATE_STOP 1 // Stopped #define MSSTC_STATE_ACCEL 2 // Accelerating #define MSSTC_STATE_DECEL 3 // Decelerating #define MSSTC_STATE_FULL 4 // Full speed #define MSSTC_STATE_COMPENSATE 5 // COMPENSATE #define MSSTC_MODE_DISTANCE_CLOSE 0 #define MSSTC_MODE_DISTANCE_OPEN 1 #define MSSTC_MODE_SPEED_OPEN 2 /* Motor control device structure */ struct MOTOR_STEP_SPEED_T_C_ATY_Dev{ /* Hardware control functions */ uint8_t (*enSet)(uint8_t en); uint8_t (*dirSet)(uint8_t dir); void (*start)(void); void (*stop)(void); void (*setTimerCompare)(uint32_t value); // MCU params uint32_t timerFreq; // Timer frequency in Hz // motor params uint32_t fullSteps; // steps per revolution, 360 / 1.8 degree = 200 steps uint32_t microstepping; // 1/8 = 8, 1/16, 1/32, 1/64, 1/128, 1/256 uint8_t enable; uint8_t direction; uint32_t fullSpeed; // rad/sec / unitDiv uint32_t unitDivision; // 10 -> 0.1 rad, set 1 to ignore uint32_t acceleration; // rad/sec^2 / unitDiv, set 0 to disable acceleration uint32_t deceleration; // rad/sec^2 / unitDiv, set 0 to disable deceleration uint8_t mode; float angleLock; uint8_t powerOnlyRun; uint8_t turnBackAllowed; uint8_t runState; uint32_t stepCountCurrent; // current total step counter uint32_t accelSteps; // accelerate to fullSpeed steps uint32_t accelLimit; // max acceleration steps before deceleration uint32_t decelSteps; // decelerate to stop steps uint32_t decelStart; // Step position to start deceleration uint8_t lock; }; uint8_t MSSTC_Move(struct MOTOR_STEP_SPEED_T_C_ATY_Dev* dev, uint32_t steps, float startAngle); void MSSTC_IRQHandler(struct MOTOR_STEP_SPEED_T_C_ATY_Dev* dev); void MSSTC_Scram(struct MOTOR_STEP_SPEED_T_C_ATY_Dev* dev); void MSSTC_Stop(struct MOTOR_STEP_SPEED_T_C_ATY_Dev* dev); uint8_t MSSTC_IsRunning(struct MOTOR_STEP_SPEED_T_C_ATY_Dev* dev); void MSSTC_UpdateFullSpeed(struct MOTOR_STEP_SPEED_T_C_ATY_Dev* dev); void MSSTC_UpdateAngle(struct MOTOR_STEP_SPEED_T_C_ATY_Dev* dev, uint32_t turn, float angle); #endif /* __MOTOR_STEP_SPEED_T_C_ATY_H */ /******************************** End Of File *********************************/