A co-processor based adaptive arctangent function computation system and method

By using a coprocessor-based adaptive arctangent function calculation system, the optimal iteration angle is adaptively selected and the iteration process is optimized. This solves the problem of the CORDIC algorithm having a large number of iterations and slow calculation speed in high-precision motor monitoring, and realizes high-speed and high-precision motor motion status monitoring.

CN117369874BActive Publication Date: 2026-08-25BEIHANG UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311337086.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-10-16
Publication Date
2026-08-25
Estimated Expiration
2043-10-16

AI Technical Summary

Technical Problem

In high-precision motor motion status monitoring, the existing technology CORDIC algorithm has high calculation accuracy but requires many iterations and has a slow calculation speed, which cannot meet the high precision requirements.

Method used

An adaptive arctangent function calculation system based on a coprocessor is adopted. Through the coprocessor control module and the arctan calculation module, the optimal iteration angle is adaptively selected. The iteration process is optimized by using the iteration register and the iteration angle selection module, simplifying the combinational logic circuit and realizing high-speed and high-precision calculation.

Benefits of technology

It achieves higher calculation accuracy with fewer iterations for the same number of iterations, increases calculation speed by 35%, reduces error to 0.23%, simplifies circuit complexity, increases operating frequency, and meets the requirements for high-precision motor motion status monitoring.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117369874B_ABST
    Figure CN117369874B_ABST
Patent Text Reader

Abstract

The present application relates to a kind of adaptive arctangent function computing system and method based on coprocessor, using coprocessor to complete data transmission and state control.The present application includes data write module, iteration register, iteration angle selection module, data iteration module and data write back module;Data write module reads input data from coprocessor interface and stores in iteration register;Iteration angle selection module selects optimal iteration angle according to the data characteristics in iteration register and sends to data iteration module;Data iteration module calculates iteration data according to the optimal iteration angle and iterates the state in iteration register;Data write back module sends the calculation completion signal to coprocessor and executes the calculation result write back through coprocessor interface.The present application can utilize coprocessor without changing the internal structure of processor, and also can utilize the internal logic calculation unit of processor to realize high-speed high-precision arctangent function calculation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to an adaptive arctangent function calculation system and method based on a coprocessor, belonging to the field of computer hardware technology. Background Technology

[0002] With the development of electromechanical technology, the accuracy of magnetic encoders for detecting the motion state of motors has become a major limiting factor for the overall operating accuracy of electromechanical systems. The hardware circuit of the general calculation method using inverse trigonometric functions through lookup tables becomes more complex as the calculation accuracy increases, and it cannot meet today's high-precision requirements.

[0003] To further meet the requirements of high-precision motor monitoring, the academic and industrial communities will focus on encoders that use the CORDIC algorithm to iteratively calculate inverse trigonometric functions. This approach has high calculation accuracy and simple circuit structure, but it also has the disadvantage of requiring a large number of iterations and slow calculation speed. Summary of the Invention

[0004] The technical problem solved by this invention is to overcome the shortcomings of the prior art and provide a coprocessor-based adaptive arctangent function calculation system and method to achieve high-speed and high-precision arctangent function calculation, and at the same time, to use in encoder systems to achieve high-speed and high-precision motor motion status monitoring.

[0005] The technical solution of this invention:

[0006] In a first aspect, the present invention provides an adaptive arctangent function calculation system based on a coprocessor, the system comprising a coprocessor control module and an arctan calculation module; the coprocessor control module controls the arctan calculation module to adaptively select the optimal iteration angle for arctan arctangent function calculation; the coprocessor control module includes a coprocessor interface and a coprocessor state machine module;

[0007] The module includes a coprocessor interface and a coprocessor state machine module;

[0008] The arctan calculation module includes: a data writing module, an iteration register, an iteration angle selection module, a data iteration module, and a data write-back module;

[0009] The data writing module reads the input data INPUT from the coprocessor interface. X INPUT Y According to INPUT X INPUT Y Determine and record the sign of the calculation result, and then input the INPUT. X INPUT Y The absolute value is written into the iteration register; INPUT X INPUTY Given the input coordinates in a Cartesian coordinate system, the final calculation result from the arctan calculation module is:

[0010] The iteration register stores the iteration variable X. i Y i and Z i Perform iterations; in the initial state, X0 = |INPUT X |,Y0=|INPUT Y |, Z0=0; i represents the iteration number, i=0 is considered the initial state, and in the i-th iteration, Z i This represents the result of the arctangent function calculation, and the iteration result Z at the end of the iteration. i Equal to the absolute value of the angle being sought During the iteration process, Z i Increase or decrease the current optimal iteration angle θ at each iteration. i And gradually approach the absolute value of the desired angle, the Z in the current state i and There is always a difference between them. This represents the residual error, which decreases accordingly based on the optimal iteration angle after each iteration and continuously approaches 0.

[0011] The iterative angle selection module selects the angle based on the formula (Y). i <<<1)+Y i >X i <<< (1-j), the smallest j in [0,20], from arctan(2 -j Select the optimal iteration angle θ) j The data is transmitted to the data iteration module, where <<< represents an arithmetic left shift operation; θ j closest It can reduce the remaining error after iteration Minimize it as much as possible; at the same time, determine the result Z of the arctangent function calculation under the current state. i If the preset accuracy is met, a calculation completion signal is sent to the data write-back module.

[0012] The data iteration module, based on the optimal iteration angle θ j With X in the iterative register i Y i Z i Calculate the next state X from the current state. i+1 Y i+1 Z i+1 The result is written to the iteration register, and the iteration state pointer is incremented by one.

[0013] The data write-back module, upon receiving a completion signal from the iteration angle selection module or when the iteration status pointer reaches its maximum value, sends an end signal to the coprocessor control module. The coprocessor control module then updates the iteration result based on the sign of the calculation result recorded by the data write-back module. Adjusted to the arctangent function calculation result of the original input data The computation results are written back via the coprocessor interface; at the same time, the iteration state pointer is reset to 0 to terminate the iteration.

[0014] Optionally, the data writing module reads input data INPUT from the coprocessor interface. X INPUT Y The system determines the sign of the final calculation result based on the positive and negative relationships of the input data; simultaneously, it converts the absolute value of the input data to a positive number, ensuring that the input X0 = |INPUT X |≥0,Y0=|INPUT Y When |≥0, X during the iteration process i It must be non-negative, therefore we only need to determine Y. i Positive and negative values ​​result in a smaller area occupied by combinational logic circuits for subsequent positive and negative relationship judgments.

[0015] Optionally, the iterative calculation process of the data X, Y, Z stored in the iterative register is as follows:

[0016] During the iterative calculation process, when Y i When X > 0, i Y i Based on the optimal iteration angle θ j =arctan(2 -j ), j∈[0,20] rotate clockwise by θ j Z i Increase θ j When Y i When <0, X i Y i Based on the optimal iteration angle θ j =arctan(2 -j ), j∈[0,20] rotate counterclockwise by θ j Z i Reduce θ j ;Y i When = 0, the iterative calculation ends;

[0017] When the iterative calculation is complete, X i Y i The Z coordinate approximately coincides with the positive half of the X-axis corresponding to the X coordinate. i It approximates the angle between the input coordinates and the X-axis.

[0018] Optionally, the optimal iteration angle θ in the iteration angle selection module i Choose from the following:

[0019] According to satisfying The minimum j determines the optimal iteration angle as θ. j =arctan(2 -j When j = 20, the target precision is considered to be achieved. This logical relationship is approximately simplified to (Y) in actual combinational logic circuits. i <<<1)+Y i >X i The form <<<(1-j),j∈[0,20] reduces the complexity of combinational logic circuits, where <<< denotes an arithmetic left shift operation.

[0020] Secondly, the present invention provides a method for implementing a coprocessor-based adaptive arctangent function calculation system, as follows:

[0021] (1) The data writing module obtains input data according to the input instructions of the coprocessor module and determines its positive and negative relationship, and then writes the input data INPUT. X INPUT Y The values ​​are uniformly converted to positive numbers and stored in the iteration register on the first rising edge of the clock, and then adjusted according to the INPUT value. X INPUT Y The positive and negative relationship is determined and recorded in the final calculation result, and stored in the positive and negative record register at the first rising edge of the clock.

[0022] (2) The iterative angle selection module selects the angle based on X. i Y i Combinatorial logic selects the optimal iteration angle θ j At the same time, determine X i Y i Z i The change in;

[0023] (3) The data iteration module based on the current Y i The positive and negative relationship of X to the current X i Y i Z i By increasing or decreasing the amount of change determined by the iteration angle selection module, X is obtained. i+1 Y i+1 Z i+1 Write it to the iteration register on the rising edge of the clock, and increment the iteration status pointer by one at the same time;

[0024] (4) When the preset accuracy or maximum number of iterations is reached, the data write-back module sends a calculation completion signal to the coprocessor module and writes back the calculation result through the coprocessor interface. At the same time, the iteration status pointer is reset to 0, and the operation of other modules is terminated.

[0025] Thirdly, an angle encoder system based on arctangent calculation is provided, comprising the aforementioned coprocessor-based adaptive arctangent function calculation system and Kalman filter; the coprocessor-based adaptive arctangent function calculation system uses the filtered digital sine signal SIN transmitted by the Kalman filter as input INPUT. Y The filtered digital cosine signal COS is used as the input INPUT. X The arctangent function is calculated and the result is fed back to the host computer. This result is the absolute angle of the rotor of the servo motor under test at this time.

[0026] Fourthly, the present invention provides an electronic device, including a memory and a processor;

[0027] Memory, used to store computer programs;

[0028] A processor is used to execute a computer program stored in memory, which, when executed, implements the aforementioned coprocessor-based adaptive arctangent function calculation system, the aforementioned method for the aforementioned coprocessor-based adaptive arctangent function calculation system, or the aforementioned angle encoder system based on arctangent calculation.

[0029] Fifthly, the present invention provides a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed, it implements the above-described coprocessor-based adaptive arctangent function calculation system or the above-described method for the coprocessor-based adaptive arctangent function calculation system or the above-described angle encoder system based on arctangent calculation.

[0030] The advantages of this invention compared to the prior art are:

[0031] (1) This invention utilizes a coprocessor to implement adaptive arctangent function calculation, and transmits arctan commands and input / output data through the coprocessor interface, resulting in high calculation accuracy and short calculation time.

[0032] This invention adaptively selects the optimal iteration, achieving higher iteration efficiency than the general CORDIC iterative algorithm while avoiding invalid iterations. It achieves higher computational accuracy with the same number of iterations and fewer iterations with the same computational accuracy, resulting in superior overall speed and accuracy. According to VCS backend simulation tests, the system can complete one arctangent calculation in an average of 9.72 system clock cycles, with a maximum calculation error of approximately 0.000067 and an average calculation error of approximately 0.000031. Compared to the general CORDIC algorithm, which takes approximately 15 clock cycles and has a maximum calculation error of approximately 0.029, this invention reduces the average number of computation clock cycles by approximately 35% while minimizing the error to 0.23%.

[0033] (2) The data writing module of the present invention can infer and record the positive and negative relationship of the calculation result based on the input data, and write the input data INPUT. X INPUT Y This is converted to an absolute value, simplifying the combinational logic circuit for determining the positive and negative relationships during the iteration process. According to the iterative relationship of the arctangent CORDIC algorithm, when X0 and Y0 are non-negative, X... i The result is non-negative and monotonically increasing; based on this relationship, only Y needs to be evaluated during the iteration process. i Positive and negative relationships do not determine X i After the iteration is complete, the data write-back module adjusts the sign of the iteration calculation result according to the pre-recorded sign relationship of the output data, changing it to... The value of ...

