Capacitance system control method based on differential control adjustment

The capacitor system control method using multi-turn absolute encoders and differential control overcomes the shortcomings of traditional capacitor system control methods in terms of accuracy, stability, and response speed, achieving high-precision and stable motor control, adapting to complex working conditions, and improving system safety and production efficiency.

CN121689909APending Publication Date: 2026-03-17江苏神州半导体科技股份有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-11-12
Publication Date
2026-03-17

Smart Images

  • Figure CN121689909A_ABST
    Figure CN121689909A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of power electronic control, and discloses a capacitance system control method based on differential control adjustment. According to the method, a multi-turn absolute value encoder is used for collecting rotation angle data of a stepping motor in real time, and an encoder signal containing turn count and a current angle value is generated. Differential error calculation is carried out on the signal and a preset target angle value, so that an angle deviation value and a turn number deviation value are obtained; then, according to the deviation values, a proportional integral differential algorithm is adopted to generate a motor control pulse sequence containing a direction control signal and a stepping frequency parameter; the pulse sequence is output to a stepping motor driver through the microcontroller, and the stepping motor is driven to be adjusted to the target angle position. In the operation process, the system can monitor the actual rotation angle of the stepping motor in real time, and once the angle deviation value is detected to exceed a threshold value for three continuous times, an encoder protection mechanism is triggered, the motor operation is stopped, and the number of turns is reset.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of power electronic control technology, specifically to a capacitor system control method based on differential control regulation. Background Technology

[0002] Capacitor system control has indispensable applications in many areas of modern industry and daily life. In the field of new energy power generation, whether it is wind power or solar power, capacitor system control plays a key role. Taking wind power generation as an example, during the operation of a wind turbine, the unstable wind speed causes fluctuations in the electrical energy output of the generator. At this time, the capacitor system can effectively smooth the output voltage and current by precisely controlling the storage and release of electrical energy, ensuring a stable supply of electrical energy to the grid, improving the stability and reliability of the wind power system, enabling wind power to be better integrated into the grid, and reducing the impact on the grid. In solar photovoltaic power generation systems, capacitor systems can be used to smooth DC voltage, reduce the impact of DC voltage fluctuations in the output of photovoltaic modules, and improve the efficiency of photovoltaic power generation systems.

[0003] In industrial automation scenarios, capacitor system control is also widely used. For example, in automated production lines, numerous motor-driven devices require a stable power supply. Capacitor systems can quickly respond and provide or absorb energy when motors start, brake, or experience load changes, ensuring smooth motor operation, preventing equipment downtime or damage due to voltage fluctuations, and improving production efficiency and product quality. In the field of industrial robotics, capacitor systems are used to store energy to support the high power demands of robots performing rapid movements, ensuring that robots can accurately and efficiently complete various tasks.

[0004] Traditional capacitor system control methods have many limitations in practical applications. Regarding accuracy, as modern industry demands ever higher precision from equipment, traditional control methods struggle to meet the needs of high-precision equipment. For example, in some precision electronic manufacturing equipment, extremely precise control of capacitor system parameters is required. Errors in the control precision of traditional methods can lead to product quality problems, unstable performance of manufactured electronic products, and increased scrap rates.

[0005] Stability is also a major weakness of traditional control methods. Under complex operating conditions, traditional control methods are prone to malfunctions and loss of control. When industrial production environments experience strong electromagnetic interference, significant temperature changes, or drastic load fluctuations, traditional capacitor system control methods cannot effectively cope with these disturbances, severely impacting system stability and potentially leading to equipment malfunctions or even safety accidents.

[0006] Slow response speed is also a prominent problem with traditional control methods. In scenarios with extremely high requirements for responsiveness to changes in electrical energy, such as rapidly changing power loads or systems requiring frequent energy conversion, traditional control methods, due to their slow response, cannot adjust the operating state of the capacitor system in a timely manner, leading to significant energy waste. Moreover, long-term operation under such conditions will significantly shorten the lifespan of the equipment, increasing maintenance costs and replacement frequency. Summary of the Invention

[0007] The purpose of this invention is to provide a capacitor system control method based on differential control adjustment to solve the problems mentioned in the background art.

[0008] To achieve the above objectives, the present invention provides a capacitor system control method based on differential control adjustment, the method comprising:

[0009] The rotation angle data of the stepper motor is collected in real time by a multi-turn absolute encoder, and an encoder signal containing the number of turns and the current angle value is generated.

[0010] The encoder signal is compared with the preset target angle value by differential error calculation to obtain the angle deviation and the number of revolutions deviation.

[0011] Based on the angle deviation and the number of revolutions deviation, a proportional-integral-derivative algorithm is used to generate a motor control pulse sequence, which includes a direction control signal and a stepping frequency parameter.

[0012] The microcontroller outputs the motor control pulse sequence to the stepper motor driver, driving the stepper motor to adjust to the target angle position;

[0013] The actual rotation angle of the stepper motor is monitored in real time. When the angle deviation exceeds the threshold three times in a row, the encoder protection mechanism is triggered to stop the motor and reset the revolution count.

[0014] Preferably, the stepper motor's rotation angle data is acquired in real time using a multi-turn absolute encoder to generate an encoder signal containing a revolution count and the current angle value, including:

[0015] Read the single-turn angle signal and number of turns signal of the multi-turn absolute encoder, and perform photoelectric isolation and noise filtering on the signal;

[0016] A clock synchronization sampling circuit is used to time-align the processed single-turn angle signal and number of turns signal to eliminate signal transmission delay differences.

[0017] The time-aligned single-turn angle signal and the number of turns signal are combined and encoded to generate a composite encoder signal containing 16-bit angle data and 8-bit number of turns data.

[0018] The composite encoder signal is subjected to parity and CRC checks to ensure data integrity before being output to the microcontroller.

[0019] Preferably, the step of calculating the differential error between the encoder signal and the preset target angle value to obtain the angle deviation and the number of revolutions deviation includes:

[0020] The current angle value and the current number of revolutions are parsed from the composite encoder signal and then subtracted from the target angle value and the target number of revolutions stored in the microcontroller.

[0021] Calculate the first-order difference between the current angle value and the target angle value to obtain the instantaneous angle deviation;

[0022] Calculate the cumulative difference between the current lap number and the target lap number to obtain the absolute lap number deviation;

[0023] The instantaneous angle deviation is averaged using a sliding window to eliminate high-frequency jitter noise and output a stable angle deviation.

[0024] Preferably, the step of generating a motor control pulse sequence using a proportional-integral-derivative algorithm based on the angle deviation and the number of revolutions deviation includes:

[0025] The stable angle deviation is input into the proportional element of the proportional-integral-derivative controller and multiplied by the proportional coefficient to generate the basic pulse frequency.

[0026] The stable angle deviation is integrated and accumulated, and then multiplied by the integration coefficient to generate the pulse frequency compensation.

[0027] The differential operation of the stable angle deviation is performed, and the result is multiplied by the differential coefficient to generate the pulse frequency damping.

[0028] The base pulse frequency, pulse frequency compensation, and pulse frequency damping are superimposed to generate the final step frequency parameters.

[0029] The level of the direction control signal is determined by the sign bit of the absolute rotation deviation.

[0030] Preferably, the step of outputting the motor control pulse sequence to the stepper motor driver via the microcontroller to drive the stepper motor to adjust to the target angular position includes:

[0031] Convert the final step frequency parameter into a timer interrupt cycle value and configure the microcontroller's timer module;

[0032] Set the direction pin level of the motor driver according to the level state of the direction control signal;

[0033] In the timer interrupt service routine, the pulse pin level of the motor driver is toggled to generate a pulse sequence of the corresponding frequency;

[0034] The encoder signal is read in real time and the angle deviation and revolution deviation are updated, and the timer interrupt cycle value is dynamically adjusted.

[0035] Preferably, the real-time monitoring of the actual rotation angle of the stepper motor triggers an encoder protection mechanism when the angle deviation exceeds a threshold three times consecutively, including:

[0036] Record the absolute value of the current angle deviation during each timer interrupt service;

[0037] If the current angle deviation exceeds the preset angle tolerance threshold, the count value of the abnormality counter will be incremented.

[0038] When the error counter reaches 3, immediately disable the timer interrupt and pull low the enable pin of the motor driver.

[0039] Write the exception event log to the microcontroller's non-volatile memory, including the angle deviation and revolution deviation when the exception occurred;

[0040] The microcontroller is reset by a hardware watchdog circuit, which reinitializes the rotation count and encoder signal sampling.

[0041] Preferably, stopping the motor and resetting the revolution count includes:

[0042] Disconnect the power supply to the stepper motor driver to release the mechanical load on the motor shaft;

[0043] Send a synchronous reset command to the multi-turn absolute encoder to clear its internal revolution counter to zero;

[0044] Reacquire the single-turn angle signal and number of turns signal of the encoder to verify the effectiveness of the reset operation;

[0045] If the encoder signal is still abnormal after the reset, the microcontroller's fault alarm pin will be activated and the system will enter standby mode.

[0046] Preferably, the proportional-integral-differential algorithm further includes an adaptive adjustment mechanism, comprising:

[0047] When the absolute number of revolutions deviation exceeds the preset number of revolutions threshold, the proportional coefficient and integral coefficient are dynamically adjusted to accelerate the convergence speed.

[0048] When the angular deviation is close to zero, the differential coefficient is automatically reduced to reduce high-frequency oscillations;

[0049] The PID parameters are adjusted in real time according to changes in motor load to ensure a balance between system response speed and stability.

[0050] Preferably, the storage and recovery mechanism for abnormal event logs includes:

[0051] The motor operating status at the time of the abnormality is recorded in non-volatile memory, including the current stepping frequency, direction control signal and encoder data;

[0052] After the system is reset, the system automatically reads the error log and performs fault diagnosis. If the error is determined to be recoverable, the target angle value is reloaded and the motor operation is restored.

[0053] If a hardware fault is detected, the motor driver will be locked and an external alarm signal will be triggered.

[0054] Preferably, the method further includes:

[0055] During the stepper motor startup phase, a trapezoidal acceleration curve is used to control the pulse frequency change, including:

[0056] The startup process is divided into an acceleration phase, a constant speed phase, and a deceleration phase, with a corresponding pulse frequency increment set for each phase.

[0057] During the acceleration phase, the timer interrupt period value is increased linearly until the maximum operating frequency is reached.

[0058] During the deceleration phase, the timer interrupt period value is decreased exponentially until the target angle position is approached.

[0059] The starting point of the deceleration section is dynamically adjusted based on the real-time angle deviation to ensure a smooth stop for the motor.

[0060] Compared with the prior art, the beneficial effects of the present invention are:

[0061] This invention employs a multi-turn absolute encoder to acquire the rotation angle data of a stepper motor in real time. This encoder can accurately measure the motor's rotation angle and record the number of turns, generating an encoder signal containing the turn count and the current angle value. By calculating the differential error between this encoder signal and a preset target angle value, extremely accurate angle and turn count deviations can be obtained. Based on these precise deviations, a proportional-integral-derivative (PID) algorithm is used to generate a motor control pulse sequence, which includes direction control signals and stepper frequency parameters. This control method enables the motor to make precise adjustments based on the deviation, ultimately accurately adjusting to the target angle position. In precision instrument manufacturing fields where extremely high angle control accuracy is required, such as the micro-manipulation platform of a lithography machine, this method can ensure that the platform's angle adjustment accuracy reaches the micrometer or even nanometer level, meeting high-precision control requirements and effectively improving the processing accuracy and quality of the product.

[0062] During system operation, this invention can monitor the actual rotation angle of the stepper motor in real time. Once the motor's operating state changes, or the working conditions and operating parameters change, such as a sudden increase in load or fluctuations in power supply voltage, the system can quickly detect these changes. Because the system can acquire the angle deviation in real time and employs advanced control algorithms, it can quickly adjust the control strategy based on the motor's real-time rotation angle. When an increase in load causes a decrease in motor speed and an increase in angle deviation, the system immediately adjusts the motor control pulse sequence, increasing the stepping frequency or changing the pulse direction, enabling the motor to overcome load changes, maintain a stable operating state, and continue moving towards the target angle position. This adapts to changes in different working conditions and operating parameters, ensuring that the capacitor system maintains good performance in complex and changing environments.

[0063] When the system detects an angle deviation exceeding a threshold three times consecutively, it triggers the encoder protection mechanism. This threshold is preset based on the normal operating parameters of the motor and capacitor system, accurately reflecting whether an abnormal situation has occurred. Once the protection mechanism is triggered, the system immediately stops the motor, preventing it from continuing to run under abnormal conditions and avoiding damage due to overload, overheating, or other reasons. It also prevents damage to other related equipment caused by excessive angle deviation. Furthermore, the system resets the revolution count, restoring the encoder's count to its initial accurate state, preparing for normal operation. In industrial production, this self-protection mechanism effectively avoids safety accidents caused by equipment failure, reduces equipment maintenance costs and production downtime, and improves production efficiency and safety.

[0064] The entire control process forms a closed-loop system. From real-time acquisition of the stepper motor's rotation angle data by a multi-turn absolute encoder, to adjusting the motor control pulse sequence based on the deviation, and then to real-time monitoring of the motor's actual rotation angle, each link is closely interconnected. Through continuous real-time monitoring and adjustment, the system can promptly detect and correct deviations during motor operation, reducing system oscillations and fluctuations. This improved stability is particularly important in capacitor systems, ensuring stable operation under various conditions and providing reliable support for other devices and systems that rely on capacitor systems for stable power or signals. For example, in the power supply system of a communication base station, stable capacitor system control ensures that the base station equipment is always in normal working condition, avoiding communication interruptions caused by capacitor system instability, and improving the reliability and stability of the communication system. Attached Figure Description

[0065] Figure 1 This is a schematic diagram illustrating the working principle of the capacitor system control method based on differential control regulation described in this invention.

[0066] Figure 2 A flowchart for generating signals from a multi-turn absolute encoder;

[0067] Figure 3 A flowchart for generating motor control pulse sequences using the proportional-integral-derivative algorithm. Detailed Implementation

[0068] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0069] Please see Figure 1 This invention provides a capacitor system control method based on differential control adjustment. The method includes: acquiring the rotation angle data of a stepper motor in real time using a multi-turn absolute encoder to generate an encoder signal containing a revolution count and the current angle value; calculating the differential error between the encoder signal and a preset target angle value to obtain the angle deviation and revolution deviation; inputting the angle deviation and revolution deviation into a proportional-integral-derivative algorithm to generate a motor control pulse sequence containing a direction control signal and stepper frequency parameters; and outputting the motor control pulse sequence to the stepper motor driver to drive the stepper motor to adjust to the target angle position. The system monitors the actual rotation angle of the stepper motor in real time. When the angle deviation exceeds a threshold three times consecutively, an encoder protection mechanism is triggered, stopping the motor and resetting the revolution count.

