Signal desaturation method for a magnetic encoder, storage medium and program product

By introducing a programmable gain amplifier and dynamic range adjustment into the magnetic encoder, combined with the observation window setup stage and zero-crossing event, the problem of magnetic encoder signal saturation distortion is solved, and stable signal processing within the ideal range is achieved, enhancing robustness and accuracy.

CN122306120APending Publication Date: 2026-06-30浙江屹晶微电子股份有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
浙江屹晶微电子股份有限公司
Filing Date
2026-04-03
Publication Date
2026-06-30

AI Technical Summary

Technical Problem

In actual operation, magnetic encoders can cause signal saturation distortion due to changes in magnetic field strength. This is especially true when the signal amplitude exceeds the allowable range of the analog-to-digital converter due to axial movement of the motor, temperature drift, or mechanical assembly tolerances. As a result, the top or bottom of the waveform acquired by the analog-to-digital converter is directly cut off, resulting in saturation distortion.

Method used

By introducing a programmable gain amplifier into the magnetic encoder, the dynamic range of the signal is monitored in real time, and the gain is actively adjusted before the signal approaches saturation. Maximum and minimum adjustment thresholds are set, and an observation window setup stage and zero-crossing events are introduced to ensure the accuracy of extreme value information and avoid frequent oscillations.

Benefits of technology

It effectively reduces the occurrence of signal saturation distortion, enhances the robustness of adaptive gain control, ensures that the signal is within the ideal range, reduces frequent oscillations caused by signal amplitude deviation, and improves the stability and accuracy of signal processing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122306120A_ABST
    Figure CN122306120A_ABST
Patent Text Reader

Abstract

A method, storage medium, and program product for signal anti-saturation of a magnetic encoder are disclosed, relating to the field of digital signal processing technology, to reduce saturation distortion in magnetic encoders. In this method, when the signal amplitude shows an increasing trend and approaches a historical extreme value, i.e., before actual saturation clipping occurs, the magnetic encoder triggers dynamic range evaluation and gain adjustment, thereby proactively reducing gain and mitigating signal saturation distortion caused by unexpected magnetic field enhancement. Simultaneously, by setting a stable range consisting of maximum and minimum adjustment thresholds, adjustment is only performed when the signal amplitude deviates from the ideal range, avoiding frequent oscillations near the target value and enhancing the robustness of the overall adaptive gain control.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of digital signal processing technology, and in particular to a signal anti-saturation method, storage medium, and program product for a magnetic encoder. Background Technology

[0002] Magnetic encoders, as non-contact angle measurement devices, are widely used in motor control, robot joint servo systems, and automotive electronic steering systems due to their oil resistance, vibration resistance, and long lifespan. Their basic working principle involves using a magnetically sensitive element (such as a Hall effect sensor or magnetoresistive sensor) to sense changes in the magnetic field generated by a rotating permanent magnet, converting these changes into analog voltage signals (typically sine and cosine signals). This analog signal is then processed and amplified by an analog front-end, converted into a digital signal by an analog-to-digital converter, and finally calculated by a digital processing unit using algorithms such as arctangent to determine the absolute or incremental angular position of the shaft.

[0003] In relevant magnetic encoder technologies, a signal amplification link is typically incorporated into the analog front-end to match the weak signal output by the magnetic sensor with the input range of the analog-to-digital converter (ADC). During product design or factory calibration, a pre-defined amplification gain value is selected and written into the magnetic encoder based on a preset mechanical mounting distance and theoretical magnetic field strength. Alternatively, a mechanical limiting design is used to strictly fix the air gap between the magnet and the sensor, ensuring that the magnetic field strength sensed by the sensor remains within a specific range. During actual operation, the magnetic encoder amplifies the acquired analog signal according to this preset gain and directly transmits the amplified signal to the ADC for sampling and digitization.

[0004] However, when the application scenario changes, such as the axial movement of the motor during high-speed operation causing the magnet to momentarily approach the sensor, or the actual magnetic field strength becoming stronger than designed due to temperature drift or mechanical assembly tolerances, the amplitude of the original signal output by the sensor will increase accordingly. Since the amplification gain at the back end is preset and constant, the amplified signal voltage is very likely to exceed the allowable input reference voltage range of the analog-to-digital converter (i.e., the upper or lower limit of the range), causing the top or bottom of the waveform acquired by the analog-to-digital converter to be directly cut off, resulting in saturation distortion. Summary of the Invention

[0005] This application provides a signal anti-saturation method, storage medium, and program product for magnetic encoders to reduce saturation distortion.

[0006] Firstly, a signal anti-saturation method for a magnetic encoder is provided. The magnetic encoder includes a magnetic sensitive element, an analog front-end, and an analog-to-digital converter (ADC). The analog front-end integrates a programmable gain amplifier. The method includes: the magnetic encoder continuously acquiring digital sampled values ​​of the output signal of the magnetic sensitive element after amplification by the programmable gain amplifier via the ADC; the magnetic encoder recording the maximum and minimum values ​​of the digital sampled values ​​within the current observation window; the magnetic encoder calculating, at each sampling moment, a first absolute value of the difference between the current digital sampled value and the maximum value, and a second absolute value of the difference between the current digital sampled value and the minimum value; and when either the first or second absolute value of the difference is less than a preset saturation risk threshold... The magnetic encoder uses the difference between the maximum and minimum values ​​as the dynamic range value of the current signal. It uses the product of the preset target dynamic range value and preset first and second coefficients as the maximum and minimum adjustment thresholds, respectively, where the preset first coefficient is greater than the preset second coefficient. When the dynamic range value is greater than the maximum adjustment threshold, the magnetic encoder subtracts a preset gain step value from the gain value of the programmable gain amplifier. When the dynamic range value is less than the minimum adjustment threshold, the magnetic encoder adds a preset gain step value to the gain value of the programmable gain amplifier. When the dynamic range value is less than or equal to the maximum adjustment threshold and greater than or equal to the minimum adjustment threshold, the magnetic encoder keeps the gain value of the programmable gain amplifier unchanged.

