Stepping motor and dynamic trajectory planning method and control system

CN122801832BActive Publication Date: 2026-10-27SHENZHEN AREED TECHNOGY CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202611311946.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2026-08-27
Publication Date
2026-10-27
Estimated Expiration
2046-08-27

AI Technical Summary

Technical Problem

[0007]本发明要解决的技术问题在于克服现有技术中步进电机的高频响应和精度不足的缺陷,从而提供一种步进电机及动态轨迹规划方法和控制系统

Benefits of technology

[0018]有益效果:本发明公开了一种步进电机及动态轨迹规划方法和控制系统,通过配置第一定时中断和第二定时中断分别执行运动学计算与脉冲输出,将复杂的轨迹解算与底层硬件脉冲翻转完全解耦。这种双中断分离架构从根本上释放了底层硬件资源,避免了高频脉冲发送过程中因夹杂大量运算而导致的中断超时问题,保证了脉冲输出的绝对均匀与平滑,有效消除了电机高速运行时的抖动与丢步现象,大幅提升了系统的响应速度与定位精度。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122801832B_ABST
    Figure CN122801832B_ABST
Patent Text Reader

Abstract

The application discloses a kind of stepper motor and dynamic trajectory planning method and control system, method includes configuring first timing interrupt to execute kinematics calculation, second timing interrupt executes pulse output;In the first interrupt period, the estimated deceleration step number of current speed brake to zero is calculated, if receiving reverse new position instruction and the remaining step number is less than the estimated deceleration step number, then do not exit current motion main state, rewrite target step number as the sum of current cumulative step number and estimated deceleration step number, control motor original direction deceleration;In the second interrupt period, according to target step number, pulse output and accumulation are executed, when target step number is reached, pulse is turned off and reverse restart flag is set;In the first interrupt period, if the flag is detected, do not exit main state directly load reverse parameter and restart pulse output.The application realizes calculation and pulse output decoupling, improves high frequency response and precision, and realizes seamless reverse restart.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of stepper motor control technology, specifically relating to a stepper motor, a dynamic trajectory planning method, and a control system. Background Technology

[0002] With the rapid development of industrial automation technology, stepper motors have been widely used in various automated equipment due to their advantages such as high positioning accuracy and simple control.

[0003] Currently, most traditional stepper motor control algorithms employ a single-threaded or single-interrupt coupled processing approach, meaning that complex kinematic acceleration / deceleration calculations and pulse output signal toggling are performed simultaneously within the same timer interrupt. This approach presents the system with numerous challenges during operation.

[0004] On the one hand, as the motor speed increases, the pulse output frequency increases dramatically. If a large number of complex mathematical operations are mixed in the pulse transmission interrupt, it is very easy to cause the interrupt execution timeout, which will cause uneven pulse transmission, motor jitter, step loss and reduced positioning accuracy.

[0005] On the other hand, traditional control logic lacks dynamic trajectory correction capabilities. When the motor receives a new position command, especially a reverse motion command, during operation, the system usually needs to send an emergency stop command first, wait for the motor to come to a complete stop, and then replan the new trajectory and start again. This approach not only increases the processing cycle time of the equipment but also easily causes mechanical shocks during start-stop switching, affecting the operating efficiency and transmission life of the equipment.

[0006] Therefore, how to improve the high-frequency response and accuracy of stepper motors, and achieve smooth connection of dynamic trajectories without interruption when receiving reverse commands, has become a technical problem that urgently needs to be solved by those skilled in the art. Summary of the Invention

[0007] The technical problem to be solved by the present invention is to overcome the defects of high frequency response and insufficient accuracy of stepper motors in the prior art, thereby providing a stepper motor, a dynamic trajectory planning method and a control system.

[0008] A dynamic trajectory planning method for a stepper motor includes the following steps: During the first timer interrupt cycle, the current instantaneous speed and preset deceleration of the motor are obtained, and the estimated number of deceleration steps required to brake to zero at the current speed are calculated. During the first timer interrupt cycle, if a new position command is received in the opposite direction, and the remaining number of steps from the current position to the new target position is less than the estimated deceleration steps, then the current main motion state is not exited, the current target step number is rewritten as the sum of the current cumulative step number and the estimated deceleration steps, and the motor is controlled to decelerate in the original direction. During the second timer interrupt cycle, pulse output and cumulative step count are performed according to the rewritten target step count. When the cumulative step count reaches the rewritten target step count, the pulse output is turned off and the reverse restart flag is set. If the reverse restart flag is detected during the first timer interrupt period, the current motion master state is not exited, the reverse motion parameters of the new position command are loaded, and the pulse output is restarted.

