High-precision 64-bit unsigned integer extraction method based on 10-bit lookup table

By adopting a high-precision 64-bit unsigned integer square method based on a 10-bit lookup table in a smart meter, the problem of slow square calculation speed at high sampling rate is solved, fast and high-precision data processing is achieved, and the measurement needs of smart meter are met.

CN119623489APending Publication Date: 2025-03-14ZHEJIANG WELLSUN INTELLIGENT TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411586364.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-08
Publication Date
2025-03-14

AI Technical Summary

Technical Problem

In smart meters, it is difficult for the existing technology to quickly perform square calculations at high sampling rates, and cannot meet the calculation needs of high-precision meters.

Method used

A high-precision 64-bit unsigned integer square method based on a 10-bit lookup table is adopted. This method quickly obtains square results through a lookup table, reducing complex real-time calculations and improving calculation speed.

Benefits of technology

On the premise of ensuring square accuracy, the calculation time is greatly shortened, the data processing efficiency of the metering module is improved, and the measurement needs of high-precision smart meters are met.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119623489A_ABST
    Figure CN119623489A_ABST
Patent Text Reader

Abstract

The invention discloses a high-precision 64-bit unsigned integer extraction method based on a 10-bit lookup table. The high-precision 64-bit unsigned integer extraction method comprises the following steps: constructing the lookup table; defining and judging an input value boundary; obtaining an index value and calculating an extraction result; and further optimization is carried out. In conclusion, the high-precision 64-bit unsigned integer extraction method based on the 10-bit lookup table is applied to a high-precision intelligent electric meter metering module, the MPU calculation time can be greatly shortened on the premise that the extraction precision is guaranteed, the data processing efficiency of the metering module is greatly improved, the high-precision metering requirement of an intelligent electric meter is met, and the practicability is high. According to the method, the maximum calculation time is shortened to 1062 system clock cycles; compared with 3782 system clock periods of an extraction algorithm in an ANSI 'C' standard library, the MPU calculation speed is increased by about 71.9%, meanwhile, the error magnitude of an extraction result reaches 10 e <-3 >, the metering requirement of a high-precision electricity meter is met, complex real-time calculation can be avoided through a table lookup method, and the performance of a result optimization program is rapidly obtained through table lookup.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of metering algorithm implementation of high-precision smart electric meters, and in particular to a high-precision 64-bit unsigned integer square root method based on a 10-bit lookup table. Background Art

[0002] In the field of smart meters, in order to meet the high-precision requirements of smart meters, a higher ADC sampling rate is required to obtain the current and voltage data in the power grid. At the same time, a large amount of data calculations are inevitably performed in the metering module, among which reactive power, current and voltage mean square values, etc. all require square root calculations. The square root algorithm in the ANSI 'C' standard library has high precision, but the operation time is relatively long, which cannot meet the calculation requirements of high-precision meters at high sampling rates. Therefore, it is necessary to increase the calculation speed of the square root operation under high sampling rates. At present, most manufacturers use hardware accelerators to improve the calculation speed. The present invention provides a high-precision 64-bit unsigned integer square root method based on a 10-bit lookup table. This method greatly improves the calculation speed of the square root while ensuring the square root accuracy, and meets the metering requirements of high-precision meters. Summary of the invention

[0003] The purpose of the present invention is to provide a high-precision 64-bit unsigned integer square root method based on a 10-bit lookup table. This high-precision 64-bit unsigned integer square root method based on a 10-bit lookup table is applied to a high-precision smart meter metering module. It can greatly shorten the MPU calculation time while ensuring the square root accuracy, greatly improve the data processing efficiency of the metering module, and meet the high-precision metering requirements of the smart meter.

[0004] To achieve the above object, the present invention provides the following technical solutions:

[0005] The high-precision 64-bit unsigned integer square root method based on a 10-bit lookup table includes the following steps:

[0006] S1: Input 64-bit unsigned integer variable Xin;

[0007] S2: When Xin<2^10, Xin is directly used as the index value Index1 of table Tab1, and the table is looked up to obtain the value Q1, which is the square root of Xin.

[0008] S3: When Xin ≥ 2^10, find the first non-zero bit n of the high order of Xin (the lowest bit of Xin is recorded as bit 0);

[0009] S4: 10 bits of data Xin[n,n-9] are intercepted from position n downward as index Index1 of table Tab1, and the number of remaining low-order bits of Xin after intercepting Index1 (m=n-9) is calculated as index Index2 of table 2;