[0007] By adopting the above technical solution, when the signal amplitude shows an increasing trend and approaches its historical extreme value, that is, before the actual saturation clipping of the signal occurs, the magnetic encoder triggers dynamic range evaluation and gain adjustment, thereby intervening in advance and actively reducing the gain, thus reducing signal saturation distortion caused by unexpected enhancement of the magnetic field. Simultaneously, by setting a stable range consisting of maximum and minimum adjustment thresholds, adjustment is only performed when the signal amplitude deviates from the ideal range, avoiding frequent oscillations near the target value and enhancing the robustness of the entire adaptive gain control.

[0008] In conjunction with some embodiments of the first aspect, in some embodiments, after the magnetic encoder adjusts the gain value of the programmable gain amplifier, the method further includes: the magnetic encoder pausing the acquisition of digital sampled values ​​within a preset gain settling time; and the magnetic encoder using the first digital sampled value acquired after the preset gain settling time ends as the new maximum value and the new minimum value.

[0009] By adopting the above technical solution, after gain adjustment, the acquisition is paused and a preset gain settling time is waited for. This shields the transient instability of the programmable gain amplifier output signal at the moment of gain switching, preventing invalid sampled values ​​containing overshoot or oscillation from being incorrectly used in subsequent calculations. Then, the first sampled value after the settling time is used as the new maximum and minimum values, providing a suitable initial benchmark for subsequent observation window reconstruction.

[0010] In conjunction with some embodiments of the first aspect, in some embodiments, after the step of the magnetic encoder taking the first digitized sampled value acquired after the preset gain settling time as the new maximum and new minimum values, the method further includes: the magnetic encoder entering the observation window establishment phase; in the observation window establishment phase, the magnetic encoder only continuously updates the maximum and minimum values, and suspends the calculation of the first absolute value of the difference and the second absolute value of the difference; when the digitized sampled value completes one zero crossing, the magnetic encoder determines that the observation window establishment phase has ended, and resumes the calculation of the first absolute value of the difference and the second absolute value of the difference.

[0011] By adopting the above technical solution, a special working state called the observation window setup phase is introduced. After gain adjustment, the magnetic encoder can temporarily suspend saturation risk judgment and focus on capturing the true signal extrema under the new gain. This avoids erroneous gain adjustment caused by using inaccurate extrema information that has not yet been fully established. By using the clear signal characteristic event of zero crossing as the marker for the end of the setup phase, saturation risk monitoring is only resumed when the observation window contains a sufficiently representative signal waveform and the recorded extrema have high reliability.

[0012] In conjunction with some embodiments of the first aspect, in some embodiments, when the digitized sampled value completes one zero-crossing, the magnetic encoder determines that the observation window establishment phase has ended and resumes the steps of calculating the first absolute value of the difference and the second absolute value of the difference. Specifically, this includes: when the historical sampled value at the previous sampling time and the current digitized sampled value are respectively located on both sides of the preset zero-point reference voltage, the magnetic encoder determines that the digitized sampled value has completed one zero-crossing; when the digitized sampled value completes one zero-crossing, the magnetic encoder determines that the observation window establishment phase has ended and resumes the calculation of the first absolute value of the difference and the second absolute value of the difference.

[0013] By employing the above technical solution, and comparing whether the current sampled value and historical sampled values ​​are located on either side of the zero-point reference voltage, the instant of signal zero crossing can be captured with lower computational overhead. This implementation method is simple and reliable, and easy to implement in resource-constrained digital control units such as microcontrollers, thereby enhancing the practicality and feasibility of the special working state of the observation window establishment phase.

[0014] In conjunction with some embodiments of the first aspect, in some embodiments, before the magnetic encoder calculates the first absolute value of the difference between the current digitized sample value and the maximum value and the second absolute value of the difference between the current digitized sample value and the minimum value at each sampling time, the method further includes: when the current digitized sample value is the upper limit or lower limit of the range of the analog-to-digital converter, the magnetic encoder determines that hard saturation has occurred; in the case of hard saturation, the magnetic encoder directly subtracts a preset gain step value from the gain value of the programmable gain amplifier and skips the calculation of the dynamic range value at the current sampling time.

[0015] By adopting the above technical solution, when the signal amplitude changes so drastically that the predictive judgment mechanism cannot react in time and the sampled value directly touches the range limit of the analog-to-digital converter, the magnetic encoder bypasses the conventional dynamic range calculation process and directly performs the gain reduction operation, thereby being able to get out of the saturation state more quickly in extreme cases.

