Logic calculation unit based on ARM kernel and data processing method
By adding a trigonometric function operation module to the battery meter and using the CORDIC algorithm for hardware calculation, the problem of slow trigonometric function operation in the existing technology is solved, faster trigonometric function operation is achieved, and the performance of the battery meter is improved.
Patent Information
- Application Number
- CN202411467483.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-21
- Publication Date
- 2025-03-18
AI Technical Summary
When performing trigonometric function operations, the calculation speed of existing power meters relying on software calculations leads to a very slow calculation speed. The sin operation requires about 461us-735us, and the cos operation requires about 486us-725us.
A trigonometric function calculation module is added to the AB bus of the battery meter, and the hardware calculation is performed using the CORDIC algorithm to realize the rapid calculation of sin and cos values.
Through hardware calculation, the speed of trigonometric function operations is significantly accelerated, and the time of sin and cos operations is reduced to about 1.2us and 73us respectively, which significantly improves the computing speed of the battery algorithm and the overall performance of the battery meter.
Smart Images

Figure CN119646364A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data processing, and in particular to a logic computing unit based on an ARM core and a data processing method. Background Art
[0002] Trigonometric functions are often used in current power algorithms, but there is no trigonometric function calculation module in the power meter. The current common practice is to use software to calculate trigonometric functions.
[0003] However, using software calculation will access the memory of the fuel gauge, making the entire calculation very slow. The sin operation takes about 461us-735us, and the cos operation takes about 486us-725us. Summary of the invention
[0004] In view of the technical defects pointed out in the background technology, the purpose of the embodiments of the present invention is to provide a logic computing unit and a data processing method based on an ARM core.
[0005] To achieve the above objectives, in a first aspect, an embodiment of the present invention provides a logic computing unit based on an ARM core, including an M0 core and a trigonometric function operation module, wherein the M0 core and the trigonometric function operation module exchange data through an ahb bus and an apb bus.
[0006] The trigonometric function operation module uses the CORDIC algorithm to iteratively calculate the sin value and the cos value.
[0007] As a specific implementation of the present application, the M0 core is specifically used for:
[0008] Receive a processing instruction sent by a user through the IIC bus, and read the data to be processed based on the processing instruction;
[0009] Parsing the data to be processed to obtain parsed data;
[0010] The parsed data, calculated angles and calculation instructions are sent to the trigonometric function operation module via the IIC bus.
[0011] As a specific implementation of the present application, the trigonometric function operation module is specifically used for:
[0012] Calculate the analytical data according to the calculation angle and the calculation instruction to obtain a calculation result;
[0013] After the calculation is completed, a completion flag is sent to the M0 core.
[0014] Furthermore, the M0 core is also used for:
[0015] After receiving the completion mark, the calculation result is read from the trigonometric function operation module.
[0016] In a second aspect, an embodiment of the present application further provides a data processing method, which is applicable to the ARM core-based electricity meter described in the first aspect, and comprises the following steps:
[0017] The M0 core obtains the data to be processed from the user through the IIC bus, and parses the data to be processed to obtain parsed data;
[0018] The M0 core sends the parsed data, calculated angles and calculation instructions to the trigonometric function operation module through the IIC bus for calculation.
[0019] Furthermore, the data processing method further includes:
[0020] The trigonometric function operation module calculates the analytical data according to the calculation angle and the calculation instruction to obtain a calculation result;
[0021] After the calculation is completed, the trigonometric function operation module sends a completion flag to the M0 core;
[0022] After receiving the completion flag, the M0 core reads the calculation result from the trigonometric function operation module.
[0023] By implementing the embodiment of the present invention, a trigonometric function operation module is added to the APB bus of the electricity meter, and hardware operation is used to speed up the operation speed. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] In order to more clearly illustrate the specific implementation of the present invention or the technical solution in the prior art, the drawings required for use in the specific implementation or the description of the prior art are briefly introduced below.
[0025] Figure 1 It is a structural diagram of a logical computing unit based on an ARM core provided in an embodiment of the present invention;
[0026] Figure 2 It is the data interaction flow chart between the M0 core and the trigonometric function operation module;
[0027] Figure 3 It is the calculation timing diagram of the trigonometric function operation module;
[0028] Figure 4 It is the overall block diagram of the trigonometric function operation module;
[0029] Figure 5 and Figure 6 It is a schematic diagram of the coordinate system. DETAILED DESCRIPTION
[0030] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0031] It should be understood that when used in this specification and the appended claims, the terms "include" and "comprises" indicate the presence of described features, integers, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or combinations thereof.
[0032] The relevant terms involved in the embodiments of the present invention are described as follows:
[0033] ARM core refers to the processor core based on ARM architecture, which has many different series and models, each of which has its own specific characteristics and uses.
[0034] The M0 core refers to the ARM Cortex-M0 core, which is a 32-bit microprocessor core with multiple features suitable for low-cost, low-power embedded applications.
[0035] The ahb (Advanced High-performance Bus) bus is a high-performance system bus that is mainly used to connect high-performance system modules such as processors, memories, and high-speed peripherals.
[0036] The apb (Advanced Peripheral Bus) bus is a low-power, low-cost peripheral bus, mainly used to connect low-bandwidth peripheral devices such as UART, I2C, SPI, etc.
[0037] Please refer to Figure 1 The embodiment of the present invention provides a logic computing unit based on the ARM core, which includes an M0 core (cortex M0) and a trigonometric function operation module. The two interact with each other through an ahb bus and an apb bus. The general data interaction process is as follows: Figure 2 shown.
[0038] Specifically, the M0 core is used for:
[0039] Receive a processing instruction sent by a user through the IIC bus, and read the data to be processed based on the processing instruction;
[0040] Parsing the data to be processed to obtain parsed data;
[0041] The parsed data, calculated angles and calculation instructions are sent to the trigonometric function operation module via the IIC bus.
[0042] The trigonometric function operation module is specifically used for:
[0043] Calculate the analytical data according to the calculation angle and the calculation instruction to obtain a calculation result;
[0044] After the calculation is completed, a completion flag is sent to the M0 core.
[0045] Furthermore, the M0 core is also used for:
[0046] After receiving the completion mark, the calculation result is read from the trigonometric function operation module.
[0047] To further understand the embodiments of the present invention, the trigonometric function operation module is specifically described below:
[0048] The operation sequence of trigonometric functions is as follows: Figure 3 As shown, when the fuel gauge needs to perform trigonometric operations when executing the fuel algorithm, the fuel gauge core will write the angle value and the start operation instruction to the register of the calculation module, and then the trigonometric operation module will start the operation until the trigonometric operation module returns the operation completion interrupt, and the core enters the interrupt to read the calculation result.
[0049] The overall block diagram of the trigonometric function operation module is as follows: Figure 4 As shown in the figure. θ is the calculated angle, start is the signal to start the calculation, when this signal becomes 1, the trigonometric function operation module starts to calculate; when the busy signal is 1, it means that the trigonometric function operation module is calculating; when the done signal is 1, it means that the calculation is completed; sinθ and cosθ represent the sin value and cos value of the angle θ calculation; error represents the angle error, because the core idea of the trigonometric function operation module calculation is to obtain the sin value and cos value by the method of the vector continuously approaching the target angle in the rectangular coordinate system, and error is the difference between the angle of the vector and the target angle at the end of the calculation.
[0050] In this embodiment, the trigonometric function calculation module uses the CORDIC algorithm for calculation. The time of the entire calculation process depends on the rate of the system clock. If the power meter works at a slow clock of 262kHz, the entire calculation cycle is about 73us; if it works at a fast clock of 16M, the entire calculation cycle is about 1.2us, which is much faster than the speed of software calculation of more than 400us. Improving the calculation speed of trigonometric functions can greatly improve the calculation speed of the power algorithm and improve the overall performance of the power meter.
[0051] Trigonometric functions can be defined using a rectangular coordinate system, such as Figure 5 As shown, define a circle O with a radius of 1. The center of the circle is the origin O of the rectangular coordinate system. P0 (x0, y0) and P1 (x1, y1) are two points on the circle O. Starting from the origin O and connecting P0, we get vector OP0. The angle between vector OP0 and the X-axis is α. Vector OP0 is rotated counterclockwise by an angle θ to get vector OP1. The intersection point with the circle O is P1. The CORDIC algorithm is derived from the rotation, and the following relationship can be obtained:
[0052]
[0053] Substituting the coordinates of point P0 into the coordinates of point P1, we can get formula 2:
[0054]
[0055] Combining the above formula and Figure 6 It is found that cos(θ) only changes the modulus of the target vector OP1. If cos(θ) is removed, OP0 is rotated by angle θ to obtain OQ. For θ, θ can be decomposed into the sum of a series of small angles:
[0056]
[0057] The result of the i+1th rotation is as follows:
[0058]
[0059] To ensure that the hardware is easy to implement, the calculation needs to be converted into addition, subtraction, and shift. From Formula 4, we can see that the remaining work only requires converting tanθ i Convert it into a shift operation, that is, use the negative power of 2 to approximate the calculation, as shown in Formula 5.
[0060] tanθ i =d i 2 -i (5)
[0061] In formula 5, d∈{-1,1}, and tanθ i In order to determine d i The value of z is introduced, and z is initialized to θ. i Performs addition or subtraction of tan -1 2 -i Operation, so that the value of z is finally 0. After i+1 rotations, z i+1 The values are as follows:
[0062] z i+1 =z i -d i tan -1 2-i (6)
[0063] d i When it is +1, it means counterclockwise rotation, and when it is -1, it means clockwise rotation. The iterative process of z is the process of converging z to 0, which is also the process of decomposing θ into a series of θ i process, so z i It can be considered as the remaining angle after the i-th rotation. The final rotation mode iteration process of the circular system of the CORDIC algorithm can be expressed as:
[0064]
[0065] In this embodiment, the trigonometric function operation module θ i The parameters are selected as follows:
[0066] Iteration number i <![CDATA[θ i (arctan(2 -i ))]]> <![CDATA[cosθ i ]]> <![CDATA[Πcosθ i ]]> <![CDATA[1 / Πcosθ i ]]> 0 45.0 0.7071067812 0.7071067812 1.414213562 1 26.56505118 0.894427191 0.632455532 1.58113883 2 14.03624347 0.9701425001 0.6135719911 1.629800601 3 7.125016349 0.9922778767 0.6088339125 1.642484066 4 3.576334375 0.9980525785 0.6076482563 1.645688916 5 1.789910608 0.9995120761 0.6073517701 1.646492279 6 0.8951737102 0.999877952 0.6072776441 1.646693254 7 0.4476141709 0.9999694838 0.6072591123 1.646743507 8 0.2238105004 0.9999923707 0.6072544793 1.64675607 9 0.1119056771 0.9999980927 0.6072533211 1.646759211 10 0.05595289189 0.9999995232 0.6072530315 1.646759996 11 0.02797645262 0.9999998808 0.6072529591 1.646760193 12 0.01398822714 0.9999999702 0.607252941 1.646760242 13 0006994113675 0.9999999925 0.6072529365 1.646760254 14 0.003497056851 0.9999999981 0.6072529354 1.646760257 15 0.001748528427 0.9999999995 0.6072529351 1.646760258
[0067] Table 1
[0068] But as mentioned before, each pseudo-rotation will make the modulus return to its original value. times, with continuous iterations, the growth of the vector modulus tends to a constant value, which we define as a factor K n .
[0069]
[0070] When n→∞, K n →1.6476
[0071] When n→∞, 1 / K n →0.6073
[0072] At the beginning of the calculation, define a modulus length of 1 / K n The vector is first rotated to the angle to be calculated, and then θ is selected according to the number of iterations. i Rotate clockwise or counterclockwise and keep approaching the X-axis. After 16 iterations of pseudo-rotation, the Y-axis coordinate is the sin value and the X-axis coordinate is the cos value.
[0073] By implementing the ARM core-based electricity meter provided in the embodiment of the present invention, a trigonometric function operation module is added to the apb bus of the electricity meter, and hardware operation is used to speed up the operation speed.
[0074] Based on the same inventive concept, an embodiment of the present invention further provides a data processing method, which is applicable to the aforementioned electricity meter, and the method comprises the following steps:
[0075] S1, the M0 core obtains the data to be processed from the user through the IIC bus, and parses the data to be processed to obtain parsed data.
[0076] S2, the M0 core sends the parsing data, calculated angles and calculation instructions to the trigonometric function operation module through the IIC bus for calculation.
[0077] S3, a trigonometric function operation module calculates the analytical data according to the calculation angle and the calculation instruction to obtain a calculation result;
[0078] S4, after the calculation is completed, the trigonometric function operation module sends a completion mark to the M0 core.
[0079] S5, after receiving the completion mark, the M0 core reads the calculation result from the trigonometric function operation module.
[0080] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed by the present invention, and these modifications or replacements should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be based on the protection scope of the claims.
Claims
1. A logical computing unit based on an ARM core, characterized in that: It includes an M0 core and a trigonometric function operation module, and the M0 core and the trigonometric function operation module exchange data via an ahb bus and an apb bus.
2. The ARM core-based logical computing unit according to claim 1, characterized in that: The trigonometric function operation module uses the CORDIC algorithm to iteratively calculate the sin value and the cos value.
3. The ARM core-based logical computing unit according to claim 1, characterized in that: The M0 core is specifically used for: Receive a processing instruction sent by a user through the IIC bus, and read the data to be processed based on the processing instruction; Parsing the data to be processed to obtain parsed data; The parsed data, calculated angles and calculation instructions are sent to the trigonometric function operation module via the IIC bus.
4. The ARM core-based logical computing unit according to claim 3, characterized in that: The trigonometric function operation module is specifically used for: Calculate the analytical data according to the calculation angle and the calculation instruction to obtain a calculation result; After the calculation is completed, a completion flag is sent to the M0 core.
5. The ARM core-based logical computing unit according to claim 4, characterized in that: The M0 core is also used to: After receiving the completion mark, the calculation result is read from the trigonometric function operation module.
6. A data processing method, characterized in that: The data processing method is applicable to the ARM core-based logical computing unit as claimed in the claim, and the data processing method comprises: The M0 core obtains the data to be processed from the user through the IIC bus, and parses the data to be processed to obtain parsed data; The M0 core sends the parsed data, calculated angles and calculation instructions to the trigonometric function operation module through the IIC bus for calculation.
7. The data processing method according to claim 6, characterized in that: The trigonometric function operation module uses the CORDIC algorithm to iteratively calculate the sin value and the cos value.
8. The data processing method according to claim 6, characterized in that: The method further comprises: The trigonometric function operation module calculates the analytical data according to the calculation angle and the calculation instruction to obtain a calculation result; After the calculation is completed, the trigonometric function operation module sends a completion flag to the M0 core.
9. The data processing method according to claim 8, characterized in that: The method further comprises: After receiving the completion flag, the M0 core reads the calculation result from the trigonometric function operation module.
Citation Information
Patent Citations
Microcontroller for controlling motor
CN104898521A
Multifunctional electric meter
CN109164297A
Electric power data processing method based on electric energy metering chip and computer equipment
CN115063052A
Method for generating trigonometric function table based on RISC-V extension instruction and extension hardware
CN116974518A