[0070] Example 1: See Figure 2 The single-turn angle and turn count signals of the multi-turn absolute encoder are read via a parallel data bus. The signal reading operation is initiated by the microcontroller's direct memory access controller, and the bus width matches the encoder's output data bit width. High-speed optocouplers are connected in series along the signal transmission path to achieve electrical isolation. The primary and secondary sides of the optocouplers are powered by independent power supplies, and the isolation voltage level meets industrial environmental standards. Noise filtering is performed after signal isolation. The analog signal is pre-processed by an RC low-pass filter, and the digital signal is fed into a Schmitt trigger for signal shaping. The filter cutoff frequency is set according to the stepper motor's maximum operating frequency.

[0071] The clock synchronization sampling circuit is built on a field-programmable gate array (FPGA). The FPGA internally features dual-channel synchronous sampling logic, with each channel containing a data latch and a buffer. Single-turn angle and revolution count signals are respectively connected to a dedicated clock domain. The global clock signal is generated by a phase-locked loop (PLL) circuit, which is synchronized with the microcontroller's master clock signal. Signal transmission delay differences are compensated for using digital delay lines. The tap parameters of the delay lines are calculated based on the signal path length difference, and the sampling time deviation is controlled to the nanosecond level. The time-aligned signal data is stored in a first-in-first-out (FIFO) queue, with the queue depth ensuring no sampling points are lost in the event of bursty data flow. The time-aligned single-turn angle and revolution count signals are encoded in a data combination unit, which uses bit-by-bit concatenation to generate the composite encoder signal. The 16-bit data of the single-turn angle signal occupies the low-order field of the composite encoder signal, and the field format uses binary original code representation, with a value range covering 0 to 65535. The 8-bit data of the revolution count signal occupies the high-order field of the composite encoder signal. The field format uses binary two's complement representation, and the value range supports positive and negative revolution counts from -128 to 127. The composite encoder signal is supplemented with a frame header identifier and a frame end identifier. The frame header identifier uses synchronization word mode, and the frame end identifier contains a checksum field.

[0072] The composite encoder signal uses a vertical parity check scheme, adding a parity bit to each data byte. The parity bit calculation follows an even parity rule. The CRC check uses a 16-bit cyclic redundancy check code with a generator polynomial of 0x1021 and an initial value of 0xFFFF. The calculation process includes all valid fields of the data frame. The check calculation is performed by the microcontroller's hardware CRC module, and the CRC result is appended to the end of the data frame. The receiver verifies data integrity by recalculating the CRC code. After successful data verification, the composite encoder signal is transmitted to the microcontroller via the serial peripheral interface. The transmission mode is full-duplex communication, and the clock polarity and phase are configured according to the encoder specifications. Upon receiving the composite encoder signal, the microcontroller's serial peripheral interface initiates the data parsing process. The data parsing program first checks the frame header identifier mode, confirms frame synchronization, and then extracts the valid data fields. The current angle value is parsed from the lower 16 bits of the composite encoder signal, and the numerical format is converted to the microcontroller's internal angle representation. This conversion process includes unit conversion and numerical normalization. The current circle value is parsed from the high 8 bits of the composite encoder signal, and the value format is converted to a signed integer representation. The conversion process includes sign bit extension and value range checking. The target angle value and target circle value are read from the microcontroller's non-volatile memory in big-endian byte order. The data reading process includes error detection and correction mechanisms.

[0073] The subtraction operation between the current angle value and the target angle value is performed in the arithmetic logic unit of the microcontroller, and the result is stored in the angle deviation register. The register width supports the full range of angle values. The subtraction operation between the current circle value and the target circle value uses signed arithmetic, and the result is stored in the circle number deviation register, which is configured with an overflow detection flag. The instantaneous angle deviation is calculated using first-order difference, which involves subtracting the current angle deviation value from the angle deviation value of the previous sampling period, and then performing numerical filtering on the difference result. The absolute circle number deviation is calculated using cumulative difference, with the cumulative value updated once per sampling period. The update process includes determining and counting the circle number direction. The sliding window averaging of the instantaneous angle deviation is implemented using a digital filter. The filter structure is a finite impulse response filter, and the window function type is a Hamming window. The length of the sliding window is set to 8 sampling points, and the window data is updated when a new sampling point arrives. The window data is stored in the microcontroller's circular buffer. The filtering calculation process includes data normalization and coefficient multiplication. The filter coefficients are pre-calculated and stored in a constant table, and the calculation process is accelerated using the microcontroller's digital signal processing instructions. The stable angle deviation is obtained from the filter output. The output data is limited to prevent outlier interference, and the limiting threshold is set according to the system control accuracy requirements. The signal sampling period of the multi-turn absolute encoder is synchronized with the microcontroller's timer interrupt. The sampling time is selected at the beginning of the timer interrupt service routine to ensure the timing accuracy of angle data acquisition. The optocoupler of the opto-isolation circuit uses a high-speed device with a transmission delay time of less than microseconds, and the common-mode rejection ratio meets the electromagnetic compatibility requirements of industrial environments. The parameters of the noise filter are adjusted according to the characteristics of the encoder output signal. The filter group delay time is controlled within the allowable range of the sampling period, and phase distortion is corrected through digital compensation. The synchronization accuracy of the clock synchronization sampling circuit is verified through a calibration procedure. The calibration process uses a standard signal source to generate a test signal and measures the deviation between the actual sampling time and the ideal sampling time.

[0074] The coding efficiency of the data combination unit is improved by optimizing the data structure. The data compression rate of the composite encoder signal has been calculated and verified, ensuring that the amount of data transmission is reduced without sacrificing accuracy. A dual verification mechanism of parity check and CRC check provides reliable data protection. The computational complexity of the verification algorithm has been optimized to meet real-time requirements. The microcontroller's data parsing algorithm combines a lookup table method and a computational method. Specifically, the lookup table method is used to quickly match the frame header identifier pattern of the composite encoder signal. The frame header identifier pattern is pre-stored in a constant table in read-only memory. The constant table index is used for parallel lookup through a hardware comparator, improving pattern recognition efficiency. The computational method is applied to the numerical conversion process of angle data. The angle value is converted from binary original code format to the microcontroller's internal floating-point representation. The conversion algorithm uses the arithmetic logic unit to perform multiplication and addition operations, dynamically calculating the normalization coefficient and unit conversion factor. The parsing speed is improved by pre-compiled macros and inline functions, and memory usage is reduced by using a shared buffer. The calculation process of angle and revolution deviation uses fixed-point arithmetic instructions. The calculation accuracy is verified by numerical analysis and error propagation theory, and the calculation error is controlled within the system's allowable range. The frequency response characteristics of the sliding window averaging filter were verified through simulation. The passband ripple and stopband attenuation parameters meet the system requirements, and the filter's computational stability is guaranteed through numerical analysis. The output data format of the stable angle deviation is matched to the input requirements of the proportional-integral-derivative (PID) controller. The data conversion process includes dimensional transformation and numerical scaling, with the transformation coefficients determined based on the system's control accuracy. The delay time of the entire signal processing link is measured using a timestamp mechanism. The total delay from encoder signal acquisition to the stable angle deviation output is used as a crucial parameter in the system design, and the delay compensation algorithm is adjusted based on the measurement results.