[0009] Furthermore, the first timer interrupt has exclusive write rights to the target number of steps, and the second timer interrupt has read rights to the target number of steps. The second timer interrupt has exclusive write rights to the current cumulative step count and absolute position, while the first timer interrupt has read rights to the current cumulative step count and absolute position. After the second timer interrupt reaches the target number of steps and turns off the pulse output, it sets the status flag bit. The status switching and new trajectory loading are handled asynchronously by the first timer interrupt.

[0010] Furthermore, when calculating the estimated number of deceleration steps, a fixed-point number calculation format is adopted, the velocity and deceleration registers are shifted, and integer multiplication and displacement operations are used for calculation; Before calculation, a non-zero validity check is performed on the preset deceleration. If a deceleration of zero is detected, the calculation is refused.

[0011] Furthermore, it also includes trajectory planning steps for probe fixed-length mode: After startup, it moves towards the target at the set search speed and continuously monitors external probe signals; When the edge of the probe signal is captured, the current cumulative step count is directly latched through a hardware interrupt; In the next first timer interrupt cycle, the original total number of steps of the moving target is overwritten as the sum of the latched cumulative number of steps and the preset long distance, and the trajectory target speed is rewritten as a fixed-length propulsion speed lower than the search speed; Determine the relationship between the current remaining available steps and the estimated deceleration steps at the current speed. If the current remaining available steps are less than the estimated deceleration steps, it is determined that inertial overtravel has occurred, and deceleration and reverse compensation are performed.

[0012] Furthermore, the deceleration and reverse compensation process specifically includes: Set the reverse restart flag, rewrite the target number of steps to the sum of the current cumulative number of steps and the estimated deceleration number of steps, and drive the motor to decelerate to zero in the original direction of motion; When the speed returns to zero, the current main motion state is maintained without exiting, and the overtravel error value that exceeds the preset long endpoint is calculated; Load the reverse motion parameters, control the motor to reverse at a preset low speed for the number of steps corresponding to the overtravel error value, and stop at the preset long end position.

[0013] Furthermore, it also includes the origin regression step: Move towards the origin sensor at the set search speed. At the instant the origin sensor is triggered, calculate the braking steps at the current speed and decelerate to a stop. Control the motor to reverse and exit the sensor's sensing area until the sensor signal is reset; Switch the target speed to a crawling speed lower than the search speed and move closer to the sensor. During the crawling process, when the edge of the sensor signal is captured again, the current absolute position counter is directly rewritten to zero via a hardware interrupt, and the pulse output is turned off.

[0014] Furthermore, during the process of moving towards the origin sensor at the search speed, if the hardware negative limit sensor is triggered first, an external hardware interrupt is triggered, and the sub-state machine is rewritten to the limit rebound state. Calculate the safe braking distance in real time and decelerate to zero; Without exiting the current origin and returning to the main state, the direction of movement is reversed, and the search for the origin is switched to the opposite direction.

[0015] Furthermore, instructions are preloaded and flowed through a multi-mode state machine. The main states include at least the idle state, jogging state, origin return state, absolute positioning state, relative positioning state, probe fixed length state, and stopping state. The host computer or main loop instruction is written into the preload register, which is triggered to start or update by the status detection mechanism. The status transition and speed update are handled by the first timer interrupt, and the pin level is flipped and the boundary is determined by the second timer interrupt. After reaching the target number of steps or triggering the brake, it returns to the idle state.

[0016] A stepper motor dynamic trajectory planning and control system, comprising: The time slice calculation module is configured to run in the first timer interrupt cycle to perform kinematic calculations, obtain the current instantaneous speed and preset deceleration of the motor, and calculate the estimated deceleration steps required to brake to zero at the current speed. If a new position command is received in the opposite direction and the remaining steps are less than the estimated deceleration steps, the module does not exit the current main motion state, but rewrites the current target step number as the sum of the current cumulative steps and the estimated deceleration steps, and controls the motor to decelerate in the original direction. If a reverse restart flag is detected, the module does not exit the current main motion state, loads the reverse motion parameters of the new position command, and restarts pulse output. The pulse execution module is configured to run in the second timer interrupt cycle, and is used to perform pulse output and cumulative step accumulation according to the rewritten target step number. When the cumulative step number reaches the rewritten target step number, the pulse output is turned off and the reverse restart flag is set.