[0034] (3) The iterative angle selection module of this invention uses simple operations such as shifting and addition / subtraction to replace complex operations such as multiplication, exponentiation, and opening during the internal calculation process with the help of an approximation algorithm. The critical point formula for iterative angle selection... middle, Partially approximates and gradually approaches 2 1-i This can be replaced by bit shift operations. Therefore, the original complex expression can be approximated as (Y i <<<1)+Y i >X i The approximation is in the form <<<(1-j), where <<< denotes an arithmetic left shift operation. This approximation only affects the choice of iteration angle, impacting only the convergence speed of the algorithm without affecting the accuracy of the final calculation result. Simultaneously, it can significantly reduce the complexity and area of ​​combinational logic circuits, further increasing the operating frequency.

[0035] (4) The specific implementation of this invention is to design a filtered digital sine signal SIN transmitted by a Kalman filter as the input INPUT. Y The filtered digital cosine signal COS is used as the input INPUT.X A magnetic encoder chip that calculates the absolute angle of the motor using the arctangent function enables high-speed and high-precision monitoring of the motor's motion status. Attached Figure Description

[0036] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of the present invention and should not be regarded as a limitation on the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.

[0037] Figure 1 For arctangent function control instructions;

[0038] Figure 2 This is a schematic diagram of the coprocessor-based adaptive arctangent function calculation system in an embodiment of the present invention;

[0039] Figure 3 This is the implementation flow of the coprocessor-based adaptive arctangent function calculation method in the embodiments of the present invention;

[0040] Figure 4 This is a structural diagram of a magnetic encoder system based on an adaptive arctangent function calculation method according to an embodiment of the present invention. Detailed Implementation

[0041] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, 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 some embodiments of the present invention, but not all embodiments.

[0042] Therefore, the following detailed description of the embodiments of the invention provided in the accompanying drawings is not intended to limit the scope of the claimed application, but merely to illustrate selected embodiments of the invention. All other embodiments obtained by those skilled in the art based on the embodiments of the invention without inventive effort are within the scope of protection of the invention.

[0043] like Figure 1As shown, this embodiment of the invention uses RISC-V R-TYPE type instructions for control, which can be directly embedded in a 32-bit RISC-V processor or, with minor modifications, embedded in mainstream common instruction set processors such as MIPS and ARM. The instruction consists of Function7, RS1, RS2, Function3, Rd, and Opcode. Function7 and Opcode together determine that this instruction is an arctan calculation instruction in the coprocessor, and Function3 determines that this instruction uses two source registers and one destination register simultaneously. RS1, RS2, and Rd are the corresponding addresses of the source register and destination register, respectively.

[0044] This instruction controls the coprocessor to read data from two source registers, RS1 and RS2, and, under the control of the coprocessor control module, uses it as (INPUT). X INPUT Y The input is sent to the arctan calculation module, which will perform the arctangent calculation and output the result. Write back to the destination register RD; the input and output data in this process are both 32-bit signed integers, and the output data is 2 times the actual floating-point value of the angle. 14 This is multiplied by a factor of 1, thus converting it into an integer representation.

[0045] like Figure 2 As shown in the figure, an adaptive arctangent function calculation system based on a coprocessor is provided in this embodiment of the invention, including: a coprocessor control module and an arctan calculation module; the arctan calculation module realizes the calculation of the arctan arctangent function by adaptively selecting the optimal iteration angle;

[0046] The coprocessor control module receives the arctan instruction and the data INPUT from input registers RS1 and RS2 through the coprocessor interface when the processor executes the arctan operation instruction. X INPUT Y .

[0047] If the coprocessor state machine is in the idle state, the coprocessor control module sets it to the arctangent calculation state ARCTAN and enables the arctan calculation module to start the arctangent function calculation; if it is not in the idle state, the coprocessor control module will wait for the coprocessor to become idle before instructing the coprocessor state machine to enter the arctangent calculation state ARCTAN.

[0048] Upon receiving a computation completion signal from the arctan computation module, the coprocessor control module will set the coprocessor state machine from the arctangent computation state ARCTAN back to the idle state IDLE.