[0016] In conjunction with some embodiments of the first aspect, in some embodiments, after the magnetic encoder adjusts the gain value of the programmable gain amplifier, the method further includes: after the magnetic encoder subtracts or adds a preset gain step value to the gain value of the programmable gain amplifier, the magnetic encoder starts a cooling counter; before the cooling counter reaches a preset value, if the dynamic range value triggers the adjustment condition again, the magnetic encoder ignores the trigger condition and keeps the current gain value unchanged; only when hard saturation occurs, the magnetic encoder forcibly interrupts the cooling counter and performs a gain reduction operation.

[0017] By adopting the above technical solution, the system is forced to enter a cooling-off period after each gain adjustment. During this period, the magnetic encoder temporarily ignores the conventional adjustment trigger conditions, avoiding excessively frequent and unnecessary gain adjustments caused by small fluctuations in the signal near the adjustment threshold, thereby suppressing system oscillation.

[0018] In conjunction with some embodiments of the first aspect, in some embodiments, before the step of the magnetic encoder multiplying the preset target dynamic range value by the preset first coefficient and the preset second coefficient respectively as the maximum adjustment threshold and the minimum adjustment threshold, the method further includes: when the rotational speed of the magnetic encoder is lower than the preset low speed threshold, the magnetic encoder increases the preset first coefficient.

[0019] By adopting the above technical solution and increasing the preset first coefficient under low-speed conditions, the upper limit requirement for the signal dynamic range is effectively relaxed. This allows for a more effective distinction between actual signal amplitude increases and random noise spikes.

[0020] In a second aspect, embodiments of this application provide a magnetic encoder comprising: one or more processors and a memory; the memory is coupled to the one or more processors and is used to store computer program code, the computer program code including computer instructions, wherein the one or more processors invoke the computer instructions to cause the magnetic encoder to perform the method described in the first aspect and any possible implementation thereof.

[0021] Thirdly, embodiments of this application provide a computer program product containing instructions that, when the computer program product is run on a magnetic encoder, cause the magnetic encoder to perform the method described in the first aspect and any possible implementation thereof.

[0022] Fourthly, embodiments of this application provide a computer-readable storage medium including instructions that, when executed on a magnetic encoder, cause the magnetic encoder to perform the method described in the first aspect and any possible implementation thereof.

[0023] Understandably, the magnetic encoder provided in the second aspect, the computer program product provided in the third aspect, and the computer storage medium provided in the fourth aspect are all used to execute the methods provided in the embodiments of this application. Therefore, the beneficial effects they can achieve can be referred to the beneficial effects in the corresponding methods, and will not be repeated here.

[0024] One or more technical solutions provided in the embodiments of this application have at least the following technical effects or advantages:

[0025] 1. When the signal amplitude shows an increasing trend and approaches its historical extreme value, i.e., before actual saturation clipping occurs, the magnetic encoder triggers dynamic range assessment and gain adjustment. This proactively reduces gain and mitigates signal saturation distortion caused by unexpected magnetic field enhancement. Simultaneously, by setting a stable range comprised of maximum and minimum adjustment thresholds, adjustment is only performed when the signal amplitude deviates from the ideal range, avoiding frequent oscillations near the target value and enhancing the robustness of the overall adaptive gain control.

[0026] 2. The magnetic encoder introduces a special operating state called the observation window setup phase. After gain adjustment, the magnetic encoder can temporarily suspend saturation risk judgment and focus on capturing the true signal extrema under the new gain. This avoids erroneous gain adjustment caused by using inaccurate extrema information that has not yet been fully established. By using the clear signal characteristic event of zero crossing as the marker for the end of the setup phase, saturation risk monitoring is only resumed when the observation window contains a sufficiently representative signal waveform and the recorded extrema have high reliability.

[0027] 3. When the signal amplitude changes so drastically that the predictive judgment mechanism cannot react in time and the sampled value directly reaches the range limit of the analog-to-digital converter, the magnetic encoder bypasses the conventional dynamic range calculation process and directly performs a gain reduction operation, thus being able to get out of the saturation state more quickly in extreme cases. Attached Figure Description

[0028] Figure 1 This is a schematic flowchart of a signal anti-saturation method for a magnetic encoder according to an embodiment of this application.

[0029] Figure 2 This is another schematic flowchart of a signal anti-saturation method for a magnetic encoder in an embodiment of this application.

[0030] Figure 3 This is a schematic diagram of the physical device structure of a magnetic encoder in the embodiments of this application. Detailed Implementation

[0031] The terminology used in the following embodiments of this application is for the purpose of describing particular embodiments only and is not intended to be limiting of this application. As used in the specification and appended claims of this application, the singular expressions “a,” “an,” “the,” “the,” “the,” and “this” are intended to include the plural expressions as well, unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used in this application refers to and includes any or all possible combinations of one or more of the listed items.

[0032] Hereinafter, the terms "first" and "second" are used for descriptive purposes only and should not be construed as implying or suggesting relative importance or implicitly indicating the number of indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature, and in the description of the embodiments of this application, unless otherwise stated, "multiple" means two or more.

[0033] This application provides a signal anti-saturation method, storage medium, and program product for magnetic encoders to reduce saturation distortion.

[0034] Please see Figure 1 This is a flowchart illustrating a signal anti-saturation method for a magnetic encoder in an embodiment of this application.

[0035] S101, the magnetic encoder continuously acquires the digital sampled value of the output signal of the magnetic sensitive element after it has been amplified by a programmable gain amplifier through an analog-to-digital converter.