[0017] A stepper motor includes a motor body, a processor, and a memory. The memory stores a computer program. When the processor calls the computer program, it can implement the dynamic trajectory planning method of the stepper motor described above to control the operation of the motor body.

[0018] Beneficial Effects: This invention discloses a stepper motor, a dynamic trajectory planning method, and a control system. By configuring a first timer interrupt and a second timer interrupt to perform kinematic calculations and pulse output respectively, the complex trajectory calculation is completely decoupled from the underlying hardware pulse flipping. This dual-interrupt separation architecture fundamentally releases underlying hardware resources, avoids interrupt timeout problems caused by a large amount of computation during high-frequency pulse transmission, ensures absolute uniformity and smoothness of pulse output, effectively eliminates jitter and step loss during high-speed motor operation, and significantly improves the system's response speed and positioning accuracy.

[0019] Simultaneously, upon receiving a reverse new position command and finding insufficient remaining steps for direct braking, the system dynamically rewrites the target step count and controls the motor to decelerate in the original direction. Once the speed reaches zero, a reverse restart flag is set, and then the system directly loads reverse parameters to restart without exiting the current main motion state. This mechanism completely eliminates redundant processes in traditional control, achieving zero-stop dynamic trajectory correction and seamless reverse connection. It significantly shortens the equipment's processing cycle time, greatly reduces the mechanical shock caused by start-stop switching, and extends the service life of transmission components. Attached Figure Description

[0020] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0021] Figure 1 This is a schematic flowchart illustrating the main method steps of the present invention; Figure 2 This is a schematic block diagram of the system structure of the present invention. Detailed Implementation

[0022] To make the above-mentioned objectives, features, and advantages of this application more apparent and understandable, the specific embodiments of this application are described in detail below with reference to the accompanying drawings. Many specific details are set forth in the following description to provide a thorough understanding of this application. However, this application can be implemented in many other ways different from those described herein, and those skilled in the art can make similar modifications without departing from the spirit of this application. Therefore, this application is not limited to the specific embodiments disclosed below.

[0023] In the description of this application, it should be understood that the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Therefore, a feature defined as "first" or "second" may explicitly or implicitly include at least one of that feature. In the description of this application, "multiple" means at least two, such as two, three, etc., unless otherwise explicitly specified.

[0024] In this application, unless otherwise expressly specified and limited, the terms "installation," "connection," "joining," and "fixing," etc., should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral part; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; they can refer to the internal communication of two components or the interaction between two components, unless otherwise expressly limited. Those skilled in the art can understand the specific meaning of the above terms in this application according to the specific circumstances.

[0025] Example 1: Reference Figure 1 As shown, this embodiment provides a dynamic trajectory planning method for a stepper motor. This method proposes a dynamic trajectory planning architecture that completely decouples time-slice acceleration / deceleration calculation from underlying pulse execution. Through the collaborative work of two independent interrupt mechanisms, combined with a dynamically calculated predicted deceleration step model, it achieves zero-stop real-time trajectory correction and microsecond-level probe cascade response. The method specifically includes the following steps: First, a first timer interrupt is configured to perform kinematic calculations, and a second timer interrupt is configured to perform pulse output, namely the time slice calculation module MC_TimeBase_Handler and the pulse execution module MC_PWM_Handler. In a practical embedded environment, the first timer interrupt relies on a function triggered by a timer periodic overflow interrupt (i.e., time slice calculation) and runs at a fixed low-frequency period; the second timer interrupt (i.e., pulse execution) runs at a high-frequency period. Instructions from the host computer or main loop are written to the preload register, and the status detection mechanism MC_StatusCheck triggers the start or dynamic update calculation of S_stop and updates the tn period. The first timer interrupt handles the state transition and speed update, and the second timer interrupt performs pin level toggling and boundary judgment. After reaching the target number of steps or triggering braking, the system returns to an idle state.