[0010] S5: Get value Q1 from table 1 through index1, and get value Q2 from table 2 through index2;

[0011] S6: Calculate the intermediate value Q3 = Q1*Q2;

[0012] S7: Calculate the final square root result Q4=Q3+(Xin>>2) / Q3;

[0013] S8: Further optimization:

[0014] 1) The lookup table can be flexibly deleted according to computing requirements to reduce memory space;

[0015] 2) During hardware implementation, the lookup table can be stored in SRAM to increase access speed.

[0016] Preferably, the table Tab1 in S4 comprises arrive The precomputed value of .

[0017] Preferably, the table Tab2 in S4 comprises arrive The precomputed value of .

[0018] Preferably, Q3 in S6 represents a rough estimate of the square root of the input variable Xin.

[0019] Preferably, (Xin>>2) / Q3 in S7 represents a correction factor of Q3, which is used to correct errors introduced by truncation and shift rounding in S4 and S5, so as to perform further refined operations.

[0020] Preferably, the error level of the calculation result of the method reaches 10e-3.

[0021] Preferably, the method is applicable to a metering module of a high-precision smart meter.

[0022] In summary, due to the adoption of the above technology, the beneficial effects of the present invention are:

[0023] 1. This high-precision 64-bit unsigned integer square root method based on a 10-bit lookup table is applied to the high-precision smart meter measurement module. It can greatly shorten the MPU calculation time while ensuring the square root accuracy, greatly improve the data processing efficiency of the measurement module, and meet the high-precision measurement requirements of the smart meter.

[0024] 2. The maximum calculation time of this method is reduced to 1062 system clock cycles. Compared with the 3782 clock cycles of the square root algorithm in the ANSI 'C' standard library, the MPU calculation speed is increased by about 71.9%. At the same time, the square root result error reaches 10e-3, which meets the measurement requirements of high-precision electricity meters.

[0025] 3. Optimize performance: The table lookup method can avoid complex real-time calculations and quickly obtain results through table lookup, thereby optimizing program performance.

[0026] 4. Simplified implementation: Compared with directly implementing a high-precision square root algorithm, the method based on a lookup table is simpler to implement and reduces the complexity of the algorithm design. BRIEF DESCRIPTION OF THE DRAWINGS

[0027] The accompanying drawings constituting a part of the present invention are used to provide a further understanding of the present invention, so that other features, purposes and advantages of the present invention become more obvious. The accompanying drawings of the exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the accompanying drawings:

[0028] Figure 1 Implement a flow chart for a high-precision 64-bit unsigned integer square root method based on a 10-bit lookup table;

[0029] Figure 2 To achieve the flow chart of obtaining the high 0 digit of the new bit. DETAILED DESCRIPTION

[0030] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work belong to the scope of protection of the present invention. Therefore, the following detailed description of the embodiments of the present invention provided in the drawings is not intended to limit the scope of the invention claimed for protection, but merely represents the selected embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work belong to the scope of protection of the present invention.

[0031] In the description of the present invention, it is necessary to understand that the terms indicating orientation or positional relationship are based on the orientation or positional relationship shown in the drawings, and are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as a limitation on the present invention.

[0032] In the present invention, unless otherwise clearly specified and limited, the terms "installed", "connected", "connected", "fixed" and the like should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection or an indirect connection through an intermediate medium, it can be the internal connection of two elements or the interaction relationship between two elements. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to the specific circumstances of the specification.

[0033] The present invention provides Figure 1 The high-precision 64-bit unsigned integer square root method based on a 10-bit lookup table shown includes the following steps:

[0034] S1: Input 64-bit unsigned integer variable Xin;

[0035] S2: When Xin<2^10 (n<10), Xin is directly used as the index value Index1 of table Tab1, and Q1 is obtained by looking up the table. At this time, Q1 is the square root of Xin.

[0036] S3: When Xin≥2^10(n≥10), obtain the number of bits of Xin's high-order 0 bits, LeadingZeros, to obtain the first non-zero bit n of Xin's high-order bits (n=64-LeadingZeros-1, Xin's lowest bit is recorded as bit 0);

[0037] S4: 10 bits of data Xin[n,n-9] are intercepted from position n downward as the index Index1 of table Tab1, and the remaining low-order bits of Xin after intercepting Index1 are calculated as m=n-9 as the index Index2 of table 2 (Index1 is obtained through Xin>>m).

[0038] S5: Get Q1 from Table 1 through index1, and get Q2 from Table 2 through index2;

[0039] S6: Calculate the intermediate value Q3 = Q1*Q2;

[0040] S7: Calculate the final square root result Q4=Q3+(Xin>>2) / Q3;

[0041] S8: Further optimization:

[0042] 1) The lookup table can be flexibly deleted according to computing requirements to reduce memory space;