[0075] Example 2: See Figure 3The stable angle deviation is input to the proportional-integral-derivative (PID) controller for linear amplification. The proportional coefficient is stored in the microcontroller's non-volatile memory parameter table, which stores multiple sets of parameters according to different operating conditions. Multiplication is performed by the microcontroller's hardware multiplier. After range checking, the multiplication result generates a base pulse frequency, the range of which is set according to the stepper motor's maximum allowable operating frequency. Simultaneously, the stable angle deviation is accumulated in the integral stage. The integrator is implemented using a 32-bit accumulator register, and the integral limit is determined based on the system's maximum allowable steady-state error. The integral result is multiplied by the integral coefficient to generate a pulse frequency compensation, which is used to eliminate the system's static error. The differential operation of the stable angle deviation uses a first-order backward difference method. The difference between the current sample value and the previous sample value is divided by the sampling period to obtain the rate of change. The differential result is low-pass filtered to suppress high-frequency noise. The differential coefficient is dynamically adjusted according to the system response speed requirements. The differential result is multiplied by the differential coefficient to generate a pulse frequency damping, which is used to improve the system's dynamic response characteristics. The basic pulse frequency, pulse frequency compensation, and pulse frequency damping are algebraically superimposed in an adder. The adder output is then limited to generate the final step frequency parameters. The limiting threshold is set based on the maximum pulse frequency acceptance capability of the stepper motor driver. The sign bit of the absolute rotation deviation is detected by a numerical comparator. The sign bit state is mapped to the level output of the direction control signal through a logic judgment circuit; a positive deviation corresponds to a high level, and a negative deviation corresponds to a low level.

[0076] The adaptive adjustment mechanism of the proportional-integral-derivative (PID) algorithm continuously monitors the magnitude of the absolute rotation deviation. When the absolute rotation deviation exceeds a preset threshold, the parameter adjustment module loads new proportional and integral coefficient values ​​from the microcontroller's memory. The rotation threshold is set based on the maximum number of rotations allowed by the stepper motor's mechanical structure, and a smooth transition algorithm is used during parameter switching to avoid abrupt changes in control parameters. When the angle deviation approaches zero, the derivative coefficient adjustment module initiates a coefficient decay program. The decay curve uses a piecewise linear function, and the decay rate is adjusted according to the system stability margin requirements. Motor load changes are detected by a Hall sensor installed in the driver's current loop. The current signal is converted from analog to digital and then input to the parameter adaptive algorithm. The parameter adaptive algorithm uses a model reference adaptive control structure. The reference model outputs an ideal system response, and the difference between the actual output and the ideal output is used to adjust the proportional-integral-derivative (PID) parameters. The proportional coefficient adjustment rule is based on the magnitude of the deviation; a larger proportional coefficient is used to improve response speed under large deviations, and a smaller proportional coefficient is used to enhance stability under small deviations. The integral coefficient is dynamically adjusted according to the integral value of the deviation. Integral separation technology prevents integral saturation, and the integral effect weakens when the deviation is large. The adjustment of the derivative coefficient takes into account the balance between the system response rate and the overshoot. The derivative coefficient should be increased appropriately when fast response is required, and decreased when high stability is required.

[0077] The microcontroller's arithmetic logic unit (ALU) performs numerical calculations using the proportional-integral-differential (PID) algorithm. Fixed-point arithmetic is employed to improve computational efficiency, while numerical accuracy is guaranteed by a scaling factor. The proportional gain is directly used as the base pulse frequency, and the range of the proportional coefficient is determined through stability analysis to ensure system stability within the global operating range. The integral stage employs anti-saturation measures, stopping integration when the control quantity reaches a limit value to prevent integrator overflow and system oscillation. The differential stage is equipped with a first-order low-pass filter, whose cutoff frequency is adaptively adjusted based on the sampling frequency and noise characteristics to effectively suppress measurement noise amplification. The final step frequency parameter is converted into the reload value of the timer / counter. The conversion formula is based on the microcontroller's main clock frequency, and the reload value is written to the timer's auto-reload register. The direction control signal is output to the stepper motor driver via general-purpose input / output pins configured in push-pull output mode. The output level is matched to the driver's logic level by a level conversion circuit. Pulse sequence generation is implemented by a timer interrupt service routine, which performs pin level toggling operations. The pulse duty cycle is set by adjusting the timer's comparison matching value. The real-time parameter adjustment mechanism is executed every time a timer is interrupted, and the new control parameters are updated to the arithmetic unit in a timely manner.

[0078] The adaptive control mechanism utilizes a hardware comparator for the revolution threshold detection. The comparison result triggers an interrupt service routine on the microcontroller, where parameter switching is performed. Adaptive adjustment of the proportional and integral coefficients employs fuzzy logic control rules. The fuzzy rule table is stored in the microcontroller's flash memory and generated offline based on expert experience. Adaptive adjustment of the derivative coefficients is based on system phase margin estimation, indirectly obtained by analyzing the system's frequency response characteristics. The adjustment process ensures sufficient stability margin for the system. Load change detection is achieved by monitoring the motor phase current; the sampled current value is digitally filtered and used for load estimation. The parameter adaptive learning function is implemented through an online identification algorithm. The system model parameters are continuously updated during operation and used to optimize the proportional-integral-derivative (PID) controller parameters. The control parameter memory function stores the optimal parameters under different operating conditions in non-volatile memory, allowing direct retrieval of stored parameters when encountering the same operating condition again. The parameter self-tuning function is executed during system startup. During tuning, test signals are applied, the system response is analyzed, and suitable initial control parameters are automatically calculated. The fault protection function monitors the parameter adaptive process and automatically switches to fixed parameter mode upon detecting abnormal adjustments, ensuring basic system operation.

[0079] The proportional-integral-derivative (PID) algorithm is implemented using a modular software design. The proportional calculation module, integral calculation module, and derivative calculation module are independently written, and the modules exchange information through a data interface. A numerical overflow detection mechanism monitors the calculation results in real time during the operation, automatically activating a backup calculation scheme when an overflow is detected. The determinism of the control cycle is guaranteed by a timer interrupt, with the interrupt priority set to the highest level to prevent other tasks from affecting the real-time performance of the control algorithm. The validity of the calculation results undergoes multiple checks; if a check fails, the output value of the previous control cycle is used to ensure the continuity of system control. The adaptive adjustment mechanism and the basic PID algorithm form a two-layer control structure. The lower-level PID algorithm achieves fast response, while the upper-level adaptive mechanism optimizes parameters. The two layers exchange data through shared memory, and a mutex lock mechanism is used during data exchange to prevent access conflicts. The smooth transition algorithm for parameter adjustment uses a first-order inertial element, and the transition time constant is adjusted according to the system's dynamic characteristics to avoid system oscillations caused by parameter jumps. The enable condition for parameter adaptation is programmable, allowing flexible activation or deactivation of the adaptive function according to different application requirements. The control parameter monitoring interface is implemented via a serial communication interface, allowing external monitoring devices to read and modify control parameters in real time. Parameter modification permissions are managed through a password protection mechanism. The parameter change history function records the time and value of each parameter modification; this data is used to analyze system operating status. The control parameter backup mechanism stores multiple parameter sets in non-volatile memory, automatically restoring to the last normally functioning parameter settings in case of system anomalies. The parameter adaptive performance evaluation function records the system's control effect under different parameters; the evaluation results are used to optimize adaptive rules.