[0026] This method uses a multi-mode state machine for instruction preloading and transition. The main states include at least the idle state (MOTOR_STATE_IDLE), jogging state (MOTOR_STATE_JOG), origin return state (MOTOR_STATE_HOMING), absolute positioning state (MOTOR_STATE_ABSOLUTE), relative positioning state (MOTOR_STATE_RELATIVE), probe fixed length state (MOTOR_STATE_FEED), and stopping state (MOTOR_STATE_STOPPING). Among them, the idle state is the initial or reset state of the motor and does not output pulses; the jog state executes the manual continuous operation mode; the origin return state executes two-level high-precision zero-finding action, controlled by the homing_status sub-state machine; the absolute positioning state is controlled by the trajectory planning of the target's absolute position; the relative positioning state is controlled by the incremental trajectory planning relative to the current position; the probe fixed length state is a flexible length measurement or cutting state in response to external hardware interrupts, controlled by the move_feed_status fixed length sub-state machine; and the stopping state is a transition state that is forcibly entered to decelerate to zero in response to deceleration braking commands.

[0027] Within the first timer interrupt cycle, the current instantaneous speed and preset deceleration of the motor are acquired, and the estimated number of deceleration steps required to brake to zero at the current speed are calculated. The core algorithm's calculations are entirely based on the real-time operating status parameters captured in the current time slice and the system's preset configuration parameters, including the current instantaneous speed. Preset system deceleration and minimum safe speed In this embodiment, 100Hz is preferred to prevent timer calculation overflow.

[0028] According to classical kinematics, the displacement relationship of an object decelerating uniformly from an initial velocity to a final velocity of zero is: ; in, Indicates the final velocity. Indicates the initial velocity, Indicates deceleration. This represents the displacement due to deceleration. Let the final velocity be... initial velocity deceleration Substituting into the above formula, we can obtain the estimated number of deceleration steps.

[0029] Estimated deceleration steps The core physical formula is: ; in, To estimate the number of deceleration steps, i.e., S_stop, This represents the actual operating speed of the motor within the current time slice (in pulses per second, Hz). The magnitude of the deceleration of the motion trajectory configured for the system (in pulses per square second, Hz / s²).

[0030] When calculating the estimated deceleration steps, a fixed-point number calculation format is adopted, the velocity and deceleration registers are shifted, and integer multiplication and displacement operations are used for calculation; before calculation, the preset deceleration is checked for non-zero validity, and if the deceleration is detected to be zero, the calculation is rejected.

[0031] Due to the limited resources of the floating-point arithmetic unit in low-end microcontrollers, this embodiment introduces a fixed-point calculation format (that is, converting floating-point numbers multiplied by 2 to the power of 16 into integer operations). The q16_t fixed-point calculation format is introduced, and efficient integer multiplication and shift operations Q16_MUL are used to replace floating-point multiplication. In the specific implementation of the code, the real-time calculation formula is as follows: ; Here, step_stop is the estimated number of deceleration steps. This is the current instantaneous velocity register value. This is a preset deceleration register value. During the instruction parsing phase, such as the MC_Stop or MC_MoveAbsolute phase, if the preset deceleration is detected to be 0, an error MOTOR_ERROR_PARAMETER is immediately thrown and the calculation is refused. This avoids causing a division-by-zero exception at the underlying level, which could lead to a microcontroller crash. This fundamentally ensures that the time slice calculation module can instantly complete trajectory prediction within low-frequency cycles.

[0032] During the first timer interrupt cycle, if a new position command is received in the opposite direction, and the remaining number of steps from the current position to the new target position is less than the estimated deceleration steps, then the current main motion state is not exited. Instead, the target number of steps currently being executed is rewritten as the sum of the current cumulative number of steps and the estimated deceleration steps, and the motor is controlled to decelerate in the original direction.

[0033] The system first checks the reverse restart flag. If the flag is triggered (restart_flag==1), the state machine does not exit the current motion master state but automatically takes over the trajectory, forcing the motor to decelerate to zero at the currently set deceleration rate. At this point, the system forcibly rewrites the current target number of steps as the current number of steps plus the estimated deceleration steps. The system does not exit the current motion state machine, forcing the motor to smoothly decelerate to zero in the original direction. This mechanism eliminates mechanical jerking and the waiting time for emergency stops issued by the host computer. During normal deceleration, when the motor approaches the original target endpoint and the remaining steps... At that moment, the system immediately rewrites the speed update strategy, causing the speed to decrease frame by frame according to the step size delta_dv, ensuring that the motor speed drops to the limit just as it reaches the end point. Shutdown.