[0036] A magnetic sensing element is a sensor that converts changes in magnetic field strength or direction into an electrical signal, such as a Hall effect sensor or anisotropic magnetoresistive sensor. Its output is a weak analog voltage signal proportional to the magnetic field component. A programmable gain amplifier is an amplifier circuit whose amplification factor can be dynamically adjusted via digital instructions. It is used to amplify the weak signal output by the magnetic sensing element to a level suitable for processing by an analog-to-digital converter (ADC). An ADC is an electronic device that converts continuous analog voltage signals into discrete digital values; the conversion result is a digitized sampled value. A digitized sampled value uses a binary number with a specific bit width (such as 12 bits or 16 bits) to represent the magnitude of an instantaneous analog voltage. For example, for a 12-bit ADC with a reference voltage of 3.3V, its output digital value ranges from 0 to 4095.

[0037] Specifically, after the magnetic encoder is powered on and initialized, its internal digital control unit (e.g., a microcontroller MCU) periodically activates the analog-to-digital converter (ADC) at a preset sampling frequency (e.g., 20kHz). At each sampling moment, the real-time magnetic field strength sensed by the magnetic sensor is converted into an analog voltage. This voltage signal flows through a programmable gain amplifier and is amplified according to the currently set gain value. The amplified analog signal is then input to the ADC, which completes one conversion and transmits the resulting digitized sampled value to the ADC for further processing. This process is continuous, providing a real-time data stream for subsequent signal analysis and gain adjustment.

[0038] S102. The magnetic encoder records the maximum and minimum values ​​of the digitized sampled values ​​within the current observation window.

[0039] The current observation window refers to a time interval used to evaluate signal characteristics. This can be a fixed time length or a dynamic interval defined by a fixed number of sampling points. The maximum value represents the largest value among all digitized sampled values ​​captured within the observation window. The minimum value represents the smallest value among all digitized sampled values ​​captured within the observation window.

[0040] Specifically, starting from the first sampling point of the observation window, the digital control unit initializes the maximum and minimum value registers (e.g., the maximum value is initialized to the ADC's minimum value of 0, and the minimum value is initialized to the ADC's maximum value of 4095). At each subsequent sampling moment, after a new digitized sampled value is obtained in step S101, the digital control unit immediately performs two comparison operations: comparing the new sampled value with the currently recorded maximum value; if the new value is larger, the maximum value register is updated. Simultaneously, comparing the new sampled value with the currently recorded minimum value; if the new value is smaller, the minimum value register is updated.

[0041] S103. The magnetic encoder calculates the absolute value of the first difference between the current digitized sampled value and the maximum value, and the absolute value of the second difference between the current digitized sampled value and the minimum value at each sampling time.

[0042] The first absolute difference refers to the absolute value of the difference between the current digitized sampled value and the maximum value recorded within the current observation window, quantifying the margin of the current signal point from the historical peak. The second absolute difference refers to the absolute value of the difference between the current digitized sampled value and the minimum value recorded within the current observation window, quantifying the margin of the current signal point from the historical trough.

[0043] Specifically, this step is performed after acquiring each new digitized sample value and updating the maximum / minimum values. The magnetic encoder's digital control unit reads the current digitized sample value, maximum value, and minimum value from the corresponding registers, and then performs two subtractions and two absolute value operations. The purpose of this calculation is to monitor the head and bottom spaces of the signal. In an ideal and stable sine wave, one of these two differences will only be zero when the signal reaches the peak or trough. If the signal amplitude tends to increase, the new sample value will be very close to or even exceed the old extreme value, causing one of these two differences to become very small. Therefore, these two differences constitute a direct basis for judging the risk of saturation.

[0044] S104. When either the absolute value of the first difference or the absolute value of the second difference is less than the preset saturation risk threshold, the magnetic encoder uses the difference between the maximum and minimum values ​​as the dynamic range value of the current signal.

[0045] The preset saturation risk threshold is a critical value used to determine whether a signal is about to enter a saturation state. Its value is typically set to a small positive integer much smaller than the signal's normal dynamic range. For example, it could be a value between 1% and 10% of the full-scale range of an analog-to-digital converter (ADC). For a 12-bit ADC, it could be set to 50 or 100. The current signal's dynamic range value refers to the peak-to-peak value of the signal captured within the current observation window. It is calculated by the difference between the maximum and minimum values ​​and directly reflects the overall amplitude of the amplified signal.

[0046] Specifically, when the signal waveform is operating normally, if the difference between its sampled value and the historical extreme value is large, exceeding the saturation risk threshold, the magnetic encoder remains silent. However, if the signal amplitude increases due to factors such as enhanced magnetic field, the new sampled value will approach or even exceed the original maximum or minimum value, causing the first or second difference to fall below the preset saturation risk threshold. The magnetic encoder then interprets this event as a saturation risk alarm and immediately initiates a complete dynamic range assessment, calculating the difference between the maximum and minimum values ​​and using this value as the actual dynamic range of the current signal for subsequent gain adjustment decisions.

[0047] S105. The magnetic encoder uses the product of the preset target dynamic range value and the preset first coefficient and the preset second coefficient as the maximum adjustment threshold and the minimum adjustment threshold, respectively.

[0048] The preset target dynamic range value represents an ideal peak-to-peak value for the signal. This value aims to ensure that the signal amplitude fully utilizes the quantization range of the analog-to-digital converter (ADC) to achieve high resolution, while retaining sufficient margin to prevent saturation. For example, it can be set to 80% or 90% of the ADC's full scale. The preset first coefficient is a value greater than 1, such as 1.1. The preset second coefficient is a value between 0 and 1, such as 0.9. The maximum adjustment threshold refers to the upper limit of the signal's dynamic range; once this value is exceeded, the gain should be reduced. The minimum adjustment threshold refers to the lower limit of the signal's dynamic range; once this value is below this value, the gain should be increased.