[0049] In some embodiments, the arctan calculation module may optionally include a data writing module, an iteration register, an iteration angle selection module, a data iteration module, and a data write-back module.

[0050] The data writing module reads input data from the coprocessor interface and writes it into the iteration register;

[0051] In some embodiments, the data writing module may specifically read input data INPUT from the coprocessor interface. X INPUT Y The algorithm determines and records the sign of the final calculation result based on the positive and negative relationship of the input data; simultaneously, it converts the absolute value of the input data to a positive number, stores it in the iteration register on the first rising edge of the clock, initializes Z0 to 0, and resets the iteration state pointer to 0; while ensuring that the input X0 = |INPUT X |≥0,Y0=|INPUT Y When |≥0, X during the iteration process i It must be non-negative, therefore we only need to determine Y. i Positive and negative values ​​result in a smaller area occupied by combinational logic circuits for subsequent positive and negative relationship judgments.

[0052] Iteration register, storing iteration variable X i Y i and Z i In the initial state, X0 = |IVPUT X |,Y0=|IVPUT Y | indicates that the arctangent function inputs rectangular coordinates, Z0 = 0; This represents the result of the arctangent function calculation; during the iteration process, Z... i Increase or decrease the current optimal iteration angle θ at each iteration. i And it gradually approaches the true value of the desired arctangent function. Z represents the remaining error, and is the calculation result under the current state. i Compared with the true value There is always a difference between them. The remaining error decreases accordingly after each iteration based on the optimal iteration angle and continuously approaches 0;

[0053] In some embodiments, the iteration register optionally stores data X used for iterative calculation. i Y i Z i The iterative calculation process is as follows:

[0054] During the iterative calculation, X i Y i Z i Follow the following relationship:

[0055]

[0056] Where sign(Y) i ) is about Y i The sign function, in Y i When >0, it is 1, Y i <0 represents -1; >>> indicates an arithmetic right shift operation; j is the iteration angle θ j =arctan(2 -j The subscript of ) is determined by the iteration angle selection module.

[0057] When the calculation is complete, (X) i ,Y i It is approximately located on the positive x-axis of the Cartesian coordinate system, Z. i It approximates the angle between the vector corresponding to the input coordinates and the X-axis.

[0058] The iterative angle selection module, based on X... i ,Y i The size relationship is from arctan(2) -j The optimal iteration angle is selected from j∈[0,20] and transmitted to the data iteration module; simultaneously, the calculation result Z is determined under the current state. i If the preset accuracy is met, a calculation completion signal is sent to the data write-back module.

[0059] In some embodiments, optionally, the optimal iteration angle θ in the iteration angle selection module j Choose from the following:

[0060] According to satisfying (Y) i <<<1)+Y i >X i The smallest j in (1-j) determines the optimal iteration angle as θ. j =arctan(2 -j ), j∈[0,20], when j≥20 satisfies the condition, it is considered to have reached the target precision, where <<< represents the arithmetic left shift operation.

[0061] The data iteration module calculates the next state data based on the optimal iteration angle and the current state in the iteration register, and writes it into the iteration register; at the same time, the iteration state pointer is incremented by one.

[0062] The data write-back module sends an end signal to the coprocessor and writes back the calculation result through the coprocessor interface when it receives a signal that the iteration angle selection module has completed the calculation or the iteration status pointer has reached its maximum value; at the same time, it resets the iteration status pointer to 0 and terminates the iteration of other modules.

[0063] like Figure 3As shown in the figure, the implementation method of the coprocessor-based adaptive arctangent function calculation system in this embodiment of the invention is as follows:

[0064] The hardware structure consists of a data writing module 1, an iteration register 2, an iteration angle selection module 3, a data iteration module 4, and a data write-back module 5.

[0065] Data writing module 1 specifically reads input data from the coprocessor interface, determines and records the sign of the final calculation result based on the positive or negative relationship of the input data, and records it in the Flag register; when the input data INPUT... X INPUT Y If the signs are opposite, the final calculation result is determined to be negative; the Flag register is set to 1, and INPUT is executed. X INPUT Y When the signs are the same, the final calculation result is judged to be positive, and the Flag register is set to 0; at the same time, the data writing module (1) converts the absolute value of the input data into a positive number and stores it in the iteration register on the first rising edge of the clock, that is, X0 = |INPUT X |,Y0=|INPUT Y | and initialize Z0 to 0;