[0034] During the second timer interrupt cycle, pulse output and cumulative step count are executed according to the rewritten target step count. When the cumulative step count reaches the rewritten target step count, the pulse output is turned off and the reverse restart flag is set, such as setting restart_flag=2. The second timer interrupt is only responsible for switching the state of the high-frequency pulse direction pin, incrementing and decrementing the current absolute position and step counter. Specifically, the physical level of the hardware GPIO is directly controlled according to the direction flag bit of the current trajectory, without any intermediate logic judgment; the absolute position counter increments if the direction is positive and decrements if the direction is negative, and the current step counter increments regardless of whether it is positive or negative. When the trigger condition is met, i.e., the current cumulative step count reaches the target total step count preloaded by the time slice module, the underlying shutdown function is immediately and unconditionally called to forcibly turn off the pulse output or close the timer channel, and the instantaneous velocity register is forcibly cleared to zero. Then, the corresponding motion completion state is modified, such as MOTOR_POSITION_DONE, to release the main motion state machine and return to the idle state.

[0035] During the first timer interrupt cycle, if the reverse restart flag is detected, the system does not exit the current motion master state, but loads the reverse motion parameters of the new position command and restarts the pulse output. When the pulse interrupt detects that the motor is completely stationary and the reverse restart flag is set, the time slice solver directly reloads the direction and number of steps of the new reverse command without returning to the idle state, achieving a seamless restart.

[0036] To achieve conflict-free coordination, the first timer interrupt has exclusive write rights to the target step count, and the second timer interrupt has exclusive read rights to the target step count. The second timer interrupt also has exclusive write rights to the current cumulative step count and absolute position, while the first timer interrupt has exclusive read rights to these. After the cumulative step count reaches the target step count and the pulse output is turned off, the second timer interrupt sets the status flag. Status switching and new trajectory loading are handled asynchronously by the first timer interrupt. For example, `move_absolute_status` is overwritten to `MOTOR_POSITION_DONE`, and `run_state` is rewritten to `MOTOR_STATE_IDLE`. Subsequent mechanical residual echoes, error reporting, or dynamic multi-mode transitions are all handled asynchronously by the low-frequency time-slice module. There are no concurrent read / write conflicts between high-frequency and low-frequency interrupts, fundamentally removing critical section locks and ensuring that the execution time of a single high-frequency interrupt remains constant at the level of hundreds of nanoseconds.

[0037] For scenarios involving external probe sensors, the system initiates movement before determining the final precise stopping boundary, dynamically locking the physical coordinate reference point through edge triggering of external real-time hardware signals. When the host computer or main control program is performing continuous material processing, synchronous conveying, or position correction, it cannot predict the exact size or arrival time of each workpiece and enters this mode upon receiving an interruption command. The probe input interface receives hardware edge interrupt signals from external photoelectric sensors, proximity switches, or microswitches.

[0038] This embodiment also includes the trajectory planning steps for the probe fixed-length mode MC_MoveFeed: after startup, at the set search speed... The device moves towards the target direction while continuously monitoring external probe signals. When the edge of the probe signal is detected, the current cumulative step count is directly latched via a hardware interrupt. In the next first timer interrupt cycle, the original total number of steps of the moving target is overwritten as the sum of the latched cumulative step count and the preset long distance, and the trajectory target speed is rewritten to be lower than the search speed. constant length propulsion speed The system determines the relationship between the current remaining available steps and the estimated deceleration steps at the current speed. If the current remaining available steps are less than the estimated deceleration steps, it is determined that inertial overtravel has occurred, and deceleration and reverse compensation are performed. The probe fixed-length sub-state machine includes the search and positioning segment MOTOR_FEED_MOVE, the fixed-length propulsion segment MOTOR_FEED_FEED, and the fixed-length completion segment MOTOR_FEED_DONE.

[0039] During the search and localization phase, the vehicle moves towards the target at a high search speed; when an external feature point triggers the sensor, the target position overwrite formula is: ; in, The updated total number of steps for the exercise target. The physical cumulative number of steps latched. The system is preset with a precise control displacement, i.e., a preset fixed-length distance, feed_distance. The system directly rewrites the trajectory target velocity into a lower fixed-length advance speed to ensure mechanical accuracy and smoothness during the final cut or bonding.

