Methods for measuring electrical energy error, chips, and standard energy meters
By using a timer to calculate the number of standard pulses, the problem of power measurement error caused by MCU interrupt delay was solved, achieving higher measurement accuracy and synchronization, simplifying the circuit structure and saving hardware resources.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SHENZHEN CLOU ELECTRONICS
- Filing Date
- 2023-12-19
- Publication Date
- 2026-05-26
AI Technical Summary
In traditional power error measurement methods, the delay caused by the interrupt processing of the MCU results in a deviation between the measured value and the actual value, affecting the measurement accuracy.
The system employs a combination of a first timer, a second timer, and a third timer, and calculates the number of standard pulses using a counter register and a period register. It also utilizes an internal event trigger function to synchronize the counting, thereby reducing hardware resources and improving synchronization.
It improves the accuracy of power error measurement, simplifies the circuit structure, saves costs, and enhances the synchronization between the tested pulse and the standard pulse through automatic synchronization via internal event triggering function.
Smart Images

Figure CN117706465B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of power error measurement technology, and in particular to a power error measurement method, chip, and standard power meter. Background Technology
[0002] When measuring energy error, a standard energy meter is typically used. The system simultaneously receives the standard energy pulses from the standard energy meter and the tested energy pulses from the meter under test. By combining the pulse constants of both meters, the energy error of the tested meter can be calculated. To ensure accurate energy error measurement, the accuracy of pulse counting and synchronization during the measurement process must be guaranteed. Traditionally, the standard pulse and the tested pulse separately trigger external interrupts on the MCU, and the pulse counts are accumulated in the corresponding interrupt response functions. However, the MCU's execution of the judgment command in the interrupt function introduces a delay, causing a deviation between the calculated and actual energy error values. Summary of the Invention
[0003] The main technical problem solved by the embodiments of this application is that the measured value obtained by measuring the power error using a standard power meter in the traditional technology deviates from the actual value.
[0004] To solve the above-mentioned technical problems, the first technical solution adopted in the embodiments of this application is: providing a method for measuring power error, including: acquiring a tested pulse constant, a tested pulse number, a standard pulse constant, and a measured power value, and calculating a measurement start count value and a measurement end count value of a first timer; starting the first timer and a second timer, receiving an externally input tested pulse through the first timer, a standard pulse output from the first channel of the second timer, and comparing the measurement start count value and the first count value of the first timer through a comparator of the first timer, wherein the first count value represents the number of tested pulses received by the first timer; when the first count value is equal to the measurement start count value, starting a third timer, wherein the clock source of the third timer is the standard pulse constant. A quasi-pulse is obtained by capturing the first count register value of the second timer through the second channel of the second timer, and obtaining the first cycle register value of the second timer, wherein the clock source of the second timer is an internal clock; when the first count value is equal to the measurement end count value, the second count register value of the second timer is captured through the second channel, and the second cycle register value of the second timer is obtained, and the third count register value of the third timer is obtained; the number of standard pulses is calculated using the first count register value, the first cycle register value, the second count register value, the second cycle register value, and the third count register value; and the power error is calculated using the tested pulse constant, the number of tested pulses, the standard pulse constant, and the number of standard pulses.
[0005] Optionally, after the step of starting the first timer to receive the externally input detected pulse and comparing the measurement start count value and the first count value through the comparator of the first timer, the method further includes: if the measurement end count value is greater than the maximum count value of the first timer, setting the overflow portion of the measurement end count value as the number of overflows to be recorded by the first timer; when the number of detected pulses is greater than the maximum count value of the first timer and the first count value is equal to the measurement start count value, disabling the comparison matching event output function of the first timer; when the third timer overflows, incrementing the overflow count value of the third timer by 1; when the first timer overflows, determining whether the number of overflows to be recorded by the first timer is greater than 0, and if it is greater than 0, decrementing the number of overflows to be recorded by 1; if the comparison matching event output function of the first timer is disabled, determining whether the number of overflows to be recorded by the first timer is less than or equal to 1 in the subsequent comparison matching interrupt response function of the first timer, and if it is less than or equal to 1, re-enabling the comparison matching event output function of the comparator.
[0006] Optionally, the step of calculating the measurement start count value and the measurement end count value of the first timer includes: calculating the measurement start count value according to formula (1):
[0007]
[0008] Wherein, P represents the measured power value, C represents the detected pulse constant, t represents the synchronization preparation time before the measurement begins, and N... start N represents the starting count value for the measurement. start The integer value is greater than 0 and less than the overflow value of the first timer; the measurement end count value is calculated according to formula (2):
[0009] N end =N start +N set (2)
[0010] Where, N set N represents the number of pulses being detected. end This indicates the end count value of the measurement.
[0011] Optionally, the step of calculating the number of standard pulses using the first count register value, the first period register value, the second count register value, the second period register value, and the third count register value includes: calculating the integer part of the number of standard pulses according to formula (3):
[0012] Cnt StdInt =Ovf T3 *N ovf +Cnt T3 (3)
[0013] Among them, Ovf T3 N represents the count overflow value of the third timer. ovf Cnt represents the number of overflows of the third timer. T3 This represents the value of the third counter register, Cnt. StdInt The integer part of the number of standard pulses is represented; the fractional part of the number of standard pulses is calculated according to formula (4):
[0014]
[0015] Where Per1 represents the value of the first cycle register, Cap1 represents the value of the first count register, Per2 represents the value of the second cycle register, Cap2 represents the value of the second count register, and Cnt represents the value of the second count register. StdDec The fractional part of the number of standard pulses is represented; the number of standard pulses is calculated according to formula (5):
[0016] Cnt Std =Cnt StdInt +Cnt StdDec (5)
[0017] Among them, Cnt Std This indicates the number of standard pulses.
[0018] Optionally, the step of calculating the energy error using the tested pulse constant, the number of tested pulses, the standard pulse constant, and the number of standard pulses includes: calculating the energy error according to formula (6):
[0019]
[0020] Wherein, E represents the power error, C1 represents the detected pulse constant, C2 represents the standard pulse constant, N represents the number of detected pulses, and M represents the number of received standard pulses.
[0021] Optionally, the number of bits of the first timer is equal to the number of bits of the third timer, and the number of bits of the second timer is greater than or equal to 32.
[0022] Optionally, before starting the first timer to receive the detected pulse from an external input, the method further includes: determining whether the first count value of the first timer is 0; if not, setting the first count value to 0.
[0023] To solve the above-mentioned technical problems, the second technical solution adopted in this application is: providing a power error measurement chip, including a first timer, a second timer, and a third timer; the external clock input port of the first timer is connected to an external detected pulse, and the count value of the first timer is used to accumulate the number of detected pulses. When the count value of the first timer is equal to the calculated measurement start count value, the comparison matching interrupt of the first timer is triggered to output a measurement start signal, and when the count value of the first timer is equal to the calculated measurement end count value, the comparison matching interrupt of the first timer is triggered to output a measurement end signal; the clock source of the second timer is an internal clock, and after the second timer is started, it outputs a standard pulse through a first channel, captures the count register value of the second timer through a second channel, and obtains the period register value of the first channel of the second timer; the external clock input port of the third timer receives the standard pulse output by the first channel of the second clock, starts when the measurement start signal is received, accumulates the integer part value of the standard pulse during one measurement, and stops when the measurement end signal is received; the power error measurement chip cooperates with the first timer, the second timer, and the third timer to execute the power error measurement method described above.
[0024] To solve the above-mentioned technical problems, the third technical solution adopted in the embodiments of this application is: to provide a standard energy meter, including the energy error measurement chip as described above.
[0025] To solve the above-mentioned technical problems, the fourth technical solution adopted in the embodiments of this application is: to provide a non-volatile computer-readable storage medium, wherein the non-volatile computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are executed by an electronic device, the electronic device performs the power error measurement method as described above.
[0026] Unlike related technologies, this application obtains the tested pulse constant, the number of tested pulses, the standard pulse constant, and the measured power value; it starts a first timer and a second timer, with the first timer receiving the tested pulse from an external input and the first channel of the second timer outputting the standard pulse; when the first count value equals the measurement start count value, a third timer is started, with the standard pulse as the clock source for the third timer, capturing the first count register value of the second timer and obtaining the first cycle register value of the second timer; when the first count value equals the measurement end count value, capturing the second count register value of the second timer, obtaining the second cycle register value of the second timer, and obtaining the third count register value of the third timer; and then sequentially calculating the number of standard pulses and the power error using the aforementioned data. This not only further simplifies the circuit for power error measurement and saves costs by using fewer hardware resources, but also defines the start and end times of power error measurement through a comparison matching function and automatically synchronizes using an internal event triggering function, increasing the synchronization between the start and end of the tested pulse and the standard pulse, and further improving the measurement accuracy of power error. Attached Figure Description
[0027] One or more embodiments are illustrated by way of example with reference to the accompanying drawings. These illustrations do not constitute a limitation on the embodiments. Elements having the same reference numerals in the drawings are denoted as similar elements. Unless otherwise stated, the figures in the drawings are not to be limited by scale.
[0028] Figure 1 This is a schematic flowchart of an embodiment of the power error measurement method provided in this application;
[0029] Figure 2 This is a pulse timing diagram of the tested pulse and the standard pulse during conventional power error measurement according to an embodiment of this application;
[0030] Figure 3 This is a schematic diagram illustrating the principle of calculating the fractional part of the number of standard pulses during power error measurement according to an embodiment of this application;
[0031] Figure 4 This is a schematic diagram of the structure of a power error measurement chip provided in an embodiment of this application;
[0032] Figure 5 This is a schematic diagram of the hardware structure of a standard energy meter that performs an energy error measurement method according to an embodiment of this application. Detailed Implementation
[0033] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0034] It should be noted that, unless otherwise specified, the various features in the embodiments of this application can be combined with each other, all of which are within the protection scope of this application. Furthermore, although functional modules are divided in the device schematic diagram and a logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the device schematic diagram or the order in the flowchart.
[0035] Unless otherwise defined, all technical and scientific terms used in this specification have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to limit the scope of this application. The term "and / or" as used in this specification includes any and all combinations of one or more of the associated listed items.
[0036] In current power error measurement technology, to accurately calculate the power error value, it is first necessary to accurately count the pulses under test and to promptly start and stop counting the standard pulses at the beginning and end of the counting process. Secondly, it is necessary to accurately count the standard pulses during the power error measurement process. However, in traditional power error measurement processes, the pulses under test and the standard pulses are generally not perfectly aligned, such as... Figure 2 As shown, Figure 2 This is a pulse timing diagram of the tested pulse and the standard pulse in the traditional electrical energy error measurement process. Figure 2 In the diagram, "Start" indicates the beginning of the electrical energy error measurement process, and "Stop" indicates the end of the electrical energy error measurement process. This can be understood from... Figure 2 It is known that the number of standard pulses is overcounted at the beginning and undercounted at the end, and these overcounted and undercounted values do not cancel each other out. Therefore, to obtain an accurate number of standard pulses, in addition to obtaining the integer part of the number of standard pulses, it is also necessary to accurately calculate the phase difference between the standard pulses and the pulse under test at the beginning and end of the power error measurement. This phase difference represents the fractional part of the number of standard pulses.
[0037] In addition, current power error measurement technologies typically trigger external interrupts on the MCU when counting the tested pulses and standard pulses. The corresponding interrupt response functions then accumulate the pulse counts. However, this leads to frequent interrupts from the MCU, impacting the real-time performance of the application layer task code. Furthermore, the MCU's need to execute a judgment command in the interrupt function each time introduces a delay, which in turn introduces errors in the calculated standard pulse count, ultimately causing a deviation between the calculated and actual power error values.
[0038] The deficiencies of the aforementioned traditional technical solutions are the result of the applicant's practical experience and careful research. Therefore, the discovery process of the above problems and the solutions proposed in this application below should be considered as contributions made by the applicant to this application during the disclosure process.
[0039] The deficiencies of the above solutions are the result of the applicant's practical experience and careful research. Therefore, the discovery process of the above problems and the solutions proposed in this application below should be considered as contributions made by the applicant to this application during the disclosure process.
[0040] Please see Figure 1 , Figure 1 This is a flowchart illustrating an embodiment of the power error measurement method provided in this application, specifically including:
[0041] S10. Set the pulse constant under test, the number of pulses under test, the standard pulse constant, and the measurement power value, and calculate the measurement start count value and measurement end count value of the first timer.
[0042] The pulse constant is used to characterize the number of energy pulses output by the energy meter during the accumulation of 1 kilowatt-hour of energy, and its unit is imp / kW·h. The choice of the pulse constant depends on the design and application requirements of the energy meter. Under the same power, the larger the pulse constant, the higher the frequency of the output energy pulses, and the higher the accuracy of the measured energy error.
[0043] The measured power value represents the current power value measured by the energy meter under test. For example, a power source with the measured power value is connected to the energy meter under test. The measurement time represents the time difference between the end time and the start time of the error measurement process for the tested pulse.
[0044] As a preferred embodiment, the steps of calculating the measurement start count value and measurement end count value of the first timer include: First, calculating the measurement start count value according to formula (1):
[0045]
[0046] Where P represents the measured power value, C represents the pulse constant under test, t represents the synchronization preparation time before the measurement begins, and N... start This indicates the count value at the start of the measurement. Then, the count value at the end of the measurement is calculated according to formula (2):
[0047] N end =N start +N set (2)
[0048] Where, N setN represents the number of pulses detected. end This indicates the count value at the end of the measurement.
[0049] As an optional implementation, the first timer can be 16 bits, in which case the first timer can count from 1 to 65536, and the measurement start count value N can be set. start It is an integer less than 50,000, which is sufficient to count the number of pulses N being detected within the counting range of the first timer. set By retaining a certain margin, the detected pulse can be maintained in a stable output state for a certain period of time before the power error measurement begins.
[0050] As another optional implementation, if the calculated measurement end count value N... end The count range of the first timer has been exceeded. For example, when the first timer is 16-bit, the measurement ends when the count value N is reached. end The value is 70000. At this point, the measurement ends with the count value N. end The high 16 bits are set as the overflow count for the first timer, and then the calculated measurement end count value N is used. end Update the lower 16 bits of the measurement end count value N. end .
[0051] S20. Start the first timer and the second timer. The first timer receives the externally input pulse under test, the first channel output standard pulse of the second timer, and the comparator of the first timer compares the measurement start count value and the first count value of the first timer. The first count value represents the number of pulses under test received by the first timer.
[0052] As an optional implementation, before starting the first timer to receive the externally input tested pulse, the method further includes: determining whether the first count value of the first timer is 0; if not, setting the first count value to 0 to avoid interference from the first count value of the first timer in the power error measurement process. Then, the externally input tested pulse is received through the external clock input port of the first timer, and the clock source of the first timer is set to the external input clock (i.e., the externally input tested pulse). This external input clock can be undivided and can be set to increment the count value by 1 on the rising edge of the tested pulse. Simultaneously, the internal comparison matching function of the timer is enabled, that is, the comparator built into the first timer compares the count value with the number of received tested pulses. It should be noted that using the comparator does not require configuring the hardware output pin corresponding to the comparison matching function; it is only necessary to enable the comparison matching interrupt and the count overflow interrupt.
[0053] As an optional implementation, after starting the first timer to receive the externally input pulses being tested and comparing the measurement start count value and the first count value through the comparator of the first timer, the method further includes: if the measurement end count value is greater than the maximum count value of the first timer, setting the overflow portion of the measurement end count value as the number of overflows to be recorded for the first timer; when the number of pulses being tested is greater than the maximum count value of the first timer and the first count value is equal to the measurement start count value, disabling the comparison matching event output function of the first timer; when the third timer overflows, incrementing the overflow count value of the third timer by 1; when the first timer overflows, determining whether the number of overflows to be recorded for the first timer is greater than 0, and if it is greater than 0, decrementing the number of overflows to be recorded by 1; if the comparison matching event output function of the first timer is disabled, determining whether the number of overflows to be recorded for the first timer is less than or equal to 1 in the subsequent comparison matching interrupt response function of the first timer, and if it is less than or equal to 1, re-enabling the comparison matching event output function of the comparator.
[0054] The power error measurement process begins when the first timer starts, triggered by a comparator-outputted comparison match event. It ends when the second comparison match event is output by the comparator. However, if the first timer has a non-zero overflow count, the comparison match event output function will be triggered before the number of received pulses reaches the set total number of pulses. This causes the power error measurement process to end due to insufficient received pulses. Therefore, the comparison match event output function of the first timer needs to be disabled when there is an overflow count, and enabled when there is no overflow count, so that the first timer triggers the power error measurement process to end only after receiving a sufficient preset total number of pulses.
[0055] S30. When the first count value equals the measurement start count value, start the second timer and the third timer. The first channel of the second timer outputs a standard pulse, and the clock source of the third timer is a standard pulse. The first count register value of the second timer is captured through the second channel of the second timer, and the first cycle register value of the second timer is obtained. The clock source of the second timer is an internal clock.
[0056] The second timer's function is to accurately calculate the fractional part of the standard pulse count using the capture function of the second channel. During the initialization phase, the clock source for the second timer is configured to be the internal high-frequency clock, without frequency division, and the value of the second timer's count register is incremented by 1 on the rising edge of the internal high-frequency clock.
[0057] It should be noted that the input capture function of the second channel in the second timer does not require enabling the capture interrupt, that is, there will be no interrupt delay, which further improves the accuracy of power error measurement.
[0058] S40. When the first count value equals the measurement end count value, the second count register value of the second timer is captured through the second channel, the second cycle register value of the second timer is obtained, and the third count register value of the third timer is obtained.
[0059] The function of the third timer is to accumulate the integer part of the number of standard pulses in a single measurement. The number of bits of the third timer can be the same as that of the first timer. The value of the third timer's counter register is incremented by 1 on the rising edge of the clock frequency.
[0060] S50. Calculate the number of standard pulses using the values of the first counter register, the first cycle register, the second counter register, the second cycle register, and the third counter register.
[0061] As an optional implementation, step S50 specifically includes: calculating the integer part of the number of standard pulses according to formula (3):
[0062] Cnt StdInt =Ovf T3 *N ovf +Cnt T3 (3)
[0063] Among them, Ovf T3 N represents the count overflow value of the third timer. ovf Cnt represents the number of overflows of the third timer. T3 This represents the value of the third counter register, Cnt. StdInt The integer part of the value represents the number of standard pulses;
[0064] Calculate the fractional part of the standard pulse count according to formula (4):
[0065]
[0066] Where Per1 represents the value of the first cycle register, Cap1 represents the value of the first count register, Per2 represents the value of the second cycle register, Cap2 represents the value of the second count register, and Cnt represents the value of the second count register. StdDec This represents the fractional part of the number of standard pulses.
[0067] The number of standard pulses is calculated according to formula (5):
[0068] Cnt Std =Cnt StdInt+Cnt StdDec (5)
[0069] Among them, Cnt Std Indicates the number of standard pulses
[0070] S60. Calculate the power error using the tested pulse constant, the number of tested pulses, the standard pulse constant, and the standard pulse number.
[0071] As an optional implementation, step S60 specifically includes: calculating the power error according to formula (6):
[0072]
[0073] Where E represents the power error, C1 represents the tested pulse constant, C2 represents the standard pulse constant, N represents the number of tested pulses, and M represents the number of received standard pulses.
[0074] In a preferred embodiment, the number of bits of the first timer is equal to the number of bits of the third timer, and the number of bits of the second timer is greater than or equal to 32.
[0075] Please see Figure 3 , Figure 3 This is a schematic diagram illustrating the principle of calculating the fractional part of the number of standard pulses during power error measurement according to an embodiment of this application. Figure 3 As can be seen from the content, the start point capture value and the end point capture value are the capture count register values of the second timer, and the start point period value and the end point period value are the acquisition period register values of the second timer. The power error measurement method provided by the embodiment of this application can accurately measure the fractional part of the number of standard pulses. If the internal clock frequency of the third clock is further increased, the accuracy of the fractional part can be further improved, which can be used for power error measurement scenarios with higher accuracy requirements.
[0076] The power error measurement method provided in this application involves acquiring the tested pulse constant, the number of tested pulses, the standard pulse constant, the measured power value, and the measurement time; starting a first timer to receive the tested pulses input externally; when the first count value equals the measurement start count value, starting a second and third timer, with the first channel of the second timer outputting a standard pulse and the clock source of the third timer being the standard pulse, capturing the first count register value of the second timer, and acquiring the first cycle register value of the second timer; when the first count value equals the measurement end count value, capturing the second count register value of the second timer, acquiring the second cycle register value of the second timer, and acquiring the third count register value of the third timer; and sequentially calculating the number of standard pulses and the power error using the aforementioned data. This method not only further simplifies the circuit used for power error measurement and saves costs by using fewer hardware resources, but also defines the start and end times of power error measurement through a comparison matching function and automatically synchronizes using an internal event triggering function, increasing the synchronization between the start and end of the tested pulses and the standard pulses, and further improving the measurement accuracy of power error.
[0077] Please see Figure 4 This application provides an energy error measurement chip 400, which includes a first timer 410, a second timer 420 and a third timer 430;
[0078] The external clock input port of the first timer 410 is connected to the external detected pulse. The count value of the first timer 410 is used to accumulate the number of detected pulses. When the count value of the first timer 410 is equal to the calculated measurement start count value, the comparison match interrupt of the first timer 410 is triggered to output the measurement start signal. When the count value of the first timer 410 is equal to the calculated measurement end count value, the comparison match interrupt of the first timer 410 is triggered to output the measurement end signal.
[0079] The clock source of the second timer 420 is an internal clock. After the second timer 420 is started, it outputs a standard pulse through the first channel, captures the count register value of the second timer 420 through the second channel, and obtains the period register value of the first channel of the second timer 420.
[0080] The external clock input port of the third timer 430 receives the standard pulse output from the first channel of the second clock 420. It starts when the measurement start signal is received, accumulates the integer part of the standard pulse during one measurement, and stops when the measurement end signal is received.
[0081] The power error measurement chip 400 cooperates with the first timer 410, the second timer 420 and the third timer 430 to execute the power error measurement method as described above.
[0082] It should be noted that the aforementioned power error measurement chip 400 can execute the power error measurement method provided in the embodiments of this application, and has the corresponding functional elements and beneficial effects for executing the method. Technical details not described in detail in the power error measurement chip embodiments can be found in the power error measurement method provided in the embodiments of this application.
[0083] Please see Figure 5 , Figure 5 This is a schematic diagram of the hardware structure of a standard energy meter 500 that performs the energy error measurement method according to an embodiment of this application. The standard energy meter 500 includes the aforementioned energy error measurement chip 400, and further includes:
[0084] One or more processors 510 and memory 520, Figure 5 Take the 510 processor as an example.
[0085] The processor 510 and the memory 520 can be connected via a bus or other means. Figure 5 Taking the example of a connection between China and Israel via a bus.
[0086] The memory 520, as a non-volatile computer-readable storage medium, can be used to store non-volatile software programs, non-volatile computer-executable programs, and modules, such as the program instructions corresponding to the energy error measurement method in the embodiments of this application. The processor 510 executes various functional applications and data processing of the standard energy meter 500 by running the non-volatile software programs, instructions, and modules stored in the memory 520, thereby implementing the energy error measurement method of the above-described method embodiments.
[0087] The memory 520 may include a program storage area and a data storage area. The program storage area may store the operating system and application programs required for at least one function. The data storage area may store data created based on the use of the power error measurement chip 400. Furthermore, the memory 520 may include high-speed random access memory and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other non-volatile solid-state storage device.
[0088] The one or more modules are stored in the memory 520. When executed by the one or more processors 510, they perform the power error measurement method in any of the above method embodiments, for example, the method described above. Figure 1 Steps S10 to S60 in the method are implemented. Figure 4The functions of the first, second, and third timers.
[0089] The above-described product can perform the methods provided in the embodiments of this application, and has the corresponding functional elements and beneficial effects for performing the methods. Technical details not described in detail in this embodiment can be found in the methods provided in the embodiments of this application.
[0090] This application provides a non-volatile computer-readable storage medium storing computer-executable instructions that are executed by one or more processors, for example... Figure 5 One of the processors 510 can enable the one or more processors to execute the power error measurement method in any of the above method embodiments, for example, to perform the above-described... Figure 1 Steps S10 to S60 in the method are implemented. Figure 4 The functions of the first, second, and third timers.
[0091] This application provides a computer program product, which includes a computer program stored on a non-volatile computer-readable storage medium. The computer program includes program instructions that, when executed by the power error measurement chip or the standard energy meter, enable the power error measurement chip or the standard energy meter to perform the power error measurement method in any of the above-described method embodiments, for example, to perform the above-described... Figure 1 Steps S10 to S60 in the method are implemented. Figure 4 The functions of the first, second, and third timers.
[0092] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.
[0093] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented using software and a general-purpose hardware platform, or of course, using hardware. Those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program instructing related hardware. The program can be stored in a computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. The storage medium can be a magnetic disk, optical disk, read-only memory (ROM), or random access memory (RAM), etc.
[0094] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and not to limit them; under the concept of this application, the technical features of the above embodiments or different embodiments can also be combined, the steps can be implemented in any order, and there are many other variations of different aspects of this application as described above, which are not provided in detail for the sake of brevity; although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the foregoing embodiments, or make equivalent substitutions for some of the technical features; and these 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.
Claims
1. A method for measuring electrical energy error, characterized in that, include: Obtain the pulse constant under test, the number of pulses under test, the standard pulse constant, and the measured power value, and calculate the measurement start count value and measurement end count value of the first timer; Start the first timer and the second timer. The first timer receives the externally input pulse to be tested, the first channel of the second timer outputs a standard pulse, and the comparator of the first timer compares the measurement start count value with the first count value of the first timer. The first count value represents the number of pulses to be tested received by the first timer. When the first count value equals the measurement start count value, the comparison match interrupt of the first timer is triggered to output the measurement start signal, and the third timer is started. The clock source of the third timer is the standard pulse. The first count register value of the second timer is captured through the second channel of the second timer, and the first cycle register value of the second timer is obtained. The clock source of the second timer is an internal clock. When the first count value equals the measurement end count value, the comparison match interrupt of the first timer is triggered to output the measurement end signal. The second count register value of the second timer is captured through the second channel, the second cycle register value of the second timer is obtained, and the third count register value of the third timer is obtained. The third timer starts when the measurement start signal is received, accumulates the integer part of the standard pulse value during one measurement, and stops when the measurement end signal is received. The number of standard pulses is calculated using the first count register value, the first cycle register value, the second count register value, the second cycle register value, and the third count register value. The power error is calculated using the tested pulse constant, the number of tested pulses, the standard pulse constant, and the number of standard pulses.
2. The method for measuring electrical energy error according to claim 1, characterized in that, After the steps of starting the first timer to receive the externally input pulse under test and comparing the measurement start count value with the first count value through the comparator of the first timer, the method further includes: If the measurement end count value is greater than the maximum count value of the first timer, the overflow portion of the measurement end count value is set as the number of overflows to be performed by the first timer; When the number of detected pulses is greater than the maximum count value of the first timer, and the first count value is equal to the measurement start count value, the comparison matching event output function of the first timer is turned off; When the third timer overflows, the overflow count value of the third timer is incremented by 1; When the first timer overflows, it is determined whether the number of overflows of the first timer is greater than 0. If it is greater than 0, the number of overflows is decremented by 1. If the comparison matching event output function of the first timer is disabled, then in the subsequent comparison matching interrupt response function of the first timer, it is determined whether the number of overflows of the first timer is less than or equal to 1. If it is less than or equal to 1, then the comparison matching event output function of the comparator is re-enabled.
3. The method for measuring electrical energy error according to claim 1, characterized in that, The steps of calculating the measurement start count value and measurement end count value of the first timer include: Calculate the measurement start count value according to formula (1): in, P This indicates the measured power value. C This represents the detected pulse constant. t This indicates the synchronization preparation time before the measurement begins. This indicates the starting count value for the measurement. It is an integer between 0 and the overflow value of the first timer; Calculate the end-of-measure count value according to formula (2): in, This indicates the number of pulses being detected. This indicates the end count value of the measurement.
4. The method for measuring electrical energy error according to claim 2, characterized in that, The step of calculating the number of standard pulses using the first count register value, the first period register value, the second count register value, the second period register value, and the third count register value includes: Calculate the integer part of the standard pulse number according to formula (3): in, This indicates the number of overflows of the third timer. This indicates the value of the third counter register. The integer part of the value represents the number of standard pulses; Calculate the fractional part of the standard pulse count according to formula (4): in, This represents the value of the first cycle register. This represents the value of the first counter register. This represents the value of the second cycle register. This represents the value of the second counter register. This represents the fractional part of the number of standard pulses. The number of standard pulses is calculated according to formula (5): in, This indicates the number of standard pulses.
5. The method for measuring electrical energy error according to claim 1, characterized in that, The step of calculating the power error using the tested pulse constant, the tested pulse count, the standard pulse constant, and the standard pulse count includes: The electrical energy error is calculated according to formula (6): in, E This indicates the electrical energy error. C 1 represents the detected pulse constant. C 2 represents the standard pulse constant. N This indicates the number of pulses being detected. M This indicates the number of received standard pulses.
6. The method for measuring electrical energy error according to claim 1, characterized in that, The number of bits in the first timer is equal to the number of bits in the third timer, and the number of bits in the second timer is greater than or equal to 32.
7. The method for measuring electrical energy error according to claim 1, characterized in that, Before the step of starting the first timer to receive the detected pulse from an external input, the method further includes: Determine whether the first count value of the first timer is 0. If not, set the first count value to 0.
8. A power error measurement chip, characterized in that, Including the first timer, the second timer, and the third timer; The external clock input port of the first timer is connected to the external detected pulse. The count value of the first timer is used to accumulate the number of detected pulses. When the count value of the first timer is equal to the calculated measurement start count value, the comparison match interrupt of the first timer is triggered to output the measurement start signal. When the count value of the first timer is equal to the calculated measurement end count value, the comparison match interrupt of the first timer is triggered to output the measurement end signal. The clock source of the second timer is an internal clock. After the second timer is started, it outputs a standard pulse through the first channel, captures the count register value of the second timer through the second channel, and obtains the period register value of the first channel of the second timer. The external clock input port of the third timer receives the standard pulse output from the first channel of the second clock. It starts when the measurement start signal is received, accumulates the integer part of the standard pulse value during one measurement, and stops when the measurement end signal is received. The power error measurement chip cooperates with the first timer, the second timer and the third timer to execute the power error measurement method according to any one of claims 1-7.
9. A standard electricity meter, characterized in that, Includes the power error measurement chip as described in claim 8.
10. A non-volatile computer-readable storage medium, characterized in that, The non-volatile computer-readable storage medium stores computer-executable instructions, which, when executed by the standard energy meter of claim 9, cause the standard energy meter to perform the energy error measurement method of any one of claims 1-7.