[0066] Iteration Angle Selection Module 3 uses combinational logic to determine whether (Y) is satisfied. i <<<1)+Y i >X i The minimum j in (1-j), j∈[0,20] determines the optimal iteration angle θ. j And send it to the data iteration module 4, where <<< represents an arithmetic left shift operation;

[0067] For example: when (Y) i <<<1)+Y i >X i When <<<1 holds true, the iteration angle selection module 3 considers theta0 to be the optimal iteration angle, j=0; when (Y i <<<1)+Y i >X i <<<1 is not true, but (Y) i <<<1)+Y i >X i When <<< 0, the iteration angle selection module 3 considers theta1 to be the optimal iteration angle, j=1, and so on; where <<< represents the arithmetic left shift operation, and >>> represents the arithmetic right shift operation;

[0068] If j=20, which means the preset accuracy requirement has been met, the iteration angle selection module 3 sends an iteration completion (DONE) signal to the data write-back module; or if the iteration status pointer reaches 15, which means the maximum number of iterations has been reached, the data iteration module sends an iteration completion (DONE) signal to the data write-back module, and the iteration ends.

[0069] Data iteration module 4 based on θ j With current X i Y i Z i Calculate the next state data X i+1 =X i +sign(Y i )*(Y i >>>j), Y i+1 =Y i -sign(Y i )*(X i >>>j), Z i+1 =Z i +sign(Y i )*θ j , where sign(Y i ) is about Y i The sign function, in Y i When >0, it is 1, Y i <0 is -1; >>> is an arithmetic right shift operation; when the rising edge of the clock arrives, the data is written into the iteration register 2, and the iteration status pointer STATE_R+1 is executed at the same time;

[0070] After receiving the iteration complete (DONE) signal, the data write-back module 5 multiplies the iteration result Z by -1 and outputs the result when the Flag register is 1. When the Flag register is 0, it directly outputs Z and resets the status pointer STATE_R to 0, terminating the iteration of other modules.

[0071] like Figure 4 As shown in the figure, an embodiment of the present invention provides a magnetic encoder system based on arctangent calculation. The system includes an on-chip system (SOC) and an off-chip system. The off-chip system includes a Hall sensor 11 and an AD7606 analog-to-digital converter 12. The on-chip system includes a core processor CPU 6 and a coprocessor 7. The coprocessor 7 includes an AD driver module 13, a Kalman filter module 14 and an adaptive arctangent function calculation module 15.

[0072] The core processor CPU6 controls the coprocessor. CPU6 consists of an instruction fetch module (IFU), an execution module (EXU), and a write-back module (WB). The IFU module fetches the data instruction from the instruction register (ITCM) via the program counter (PC), including the operand register index, write-back register index, instruction type, and instruction operation information, and stores it in the instruction register (IR). If the instruction is an adaptive arctangent angle calculation instruction (Adaptive_arctan) extended from the instruction set, the decode module (Decode) in the EXU module decodes the instruction in the instruction register (IR) and dispatches it to the logic calculation unit (ALU) via the dispatch module (Disp). The ALU then transmits the instruction and several register data to the coprocessor 7 via the coprocessor interface (NICE interface). The coprocessor control module enables the adaptive arctangent function calculation module 15 to perform the calculation. After the calculation is complete, the result is written to the write-back arbitrator (WB) via the coprocessor interface (NICE interface), and the arbitration result is written to the write-back register group (WB-Regfile).