[0040] The deceleration and reverse compensation process specifically includes: setting the reverse restart flag, rewriting the target step count as the sum of the current cumulative step count and the estimated deceleration step count, and driving the motor to decelerate to zero in the original direction of motion; when the speed reaches zero, maintaining the current main motion state without exiting, and calculating the overtravel error value that exceeds the preset long endpoint; loading the reverse motion parameters, controlling the motor to reverse at a preset low speed for the number of steps corresponding to the overtravel error value, and stopping at the preset long endpoint position. When the probe signal is triggered, the minimum estimated deceleration step count required for the motor to decelerate from high speed to standstill is calculated. It may be greater than the preset fixed distance. The system will display the current remaining number of available steps. Estimated braking steps at current speed Perform a hard boundary comparison. If overtravel is determined, calculate the overtravel error value due to inertia, using the following formula: ; in, This is the overtravel error value. This represents the number of steps corresponding to the actual stopping position of the motor. The system automatically loads the reverse motion parameters and controls the motor to reverse at a very high precision crawling speed to make up for the number of steps corresponding to the overtravel error value. Finally, it stops precisely and without any jerks at the expected compensation point. The sub-state machine then transitions to the fixed-length completion segment and returns to the idle state.

[0041] For the origin regression scenario, this embodiment also includes the origin regression step MC_Home: at a set search speed Move towards the origin sensor; upon triggering the origin sensor, calculate the braking steps at the current speed and decelerate to a stop; control the motor to reverse and exit the sensor's sensing area until the sensor signal is reset; switch the target speed to a speed lower than the search speed. Origin crawling speed (Preferably 1 / 10 or even lower of the search speed) it re-approaches the sensor; during the crawling process, when the edge of the sensor signal is captured again, the current absolute position counter is directly rewritten to zero via a hardware interrupt, and the pulse output is turned off. This process is controlled by a sub-state machine including the origin search state MOTOR_HOMING_SEARCH, the deceleration disengagement state MOTOR_HOMING_SEARCH_HOME, the extreme rebound state MOTOR_HOMING_SEARCH_NL, the origin crawling state MOTOR_HOMING_FINE, and the zero-return completion states MOTOR_HOMING_FINE_DONE and MOTOR_HOMING_DONE. During the origin search state, it moves at high speed, and the braking steps are calculated at the moment of triggering. It smoothly decelerates to a standstill and then reverses to exit the sensing area. While crawling at the origin, the motor switches to extremely low speed and approaches again. When the edge trigger is captured again, the hardware interrupt service routine responds instantaneously within microseconds, forcibly rewriting the absolute position counter to zero (i.e., position=0) and immediately and unconditionally shutting off the pulse output (calling Motor_Port_MoveStop()). Because the speed is extremely low at this point, the inertia is close to zero, and the motor stops instantly, directly completing the physical calibration of the absolute zero point and eliminating the time lag error caused by software scheduling.

[0042] In the search speed During the movement towards the origin sensor, if the hardware negative limit sensor (Negative Limit, nl) is triggered first, an external hardware interrupt is triggered, rewriting the sub-state machine into a limit rebound state. The safe braking distance is calculated in real time, and the speed is reduced to zero. Without exiting the current origin and returning to the main state, the direction of movement is reversed, switching to a reverse search for the origin. Specifically, if the hardware negative limit sensor is triggered first during high-speed search, the system instantly triggers an external hardware interrupt to enter the limit rebound state, using the current speed to calculate the safe braking distance in real time. It then performs a smooth deceleration, reducing the speed to zero before reaching a physical hard limit. Subsequently, without exiting the origin and returning to the main state machine, the system adaptively reverses the direction of motion, forcibly switching to a high-speed reverse search. This mechanism achieves seamless soft transition, avoids system errors and crashes, and greatly improves the self-healing capability of automated equipment and the safety of industrial sites.

[0043] Through the refined design of the multi-mode state machine, this zero-return scheme achieves decoupling between high speed and high precision: In terms of hardware-level high-frequency response, the edge transition judgment, final latching, and pulse forced shutdown during the two-stage zero-return process are all completed synchronously in the highest-priority hardware interrupt or pulse execution module, ensuring the hard real-time performance of signal acquisition; in terms of software-level low-frequency calculation, the first-stage braking step prediction, reverse exit trajectory coverage, and rebound smooth trajectory reconstruction after triggering the limit sensor are all asynchronously completed by the low-frequency time-slice calculation module. The unidirectional collaboration between the high- and low-frequency state machines ensures the purity and stability of the high-frequency pulse stream, achieving extremely high accuracy in repeatedly finding the origin.