[0049] Specifically, after triggering and calculating the dynamic range value of the current signal in step S104, the magnetic encoder needs a standard to determine whether this dynamic range value is too large, too small, or just right. By introducing a target dynamic range value and using two coefficients (such as 1.1 and 0.9) to construct a hysteresis interval around the target, the magnetic encoder obtains a clear adjustment target. For example, if the analog-to-digital converter is 12-bit (range 4096), and the target dynamic range is set to 4096 * 0.8 ≈ 3277, then the maximum adjustment threshold is 3277 * 1.1 ≈ 3605, and the minimum adjustment threshold is 3277 * 0.9 ≈ 2949. Subsequent steps will compare the currently calculated dynamic range value with this interval [2949, 3605]. Furthermore, these coefficients can be dynamically adjusted to adapt to different operating conditions. For example, when the magnetic encoder speed is detected to be lower than the preset low-speed threshold, the signal changes slowly and the noise effect is relatively prominent. At this time, the first coefficient can be appropriately increased (e.g., from 1.1 to 1.15) to relax the tolerance for the upper limit of the signal amplitude, so as to reduce unnecessary gain reduction caused by peak jitter due to noise and enhance the stability of the system at low speed.

[0050] S106. When the dynamic range value is greater than the maximum adjustment threshold, the magnetic encoder will subtract a preset gain step value from the gain value of the programmable gain amplifier.

[0051] The preset gain step value represents the smallest unit of change when adjusting the gain, which is usually the smallest gain adjustment supported by the programmable gain amplifier, such as 1. Subtracting one step value from the gain value means making a small, gradual reduction in the amplification of the signal.

[0052] Specifically, this step is executed after step S105. When the calculated signal dynamic range value is greater than the maximum adjustment threshold, the magnetic encoder determines that the current gain is too high, resulting in an excessively large signal amplitude and a high risk of saturation. To bring the signal amplitude back to the ideal range, the magnetic encoder reads the current gain value of the programmable gain amplifier, performs a subtraction operation, subtracts a preset gain step value from the current gain value, and obtains a new, lower gain value. Then, the magnetic encoder writes this new gain value into the configuration register of the programmable gain amplifier through a communication interface (such as SPI or I2C bus) connected to the programmable gain amplifier. After receiving the new instruction, the feedback network of its internal amplification circuit changes, thereby reducing the amplification factor. This step-by-step adjustment method makes the gain change smoother and reduces the oscillation that may be caused by sudden gain changes.

[0053] S107. When the dynamic range value is less than the minimum adjustment threshold, the magnetic encoder adds a preset gain step value to the gain value of the programmable gain amplifier.

[0054] Specifically, this step is also executed after step S105. When the calculated current signal dynamic range value is less than the minimum adjustment threshold, the digital control unit of the magnetic encoder determines that the current gain is too low. This will result in a smaller signal amplitude. Although there is no risk of saturation, the signal details may be overwhelmed by the quantization noise of the analog-to-digital converter, reducing the effective resolution and accuracy of the angle measurement. In order to make full use of the dynamic range of the analog-to-digital converter, the digital control unit of the magnetic encoder performs an addition operation, adding a preset gain step value to the gain value of the programmable gain amplifier to obtain a new, higher gain value. Subsequently, this new gain value is configured to the programmable gain amplifier through the digital interface to increase its amplification factor, thereby boosting the signal amplitude to the ideal range.

[0055] S108. When the dynamic range value is less than or equal to the maximum adjustment threshold and greater than or equal to the minimum adjustment threshold, the magnetic encoder will keep the gain value of the programmable gain amplifier unchanged.

[0056] Specifically, this step is also performed after step S105. When the dynamic range value is less than or equal to the maximum adjustment threshold and greater than or equal to the minimum adjustment threshold, it indicates that the signal amplitude is neither too large nor too small, just right, and the magnetic encoder will keep the gain value of the programmable gain amplifier unchanged.

[0057] In the above embodiments, when the signal amplitude shows an increasing trend and approaches a historical extreme value, that is, before the actual saturation clipping of the signal occurs, the magnetic encoder triggers dynamic range evaluation and gain adjustment, thereby intervening in advance and actively reducing the gain, thus reducing signal saturation distortion caused by unexpected enhancement of the magnetic field. Simultaneously, by setting a stable range consisting of maximum and minimum adjustment thresholds, adjustment is only performed when the signal amplitude deviates from the ideal range, avoiding frequent oscillations near the target value and enhancing the robustness of the entire adaptive gain control.

[0058] However, after performing gain adjustment (step S106 or S107), the output signal of the programmable gain amplifier undergoes a brief settling process, and the previously recorded maximum and minimum values ​​become invalid for the new gain. If the saturation risk judgment in step S103 is immediately resumed before the signal has stabilized and the extreme value information has been reconstructed, erroneous triggering may occur due to transient signal fluctuations or inaccurate extreme values, causing the magnetic encoder to perform unnecessary secondary adjustments, or even triggering oscillations. To solve this problem and improve the stability and convergence speed of the magnetic encoder after gain switching, this application also provides the following embodiments.