[0073] After the System-on-Chip (SOC) starts up and completes a reset, the AD driver module 13 and Kalman filter module 14 in the coprocessor 7 will start automatically. The AD driver module 13 will drive the AD7606 analog-to-digital converter 12 through the SPI interface to continuously read analog signals from the Hall sensor 11 and convert them into digital signals, which will then be sent to the AD driver module 13. The AD driver module 13 will then send this data to the Kalman filter module 14 for digital filtering to eliminate Gaussian noise. After filtering, the Kalman filter module 14 will write the filtering result to the arbitrator WB through the coprocessor interface (NICE interface). The arbitration result will be written to the write-back register group WB-Regfile. This result can be read and calculated when the System-on-Chip (SOC) executes instructions such as Adaptive_arctan.

[0074] Optionally, the present invention also provides an electronic device (computer, server, smartphone, network device, etc.) including a memory and a processor, wherein the memory is used to store a computer program executable by the processor, and when the processor executes the computer program, it implements the above-described method embodiments or system embodiments.

[0075] Optionally, the present invention also provides a program product, such as a computer-readable storage medium, including a program that, when executed by a processor, is used to perform the above-described method embodiments or system embodiments.

[0076] The above are merely preferred embodiments of the present invention and are not intended to limit the present invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.

Claims

1. A coprocessor-based adaptive arctangent function calculation system, characterized in that: The system includes a coprocessor control module and an arctan calculation module; The coprocessor control module controls the arctan calculation module to adaptively select the optimal iteration angle for the arctan arctangent function calculation; The arctan calculation module includes: a data writing module, an iteration register, an iteration angle selection module, a data iteration module, and a data write-back module; The data writing module reads the input data INPUT from the coprocessor interface. X and INPUT Y According to INPUT X and INPUT Y Determine and record the sign of the calculation result, and then input the INPUT. X and INPUT Y The absolute value is written into the iteration register; INPUT X and INPUT Y The input coordinates are in a Cartesian coordinate system, and the final calculation result of the arctan calculation module is... The iteration register stores the iteration variable X. i Y i and Z i And iterate; X i Y i and Z i In the initial state, X0 = |INPUT X |,Y0=|INPUT Y |, Z0=0; i represents the iteration number, i=0 is considered the initial state, and in the i-th iteration, Z i This represents the result of the arctangent function calculation, and the iteration result Z at the end of the iteration. i Equal to the absolute value of the angle being sought During the iteration process, Z i Increase or decrease the current optimal iteration angle θ at each iteration. i And gradually approach the absolute value of the desired angle, the Z in the current state i and There is always a difference between them. This represents the residual error, which decreases accordingly based on the optimal iteration angle after each iteration and continuously approaches 0. The iterative angle selection module selects the angle based on the formula (Y). i <<<1)+Y i >X i <<<(1-j), the smallest j in [0, 20], from arctan(2 -j Select the optimal iteration angle θ) j The data is transmitted to the data iteration module, where <<< represents an arithmetic left shift operation, and j is the subscript of the iteration angle; θ j closest Make the remaining error after iteration Minimize it as much as possible; at the same time, determine the result Z of the arctangent function calculation in the current state. i If the preset accuracy is met, a calculation completion signal is sent to the data write-back module. The data iteration module, based on the optimal iteration angle θ j With X in the iterative register i Y i Z i Calculate the next state X from the current state. i+1 Y i+1 Z i+1 The result is written to the iteration register, and the iteration state pointer is incremented by one. The data write-back module, upon receiving a completion signal from the iteration angle selection module or when the iteration status pointer reaches its maximum value, sends a termination signal to the coprocessor control module. Based on the sign of the calculation result recorded by the data write-back module, it assigns the iteration result to the appropriate value. Adjusted to the arctangent function calculation result of the original input data The computation results are written back via the coprocessor interface; at the same time, the iteration state pointer is reset to 0 to terminate the iteration.

2. The coprocessor-based adaptive arctangent function calculation system according to claim 1, characterized in that: When X0 = |INPUT X |≥0,Y0=|INPUT Y When |≥0, X during the iteration process i It must be non-negative; we only need to determine Y. i Positive and negative values ​​result in a smaller area occupied by the subsequent combinational logic circuits for positive and negative value determination.