[0080] Example 3: The final step frequency parameter is calculated to obtain the timer interrupt cycle value through a frequency-cycle conversion algorithm. The timer interrupt cycle value is derived based on the microcontroller's main clock frequency and the preset step frequency parameter. The conversion process is expressed mathematically as follows:

[0081]

[0082] in: Indicates the timer reload value (dimensionless integer). This indicates the microcontroller's main clock frequency (in Hertz). This represents the frequency (in Hertz) of the stepper motor control pulse sequence. The timer reload value is written to the microcontroller's timer reload register, with the register width matching the timer's count bit width. The write operation is completed through a memory-mapped interface. The direction control signal's level is output to the microcontroller's general-purpose input / output pins, configured in push-pull output mode, with the output drive capability matching the stepper motor driver's input logic level requirements. The timer interrupt service routine includes a pulse pin level toggling routine. Each time an interrupt is triggered, the pin state is inverted, generating a square wave pulse sequence with a 50% duty cycle. The frequency of the pulse sequence follows the stepper motor frequency parameters in real time; frequency adjustment is achieved by dynamically modifying the timer reload value.

[0083] The encoder signal sampling program and the timer interrupt service routine execute synchronously. The sampling time is selected at the beginning of the interrupt service routine to ensure the timing accuracy of angle data acquisition. The current angle deviation and revolution deviation are read from the shared memory area, which is jointly maintained by the main program and the intermediate service routine. Data updates use atomic operations to avoid race conditions. The new angle deviation and revolution deviation are used to recalculate the step frequency parameters. The calculation process uses a floating-point arithmetic library to ensure numerical accuracy, and the calculation results are subjected to amplitude limiting to prevent frequency overshoot. The dynamic adjustment of the timer interrupt period value is based on the rate of change of the deviation, which is obtained through differential calculation. The differential window length is set according to the system response time. The timer interrupt service routine integrates the angle deviation monitoring function. The absolute value of the current angle deviation is read from the data register, and the absolute value calculation is accelerated using hardware absolute value instructions. The value of the angle deviation is compared with the preset angle tolerance threshold. The comparison operation is performed by the arithmetic logic unit, and the comparison result directly affects the state of the exception counter. The exception counter is implemented using an 8-bit up counter. The counter is initially set to zero, and it increments each time the comparison exceeds the threshold. The counter overflow value is set to three. When the error counter reaches three, the system control logic immediately disables the timer interrupt enable bit. Interrupt disabling is accomplished by writing to the control register, and at the same time, the enable pin of the stepper motor driver is pulled low to logic zero.

[0084] The abnormal event logging process begins after the protection mechanism is triggered. Log data includes the angle deviation, revolution deviation, step frequency parameters, direction control signal status, and timestamp information at the time of the abnormality. The timestamp is obtained from the microcontroller's real-time clock module, using a Unix time format, and is encoded and compressed before data storage. Non-volatile memory uses flash memory devices, with the storage area divided into multiple sectors. Sector management employs a wear-leveling algorithm to extend memory lifespan. Log write operations use a transaction mechanism to ensure data integrity; if the write process is interrupted, it automatically rolls back to the previous complete state. The hardware watchdog circuit receives a feed signal during abnormality handling. After the watchdog counter times out, it generates a system reset pulse, the width of which meets the microcontroller's reset timing requirements. After system reset, the log recovery program starts. The fault diagnosis algorithm analyzes the data patterns in the abnormal event log. The diagnosis process is based on a rule engine, and the rule base is stored in the microcontroller's read-only memory. Recoverable error judgment conditions include transient faults such as temporary encoder signal interference and power supply voltage fluctuations. After a judgment is passed, the system automatically reloads the target angle value and resumes motor operation. Hardware fault detection criteria include persistent faults such as encoder hardware damage and motor driver failure. Upon successful detection, the system locks the motor driver output and activates the external alarm signal circuit. The alarm signal drive circuit employs an optocoupler isolation design, with a pull-up resistor connected to the signal output terminal to ensure signal level stability.

[0085] The exception event log is stored in a structured data format. Data fields include a header identifier, data length, checksum, and payload. The header identifier is used for data frame synchronization, the data length field indicates the number of bytes in the payload, and the checksum is calculated using the CRC16 algorithm. The storage area allocation strategy uses a circular buffer model, where new data overwrites old data, and the buffer size is set according to system runtime requirements. The data reading process includes an error detection mechanism; if a read fails, it will retrace up to three times, with the retry interval increasing exponentially over time. Log data backup is performed when the system is idle, and backup data is transferred to an external storage device using a serial communication standard. Interrupt priority settings ensure that timer interrupts have the highest priority, preventing other interrupt sources from affecting the real-time performance of pulse generation. Pulse pin level toggling operations are accelerated using bit-banding technology; the bit-band region is mapped to the memory address space, and the write operation is completed in a single cycle. The level update of the direction control pin is handled outside the interrupt service routine, and the update timing is chosen after the control parameters are calculated to avoid excessive interrupt service routine execution time.

[0086] The sampling frequency for angle deviation monitoring is consistent with the timer interrupt frequency. The sampled data undergoes digital filtering, with a moving average filter selected and the filter order adjusted based on noise characteristics. The reset condition for the anomaly counter includes a deviation below a threshold during normal system operation; the reset operation is achieved by writing to the counter register. System state saving after the protection mechanism is triggered includes register contents, stack pointer, and program counter, stored in a dedicated area of ​​non-volatile memory. The initialization process after system reset includes peripheral reconfiguration, parameter loading, and a self-test program, which verifies the functional integrity of critical hardware modules. The rule base for the fault diagnosis algorithm supports online updates; updated data is received via a communication interface, and the receiving process includes data verification and authentication. Recoverable error handling procedures include environmental condition checks, parameter recalibration, and a gradual recovery strategy. Hardware fault handling procedures include fault isolation, degraded operation, and maintenance notification. Alarm signal management includes multi-level alarm support, with different severity levels triggering different response actions. System operation status monitoring is continuous, and monitoring data is used for predictive maintenance; maintenance recommendations are based on historical data trend analysis.

[0087] The quality assessment of pulse sequence generation is performed by analyzing pulse duty cycle and frequency stability; the assessment results are used to optimize timer configuration parameters. The reliability of encoder signal sampling is enhanced through signal integrity checks, including eye diagram analysis and timing verification. Anomaly log analysis tools are integrated into the development environment, supporting data visualization queries and statistical report generation. System performance testing covers various load conditions and operating scenarios; test data is used to verify the robustness of the control algorithm. The maintenance interface provides remote access capabilities, with access security ensured through encryption protocols and access control lists. The software architecture of the entire implementation adopts a modular design, with clearly defined interfaces between modules, low coupling, and easy maintenance and upgrades. Hardware resource configuration fully considers real-time requirements and computational complexity, selecting high-performance microcontrollers and dedicated peripheral circuits. The development process follows embedded system design specifications, and code quality is guaranteed through static analysis and dynamic testing. Detailed documentation records design decisions and implementation details, facilitating subsequent traceability and auditing. Version management uses professional tools to track change history, ensuring software repeatability and traceability.