[0059] Please see Figure 2 This is another flowchart illustrating a signal anti-saturation method for a magnetic encoder in an embodiment of this application.

[0060] S201, the magnetic encoder continuously acquires the digital sampled value of the output signal of the magnetic sensitive element after it has been amplified by a programmable gain amplifier through an analog-to-digital converter.

[0061] S202. The magnetic encoder records the maximum and minimum values ​​of the digitized sampled values ​​within the current observation window.

[0062] Step S201 is similar to step S101, and step S202 is similar to step S102, so they will not be described again here.

[0063] S203. The magnetic encoder calculates the absolute value of the first difference between the current digitized sampled value and the maximum value, and the absolute value of the second difference between the current digitized sampled value and the minimum value at each sampling time.

[0064] Step S203 is similar to step S103, and will not be described again here.

[0065] In some embodiments, before the magnetic encoder calculates the absolute value of the first difference between the current digitized sample value and the maximum value, and the absolute value of the second difference between the current digitized sample value and the minimum value at each sampling time,

[0066] S204. When either the absolute value of the first difference or the absolute value of the second difference is less than the preset saturation risk threshold, the magnetic encoder uses the difference between the maximum and minimum values ​​as the dynamic range value of the current signal.

[0067] S205. The magnetic encoder uses the product of the preset target dynamic range value and the preset first coefficient and the preset second coefficient as the maximum adjustment threshold and the minimum adjustment threshold, respectively.

[0068] S206. When the dynamic range value is greater than the maximum adjustment threshold, the magnetic encoder will subtract a preset gain step value from the gain value of the programmable gain amplifier.

[0069] S207. When the dynamic range value is less than the minimum adjustment threshold, the magnetic encoder adds a preset gain step value to the gain value of the programmable gain amplifier.

[0070] S208. When the dynamic range value is less than or equal to the maximum adjustment threshold and greater than or equal to the minimum adjustment threshold, the magnetic encoder will keep the gain value of the programmable gain amplifier unchanged.

[0071] Step S204 is similar to step S104, step S205 is similar to step S105, step S206 is similar to step S106, step S207 is similar to step S107, and step S208 is similar to step S108, so they will not be repeated here.

[0072] S209. The magnetic encoder pauses the acquisition of digital sampled values ​​within the preset gain settling time.

[0073] The preset gain settling time refers to the physical time required from when the programmable gain amplifier receives a new gain command to when its output analog signal stabilizes to the new amplitude. The length of this time depends on the slew rate and bandwidth of the operational amplifier within the programmable gain amplifier, as well as the response characteristics of the subsequent filtering circuit, and is typically on the order of microseconds. Pausing acquisition does not mean the analog-to-digital converter stops working, but rather that the digital control unit of the magnetic encoder temporarily ignores or discards the data converted by the analog-to-digital converter during this period.

[0074] Specifically, this step is performed after gain adjustment in step S206 or S207. When the digital control unit of the magnetic encoder writes a new gain value to the programmable gain amplifier, the internal circuit state of the programmable gain amplifier changes. The output analog signal does not instantly jump to the new stable amplitude but undergoes a brief transient process, which may include overshoot and oscillation. If sampling is performed during this period and used for subsequent extreme value judgment, incorrect and unstable data will be obtained, thus interfering with the gain adjustment decision in the next round. Therefore, this step initiates a short delay (e.g., through a for loop or a hardware timer) by having the digital control unit of the magnetic encoder not process the analog-to-digital converter data during the delay, so that subsequent steps (such as S210) obtain a stable signal sample value.

[0075] S210, the magnetic encoder uses the first digitized sample value acquired after the preset gain settling time ends as the new maximum and minimum values.

[0076] The first digitized sample value refers to the first data output by the analog-to-digital converter after the preset gain settling time in step S209. The new maximum and minimum values ​​refer to the initialization assignments made to the registers (maximum and minimum values) used to record the extreme values ​​of the signal within the observation window.

[0077] Specifically, since the gain has changed, the previously recorded maximum and minimum values ​​are invalid and need to be reset. After the preset gain settling time in S209 ends, the first sampled value acquired by the magnetic encoder is the first valid signal point under the new gain. Although this point may not be the true extreme value of the new signal waveform, initializing both the maximum and minimum values ​​to this value provides a suitable starting point for subsequent extreme value search. This ensures that from this moment on, the maximum value will only be updated upwards, and the minimum value will only be updated downwards, thus recapturing the true peak and valley values ​​of the signal under the new gain in a shorter time.

[0078] S211, The magnetic encoder enters the observation window establishment stage.

[0079] The observation window establishment phase refers to a special working state in which the main task of the magnetic encoder is to capture the maximum and minimum values ​​of the signal under the new gain as soon as possible, without temporarily judging the saturation risk or triggering the gain adjustment.

[0080] Specifically, this step is executed immediately after the extreme value register is reset in S210, marking the switch of the magnetic encoder state. Gain adjustment is an operation that has a significant impact on the magnetic encoder. After adjustment, the magnetic encoder needs to be given a recovery period to readjust and learn the new signal characteristics. Entering the observation window establishment stage means that the digital control unit of the magnetic encoder temporarily suspends its saturation risk monitoring function (i.e., suspends the execution of S203 and subsequent judgment steps) and focuses on executing the extreme value update task in S202. This stage avoids making incorrect saturation judgments due to inaccurate maximum and minimum values ​​when new and old signals are alternating and extreme value information is not yet accurate, thus preventing a chain reaction of unstable gain adjustments.