[0043] 2) During hardware implementation, the lookup table can be stored in SRAM to increase access speed.

[0044] Specific operation steps example:

[0045] Example 1

[0046] Assume that the input variable Xin is 999 (decimal), that is, Xin=999.

[0047] 1. Input variables

[0048] Input: Xin = 999

[0049] 2. Determine the value of Xin

[0050] Check condition: 999<2^10

[0051] ·Use Xin directly as index index1: index1 = 999

[0052] 3. Find table Tab1

[0053] · Lookup value: Q1 = Tab1

[999] = 31.606962203979492187500000

[0054] 5. Output results

[0055] Since Xin<2^10, the output square root result is:

[0056] Q1=31.606962203979492187500000.

[0057] Example 2

[0058] Assume that the input variable Xin is 15000 (decimal), that is, Xin=15000.

[0059] 1. Input variables

[0060] Input: Xin = 15000

[0061] 2. Determine the value of Xin

[0062] Check condition: 15000>2^10

[0063] 3. Find the high non-zero bit

[0064] The binary number of 15000 is 11 1010 1001 1000. Find the first non-zero bit n=13 (the lowest bit is 0).

[0065] 4. Data interception

[0066] ·Truncate the high 10 bits (from bit n-9 to bit n), that is: 11 1010 1001 (from bit 4 to bit 13)

[0067] Calculate the index Index1: Index1 = 11 1010 1001 (binary) = 937 (decimal)

[0068] · Calculate the remaining digits: 13-9=4, so Index2=4.

[0069] 5. Find Table Tab1 and Table Tab2

[0070] · Lookup value: Q1 = Tab1

[937] = 30.610456466674804687500000;

[0071] Q2=Tab2[4]=2

[0072] 6. Calculate intermediate results

[0073] Calculate Q3:

[0074] Q3=Q1×Q2=30.6104564666748046875×2=61.220912933349609375

[0075] 7. Calculate the final result

[0076] Calculate Q4: Q4 = Q3 + (15000>>2) / Q3

[0077] Right shift calculation: 15000 >> 2 = 1110 1010 0110 (binary) = 3750 (decimal)

[0078] Final calculation:

[0079] Q4=61.220912933349609375+234 / 61.220912933349609375

[0080] =122.474491495344837024350929

[0081] Summarize:

[0082] The above examples show the specific steps of how to perform square root calculations based on different input values, including conditional judgment, data interception, table lookup to obtain values, calculation of intermediate results and final results. These steps provide a detailed execution flow to help understand how the algorithm works.

[0083] Example:

[0084] This method is mainly based on the implementation of lookup tables. The tables involved are Tab1 and Tab2. The data type in the table is single-precision floating point. 10 bits of data are intercepted from the input variable. On this basis, the indexes of tables Tab1 and Tab2 are obtained, and Q1 and Q2 are obtained by table lookup. Finally, Q1 and Q2 are substituted into the formula to obtain the square root result of the input variable, and the result data type is single-precision floating point. The maximum calculation time of this method is reduced to 1062 system clock cycles. Compared with the 3782 clock cycles of the square root algorithm in the ANSI'C' standard library, the MPU calculation speed is increased by about 71.9%. At the same time, the square root result error magnitude reaches 10e-3, which meets the measurement requirements of high-precision electricity meters.

[0085] The method is applicable to a smart meter measurement module, wherein a specific embodiment includes the following steps:

[0086] Step 1: Determine whether the input variable Xin is less than 2^10;

[0087] Case 1: Xin is less than 2^10.

[0088] Step 2: Use Xin as the index value of Tab1, and look up the table to obtain the value Q1, which is the output result of the square root of Xin;

[0089] Case 2: Xin is greater than or equal to 2^10.

[0090] Step 2: Take 10 bits of data from the first non-0 bit in the high position of Xin as the index value of Tab1, and get Q1 by looking up the table according to the index value;

[0091] Step 3: Get the low-order digits after the index value of Tab1 in Xin, use it as the index value of Tab2, and look up the table to get Q2 according to the index value;