[0044] Example 2: Reference Figure 2 As shown, based on the same inventive concept as Embodiment 1, this embodiment provides a stepper motor dynamic trajectory planning and control system, including: The time-slice calculation module MC_TimeBase_Handler is configured to run in the first timer interrupt cycle. It performs kinematic calculations, obtains the motor's current instantaneous speed and preset deceleration, and calculates the estimated deceleration steps required to brake to zero at the current speed. If a new position command is received in the opposite direction, and the remaining steps are less than the estimated deceleration steps, the module does not exit the current motion main state. Instead, it rewrites the current target step count as the sum of the current cumulative steps and the estimated deceleration steps, controlling the motor to decelerate in the original direction. If a reverse restart flag is detected, the module does not exit the current motion main state, loads the reverse motion parameters of the new position command, and restarts pulse output. This module performs trajectory prediction through a fixed-point acceleration architecture and is responsible for the transitions of the multi-mode state machine and asynchronous soft transitions, separating complex calculations from high-frequency pulse interrupts.

[0045] The pulse execution module MC_PWM_Handler is configured to run in the second timer interrupt cycle. It is used to execute pulse output and accumulate steps based on the modified target step number. When the accumulated step number reaches the modified target step number, it shuts off the pulse output and sets the reverse restart flag. This module is only responsible for directly controlling the physical level of the hardware pins based on the direction flag bit, executing the increment / decrement of the absolute position and current step number, and determining the hardware hard boundary of the target step number. When the trigger condition is met, it immediately shuts off the pulse and clears the speed register.

[0046] The time-slice calculation module has exclusive write rights to the target step count and read rights to the current cumulative step count and absolute position; the pulse execution module has read rights to the target step count and exclusive write rights to the current cumulative step count and absolute position. There are no concurrent conflicts between high-frequency and low-frequency interrupts, fundamentally removing critical section locks and ensuring the purity and stability of the high-frequency pulse stream.

[0047] Example 3: Based on the same inventive concept as Embodiment 1 and Embodiment 2, this embodiment provides a stepper motor, including a motor body, a processor, and a memory. The memory stores a computer program, and when the processor calls the computer program, it can implement the dynamic trajectory planning method of the stepper motor as described in Embodiment 1 to control the operation of the motor body.

[0048] This stepper motor overcomes the pulse jitter problem caused by single-threaded processing through a collaborative hardware and software design, enabling even ordinary microcontrollers to output extremely smooth high-frequency control pulses. The motor operates at high speeds without abnormal noise or missed steps. Simultaneously, relying on dynamic estimation of deceleration steps and a reverse restart mechanism, the device achieves smooth transitions and flexible commutation when frequently changing target positions, significantly reducing impact wear on mechanical transmission components and extending mechanical lifespan.

[0049] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0050] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this patent application should be determined by the appended claims.

Claims

1. A dynamic trajectory planning method for a stepper motor, characterized in that, Includes the following steps: During the first timer interrupt cycle, the current instantaneous speed and preset deceleration of the motor are obtained, and the estimated number of deceleration steps required to brake to zero at the current speed are calculated. During the first timer interrupt cycle, if a new position command is received in the opposite direction, and the remaining number of steps from the current position to the new target position is less than the estimated deceleration steps, then the current main motion state is not exited, the current target step number is rewritten as the sum of the current cumulative step number and the estimated deceleration steps, and the motor is controlled to decelerate in the original direction. During the second timer interrupt cycle, pulse output and cumulative step count are performed according to the rewritten target step count. When the cumulative step count reaches the rewritten target step count, the pulse output is turned off and the reverse restart flag is set. If the reverse restart flag is detected during the first timer interrupt period, the current motion master state is not exited, the reverse motion parameters of the new position command are loaded, and the pulse output is restarted.

2. The dynamic trajectory planning method for a stepper motor according to claim 1, characterized in that, The first timer interrupt has exclusive write rights to the target number of steps, and the second timer interrupt has read rights to the target number of steps; The second timer interrupt has exclusive write rights to the current cumulative step count and absolute position, while the first timer interrupt has read rights to the current cumulative step count and absolute position. After the second timer interrupt reaches the target number of steps and turns off the pulse output, it sets the status flag bit. The status switching and new trajectory loading are handled asynchronously by the first timer interrupt.

3. The dynamic trajectory planning method for a stepper motor according to claim 1, characterized in that, When calculating the estimated number of deceleration steps, a fixed-point number calculation format is used, the velocity and deceleration registers are shifted, and integer multiplication and displacement operations are used for calculation. Before calculation, a non-zero validity check is performed on the preset deceleration. If a deceleration of zero is detected, the calculation is refused.