[0081] S212. During the observation window establishment phase, the magnetic encoder only continuously updates the maximum and minimum values, and pauses the calculation of the first and second absolute differences.

[0082] Specifically, "continuously updating only the maximum and minimum values" means that during the observation window setup phase, for each acquired digitized sample value, the magnetic encoder only executes the logic described in S202, i.e., comparing and updating the maximum and minimum value registers. "Pausing calculation" means the system skips calculation steps such as S203 and S204 used for risk assessment and triggering adjustments.

[0083] Specifically, during the observation window establishment phase, the computational task of the digital control unit of the magnetic encoder is simplified. The core logic of its main loop becomes: acquire a new sample - compare and update with the current maximum value - compare and update with the current minimum value - acquire the next new sample. This process is repeated continuously, so that the values ​​of the maximum and minimum values ​​start from the initial values ​​set in S210 and gradually converge to the true peak and valley values ​​of the new signal as the signal waveform evolves.

[0084] S213. When the digital sampled value completes one zero crossing, the magnetic encoder determines that the observation window establishment phase has ended and resumes the calculation of the absolute value of the first difference and the absolute value of the second difference.

[0085] Zero-crossing refers to the event where the digitized sampled value of a signal changes from positive to negative, or from negative to positive, crossing its DC bias or zero-level reference point. For a unipolar analog-to-digital converter signal biased around VCC / 2, zero-crossing means the sampled value crosses half the range of the analog-to-digital converter (e.g., 2048). The end of the observation window establishment phase signifies that the magnetic encoder considers it to have acquired a sufficiently representative signal waveform, and the recorded maximum and minimum values ​​are close to or equal to the true extreme values, which can be used for saturation risk assessment.

[0086] Specifically, during the continuous updating of extreme values ​​in S212, the magnetic encoder simultaneously monitors zero-crossing events of the sampled values. For example, the magnetic encoder records the sampled value S1 from the previous moment and compares it with the current sampled value S2. If (S1 - preset zero-point reference voltage) * (S2 - preset zero-point reference voltage) < 0 (where the zero-point reference voltage can be 2048), it indicates that a zero-crossing has occurred. A zero-crossing typically means that the signal has experienced at least one quarter-cycle. For greater reliability, the magnetic encoder can wait for a complete crossover from positive to negative and back to positive, or use the first detected crossover event as the benchmark. Once a zero-crossing is detected, the magnetic encoder considers the observation window to have been successfully established, and the recorded maximum and minimum values ​​are now sufficiently reliable. The magnetic encoder then exits the observation window establishment phase and resumes the difference calculation in S203 and the saturation risk assessment in S204, starting from the next sampling point.

[0087] In the above embodiments, after gain adjustment, a recovery process is introduced that includes a preset gain build-up time and an observation window establishment phase. By pausing data processing during gain build-up and then resetting the extreme values, the starting point for subsequent analysis is ensured to be valid. By establishing a dedicated observation window establishment phase, the magnetic encoder can reconstruct its understanding of the signal waveform under the new gain without being disturbed by saturation judgment, and the zero-crossing event is used as the marker for resuming normal monitoring. This series of steps allows for a smoother transition in the gain adjustment process, making the entire adaptive gain control method more robust.

[0088] The above describes a signal anti-saturation method for a magnetic encoder in the embodiments of this application. The following describes an exemplary magnetic encoder 300 provided in the embodiments of this application.

[0089] Figure 3This is a schematic diagram of an exemplary hardware structure of a magnetic encoder 300 provided in an embodiment of this application. The magnetic encoder includes a processor, a memory, a communication interface, and an analog front-end connected via a bus. The processor provides computational and control capabilities. The memory includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores computer programs and a database. The internal memory provides an environment for the execution of the computer programs in the non-volatile storage medium. The database stores data. When executed by the processor, the computer program implements a signal anti-saturation method for a magnetic encoder according to an embodiment of this application. The communication interface interacts with an external master control device. In some embodiments, the communication interface may be an industry-standard interface such as SPI, I2C, SSI, BiSS, PWM output interface, or ABZ incremental interface, used to output calculated angle data or receive configuration commands. The analog front-end of the magnetic encoder integrates a magnetic sensing element, a programmable gain amplifier, and an analog-to-digital converter, used to convert the magnetic field signal into a digital signal that the processor can process, and adjust the gain of the programmable gain amplifier according to the processor's instructions.

[0090] Those skilled in the art will understand that Figure 3 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the magnetic encoder to which the present application is applied. A specific magnetic encoder may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.

[0091] In some embodiments of this application, a computer-readable storage medium is also provided, including instructions that, when executed on the magnetic encoder 300, cause the magnetic encoder 300 to perform a signal anti-saturation method for a magnetic encoder according to an embodiment of this application.

[0092] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit it. 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 of the technical features. 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.

[0093] As used in the above embodiments, depending on the context, the term "when..." can be interpreted as meaning "if...", "after...", "in response to determining...", or "in response to detecting...". Similarly, depending on the context, the phrase "when determining..." or "if (the stated condition or event) is interpreted as meaning "if determining...", "in response to determining...", "when (the stated condition or event) is detected", or "in response to detecting (the stated condition or event)".

[0094] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid-state drive), etc.