[0088] Example 4: The power supply control loop of the stepper motor driver includes a high-power metal-oxide-semiconductor (MOSFET) transistor as a switching element. The gate drive signal of the MOSFET is generated by the microcontroller through an isolated gate driver chip. The input signal of the gate driver chip is directly connected to the general-purpose input / output pins of the microcontroller, and the output is connected to the gate of the MOSFET through a gate resistor. The power supply loop uses soft-turn-off technology, which is achieved by adjusting the fall time of the gate drive signal. The fall time is controlled on the order of microseconds to avoid voltage spikes. A buffer circuit is connected in parallel between the drain and source of the MOSFET. The buffer circuit consists of a resistor, a capacitor, and a diode to absorb the surge energy generated during the turn-off process. The multi-turn absolute encoder receives a synchronous reset command sent through a serial peripheral interface. The format of the synchronous reset command conforms to the communication protocol standard defined by the encoder manufacturer. The command frame structure includes a start bit, a device address field, a command code field, a data field, and a checksum field. The device address field is used to distinguish multiple encoder devices on the bus. The command code field, set to a numerical value, indicates a synchronous reset operation. The data field contains reset parameters such as the reset mode selection bit and the checksum bit. The checksum field is calculated using a cyclic redundancy check algorithm to ensure the integrity of the transmitted command. The timing of the synchronous reset command transmission is controlled by the microcontroller's timer module. The timer generates precise time intervals to ensure that the encoder performs the reset in a safe state.

[0089] The encoder reset verification process initiates a new signal acquisition cycle, which includes an initialization phase, a data request phase, and a response reception phase. The initialization phase configures the communication parameters of the serial peripheral interface, including clock polarity, phase, and baud rate, with the baud rate matching the encoder's rated communication rate. The data request phase sends an encoder data read command; the command format is similar to the synchronous reset command but the command code field is different, and the data field specifies the address of the register to be read. The response reception phase monitors the receive buffer of the serial peripheral interface, with a timeout mechanism to prevent indefinite waiting; the receive timeout period is set according to the encoder response time. The received encoder data is compared with the expected reset value, including the revolution counter value and the status register bit pattern. The encoder signal anomaly detection circuit includes an analog comparator and a digital logic unit. The analog comparator monitors the voltage amplitude of the encoder output signal; a primary alarm is triggered when the voltage amplitude exceeds the normal range. The digital logic unit analyzes the timing characteristics of the encoder signal, including pulse width measurement and edge interval statistics; abnormal timing patterns trigger a secondary alarm. In a continuous abnormal state, the microcontroller activates a fault alarm pin, which is connected to an external indicator circuit and the system monitoring unit. The indicator circuit uses multi-color LEDs to display different fault levels: green indicates normal, yellow indicates warning, and red indicates a serious fault. The system monitoring unit records the time and type of the fault, and the recorded data is uploaded to the host system via a communication interface for subsequent analysis.

[0090] Referring to Table 1, when the microcontroller enters low-power standby mode, it executes a power management sequence, which includes peripheral module clock gating, power-off of unused interfaces, and core voltage regulation. Clock gating technology cuts off the clock signals of idle peripheral modules, reducing dynamic power consumption loss; the gating control bit is set in the microcontroller's power management register. Power-off of unused interfaces is implemented by configuring the interface control register; interfaces can be powered down independently when their power domains are powered separately. Core voltage regulation dynamically adjusts the microcontroller's core voltage according to the operating mode; in standby mode, the core voltage is reduced to the minimum level required to maintain data retention. Wake-up source configuration allows events to trigger system recovery; wake-up events include external interrupt signals and timer timeout signals.

[0091] Table 1: Power Control Parameters for Stepper Motor Driver

[0092]

[0093] The synchronous reset command execution process of a multi-turn absolute encoder comprises four stages: command encoding, transmission, decoding, and execution. In the command encoding stage, the reset command is converted into a binary data stream, which is then assembled into a complete command frame according to the communication protocol format. In the transmission stage, the command frame is sent bit by bit through the shift register of the serial peripheral interface, with a clock signal synchronizing the data transmission process. The decoding stage occurs internally within the encoder, where the encoder's communication controller parses the received command frame and verifies address matching and checksum correctness. In the execution stage, the encoder's reset circuit is activated, clearing the revolution counter and initializing the status register. A reset completion signal is fed back through the status bit. The data comparison algorithm during the encoder reset verification process uses a bit-by-bit comparison method, covering all bits of the revolution counter and key bits of the status register. The comparison result is categorized into three cases: complete match, partial match, and no match. A complete match indicates a successful reset; a partial match initiates a retry mechanism; and a no match indicates a reset failure. The retry mechanism includes an exponential backoff strategy: the retry interval increases exponentially with each consecutive failure, and a maximum retry limit prevents infinite loops. The reset failure handling process includes fault logging, system alarms, and safety state transitions. The fault logging information includes the number of failures, the last error code, and a timestamp.

[0094] The analog circuit for encoder signal anomaly detection includes a voltage comparator composed of operational amplifiers. The reference voltage of the voltage comparator is set by a digital potentiometer, which is programmed via a serial interface. The comparator output is connected to the microcontroller's external interrupt pin. The interrupt service routine reads the comparator state and performs preliminary processing. The digital logic section is implemented in a field-programmable gate array (FPGA). The timing analysis circuit uses a state machine structure, and the state transition conditions are based on measured timing parameters. The anomaly detection threshold is stored in non-volatile memory, and the threshold parameter can be modified online via a debug interface, requiring password authentication. The entry and exit procedures for low-power standby mode are optimized. The entry procedure saves the state of critical registers and gradually reduces system power consumption. The exit procedure restores the register state and reinitializes peripheral modules. The state of critical registers is saved to the microcontroller's backup register area, which is powered by a backup battery to ensure data integrity when the main power supply fails. The reinitialization sequence of peripheral modules is arranged according to dependencies: first, the clock system and power management module are initialized, followed by the communication interface and input / output pins. The processing priority of wake-up sources can be set programmably. When multiple wake-up sources are triggered simultaneously, they are processed in priority order, and the handler performs necessary debouncing operations.

[0095] The protection functions of the stepper motor driver power control circuit include overcurrent protection, overtemperature protection, and undervoltage protection. Overcurrent protection monitors the power supply current through a sampling resistor. The current signal is amplified and compared with a threshold; if the threshold is exceeded, the metal-oxide-semiconductor field-effect transistor (MOSFET) is immediately shut down. Overtemperature protection uses a temperature sensor to monitor the driver's heatsink temperature. The temperature data is read by an analog-to-digital converter (ADC), and a software algorithm predicts the temperature trend. Undervoltage protection detects voltage drops. When the voltage drops below a threshold, an orderly shutdown procedure is initiated to prevent the power devices from operating in the linear region. The communication reliability of the multi-turn absolute encoder is ensured through multiple mechanisms. The physical layer uses differential signal transmission to suppress common-mode interference; the data link layer adds a retransmission mechanism to handle transmission errors; and the application layer includes timeout management and heartbeat detection. Differential signal transmission uses the RS-485 interface standard, and the interface chip has a high common-mode rejection ratio and electrostatic discharge protection. The retransmission mechanism automatically retransmits data frames if no acknowledgment frame is received within a specified time; the number of retransmissions is configurable. The heartbeat detection periodically checks the encoder status; if there is no response after a timeout, the encoder is considered offline, triggering a system maintenance alarm. The system fault recovery strategy distinguishes between temporary and permanent faults. Temporary faults employ an automatic recovery mechanism, which includes status checks and a gradual restart. Permanent faults require manual intervention, and the system provides detailed fault codes and maintenance guidance information. Fault codes are output via display devices or communication interfaces, and maintenance guidance information includes testing procedures and a list of replacement parts. The system maintenance interface supports remote access, with access security ensured through encryption authentication and access logs.