4. The dynamic trajectory planning method for a stepper motor according to claim 1, characterized in that, It also includes trajectory planning steps for probe fixed-length mode: After startup, it moves towards the target at the set search speed and continuously monitors external probe signals; When the edge of the probe signal is captured, the current cumulative step count is directly latched via a hardware interrupt; In the next first timer interrupt cycle, the target number of steps is overwritten as the sum of the latched cumulative number of steps and the preset long distance, and the target speed is rewritten as a fixed-length advance speed lower than the search speed. Determine the relationship between the current remaining available steps and the estimated deceleration steps at the current speed. If the current remaining available steps are less than the estimated deceleration steps, it is determined that inertial overtravel has occurred, and deceleration and reverse compensation are performed.

5. The dynamic trajectory planning method for a stepper motor according to claim 4, characterized in that, The deceleration and reverse compensation include: Set the reverse restart flag, rewrite the target number of steps as the sum of the current cumulative number of steps and the estimated deceleration number of steps, and drive the motor to decelerate to zero in the original direction of motion; When the speed returns to zero, the current main motion state is maintained without exiting, and the overtravel error value of crossing the preset long distance endpoint is calculated; Load the reverse motion parameters, control the motor to move in the reverse direction at a preset low speed for the number of steps corresponding to the overtravel error value, and stop at the endpoint of the preset long distance.

6. The dynamic trajectory planning method for a stepper motor according to claim 1, characterized in that, It also includes the origin regression step: Move towards the origin sensor at the set search speed. At the instant the origin sensor is triggered, calculate the braking steps at the current speed and decelerate to a stop. Control the motor to reverse and exit the sensor's sensing area until the sensor signal is reset; Switch the target speed to a crawling speed lower than the search speed and move closer to the sensor. During the crawling process, when the edge of the sensor signal is captured again, the current absolute position counter is directly rewritten to zero via a hardware interrupt, and the pulse output is turned off.

7. The dynamic trajectory planning method for a stepper motor according to claim 6, characterized in that, During the movement towards the origin sensor at the set search speed, if the hardware negative limit sensor is triggered first, an external hardware interrupt is triggered, and the sub-state machine is rewritten to the limit rebound state. Calculate the safe braking distance in real time and decelerate to zero; Without exiting the current origin and returning to the main state, the direction of movement is reversed, and the search for the origin is switched to the opposite direction.

8. The dynamic trajectory planning method for a stepper motor according to claim 1, characterized in that, Instruction preloading and flow are performed through a multi-mode state machine. The main states include at least the idle state, jogging state, origin return state, absolute positioning state, relative positioning state, probe fixed length state, and stopping state. The host computer or main loop instruction is written into the preload register, which is triggered to start or update by the status detection mechanism. The status transition and speed update are handled by the first timer interrupt, and the pin level is flipped and the boundary is determined by the second timer interrupt. After reaching the target number of steps or triggering the brake, it returns to the idle state.

9. A control system for a stepper motor, characterized in that, include: The time slice calculation module is configured to run in the first timer interrupt cycle to perform kinematic calculations, obtain the current instantaneous speed and preset deceleration of the motor, and calculate the estimated number of deceleration steps required to brake to zero at the current speed. If a new position command is received in the opposite direction, and the remaining number of steps from the current position to the new target position is less than the estimated deceleration steps, then the current main motion state is not exited. Instead, the current target step number is rewritten as the sum of the current cumulative step number and the estimated deceleration steps, and the motor is controlled to decelerate in the original direction. If a reverse restart flag is detected, the current motion master state is not exited; instead, the reverse motion parameters of the new position command are loaded and the pulse output is restarted. The pulse execution module is configured to run in the second timer interrupt cycle, and is used to perform pulse output and cumulative step accumulation according to the rewritten target step number. When the cumulative step number reaches the rewritten target step number, the pulse output is turned off and the reverse restart flag is set.

10. A stepper motor, characterized in that, The device includes a motor, a processor, and a memory, wherein the memory stores a computer program, and the processor, when calling the computer program, is able to implement the dynamic trajectory planning method for a stepper motor as described in any one of claims 1 to 8, so as to control the operation of the motor.

Citation Information

Patent Citations

  • Electronic timepiece and motor control circuit

    CN111740659A

  • Motor control digital circuit and driving system

    CN120979241A