[0092] Step 4: Calculate the output result of Xin square root based on Q1 and Q2. Q3 = Q1*Q2; Q4 = Q3 + (Xin>>2) / Q3, Q4 is the output result of Xin square root.

[0093] This high-precision 64-bit unsigned integer square root method based on a 10-bit lookup table is applied to the high-precision smart meter measurement module. It can greatly shorten the MPU calculation time while ensuring the square root accuracy, greatly improve the data processing efficiency of the measurement module, and meet the high-precision measurement requirements of the smart meter.

[0094] A high-precision 64-bit unsigned integer square root method based on a 10-bit lookup table includes the following steps:

[0095] Step 1: Define arrays Tab1 and Tab2.

[0096] in:

[0097]

[0098] Step 2: Determine the boundary conditions of Xin

[0099] Case 1: Xin<2 10 .

[0100] Step 3: Use Xin as the index of Tab1, and look up the table to obtain Q1=Tab1[Xin]. At this time, Q1 is the square root of Xin.

[0101] Case 2: Xin ≥ 2 10 .

[0102] Step 3: Get the number of leading zeros in Xin. The implementation process is as follows: Figure 2 As shown, the first non-zero value position n (n=64-LeadingZeros-1) of the high bit of Xin is obtained through LeadingZeros.

[0103] Step 4: Truncate 10 bits of data Xin[n,n-9] from position n downward as the index Index1 of table Tab1, and calculate the remaining low-order bits m=n-9 of Xin after truncating Index1 as the index Index2 of table 2 (Index1 is obtained through Xin>>m);.

[0104] Step 5: Get Q1 from Table 1 through index1, and get Q2 from Table 2 through index2;

[0105] Step 6: Calculate the intermediate value Q3 = Q1*Q2;

[0106] Step 7: Calculate the final square root result Q4 = Q3 + (Xin>>2) / Q3;

[0107] Step 8: Further optimization:

[0108] 1) The lookup table can be flexibly deleted according to computing requirements to reduce memory space;

[0109] 2) During hardware implementation, the lookup table can be stored in SRAM to increase access speed.

[0110] The implementation flow chart of the above steps is as follows Figure 1 shown.

Claims

1. A high-precision 64-bit unsigned integer square root method based on a 10-bit lookup table, characterized in that: The method comprises the following steps: S1: Input 64-bit unsigned integer variable Xin; S2: When Xin<2^10, Xin is directly used as the index value Index1 of table Tab1, and the table is looked up to obtain the value Q1, which is the square root of Xin. S3: When Xin ≥ 2^10, find the first non-zero bit n of the high order of Xin (the lowest bit of Xin is recorded as bit 0); S4: 10 bits of data Xin[n,n-9] are intercepted from position n downward as index Index1 of table Tab1, and the number of remaining low-order bits of Xin after intercepting Index1 (m=n-9) is calculated as index Index2 of table 2; S5: Get value Q1 from table 1 through index1, and get value Q2 from table 2 through index2; S6: Calculate the intermediate value Q3 = Q1*Q2; S7: Calculate the final square root result Q4=Q3+(Xin>>2) / Q3; S8: Further optimization: 1) The lookup table can be flexibly deleted according to computing requirements to reduce memory space; 2) During hardware implementation, the lookup table can be stored in SRAM to increase access speed.

2. The high-precision 64-bit unsigned integer square root method based on a 10-bit lookup table according to claim 1, characterized in that: Table Tab1 contains arrive The precomputed value of .

3. The high-precision 64-bit unsigned integer square root method based on a 10-bit lookup table according to claim 1, characterized in that: Table Tab2 contains arrive The precomputed value of .

4. The high-precision 64-bit unsigned integer square root method based on a 10-bit lookup table according to claim 1, characterized in that: Q3 in S6 represents a rough estimate of the square root of the input variable Xin.

5. The high-precision 64-bit unsigned integer square root method based on a 10-bit lookup table according to claim 1, characterized in that: In S7, (Xin>>2) / Q3 represents the correction factor of Q3, which is used to correct the errors introduced by truncation and shift rounding in S4 and S5 for further refined calculation.

6. The high-precision 64-bit unsigned integer square root method based on a 10-bit lookup table according to claim 1, characterized in that: The error level of the calculation results described therein reaches 10e-3.

7. The high-precision 64-bit unsigned integer square root method based on a 10-bit lookup table according to claim 1, characterized in that: The method is applicable to a metering module of a high-precision smart meter.