[0096] Example 5: Trapezoidal acceleration curve control during the stepper motor start-up phase divides the entire motion process into three distinct phases. The acceleration phase gradually increases the pulse frequency from its initial value to the system-set maximum operating frequency. The constant speed phase maintains the maximum operating frequency to achieve efficient displacement. The deceleration phase smoothly reduces the pulse frequency to the minimum step frequency when approaching the target position. The pulse frequency increment parameters for each phase are pre-stored in the microcontroller's non-volatile memory. The parameter table is categorized and stored according to different load inertia and motion distances. The parameter selection logic dynamically calls the corresponding parameter set based on the real-time calculated motion characteristics. The pulse frequency change in the acceleration phase adopts a linear growth pattern, and the timer interrupt cycle value decreases in an arithmetic sequence. The decreasing step size is calculated based on the stepper motor torque characteristic curve and load inertia to ensure that the motor achieves the fastest acceleration without exceeding the maximum allowable torque. The constant speed phase maintains a constant maximum operating frequency, and the timer interrupt cycle value remains fixed. The duration of this phase is dynamically calculated based on the remaining motion distance, and the real-time angle deviation monitoring program continuously evaluates the timing of the deceleration point trigger. The deceleration phase employs an exponentially decreasing timer interrupt cycle value. The exponential curve is pre-calculated to generate a discrete numerical table stored in the microcontroller's read-only memory. The index of the numerical table is derived by mapping the real-time angle deviation, achieving nonlinear deceleration characteristics. The starting point of the deceleration phase is adjusted in real time using a dynamic algorithm. The algorithm input includes the current angle deviation, the current operating frequency, and the motor deceleration characteristic parameters. The algorithm calculates and outputs the optimal deceleration starting position, avoiding premature deceleration that affects efficiency or premature deceleration that causes overshoot.

[0097] The specific configuration values ​​of the pulse frequency increment parameters are determined based on the torque-frequency characteristic curve provided in the stepper motor technical manual. The increment parameters in the acceleration phase ensure the motor operates in the flat region of the torque characteristic curve, avoiding resonance frequency points. The frequency in the constant speed phase is selected below the frequency point corresponding to the motor's maximum holding torque, leaving sufficient torque margin to cope with load fluctuations. The frequency change rate in the deceleration phase matches the load's rotational inertia; a gentle deceleration curve is used when the inertia is large, and a steep deceleration curve is used when the inertia is small. The parameter adaptive mechanism fine-tunes the curve parameters based on actual operating data, including acceleration sampling values ​​and position deviation records from the historical motion process. The calculation of the timer interrupt cycle value uses fixed-point arithmetic to improve efficiency. The formula for decreasing the acceleration phase cycle value is: New cycle value = Original cycle value - Fixed step size. The fixed step size value is discretized according to the acceleration time requirements, and the discretization level matches the timer resolution to avoid the accumulation of rounding errors. The deceleration phase cycle value is obtained through a lookup table method. The numerical table index calculation uses a linear interpolation algorithm to improve accuracy; the index value is determined by the ratio of the current angle deviation to the total deceleration distance. The dynamic adjustment algorithm monitors the rate of change of the angle deviation in real time. The rate of change is calculated by the difference value of multiple consecutive sampling points. When the rate of change is abnormal, the backup deceleration parameter set is activated.

[0098] The duration of the acceleration phase is controlled by pulse counting. The pulse counter records the number of pulses emitted, and automatically switches to the constant speed phase when the number of pulses reaches a preset threshold. The switch from the constant speed phase to the deceleration phase is based on the angle deviation. The deceleration phase is triggered when the angle deviation is less than a set threshold. The end condition of the deceleration phase is determined by a comprehensive judgment, including the angle deviation entering the dead zone and the operating frequency dropping below the threshold. The phase switching process adopts a smooth transition strategy, limiting the rate of change of frequency of several pulses before and after the switching point to avoid mechanical vibration caused by sudden torque changes. Pulse frequency parameter updates are completed in the timer interrupt service routine. The interrupt service routine reads the current motion phase flag and selects the corresponding parameter update algorithm according to the phase flag. The acceleration phase parameter update performs a linear decrement operation using a fixed-point subtraction instruction, and the result is checked for range to prevent underflow. The constant speed phase parameter update keeps the current value unchanged, and a fixed value is written to the timer reload register. The deceleration phase parameter update performs a lookup operation. The table index is calculated based on the real-time position deviation, and the lookup result is interpolated to improve resolution. An interrupt protection mechanism ensures data consistency during parameter updates, and interrupt response is disabled during critical parameter operations.

[0099] The real-time angle deviation monitoring program executes synchronously with pulse transmission. Immediately after each pulse transmission, the encoder signal is sampled, and the latest angle deviation is calculated. The angle deviation is used to evaluate the stage switching conditions. The condition for switching from the acceleration stage to the constant speed stage is that the number of transmitted pulses reaches the total number of pulses in the acceleration stage. The condition for switching from the constant speed stage to the deceleration stage is that the real-time angle deviation reaches the deceleration point trigger threshold. The condition for ending the deceleration stage is that the angle deviation enters the positioning dead zone and the motor speed is lower than the crawling speed threshold. Condition judgments are accelerated using a hardware comparator, and the comparison result directly triggers the state machine transition. The dynamic adjustment algorithm is based on predictive control principles. The algorithm predicts the future trajectory based on the current motion state and adjusts parameters to minimize the error between the predicted trajectory and the ideal trajectory. The prediction model includes the motor dynamics equations and the load model; the model parameters are obtained through system identification. The optimization objective function considers multiple factors such as positioning time, energy consumption, and impact vibration, with weighting coefficients adjusted according to the application scenario. Real-time optimization calculations use a simplified algorithm, which reduces computational complexity through pre-calculation and table lookup to meet real-time requirements.

[0100] The parameter tuning process for the trapezoidal acceleration curve includes two stages: offline modeling and online debugging. In the offline modeling stage, motor parameters and load characteristics are measured to establish a mathematical model. In the online debugging stage, actual operating data is collected, including position curves, velocity curves, and current waveforms. Data analysis is used to optimize control parameters. The debugging interface is implemented via serial communication, and the debugging software runs on a host computer, providing a graphical parameter tuning interface. The automatic tuning function applies test signals and analyzes the response, recommending parameter combinations based on response characteristics. Engineers can manually fine-tune the recommended parameters. Motion trajectory monitoring records actual operating data, including planned position, actual position, speed command, and actual speed. Data records are stored in a circular buffer, overwriting the oldest data when the buffer is full. The fault diagnosis function analyzes trajectory deviations and identifies faults such as abnormal mechanical transmission or sudden load changes. The maintenance early warning function assesses the system's health status based on historical data trends and provides early warnings of maintenance needs. Operating data can be exported via the communication interface, with export formats supporting common data analysis tools. The system provides various trapezoidal curve variants to adapt to different application requirements, including S-curves to adjust the smoothness of acceleration and deceleration segments, and parabolic curves to optimize high-speed performance. Curve type is selected via parameters, which are stored in a configuration file. Parameter switching can be completed during runtime, ensuring motion continuity. The parameterized description of curves facilitates portability to different hardware platforms, and the parameterization method abstracts hardware-related details.