[0095] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. This program can be stored in a computer-readable storage medium, and when executed, it can include the processes described in the above method embodiments. The aforementioned storage medium includes various media capable of storing program code, such as ROM or random access memory (RAM), magnetic disks, or optical disks.

Claims

1. A method for signal anti-saturation of a magnetic encoder, characterized in that, Applied to a magnetic encoder, the magnetic encoder including a magnetic sensitive element, an analog front-end, and an analog-to-digital converter, wherein the analog front-end integrates a programmable gain amplifier, the method includes: The magnetic encoder continuously acquires digital sample values ​​of the output signal of the magnetic sensitive element after it has been amplified by the programmable gain amplifier through the analog-to-digital converter. The magnetic encoder records the maximum and minimum values ​​of the digitized sampled values ​​within the current observation window; The magnetic encoder calculates the absolute value of the first difference between the current digitized sampled value and the maximum value, and the absolute value of the second difference between the current digitized sampled value and the minimum value at each sampling time. When either the absolute value of the first difference or the absolute value of the second difference is less than a preset saturation risk threshold, the magnetic encoder uses the difference between the maximum value and the minimum value as the dynamic range value of the current signal. The magnetic encoder uses the product of the preset target dynamic range value and the preset first coefficient and the preset second coefficient as the maximum adjustment threshold and the minimum adjustment threshold, respectively, wherein the preset first coefficient is greater than the preset second coefficient; When the dynamic range value is greater than the maximum adjustment threshold, the magnetic encoder subtracts a preset gain step value from the gain value of the programmable gain amplifier. When the dynamic range value is less than the minimum adjustment threshold, the magnetic encoder adds a preset gain step value to the gain value of the programmable gain amplifier. When the dynamic range value is less than or equal to the maximum adjustment threshold and greater than or equal to the minimum adjustment threshold, the magnetic encoder keeps the gain value of the programmable gain amplifier unchanged.

2. The method according to claim 1, characterized in that, After the magnetic encoder adjusts the gain value of the programmable gain amplifier, the method further includes: The magnetic encoder pauses acquiring the digitized sampled values ​​within a preset gain build-up time. The magnetic encoder takes the first digitized sample value acquired after the preset gain settling time ends as the new maximum value and the new minimum value.

3. The method according to claim 2, characterized in that, After the step of using the first digitized sample value acquired by the magnetic encoder after the preset gain settling time as the new maximum and minimum values, the method further includes: The magnetic encoder enters the observation window establishment phase; During the observation window establishment phase, the magnetic encoder only continuously updates the maximum value and the minimum value, and pauses the calculation of the first absolute value of the difference and the second absolute value of the difference; When the digitized sampled value completes one zero-crossing, the magnetic encoder determines that the observation window establishment phase has ended and resumes calculating the first absolute value of the difference and the second absolute value of the difference.

4. The method according to claim 3, characterized in that, The step of determining the end of the observation window establishment phase and resuming the calculation of the first absolute value of the difference and the second absolute value of the difference when the digitized sampled value completes one zero-crossing is specifically included: When the historical sampled value at the previous sampling moment and the current digital sampled value are located on both sides of the preset zero-point reference voltage, the magnetic encoder determines that the digital sampled value has completed a zero-crossing. When the digitized sampled value completes one zero-crossing, the magnetic encoder determines that the observation window establishment phase has ended and resumes calculating the first absolute value of the difference and the second absolute value of the difference.

5. The method according to claim 1, characterized in that, Before the step of the magnetic encoder calculating the absolute value of the first difference between the current digitized sample value and the maximum value, and the absolute value of the second difference between the current digitized sample value and the minimum value at each sampling time, the method further includes: When the current digital sampling value is the upper or lower limit of the range of the analog-to-digital converter, the magnetic encoder determines that hard saturation has occurred. In the event of hard saturation, the magnetic encoder directly subtracts a preset gain step value from the gain value of the programmable gain amplifier and skips the calculation of the dynamic range value at the current sampling time.

6. The method according to claim 5, characterized in that, After the magnetic encoder adjusts the gain value of the programmable gain amplifier, the method further includes: After the magnetic encoder subtracts or adds a preset gain step value to the gain value of the programmable gain amplifier, the magnetic encoder starts a cooling counter. If the dynamic range value triggers the adjustment condition again before the cooling counter reaches the preset value, the magnetic encoder ignores the trigger condition and keeps the current gain value unchanged. Only in the event of hard saturation will the magnetic encoder forcibly interrupt the cooling counter and perform a gain reduction operation.

7. The method according to claim 1, characterized in that, Before the step of the magnetic encoder multiplying the preset target dynamic range value by a preset first coefficient and a preset second coefficient, respectively, as the maximum adjustment threshold and the minimum adjustment threshold, the method further includes: When the rotational speed of the magnetic encoder is lower than a preset low-speed threshold, the magnetic encoder increases the preset first coefficient.

8. A magnetic encoder, characterized in that, The magnetic encoder includes: one or more processors and a memory; the memory is coupled to the one or more processors, the memory is used to store computer program code, the computer program code including computer instructions, and the one or more processors call the computer instructions to cause the magnetic encoder to perform the method as described in any one of claims 1-7.

9. A computer program product containing instructions, characterized in that, When the computer program product is run on the magnetic encoder, it causes the magnetic encoder to perform the method as described in any one of claims 1-7.

10. A computer-readable storage medium comprising instructions, characterized in that, When the instructions are executed on the magnetic encoder, the magnetic encoder performs the method as described in any one of claims 1-7.