3. The adaptive arctangent function calculation system based on a coprocessor according to claim 1, characterized in that: The iteration register stores the iteration variable X. i Y i and Z i The iterative process is as follows: During the iteration process, when Y i When X > 0, i Y i Based on the optimal iteration angle θ j =arctan(2 -j ), j∈[0,20] rotated clockwise by θ j Z i Increase θ j When Y i When <0, X i Y i Based on the optimal iteration angle θ j =arctan(2 -j ), j∈[0,20] rotate counterclockwise by θ j Z i Reduce θ j ;Y i When = 0, the iteration ends; When the iteration is complete, X i Y i The Z coordinate approximately coincides with the positive half of the X-axis corresponding to the X coordinate. i It approximates the angle between the input coordinates and the X-axis.

4. The coprocessor-based adaptive arctangent function calculation system according to claim 1, characterized in that: In the iteration angle selection module, the optimal iteration angle θ j Choose from the following: According to satisfying (Y) i <<<1)+Y i >X i The smallest j in (1-j), j∈[0,20] determines the optimal iteration angle as θ. j =arctan(2 -j ), where <<< represents an arithmetic left shift operation, and the preset precision is considered to be reached when j=20 meets the condition.

5. A method for implementing the coprocessor-based adaptive arctangent function calculation system according to any one of claims 1-4, characterized in that... as follows: (1) Data writing module, reads input data INPUT from the coprocessor interface. X and INPUT Y According to INPUT X and INPUT Y The sign of the calculation result is determined and recorded. On the first rising edge of the clock, the sign of the calculation result is written into the sign record register, and INPUT is simultaneously set. X and INPUT Y The absolute value is written into the iteration register; (2) Iteration angle selection module, based on satisfying the formula (Y i <<<1)+Y i >X i <<<(1-j), the smallest j in [0, 20], from arctan(2 -j Select the optimal iteration angle θ) j The data is transmitted to the data iteration module, where <<< represents an arithmetic left shift operation; simultaneously, the result Z of the arctangent function calculation in the current state is determined. i If the preset accuracy is met, a calculation completion signal is sent to the data write-back module. (3) Data iteration module, based on the optimal iteration angle θ j With X in the iterative register i Y i Z i Calculate the next state X from the current state. i+1 Y i+1 Z i+1 The iteration register is written on the rising edge of the clock, and the iteration status pointer is incremented by one. (4) The data write-back module, upon receiving the completion signal from the iteration angle selection module or when the iteration status pointer reaches its maximum value, sends an end signal to the coprocessor control module, and updates the iteration results according to the sign of the calculation results recorded by the data write-back module. Adjusted to the arctangent function calculation result of the original input data The computation results are written back via the coprocessor interface; at the same time, the iteration state pointer is reset to 0 to terminate the iteration.

6. An angle encoder system based on arctangent calculation, characterized in that: The system includes a coprocessor-based adaptive arctangent function calculation system and a Kalman filter, as described in any one of claims 1-4; the coprocessor-based adaptive arctangent function calculation system uses the filtered digital sine signal SIN transmitted by the Kalman filter as input INPUT. Y The filtered digital cosine signal COS is used as the input INPUT. X The arctangent function is calculated and the result is fed back to the host computer. This result is the absolute angle of the rotor of the servo motor under test at this time.

7. An electronic device, characterized in that, Including memory and processor; Memory, used to store computer programs; A processor is used to execute a computer program stored in memory, which, when executed, implements the coprocessor-based adaptive arctangent function calculation system as described in any one of claims 1-4, the method of the coprocessor-based adaptive arctangent function calculation system as described in claim 5, or the angle encoder system based on arctangent calculation as described in claim 6.

8. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed, it implements the coprocessor-based adaptive arctangent function calculation system according to any one of claims 1-4, the method of the coprocessor-based adaptive arctangent function calculation system according to claim 5, or the angle encoder system based on arctangent calculation according to claim 6.

Citation Information

Patent Citations

  • Trigonometric function operation circuit based on fixed point number

    CN108733349A

  • Hardware platform for trusted computing

    CN114629665A