A method, system and device for multi-mode linkage control of a stepper motor
Patent Information
- Application Number
- CN202611290799.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-25
- Publication Date
- 2026-09-22
AI Technical Summary
普通匀速、简单暂停或往复动作的视觉表现也较为单一,模式切换时容易残留方向、暂停、随机段或顿挫段状态;音频联动若在无音频时直接长时间停机,则容易被误认为卡顿或故障,并可能造成重新启动时的机械冲击
本申请通过将持久化开关与联动门控进行联合控制并共同判断电机运行条件,使步进电机能够在光源机联动条件变化时可靠启停;通过引入基于累计时间的步进补偿机制,降低主循环调用延迟对电机速度的影响,使电机在通信、灯效刷新等任务同时运行时仍能保持较稳定的平均速度;并在统一调度框架下实现多种动态运行效果,提高了光源机步进电机控制的准确性、连续性和扩展性。
Smart Images

Figure CN122801831A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of stepper motor technology, and in particular to a multi-mode linkage control method, system and device for stepper motors. Background Technology
[0002] In lighting products, lighting effects, motor rotation, and music detection are typically treated as separate functions. The motor section usually only offers simple on / off switching, fixed-speed rotation, or a few preset actions, such as continuous forward rotation, timed stop, or fixed-angle reciprocating motion. In some products with a music mode, the music signal is mainly used to drive the lighting changes; the motor still runs at a fixed speed and cannot produce significant dynamic changes in response to the audio, resulting in a rather monotonous overall performance.
[0003] In stepper motor control, a common approach is to drive the phase sequence output through a timer or main cycle, performing forward or reverse steps according to a fixed stepping cycle, and directly converting the speed level into the step interval. This method is simple in structure, but lacks a unified linkage between user motor settings and light switches, remote control main switches, application switches, or audio inputs; when the lights are off or the entire unit is turned off, the motor may still run, or temporarily turning off the lights may incorrectly modify the motor's persistent switch.
[0004] Furthermore, if the motor task compensates for at most one step per call, when the main loop is occupied by communication parsing, light refreshing, or other tasks, the task call interval becomes longer, and the motor speed will decrease significantly, even appearing as if it is not turning. Integer millisecond timing will also cause cumulative errors in non-integer step cycles. The visual representation of ordinary constant speed, simple pause, or reciprocating motion is also relatively monotonous, and it is easy to leave behind directional, pause, random segment, or jerky segment states when switching modes; if the audio linkage stops for a long time without audio, it can easily be mistaken for a stutter or malfunction, and may cause mechanical shock when restarting.
[0005] Therefore, the existing technology has at least the following technical problems: the persistent setting of the motor and the temporary linkage conditions are not separated; it is difficult to balance speed accuracy and main loop delay compensation when scheduling fixed delay and integer time; multiple dynamic effects lack a unified control framework and mode switching is prone to state residue; and audio linkage is difficult to achieve smooth operation when there is audio and perceptible stuttering when there is no audio. Summary of the Invention
[0006] The purpose of this application is to provide a multi-mode linkage control method, system, and device for stepper motors to improve the above-mentioned problems in the prior art.
[0007] For the purposes mentioned above, this application provides the following technical solution: The first aspect of this application provides a multi-mode linkage control method for a stepper motor, including: The stepper motor is determined to be in an allowed operating state by reading its persistent switch and linkage gate control. If the persistent switch is in the open state and the linkage gate control is in the open state, the stepper motor is determined to be in an allowed operating state. If the stepper motor is in a permitted operating state, the stepping cycle of the stepper motor is determined according to the current speed level. The execution time difference between the current motor control task and the previous motor control task is added to the scheduling accumulation. When the scheduling accumulation exceeds the stepping cycle, a phase sequence step is executed according to the operating rules corresponding to the current motor mode. The scheduling accumulation is updated by subtracting the stepping cycle from the scheduling accumulation. The current motor mode is one of a number of preset switchable motor modes, and different motor modes correspond to different phase sequence stepping operating rules.
[0008] Furthermore, the state of the persistent switch is determined by receiving the motor switch command issued by the user; the state of the linkage door control is determined by the light switch state of the light source machine, the remote control master switch state, or the interface switch state. If the persistent switch is in the off state or the linkage gate is in the off state, it is determined that the stepper motor is in a state where it is not allowed to run.
[0009] Preferably, when the stepper motor switches from a state where it is not allowed to operate to a state where it is allowed to operate, it immediately performs a phase sequence step and sets the cumulative scheduling amount to 0.
[0010] Further, determining the stepper motor's stepping cycle based on the current speed setting includes: The time required for the stepper motor to rotate one revolution is determined based on the current speed setting, and the time required for the stepper motor to rotate one revolution is inversely proportional to the current speed setting. The stepping cycle is obtained based on the time required for the stepper motor to rotate one revolution and the number of phase sequence steps required for the stepper motor output shaft to rotate one revolution.
[0011] Furthermore, the stepping period and the cumulative scheduling amount are amplified by a preset amplification factor, and subsequent data processing and data storage are performed based on the amplified stepping period and the cumulative scheduling amount. Preferably, after updating the cumulative scheduling amount by subtracting the stepping period from the cumulative scheduling amount, if the updated cumulative scheduling amount exceeds the stepping period, the next phase sequence stepping is executed according to the operating rules corresponding to the current motor mode.
[0012] Preferably, a maximum number of compensation steps is set, and during the execution of the current motor control task, the number of times the phase sequence stepping is executed does not exceed the maximum number of compensation steps.
[0013] Preferably, the motor modes include a basic rotation mode, a half-turn reciprocating mode, an intermittent operation mode, a random speed change mode, and an audio linkage mode, and the internal states of each motor mode are different; If the current motor mode is inconsistent with the previous motor mode, clear the internal state of the current motor mode. The internal state includes at least the direction state, pause state, remaining steps of the segment, and deceleration factor.
[0014] Furthermore, the audio linkage mode includes: Obtain audio detection results; When the audio detection result indicates the presence of valid audio, the stepping cycle is determined based on the highest speed setting of the current speed gear and the first speed factor. When the audio detection result indicates that there is no valid audio, phase sequence stepping is performed between the smooth segment and the stuttering segment. The stepping period of the stuttering segment is determined based on the highest speed of the current speed level and the second speed factor, and the stepping period of the stuttering segment is determined based on the highest speed of the current speed level and the third speed factor. Preferably, the current speed setting is used as the input to the audio detection sensitivity, and the audio detection result is determined based on the input audio detection sensitivity value.
[0015] The second aspect of this application provides a multi-mode linkage control system for a stepper motor, the system being used to execute the multi-mode linkage control method for a stepper motor described in the first aspect of this application.
[0016] A third aspect of this application provides an electronic device, comprising: a processor; and a memory for storing processor-executable instructions; wherein the processor is used for the instructions to implement a stepper motor multi-mode linkage control method as described in the first aspect of this application.
[0017] The fourth aspect of this application provides a storage medium, which is a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, it implements the stepper motor multi-mode linkage control method described in the first aspect of this application.
[0018] The fifth aspect of this application provides a computer program product, which includes a computer program that, when executed by a processor, implements the steps of a multi-mode linkage control method for a stepper motor as described in the first aspect of this application.
[0019] The stepper motor multi-mode linkage control method described above in this application can achieve at least the following technical effects: This application enables the stepper motor to reliably start and stop when the linkage conditions of the light source machine change by jointly controlling the persistent switch and the linkage gate control and jointly judging the motor operating conditions; by introducing a step compensation mechanism based on cumulative time, the impact of the main loop call delay on the motor speed is reduced, so that the motor can maintain a relatively stable average speed when tasks such as communication and lighting effect refresh are running simultaneously; and under the unified scheduling framework, various dynamic operation effects are realized, which improves the accuracy, continuity and scalability of the stepper motor control of the light source machine. Attached Figure Description
[0020] To more clearly illustrate the technical solutions in the specific embodiments of this application or the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0021] Figure 1 This application provides a schematic diagram of a multi-mode linkage control system for a stepper motor. Figure 2 A schematic diagram illustrating the steps of a multi-mode linkage control method for a stepper motor provided in this application embodiment; Figure 3 This is a schematic diagram of a computer device provided in an embodiment of this application.
[0022] Reference numerals: 100, Multi-mode linkage control system for stepper motors; 101, Main control MCU; 102, Stepper motor drive circuit; 103, Motor actuator; 104, Lighting control module; 105, Communication module; 106, Audio detection module; 107, System timing module; 301, Memory; 302, Processor. Detailed Implementation The technical solutions of this application will be clearly and completely described below with reference to the embodiments. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0023] like Figure 1 As shown, this embodiment provides a stepper motor multi-mode linkage control system 100 for driving the rotation of a rotating disk, optical plate, projection plate, or other rotating components inside a light source to produce dynamic light effects of continuous rotation, reciprocating motion, intermittent motion, random speed variation, or audio linkage. The stepper motor multi-mode linkage control system 100 specifically includes: The main control MCU101 is used to run lighting control tasks, motor control tasks, communication parsing tasks, audio detection tasks, and system timing tasks. It reads persistent switches and linkage gate controls, determines the operating status of stepper motors, performs fixed-point time scheduling according to speed levels, and outputs phase sequence control signals according to the current motor mode. The stepper motor drive circuit 102 is connected to the main control MCU 101 and is used to drive the phase sequence control signal and output it to the stepper motor. The stepper motor drive circuit 102 can be adapted to a four-phase stepper motor, a stepper motor with other phases, or a pulse input drive structure. The motor actuator 103 is used to drive the rotating disk, optical sheet, projection sheet, rotating assembly or other mechanical components inside the light source machine to move according to the control state of the stepper motor. The lighting control module 104 is used to output RGB, RGBW or other lighting channels, and to provide the main control MCU 101 with the lighting switch status or the overall machine switch status. The communication module 105 is used to receive motor switch, mode switch, speed gear or light switch commands issued by the user through APP, remote control or other control terminal, and to establish communication with the main control MCU 101, stepper motor drive circuit 102, motor actuator 103, light control module 104 and audio detection module 106. The audio detection module 106 is used to determine whether there is audio input and send the audio detection result to the main control MCU 101. The audio detection module 106 can obtain the audio detection result through microphone ADC sampling, line audio detection, external audio envelope detection chip, digital audio processing module, Bluetooth music data or beat data sent by APP. The system timing module 107 is used to provide a time base for motor control tasks and to provide the time difference between task calls to the main control MCU 101. The system timing module 107 can be composed of an independent timer, or it can be implemented by a timer or periodic task inside the main control MCU 101.
[0024] In one implementation, the motor task counting cycle is 1ms; the system timing module 107 can be set independently or implemented by the timer inside the main control MCU 101.
[0025] Based on the same inventive concept, this embodiment also provides a stepper motor multi-mode linkage control method. Since the stepper motor multi-mode linkage control method is implemented based on the stepper motor multi-mode linkage control system 100 described above, the implementation of the stepper motor multi-mode linkage control method can be referred to the implementation of the stepper motor multi-mode linkage control system 100, and repeated details will not be elaborated further. Although the system described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.
[0026] like Figure 2 As shown, the multi-mode linkage control method for a stepper motor provided in this embodiment specifically includes the following steps: Step S100: Determine whether the stepper motor is in an allowed operating state by reading the persistent switch and linkage gate control of the stepper motor. If the persistent switch is in the open state and the linkage gate control is in the open state, determine that the stepper motor is in an allowed operating state.
[0027] Specifically, in this embodiment, the stepper motor is configured with two operating states: an allowed operating state and an unallowed operating state. A persistent switch for the stepper motor indicates whether the user has explicitly turned the motor on or off. Its state can be received by the communication module 105 from the user's motor switch command via APP or remote control and written to non-volatile memory, thus remaining persistent even after the device is powered on again. A linkage gate indicates whether the current light source meets the temporary linkage conditions. The main control MCU 101 can determine the linkage gate based on the light switch state of the lighting control module 104, the remote control master switch state, the interface switch state, or the overall machine operating state. The linkage gate is typically used as a real-time state and is not written to non-volatile memory. When both the persistent switch and the linkage gate are in the on state, the stepper motor is determined to be in the allowed operating state; when either condition is in the off state, the stepper motor is determined to be in the unallowed operating state, and the output of phase sequence control signals to the stepper motor drive circuit 102 is stopped. By using the above-mentioned combined control conditions, situations such as the motor continuing to run when the lights are turned off, or the user only temporarily turning off the lights but mistakenly turning off the motor's persistent switch, resulting in the motor not being able to restore its original settings when the lights are turned on again, are avoided.
[0028] Furthermore, in step S100, when the stepper motor is in a state where operation is not permitted, a stop reset procedure is executed, including stopping the motor task output and clearing all internal states related to the operation process. These internal states include step accumulation, direction state, mode count, pause state, random deceleration segment state, and audio pause segment state. Therefore, when the motor restarts, it will not continue executing the pause, random deceleration, or audio pause segments remaining from the previous stop, ensuring the determinism of state transitions.
[0029] Furthermore, in step S100, when the stepper motor switches from a disallowed operating state to a permitted operating state, the main control MCU 101 immediately outputs a phase sequence step according to the current direction state and sets the cumulative scheduling amount to 0. This start step is used to eliminate the lack of response caused by waiting for a complete step cycle at low speeds; after the first phase sequence step is executed, the motor control task resumes the subsequent cycle scheduling process according to steps S100~S200. This embodiment, through the above method, enables the motor to respond immediately when it is in the permitted operating state, avoiding the response lag caused by a long current step cycle.
[0030] Optionally, when the linkage gate control is not explicitly set, the linkage gate control can be set to the on state by default when the light brightness is not 0 or the light mode is not off, and the linkage gate control can be set to the off state by default when the light is off.
[0031] Step S200: If the stepper motor is in an allowed operating state, determine the stepping cycle of the stepper motor according to the current speed gear, add the execution time difference between the current motor control task and the previous motor control task to the scheduling accumulation. When the scheduling accumulation exceeds the stepping cycle, perform a phase sequence stepping according to the operating rules corresponding to the current motor mode, and update the scheduling accumulation by subtracting the stepping cycle. The current motor mode is one of a number of preset switchable motor modes, and different motor modes correspond to different phase sequence stepping operating rules.
[0032] Specifically, the communication module 105 receives mode switching commands and speed gear commands issued by the user via APP, remote control, up button, or down button. In this embodiment, preferably, the motor mode can be set to 1 to 5, corresponding to the basic rotation mode, half-turn reciprocating mode, intermittent operation mode, random speed change mode, and audio linkage mode, respectively. When the read mode value is less than 1 or greater than 5, the main control MCU 101 restores it to the default mode. The speed gear can be set to 1 to 10; when the read speed gear is less than 1 or greater than 10, it restores it to the default gear. These settings prevent the motor from entering an unknown state due to communication abnormalities, storage abnormalities, or uninitialized data.
[0033] Preferably, the motor mode is switched cyclically using the up button, down button, or APP command; the motor mode switching command adopts a cyclic switching method, when the previous mode is selected, it returns from the minimum mode to the maximum mode, and when the next mode is selected, it returns from the maximum mode to the minimum mode.
[0034] Further, in step S200, determining the stepper motor's stepping cycle based on the current speed setting includes: Step S201: Determine the time required for the stepper motor to rotate one revolution based on the current speed setting. The time required for the stepper motor to rotate one revolution is inversely proportional to the current speed setting. Step S202: Obtain the stepping cycle based on the time required for the stepper motor to rotate one revolution and the number of phase sequence steps required for the stepper motor output shaft to rotate one revolution.
[0035] Specifically, the main control MCU101 determines the speed level based on the current speed setting. The time T required for the stepper motor to rotate one revolution is determined as shown in Equation 1 below. Current speed setting. The higher the speed, the shorter the time T required for one rotation; current speed gear. The lower the speed setting, the longer the time T required for one rotation. In other words, the time T required for one rotation is proportional to the current speed setting. Inversely proportional to the current speed gear The higher the phase sequence number, the faster the motor rotates. Let N be the number of phase sequence steps required for one revolution of the stepper motor output shaft, and T be the time required for one revolution. The stepping period can then be determined by T / N. N is determined by the stepper motor's phase sequence control method, microstepping method, and reduction mechanism. For example, when using a preset phase sequence table to drive the motor, N can be determined based on the total number of phase sequence steps actually required for one revolution of the output shaft, and updated according to different microstepping methods or transmission ratios.
[0036] (1) For example, in one implementation, the highest speed setting is 10, and the time for one revolution at the highest speed setting is 6000ms. When the current speed setting is d, the time required for the stepper motor to rotate one revolution at the current speed setting is 6000ms × 10 / d. Under the above parameters, the time required for the motor to rotate one revolution at speed 10 is approximately 6000ms / revolution, at speed 5 it is approximately 12000ms / revolution, and at speed 1 it is approximately 60000ms / revolution. Different hardware versions can adjust the time for one revolution at the highest speed according to the motor reduction ratio, load size, noise, and visual experience.
[0037] Furthermore, to reduce the cumulative error caused by integer millisecond timing, the main control MCU 101 amplifies both the stepping cycle and the cumulative scheduling amount according to a preset amplification factor, and stores and calculates them as fixed-point numbers. At the start of each motor control task, the main control MCU 101 reads the execution time difference between the current motor control task and the previous motor control task provided by the system timing module 107, amplifies this execution time difference according to the preset amplification factor, and adds it to the cumulative scheduling amount. When the time difference is 0, the current task ends; when the time difference is not 0, the external cumulative count is cleared or updated, and subsequent calculations begin. When the cumulative scheduling amount is greater than or equal to the stepping cycle, a phase sequence step is executed according to the operating rules corresponding to the current motor mode, and the cumulative scheduling amount is updated by subtracting the stepping cycle. If the execution time difference is large, causing the updated cumulative scheduling amount to still be greater than or equal to the stepping cycle, the next phase sequence step is executed, and the stepping cycle is subtracted again, thereby compensating for steps that should have been executed but were not during the main loop's occupation by communication parsing, light refreshing, or other tasks.
[0038] Furthermore, phase sequence stepping refers to sequentially changing the energizing state of each phase winding of the stepper motor according to a preset phase sequence table, causing the motor rotor to rotate in a predetermined direction. The main control MCU 101 updates the phase sequence state according to the direction, speed factor, or pause state determined by the current mode, and then outputs the corresponding phase sequence control signal to the stepper motor drive circuit 102. During forward operation, the phase sequence state increments, returning to 0 after reaching the maximum phase sequence state; during reverse operation, the phase sequence state decrements, returning to the maximum phase sequence state when the phase sequence state is 0. Each time a phase sequence step is executed, the system first updates the phase sequence state according to the direction, and then calls the motor's underlying drive function to output the current phase sequence. Taking an 8-beat half-step sequence as an example, the phase sequence state can cycle between 0 and 7; in other embodiments, 4 beats, 16 microsteps, or a drive chip pulse input method can also be used. The phase sequence update method described above in this embodiment can support forward rotation, reverse rotation, and forward / reverse switching, and is applicable to various subsequent motor modes, including half-turn reciprocating mode, intermittent operation mode, random speed change mode, and audio linkage mode.
[0039] Preferably, this embodiment sets a maximum number of compensation steps per execution, ensuring that the number of phase sequence steps executed during the current motor control task does not exceed the set maximum number of compensation steps. In one implementation, the maximum number of compensation steps per execution can be 96 steps. This not only corrects the average speed error caused by short-term delays in the main loop, but also avoids excessive output of steps at once after a long period of blocking, which could affect other tasks.
[0040] Preferably, this embodiment uses Q16 format to represent the stepping period and the cumulative scheduling amount as a fixed-point number, i.e., a fixed-point decimal. Shifting it left by 16 bits is equivalent to magnifying the integer time by 65536 times, which is used to save the time fraction and avoid losing the remainder after multiple accumulations.
[0041] Specifically, in step S300, the motor modes include a basic rotation mode, a half-turn reciprocating mode, an intermittent operation mode, a random speed change mode, and an audio-linked mode. These five modes share the operation gating, fixed-point scheduling, delay compensation, and phase sequence output framework of steps S100 to S300, updating the direction, segment count, pause status, or speed factor only before each phase sequence step based on the current mode. The internal states of each motor mode are different. The main control MCU101 clears the internal state of the current motor mode, which includes at least the scheduling accumulation, direction status, half-turn steps, pause status, number of steps already run, remaining pause time, remaining segment steps, and deceleration factor. After a mode switch, the state is re-established according to the initial rules of the new mode, avoiding the use of the old mode's direction, pause count, random segment count, or speed parameters.
[0042] Furthermore, in the basic rotation mode, the stepping cycle is calculated according to the current speed setting, and phase sequence stepping is continuously executed along the preset positive direction, causing the optical component to rotate continuously in one direction. This mode is suitable for uniform rotation of the turntable, uniform change of pattern pieces, or conventional dynamic lighting effects. The motor control task execution flow in the basic rotation mode includes: 1. Read the current speed gear; 2. Calculate the time T required for the stepper motor to rotate one revolution at the current speed setting; 3. Calculate the stepping cycle based on the number of phase sequence steps N and T required for one revolution of the stepper motor output shaft; 4. When the cumulative scheduling amount is greater than or equal to the stepping period, perform one phase sequence stepping. 5. Repeat the above process.
[0043] In half-circle reciprocating mode, the phase sequence stepping is first performed in the current direction, and the number of steps already executed in this direction is accumulated. When the accumulated number of steps reaches the preset number corresponding to half a circle of the output shaft, the direction is reversed and the half-circle count is cleared, thereby causing the optical component to reciprocate between two relative positions. In one embodiment, the phase sequence step number N corresponding to one revolution of the stepper motor output shaft is 4096 steps, and the half-circle step number is 2048 steps. The motor control task execution flow in half-circle reciprocating mode includes: 1. Determine the current direction of travel; 2. Perform one phase sequence step according to the current running direction; 3. Increment the execution step count of the phase sequence step by 1; 4. If the number of steps executed in the previous step reaches the preset number of steps corresponding to half a revolution of the output axis, clear the execution step count and switch to the reverse direction; 5. Continue the next round of reciprocating operation.
[0044] In intermittent operation mode, the phase sequence stepping is accumulated along a preset direction, and the number of steps is accumulated. When the accumulated number of steps reaches the preset number of revolutions, a pause state is entered, and the remaining pause time is set to the task count value corresponding to the preset pause duration. In one embodiment, the preset number of revolutions is 3 revolutions, each revolution has 4096 steps, and the pause time is 5000ms. In the pause state, no steps are executed, only the remaining pause time is deducted. After the pause ends, the pause flag and the number of steps are cleared, and the next round of operation begins. When entering the pause state, the accumulated speed is cleared simultaneously to avoid the time difference accumulated during the pause being compensated for all at once when the operation resumes. The motor control task execution flow in intermittent operation mode includes: 1. Determine if the current state is paused; 2. If the device is in a paused state, the remaining pause time will be deducted, and the phase sequence step will not be executed. 3. If the pause state ends, clear the pause flag and the number of steps run; 4. If not in a paused state, continue executing the phase sequence stepping in the current running direction; 5. Accumulate the number of steps after each phase sequence step; 6. If the number of steps reaches the set number of laps, the game will enter pause mode. 7. After the pause ends, the next round will begin.
[0045] In random speed variation mode, the continuous operation is divided into multiple segments of random length. Each segment is assigned a speed factor, and the operating speed is adjusted according to the relationship that the current step cycle equals the base step cycle multiplied by the current speed factor. When the remaining steps of the current segment reach 0, the segment length and speed factor of the next segment are regenerated using pseudo-random numbers. The segment length can be 16 to 80 steps, with approximately one-third probability of entering the deceleration segment. The deceleration factor can be 2 to 5 times. When not entering the deceleration segment, the speed factor is 1. The pseudo-random number can use XORShift, linear congruence, hardware random numbers, or other lightweight algorithms. In one implementation, the segment length can be determined using the low-order bits of the pseudo-random number, the entry into the deceleration segment can be determined by taking the pseudo-random number modulo 3, and the deceleration factor can be selected using the middle bits or different bits of the pseudo-random number, so that the speed variation of the segment does not exhibit a mechanically repetitive cycle. The motor control task execution flow in random speed variation mode includes: 1. Determine if the current running segment has ended; 2. If the current running segment ends, a new running segment is extracted; 3. Determine whether the running segment is a deceleration segment based on the random number; 4. If it is a deceleration section, then extract a deceleration factor of 2 to 5 times; if it is not a deceleration section, then the deceleration factor is 1. 5. Calculate the current stepping cycle based on the base stepping cycle and the deceleration factor; 6. When the accumulated time reaches the current step cycle, perform a phase sequence step; 7. Decrement the remaining execution steps of the current running segment by 1; 8. When the remaining execution steps of the current running segment are 0, the current running segment ends and the next running segment is extracted.
[0046] In audio linkage mode, the audio detection module 106 collects audio input from the environment where the light source is located or from the matching audio source, and performs amplitude detection, energy detection, or threshold judgment on the audio signal to obtain an audio detection result indicating whether valid audio exists. The audio detection module 106 can periodically sample via a microphone ADC and calculate the audio trigger threshold based on the sensitivity level, or it can receive line audio, external audio envelope detection chip, digital audio processing module, Bluetooth music data, or beat data sent by the APP; the audio detection result can be a binary state of having or not having audio, or it can be an audio intensity level. The main control MCU 101 selects continuous smooth operation or short-term jerky operation based on the audio detection result, realizing a dynamic linkage effect of "the motor rotating continuously and smoothly when there is sound, and forming a slight jerky motion through short-segment deceleration when there is no sound". The jerky segment extends the stepping cycle so that the motor exhibits slow stepping rather than complete stopping, avoiding the misinterpretation of a fault due to prolonged stillness, and also reducing start-stop shock; the smooth segment is interspersed to ensure the continuity of the overall action, allowing users to clearly perceive the change in the presence or absence of audio, and improving the synergistic performance of the light source effect and music.
[0047] When the audio detection result indicates the presence of valid audio, the audio linkage mode continuously operates at the highest speed of the current speed setting, clearing the current stuttering segment and setting the first speed factor to 1. It then executes phase sequence stepping according to the stepping cycle determined by the highest speed setting, causing the optical components to move smoothly in response to the audio state. In one embodiment, the time for the motor to complete one revolution at the highest speed setting is approximately 6000ms. The above control logic is used to present a visual effect of stable motor rotation and synchronized enhancement with lighting and sound effects during music playback.
[0048] When the audio detection result indicates the absence of valid audio, the motor is not stopped for an extended period. Instead, phase-sequence stepping is executed, switching between a smooth segment and a jerky segment. The third speed factor for the smooth segment is 1, the second speed factor for the jerky segment is selected from 4 to 20, the duration of the jerky segment is selected from 1 to 6 steps, and the duration of the smooth segment is selected from 8 to 28 steps. The stepping cycle corresponding to the smooth segment and the jerky segment is equal to the stepping cycle corresponding to the current highest speed setting multiplied by the selected speed factor. Thus, the jerky segment creates a short, slow rotation or pause by extending the stepping cycle by several steps, but still executes phase-sequence stepping, and the duration of the jerky segment is shorter than that of the smooth segment, avoiding prolonged motor stops. If the remaining steps for the current segment are 0, the segment type and parameters for the next segment are regenerated based on the preset jerky probability.
[0049] Preferably, the current speed setting is reused as the input for audio detection sensitivity, and the valid audio determination result is determined based on the input audio detection sensitivity value. In one embodiment, the sensitivity range is 1 to 10, with higher values making it easier to determine the presence of valid audio. To maintain a consistent feel when there is no audio, the probability of a pause can be fixed according to a preset intermediate sensitivity model, and will not change with user sensitivity adjustments. For example, the highest sensitivity of 10 corresponds to approximately a 10% probability of a pause; for each decrease in sensitivity by one level, the probability of a pause increases by approximately 8%, and the probability corresponding to sensitivity 5 is used to calculate the pause segment. Thus, user speed adjustments mainly affect the audio detection result and do not cause frequent changes in the strength and frequency of the pauses.
[0050] Furthermore, when generating a new segment in the absence of audio, a pseudo-random number can be modulo 100 and the result can be compared with the stuttering probability to determine whether a stuttering segment has been entered. If a stuttering segment has been entered, the deceleration factor and the duration of the stuttering segment can be selected using different segments of the random number. If a stuttering segment has not been entered, the duration of the smooth segment can be selected.
[0051] Furthermore, in actual motor control tasks, Mode 5 can be executed according to the following steps. This process can be combined with the aforementioned time accumulation compensation mechanism to ensure the stable realization of the stepping cycle: 1. Read the current speed setting value and use it as the audio detection sensitivity; 2. Call the audio detection interface to obtain the current valid audio flag; 3. If the audio valid flag is true, clear the stuttering segment status (including the remaining number of steps in the segment being set to zero and the segment type being reset), set the speed factor to 1, make the motor run continuously at the basic cycle, and jump to step 8; 4. If the audio validity flag is false, check if the remaining number of steps in the current segment is greater than 0. If so, keep the parameters of the current segment unchanged and jump to step 8. 5. If the remaining steps are 0, extract the next segment type according to a fixed pause probability (e.g., 50%); 6. If the extracted segment is a pause segment, randomly generate a deceleration multiple (4~20) as a speed factor, randomly generate a length (1~6) as the segment step number, and write the remaining steps of the current segment; 7. If the extracted segment is a smooth segment, set the velocity factor to 1 and randomly generate a length (8-28) as the segment step number; 8. Calculate the current step cycle based on the step cycle corresponding to the current speed gear and the current speed factor; 9. Under the control of the time accumulation compensation mechanism, when the accumulated time reaches the current stepping cycle obtained in step 8, perform a step motor phase sequence update and output; 10. Decrease the remaining steps of the current segment by 1, and return to step 2 above to enter the next control cycle.
[0052] Furthermore, the system timing module can use a 1ms cycle as the external timing reference for motor tasks. This cycle can cover low-speed and medium-speed operation requirements and is easy to implement in the main control MCU; a shorter cycle can be used when the main control performance is high, and a longer cycle can be used when the motor speed is low or the system load is high, but the actual call interval is compensated by the task time difference.
[0053] Furthermore, the number of steps N per revolution is determined based on the stepper motor type, phase sequence drive method, microstepping method, and reduction mechanism. In one embodiment, the output shaft executes 4096 phase sequence steps per revolution; by replacing the motor, drive chip, or reduction mechanism, the number of phase sequence steps corresponding to one revolution of the output shaft can be recalibrated without changing the gating, scheduling, and mode control processes.
[0054] Furthermore, the rotation time of the highest speed setting is used to establish a unified benchmark for speed levels, which can be determined based on mechanical load, noise, heat generation, and user visual experience. In one implementation, the motor rotation time for the highest speed setting is 6000ms. This time can be shortened when the load is low, noise requirements are low, or faster visual changes are needed; conversely, it can be lengthened when the load is high, heat generation is high, or mechanical noise needs to be reduced. Speed levels can be set from 1 to 10, or from 1 to 5, 1 to 20, or as a percentage. The core principle is to determine the rotation time based on the speed setting and further determine the stepping cycle. Furthermore, the number of rotations in the intermittent operation mode can be set to 3, and the pause time can be set to 5000ms. The number of rotations is used to form a relatively complete rotating display, and the pause time is used to form the intermittent rhythm. Under different optical components or projection patterns, the number of rotations and the pause time can be adjusted according to the pattern change cycle, mechanical inertia, and user experience. Furthermore, the length of the random segment in the random speed change mode can be between 16 and 80 steps, the deceleration probability can be approximately one-third, and the deceleration factor can be between 2 and 5 times. If the random segment is too short, the speed changes will be too fragmented; if the random segment is too long, the sense of randomness will be reduced. If the deceleration factor is too low, the speed difference will not be obvious; if the deceleration factor is too high, it will be easy to approach a stop. Optionally, the stepping cycle, scheduling cumulative amount, running steps, pause timer, and remaining steps of the segment can be maintained using timer interrupts, RTOS timed tasks, or periodic tasks; the cycle of the motor control task can be set according to the real-time load of the main control MCU, or it can be implemented using the pulse input method of a dedicated motor drive chip. Optionally, the preset amplification factor, maximum compensation steps, speed factor, random segment length, pause duration, effective audio judgment threshold, and stuttering probability can be configured through the firmware parameter table and adjusted according to the stepper motor model, reduction mechanism, optical component inertia, real-time load of the main control MCU, lighting effect requirements, mechanical noise, and user feel. Alternatively, in addition to stepper motors, DC geared motors, brushless motors, or servo motors can also be used without changing the gating, time scheduling, and operation mode control concepts. If a DC geared motor is used, the phase sequence step output can be replaced with PWM (Pulse Width Modulation) duty cycle control. If a brushless motor is used, the phase sequence output can be replaced with electronic commutation control. If a servo motor is used, the step count can be replaced with angle position control. Optionally, the stuttering multiplier, stuttering duration, smoothing duration, and stuttering probability of the audio linkage mode can be adjusted according to the feel of the product; for example, the stuttering multiplier can be selected from 2 to 30 times, the stuttering duration can be selected from 1 to 20 steps, and the smoothing duration can be selected from 5 to 60 steps, or it can be determined by the user's gear, music intensity, and current lighting effect mode. Optionally, the motor mode can be extended beyond basic rotation, half-circle reciprocating, intermittent operation, random speed change and audio linkage to fixed angle swing mode, random forward and reverse rotation mode, music intensity speed adjustment mode or lighting effect synchronized rotation mode; the extended mode can still reuse persistent switch and linkage gate control, fixed point time accumulation, main loop delay compensation, phase sequence output and stop reset frame. Optionally, the linkage gate control can be determined by one or more of the following: light switch, remote control switch, APP switch, timer status, sensor status, or device operating mode. Different products may use a combination of logical AND, logical OR, or hierarchical gate control. However, in implementations that need to simultaneously meet the user's motor settings and the overall machine operating conditions, a persistent switch and linkage gate control are used to jointly determine whether the motor runs.
[0055] In this embodiment, a computer device is also provided, such as... Figure 3As shown, it includes a memory 301, a processor 302, and a computer program stored in the memory 301 and executable on the processor 302. When the processor 302 executes the computer program, it implements any of the above-mentioned multi-mode linkage control methods for stepper motors.
[0056] Specifically, the computer device can be a computer terminal, a server, or a similar computing device.
[0057] In this embodiment, a storage medium is provided, which is a computer-readable storage medium. The storage medium stores a computer program, and when the computer program is executed by a processor, it implements the stepper motor multi-mode linkage control method described above in this embodiment.
[0058] In this embodiment, a computer program product is provided, which includes a computer program. When the computer program is executed by a processor, it implements the steps of the stepper motor multi-mode linkage control method described above in this embodiment.
[0059] In this embodiment, a computer-readable storage medium is provided, which stores a computer program that executes any of the above-described multi-mode linkage control methods for stepper motors.
[0060] Specifically, computer-readable storage media, including both permanent and non-permanent, removable and non-removable media, can store information using any method or technology. The information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer-readable storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, and optical disc read-only memory (CD-ROM). ROM, digital multifunction optical disc (DVD) or other optical storage, magnetic cassette tape, magnetic magnetic disk storage or other magnetic storage devices or any other non-transfer medium, may be used to store information that can be accessed by a computing device. As defined herein, computer-readable storage media does not include transient media such as modulated data signals and carrier waves.
[0061] The embodiments of the present invention achieve the following technical effects: 1. By using persistent switches and linkage gate control together to determine operating conditions, the system avoids changes to user-saved motor settings caused by lights or temporary linkage states, and can stop phase sequence output when linkage conditions are not met. 2. Reduce the impact of integer time rounding error and main loop blockage on average speed by fixed-point time cumulative scheduling and multi-step compensation, and limit sudden compensation movement by the maximum number of compensation steps; 3. By reusing basic rotation, half-circle reciprocation, intermittent operation, random speed change and audio linkage modes through unified scheduling skeleton, repetitive control logic is reduced and mode scalability is improved; by clearing the internal state when switching modes, operation abnormalities caused by state residue are avoided. 4. By switching between smooth segments and short-duration stuttering segments in the audio linkage mode, the system avoids freezing, misjudgment, or mechanical impact caused by prolonged shutdown when there is no audio. The system also simplifies user settings by using multiplexed speed levels as audio detection sensitivity input.
[0062] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features therein. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application.
Claims
1. A multi-mode linkage control method for a stepper motor, characterized in that, include: The stepper motor is determined to be in an allowed operating state by reading its persistent switch and linkage gate control. If the persistent switch is in the open state and the linkage gate control is in the open state, the stepper motor is determined to be in an allowed operating state. If the stepper motor is in a permitted operating state, the stepping cycle of the stepper motor is determined according to the current speed level. The execution time difference between the current motor control task and the previous motor control task is added to the scheduling accumulation. When the scheduling accumulation exceeds the stepping cycle, a phase sequence step is executed according to the operating rules corresponding to the current motor mode. The scheduling accumulation is updated by subtracting the stepping cycle from the scheduling accumulation. The current motor mode is one of a number of preset switchable motor modes, and different motor modes correspond to different phase sequence stepping operating rules.
2. The multi-mode linkage control method for a stepper motor according to claim 1, characterized in that, The state of the persistent switch is determined by receiving the motor switch command issued by the user; the state of the linkage door control is determined by the light switch state of the light source machine, the remote control master switch state, or the interface switch state. If the persistent switch is in the off state or the linkage gate is in the off state, it is determined that the stepper motor is in a state where it is not allowed to run.
3. The multi-mode linkage control method for a stepper motor according to claim 2, characterized in that, When the stepper motor switches from a state where it is not allowed to run to a state where it is allowed to run, it immediately performs a phase sequence step and sets the cumulative scheduling amount to 0.
4. The multi-mode linkage control method for a stepper motor according to claim 1, characterized in that, Determining the stepper motor's stepping cycle based on the current speed setting includes: The time required for the stepper motor to rotate one revolution is determined based on the current speed setting, and the time required for the stepper motor to rotate one revolution is inversely proportional to the current speed setting. The stepping cycle is obtained based on the time required for the stepper motor to complete one revolution and the number of phase sequence steps required for the stepper motor to complete one revolution.
5. The multi-mode linkage control method for a stepper motor according to claim 1, characterized in that, The stepping period and the cumulative scheduling amount are amplified by a preset amplification factor, and subsequent data processing and data storage are performed based on the amplified stepping period and the cumulative scheduling amount.
6. The multi-mode linkage control method for a stepper motor according to claim 1, characterized in that, After updating the cumulative scheduling amount by subtracting the stepping period, if the updated cumulative scheduling amount exceeds the stepping period, the next phase sequence stepping will continue to be executed according to the operating rules corresponding to the current motor mode.
7. The multi-mode linkage control method for a stepper motor according to claim 5, characterized in that, A maximum compensation step number is set, and during the execution of the current motor control task, the number of times the phase sequence stepping is executed does not exceed the maximum compensation step number.
8. The multi-mode linkage control method for a stepper motor according to claim 1, characterized in that, The motor modes include basic rotation mode, half-circle reciprocating mode, intermittent operation mode, random speed change mode and audio linkage mode, and the internal states of each motor mode are different. If the current motor mode is inconsistent with the previous motor mode, clear the internal state of the current motor mode. The internal state includes at least the direction state, pause state, remaining steps of the segment, and deceleration factor.
9. The multi-mode linkage control method for a stepper motor according to claim 8, characterized in that, The audio linkage mode includes: Obtain audio detection results; When the audio detection result indicates the presence of valid audio, the stepping cycle is determined based on the highest speed setting of the current speed gear and the first speed factor. When the audio detection result indicates that there is no valid audio, phase sequence stepping is performed between the smooth segment and the stuttering segment. The stepping period of the stuttering segment is determined based on the highest speed of the current speed level and the second speed factor, and the stepping period of the stuttering segment is determined based on the highest speed of the current speed level and the third speed factor.
10. A multi-mode linkage control method for a stepper motor according to claim 9, characterized in that, The current speed setting is used as the input for audio detection sensitivity, and the audio detection result is determined based on the input audio detection sensitivity value.
11. A multi-mode linkage control system for a stepper motor, characterized in that, The system is used to execute a multi-mode linkage control method for a stepper motor as described in any one of claims 1 to 10.
12. An electronic device, characterized in that, include: processor; A memory for storing executable instructions of the processor; wherein the processor is used for the executable instructions to implement a multi-mode linkage control method for a stepper motor as described in any one of claims 1 to 10.