[0101] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus.

[0102] Although embodiments of the invention have been shown and described, it will be understood by those skilled in the art that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of the invention, the scope of which is defined by the appended claims and their equivalents.

Claims

1. A method of controlling a capacitance system based on differential control adjustment, characterized by, The method comprises the following steps: Real-time acquisition of the rotation angle data of the stepper motor by a multi-turn absolute value encoder to generate an encoder signal containing the number of turns and the current angle value; Differential error calculation of the encoder signal and the preset target angle value to obtain the angle deviation and the number of turns deviation; Generation of the motor control pulse sequence by the proportional-integral-derivative algorithm according to the angle deviation and the number of turns deviation, wherein the pulse sequence contains the direction control signal and the step frequency parameter; Output of the motor control pulse sequence to the stepper motor driver by the microcontroller to drive the stepper motor to adjust to the target angle position; Real-time monitoring of the actual rotation angle of the stepper motor, and triggering of the encoder protection mechanism when the angle deviation exceeds the threshold value for three consecutive times to stop the motor operation and reset the number of turns.

2. The capacitance system control method based on a differential control adjustment according to claim 1, characterized by, The real-time acquisition of the rotation angle data of the stepper motor by the multi-turn absolute value encoder to generate the encoder signal containing the number of turns and the current angle value comprises: Reading the single-turn angle signal and the number of turns signal of the multi-turn absolute value encoder, and performing photoelectric isolation and noise filtering processing on the signals; Time alignment of the processed single-turn angle signal and the number of turns signal by the clock synchronization sampling circuit to eliminate the signal transmission delay difference; Combination encoding of the time-aligned single-turn angle signal and the number of turns signal to generate a composite encoder signal containing 16-bit angle data and 8-bit number of turns data; After the composite encoder signal is subjected to parity check and CRC check to ensure data integrity, it is output to the microcontroller.

3. The capacitance system control method based on a differential control adjustment according to claim 2, characterized by, The differential error calculation of the encoder signal and the preset target angle value to obtain the angle deviation and the number of turns deviation comprises: Parsing the current angle value and the current number of turns value from the composite encoder signal, and performing subtraction operation with the target angle value and the target number of turns value stored in the microcontroller; Calculating the first-order difference of the current angle value and the target angle value to obtain the instantaneous angle deviation; Calculating the cumulative difference of the current number of turns value and the target number of turns value to obtain the absolute number of turns deviation; Sliding window average processing of the instantaneous angle deviation to eliminate high-frequency jitter noise and output the stable angle deviation.

4. The capacitance system control method based on a differential control adjustment according to claim 3, characterized by, The generation of the motor control pulse sequence by the proportional-integral-derivative algorithm according to the angle deviation and the number of turns deviation comprises: Inputting the stable angle deviation into the proportional element of the proportional-integral-derivative controller, multiplying by the proportional coefficient to generate the basic pulse frequency; Integrating and adding the stable angle deviation, multiplying by the integral coefficient to generate the pulse frequency compensation; Differentiating the stable angle deviation, multiplying by the differential coefficient to generate the pulse frequency damping amount; Superimposing the basic pulse frequency, the pulse frequency compensation and the pulse frequency damping amount to generate the final step frequency parameter; Determining the level state of the direction control signal according to the sign bit of the absolute number of turns deviation.

5. The capacitance system control method based on a differential control adjustment according to claim 4, characterized by, The output of the motor control pulse sequence to the stepper motor driver by the microcontroller to drive the stepper motor to adjust to the target angle position comprises: Converting the final step frequency parameter into the timer interrupt period value to configure the timer module of the microcontroller; Setting the direction pin level of the motor driver according to the level state of the direction control signal. Flip the pulse pin level of the motor driver in the timer interrupt service routine to generate a pulse sequence of corresponding frequency; Read the encoder signal in real time and update the angle deviation and the number of turns deviation, dynamically adjust the timer interrupt period value.

6. The capacitance system control method based on a differential control adjustment according to claim 5, wherein, Real-time monitoring of the actual rotation angle of the stepper motor, when the angle deviation is detected for three consecutive times and exceeds the threshold value, trigger the encoder protection mechanism, including: Record the absolute value of the current angle deviation in each timer interrupt service; If the current angle deviation exceeds the preset angle tolerance threshold, increment the count value of the abnormal counter; When the count value of the abnormal counter reaches 3, immediately turn off the timer interrupt and pull down the enable pin of the motor driver; Write the abnormal event log to the non-volatile memory of the microcontroller, including the angle deviation and the number of turns deviation when the abnormality occurs; Reset the microcontroller through the hardware watchdog circuit, reinitialize the number of turns count and the encoder signal sampling.

7. The capacitance system control method based on a differential control adjustment according to claim 6, characterized by, The motor is stopped and the number of turns is reset, including: Cut off the power supply of the stepper motor driver, release the mechanical load of the motor shaft; Send a synchronous reset command to the multi-turn absolute encoder to clear its internal number of turns counter; Reacquire the single-turn angle signal and the number of turns signal of the encoder to verify the effectiveness of the reset operation; If the encoder signal still has an abnormality after reset, activate the fault alarm pin of the microcontroller and enter standby mode.

8. The capacitance system control method based on a differential control adjustment according to claim 4, wherein, The proportional-integral-derivative algorithm also includes an adaptive adjustment mechanism, including: When the absolute number of turns deviation exceeds the preset number of turns threshold, dynamically adjust the proportional coefficient and the integral coefficient to speed up the convergence speed; When the angle deviation is close to zero, automatically reduce the differential coefficient to reduce high-frequency oscillation; Adjust the PID parameters in real time according to the change of motor load to ensure the balance between system response speed and stability.

9. The capacitance system control method based on a differential control adjustment according to claim 6, wherein, The storage and recovery mechanism of the abnormal event log includes: Record the motor running state when the abnormality occurs in the non-volatile memory, including the current stepping frequency, direction control signal and encoder data; After system reset, automatically read the abnormal log and perform fault diagnosis, if it is determined to be a recoverable error, reload the target angle value and resume motor operation; If it is determined to be a hardware failure, lock the motor driver and trigger an external alarm signal.

10. The method of claim 1, wherein the differential control adjustment-based capacitance system control method is characterized by, It also includes: Use a trapezoidal acceleration curve to control the pulse frequency change during the startup phase of the stepper motor, including: Divide the startup process into acceleration segment, constant speed segment and deceleration segment, set corresponding pulse frequency increment for each segment; Increase the timer interrupt period value in the acceleration segment according to the linear law until the maximum running frequency is reached; Decrease the timer interrupt period value in the deceleration segment according to the exponential law until it approaches the target angle position; Dynamically adjust the starting point of the deceleration segment according to the real-time angle deviation to ensure smooth stopping of the motor.