A method and apparatus for generating electrical energy pulses for non-real time systems
By calculating the delay time and effective level width of the power pulse in a non-real-time system, the problem of uncertain power pulse output in a non-real-time system is solved, and stable output of high-precision power pulses is achieved.
Patent Information
- Application Number
- CN202310842098.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-10
- Publication Date
- 2026-11-27
- Estimated Expiration
- 2043-07-10
AI Technical Summary
In the existing technology, the power pulse output method is only applicable to real-time systems or integrated circuits. When applied to non-real-time systems, it cannot output high-precision power pulses because non-real-time systems do not support nesting and cannot respond to high-frequency interrupts in a timely manner, resulting in uncertain power pulse output timing.
By calculating the accumulated power value and the pulse occurrence time using the current system time and clock synchronization count value when the sampling pulse triggers an interrupt, and setting the delay time and the effective level width of a single pulse, the system ensures accurate output of power pulses in non-real-time systems.
It enables the output of high-precision power pulses in non-real-time systems such as Linux, eliminating the uncertainty of task software processing time and improving the accuracy and stability of power pulse output.
Smart Images

Figure CN116879597B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to a method and apparatus for generating electrical energy pulses for non-real-time systems, belonging to the field of electrical energy calculation technology. Background Technology
[0002] Currently, the accuracy of electricity metering is achieved through comparison of energy pulses during testing and production inspection. Under the same standard power input, the time between the high-level energy pulses output by the electricity meter and the standard metering equipment used for testing and inspection is compared to determine the electricity metering error.
[0003] Existing electricity metering algorithms are implemented based on real-time systems such as microcontrollers or integrated circuits, and their principles are as follows: Figure 1 As shown. In this process, the pulse occurs every time the analog-to-digital conversion time T passes. C This occurs during the interruption following the completion of the sampling conversion. The specific process is as follows: first, the sampled data is read, then parameters such as voltage, current, and power are calculated, and the accumulated energy value E(k) is calculated.
[0004] E(k)=E(k-1)+P(k·T) S
[0005] Where k is the sampling count sequence number, T S Let P(k) be the sampling period time, and P(k) be the power accumulated during the k-th sampling period. If k = i, the accumulated power reaches or exceeds the power pulse generation threshold E. TH That is, satisfying:
[0006] E(i-1)+P(i)·T S >E TH
[0007] It immediately outputs a power pulse signal p through the hardware pin. E The effective level is updated, and the energy accumulation value is updated:
[0008] E(i)=E(i-1)+P(i·T) S -E TH
[0009] After passing M P The pulse width time M corresponding to each sampling period P ·T S Then the electrical energy pulse signal p E Set the output pin to an invalid level.
[0010] The above method is implemented in a real-time system or integrated circuit, outputting an electrical energy pulse p. E The effective level time accuracy is the sampling period time T. STo improve the accuracy of meters or testing equipment, the sampling rate needs to be increased, which undoubtedly increases the computational workload significantly. Furthermore, the above method is only applicable to real-time systems such as microcontrollers or integrated circuits. If applied to non-real-time systems such as Linux, the lack of nested interrupts and the inability of high-frequency interrupts to respond promptly prevent calculations from being performed immediately after each sampling. In some cases, interrupts may fail to interrupt in time, resulting in delays of several sampling cycles. Therefore, continuing to output power pulses using the above method will introduce significant uncertainty to the timing of power pulse output, making it impossible to output high-precision power pulses. Summary of the Invention
[0011] The purpose of this invention is to provide a method and apparatus for generating electrical energy pulses for non-real-time systems, in order to solve the problem that when the electrical energy pulse output method applied to real-time systems or integrated circuits is applied to non-real-time systems, it cannot output high-precision electrical energy pulses because the non-real-time system does not support nesting and cannot respond in time to high-frequency interrupts.
[0012] To solve the above-mentioned technical problems, the solutions and corresponding technical effects provided by the present invention include:
[0013] The present invention provides a method for generating electrical energy pulses for a non-real-time system, comprising the following steps:
[0014] 1) Upon entering the sampling pulse trigger interrupt, determine the clock synchronization count value C at the completion time of the i-th sampling based on the acquired current system time. s (i);
[0015] 2) Calculate the accumulated energy value E for the i-th sampling period based on the read sampling data. I (i);
[0016] 3) The accumulated energy value in the i-th sampling period is greater than the threshold E generated by the energy pulse. TH At that time, calculate the accumulated value E of the remaining electrical energy after the generation of the electrical energy pulse. I (i) Utilizing the remaining accumulated electrical energy value E I (i) Calculate the delay T between the pulse occurrence time and the clock synchronization time of the corresponding sampling point. S2P ; Obtain the current system time again, and use the current system time and the single pulse effective level width T PE Delay time T S2P The clock synchronization count value C at the time of completion of the i-th sampling. s (i) Calculate the period T of single pulse generation D ;
[0017] 4) Utilizing the occurrence period T D and single pulse effective level width T PEOutput electrical energy pulse signal.
[0018] Its beneficial effects are as follows: Addressing the situation where power pulse signal calculation cannot be performed immediately after each sampling, this invention first reads the current system time when the accumulated power value exceeds a threshold. Then, using parameters such as the remaining accumulated power value after the power pulse generation, the delay time between the pulse generation time and the clock synchronization time of the corresponding sampling point, and the effective level width of the single pulse, the period of single pulse generation is calculated. That is, the power pulse generation time is generated after a delay. The delay time setting avoids the problems of untimely sampling data processing and delayed power accumulation calculation that may be caused by non-real-time systems handling other processes. Furthermore, the single pulse generation period is used to enable pulse output for high-precision power pulses, thereby achieving high-precision power pulse generation in non-real-time systems such as Linux. Overall, this invention eliminates the uncertainty of software processing time in non-real-time systems and improves the accuracy and stability of power pulse output.
[0019] Furthermore, the clock synchronization count value C at the time of completion of the i-th sampling... s The formula for calculating (i) is:
[0020]
[0021] Among them, D m X is the clock synchronization degradation value. CS (i) is the count value corresponding to the current system time; T S f is the sampling period of the sampling pulse; CS The counting frequency; s (i-1) is the clock synchronization count value at the time when the (i-1)th sampling is completed.
[0022] Its beneficial effect is that selecting a value closer to the clock synchronization time is the clock synchronization count value at the time of completion of the i-th sampling, thus ensuring the accuracy of the power pulse output.
[0023] Furthermore, the delay time T S2P The calculation formula is:
[0024] T S2P =N d +D p )×T s
[0025] Among them, T S2P N is the delay time; d It is a fixed number of delay pulses; T S D is the sampling period of the sampling pulse; p The position of the pulse occurrence time relative to one sampling period. PD (i) represents the power of the i-th sampling period.
[0026] Its beneficial effects are: the calculation of the delay time takes into account a fixed number of delay pulses, and takes into account the situation where the delay is several sampling periods due to the inability to interrupt in time.
[0027] Furthermore, the period T of single pulse generation D The calculation formula is:
[0028]
[0029] in, D (i) is the count value corresponding to the current system time obtained again; f CS This represents the counting frequency.
[0030] Its beneficial effect is that the period of single pulse generation can be accurately calculated according to the above calculation formula, which facilitates the generation of high-precision electrical energy pulses.
[0031] Furthermore, the fixed number of delay pulses N d It exceeds the maximum number of sampling interruptions that the non-real-time system cannot respond to in a timely manner.
[0032] Its beneficial effects are: it can ensure the effective output of electrical energy pulses without being interrupted by other interrupts, as it exceeds the maximum number of sampling interrupts that a non-real-time system cannot respond to in a timely manner.
[0033] Furthermore, if |X| is not satisfied in multiple consecutive sampling periods CS (i)-C s (i)|≤T S · CS If the synchronous counting calculation fails, the interrupt handling will end.
[0034] Its beneficial effect is that it exits the interrupt when the synchronous technology calculation fails, so as to avoid getting stuck in an infinite calculation and avoid handling the fault.
[0035] Furthermore, the remaining accumulated electrical energy value E I (i) is:
[0036] E I (i)= I (i-1)+P D (i)×T s -E TH
[0037] Among them, E I (i-1) is the accumulated energy value in the (i-1)th sampling period; P D (i) represents the power in the i-th sampling period; T SThe sampling period is the sampling pulse.
[0038] Furthermore, the accumulated energy value in the i-th sampling period is less than or equal to the threshold E generated by the energy pulse. TH When the interruption occurs, the current interruption process ends.
[0039] The present invention provides an electrical pulse generator for a non-real-time system, comprising a processor and a memory, wherein the processor is configured to execute computer program instructions stored in the memory to implement the described electrical pulse generator method for a non-real-time system.
[0040] Its beneficial effects are: it provides a carrier for the implementation of the power pulse generation method for non-real-time systems of the present invention, and ensures the effective and reliable execution of the method. Attached Figure Description
[0041] Figure 1 It is a timing diagram of the power pulse generation method in a real-time system or integrated circuit of the prior art;
[0042] Figure 2 This is a flowchart of the power pulse generation method for non-real-time systems according to the present invention;
[0043] Figure 3 This is a timing diagram of the power pulse generation method for non-real-time systems according to the present invention. Detailed Implementation
[0044] The present invention will now be described in further detail with reference to the accompanying drawings and embodiments.
[0045] Method Implementation Examples:
[0046] This invention provides an embodiment of a power pulse generation method for a non-real-time system, where the non-real-time system refers to a Linux operating system. In this embodiment, the method is mounted to the aforementioned sampling pulse interrupt via a Linux driver. In this embodiment, a periodic pulse generated by one PWM output from a selected CPU is used as the sampling pulse for an external ADC chip. S Its sampling period is T S =100us, i.e., sampling rate F S 10k; ADC sampling pulse p S The change in the active level initiates analog-to-digital conversion, and the width of the active level corresponds to the time T required to complete the conversion. C and set T C For 60µs, during the ADC sampling pulse p S An interrupt is generated when the level becomes invalid, and the following is executed in each interrupt handler: Figure 2 The steps are shown, and the overall timing diagram of the implemented steps is as follows. Figure 3 As shown.
[0047] Step 1: Call the `ktime_get_real()` function to obtain the current system time, and then multiply it by the counting frequency `f`. CS =100MHz to obtain the corresponding count value X CS (i) Further utilize the count value X corresponding to the current system time. CS (i) Calculate the clock synchronization count C at the time when the i-th sampling is completed. s (i), the calculation formula is as follows:
[0048]
[0049] Among them, D m The clock synchronization degradation value, whose value satisfies D m / (T S ·f CS This is slightly greater than the maximum error between the actual accuracy of the CPU processing clock and the actual accuracy of the sampling pulse clock. This means that if the clock generating the sampling is not the same as the CPU processing clock, an accuracy error will occur. For example, if the actual error of the CPU processing clock is 8 ppm, while the actual accuracy error of the sampling pulse clock is -16 ppm, the maximum error between the actual accuracy of the sampling pulse clock and the actual accuracy of the CPU processing clock is 8 - (-16) = 24 ppm. In this case, T... S ·f CS The estimated CPU clock count value corresponding to the sampling period is smaller than the actual value. If no clock synchronization degradation value is set, i.e., Dm = 0, the synchronization tracking count value C s (i) Each calculation becomes progressively smaller, making synchronous tracking impossible. Therefore, in this embodiment, Dm = 1, corresponding to Dm / (T) S ·f CS If the value is 100ppm > 24ppm, it will compensate for the clock error and ensure clock synchronization tracking convergence.
[0050] To avoid this processing failure, the method execution also includes synchronous failure monitoring; if |X| is not satisfied for K = 1000 consecutive sampling periods... CS (i)-C s (i)|≤T C · CS If the clock synchronization counting calculation fails, the power pulse generation cannot be completed, and subsequent steps are aborted.
[0051] Step 2: Read data from the external ADC chip via the SPI interface to obtain the power P of the i-th sampling period. D (i) Further calculate the accumulated electrical energy value E I (i), E I(i) The following calculation method is used:
[0052] E I (i)= I (i-1)+P D (i)×T s
[0053] Among them, E I (i) The accumulated energy value corresponding to the i-th sampling period, P D (i) The power corresponding to the i-th sampling period, T s Corresponding sampling period time.
[0054] Step 3: Determine the accumulated energy value E in the i-th sampling period. I (i) Whether it exceeds the threshold E for determining the occurrence of an electrical pulse TH If the value is greater than the threshold, proceed to step 4; otherwise, end the current interruption process.
[0055] Step 4: Calculate the entire cycle time T of the PWM single pulse generation using the following steps. D :
[0056] 1) The cumulative electrical energy value E for the i-th sampling period I (i) Processing is performed to obtain the accumulated value of the remaining electrical energy after the generation of the electrical energy pulse, processing E I (i) The following calculation method is used:
[0057] E I (i)= I (i)-E TH
[0058] Among them, E I (i) The accumulated energy value corresponding to the i-th sampling period, E TH It is the threshold for the generation of electrical energy pulses.
[0059] 2) Calculate the position D of the pulse occurrence time relative to one sampling period. p :
[0060]
[0061] 3) Calculate the delay time T between the pulse occurrence time and the clock synchronization time of the corresponding sampling point. S2P :
[0062] T S2P =N d +D p )×T s
[0063] Where, N dIt is a fixed number of delay pulses, the value of which is greater than the maximum number of sampling interrupts that the non-real-time system cannot respond to in a timely manner. In this embodiment, the maximum number of sampling interrupts that cannot be responded to in a timely manner on the selected hardware platform is 2. To leave a margin, N d The value is 4.
[0064] 4) Call the `ktime_get_real()` function again to get the current system time (which is different from the current system time in step 1), and then multiply it by the counting frequency `f`. cs Get the count value X corresponding to the current system time. D (i) and then calculate the entire cycle time T of the PWM single pulse generation. D T D The following formula is used to calculate:
[0065]
[0066] Among them, T PE This is the effective level width and time of the power pulse configured for the PMW single pulse generator; in this embodiment, it is set to 80ms.
[0067] Step 5, call the pwm_config() function according to the entire cycle time T of the PWM single pulse. D And single pulse effective level width and time T PE Set the corresponding configuration parameters, and then call the pwm_enable() function to enable the single pulse generation of PWM, outputting the power pulse signal p at the corresponding pin. E And end the interruption.
[0068] In summary, this invention proposes a method for generating power pulses in non-real-time systems. This method can generate high-precision power pulses in non-real-time systems such as Linux, and specifically has the following characteristics: First, a clock synchronization count value C is constructed that is synchronized with the sampling completion time. s (i) Based on the system time count value X at the sampling processing time CS (i) and the synchronous estimated time count value C s (i-1)+T S · CS The comparison is performed, and the minimum value is taken to eliminate the delay effect of other processes in the non-real-time system on the sampling interruption; at the same time, the synchronous estimation time count value is increased by a small degradation value D. m This avoids synchronization issues caused by clock errors and interference. Secondly, the invention, after a delay time T... S2P The time of generation of the electrical energy pulse and the delay time T S2PThis setting avoids the problems of untimely processing of sampling data and delays in power accumulation calculation that may be caused by non-real-time systems processing other processes. Third, this invention, based on the PWM single-pulse generation function of the non-real-time system, sets the single-pulse generation period T... D and single pulse effective level width T PE The final output requires an electrical pulse, which is generated by a hardware circuit and is unaffected by software, thus ensuring the accuracy of the output pulse timing. Therefore, the method of this invention eliminates the uncertainty of software processing time in non-real-time system tasks, improving the accuracy and stability of the electrical pulse output.
[0069] Device Example:
[0070] This invention discloses an electrical pulse generator for a non-real-time system, comprising a memory, a processor, and an internal bus. The processor and memory communicate and exchange data via the internal bus. The processor can be a microprocessor (MCU), a programmable logic device (FPGA), or other processing devices. The memory can be any type of memory that stores information using electrical energy, such as RAM or ROM, or other types of memory. The processor executes program instructions stored in the memory to implement the electrical pulse generation method for a non-real-time system described in the method embodiments of this invention. This method has been described in detail in the method embodiments and will not be repeated here.
Claims
1. A method for generating electrical pulses for a non-real-time system, characterized in that, Includes the following steps: 1) Upon entering the sampling pulse trigger interrupt, determine the clock synchronization count value at the completion time of the i-th sampling based on the acquired current system time. : X is the clock synchronization degradation value. CS (i) is the count value corresponding to the current system time; f CS The counting frequency; This is the clock synchronization count value at the time when the (i-1)th sampling is completed; 2) Calculate the accumulated energy value for the i-th sampling period based on the read sampling data. ; 3) In Greater than the threshold generated by the electrical pulse At that time, calculate the accumulated value of the remaining electrical energy after the generation of the electrical energy pulse. ; Accumulate the remaining electrical energy Calculate the delay T between the pulse occurrence time and the clock synchronization time of the corresponding sampling point. S2P : N d It is a fixed number of delay pulses, and N d Greater than the maximum number of sampling interruptions that the non-real-time system cannot respond to in a timely manner; T S The sampling period of the sampling pulse; The position of the pulse occurrence time relative to one sampling period. , Let be the power in the i-th sampling period; Obtain the current system time again, and use the current system time and the effective pulse width. Delay time T S2P and The period T of single pulse generation is calculated. D : This is the count value corresponding to the current system time that is retrieved again. 4) Using T D and Output electrical energy pulse signal.
2. The method for generating electrical pulses for a non-real-time system according to claim 1, characterized in that, D m The value of satisfies D m / (T S ·f CS This is greater than the maximum error between the actual accuracy of the CPU processing clock and the actual accuracy of the sampling pulse clock.
3. The method for generating electrical pulses for a non-real-time system according to claim 1, characterized in that, Step 4) involves outputting the power pulse signal, which includes calling the pwm_config() function according to the entire cycle time of the PWM single pulse. and single pulse effective level width and time Set the corresponding configuration parameters, and then call the pwm_enable() function to enable the single pulse generation of PWM, outputting the power pulse signal p at the corresponding pin. E .
4. The method for generating electrical pulses for a non-real-time system according to claim 1, characterized in that, The sampling period is T. S =100us, sampling rate F S It is 10k.
5. The method for generating electrical pulses for a non-real-time system according to claim 1, characterized in that, The value is 80ms.
6. The method for generating electrical pulses for a non-real-time system according to claim 1, characterized in that, If the condition is not met for multiple consecutive sampling periods If the synchronous counting calculation fails, the interrupt handling will end.
7. The method for generating electrical pulses for a non-real-time system according to any one of claims 1 to 6, characterized in that, Remaining accumulated electrical energy for: in, This represents the accumulated energy value during the (i-1)th sampling period; T is the power in the i-th sampling period; S The sampling period is the sampling pulse.
8. The method for generating electrical pulses for a non-real-time system according to claim 1, characterized in that, The accumulated energy value in the i-th sampling period is less than or equal to the threshold value generated by the energy pulse. When the interruption occurs, the current interruption process ends.
9. An electrical pulse generator for a non-real-time system, characterized in that, The system includes a processor and a memory, the processor being configured to execute computer program instructions stored in the memory to implement a method for generating electrical energy pulses for a non-real-time system, as described below, the method comprising the following steps: 1) Upon entering the sampling pulse trigger interrupt, determine the clock synchronization count value at the completion time of the i-th sampling based on the acquired current system time. : X is the clock synchronization degradation value. CS (i) is the count value corresponding to the current system time; f CS The counting frequency; This is the clock synchronization count value at the time when the (i-1)th sampling is completed; 2) Calculate the accumulated energy value for the i-th sampling period based on the read sampling data. ; 3) In Greater than the threshold generated by the electrical pulse At that time, calculate the accumulated value of the remaining electrical energy after the generation of the electrical energy pulse. ; Accumulate the remaining electrical energy Calculate the delay T between the pulse occurrence time and the clock synchronization time of the corresponding sampling point. S2P : N d It is a fixed number of delay pulses, and N d Greater than the maximum number of sampling interruptions that the non-real-time system cannot respond to in a timely manner; T S The sampling period of the sampling pulse; The position of the pulse occurrence time relative to one sampling period. , Let be the power in the i-th sampling period; Obtain the current system time again, and use the current system time and the effective pulse width. Delay time T S2P and The period T of single pulse generation is calculated. D : This is the count value corresponding to the current system time that is retrieved again. 4) Using T D and Output electrical energy pulse signal.
10. The power pulse generator for a non-real-time system according to claim 9, characterized in that, D m The value of satisfies D m / (T S ·f CS This is greater than the maximum error between the actual accuracy of the CPU processing clock and the actual accuracy of the sampling pulse clock.
11. The power pulse generator for a non-real-time system according to claim 9, characterized in that, Step 4) involves outputting the power pulse signal, which includes calling the pwm_config() function according to the entire cycle time of the PWM single pulse. and single pulse effective level width and time Set the corresponding configuration parameters, and then call the pwm_enable() function to enable the single pulse generation of PWM, outputting the power pulse signal p at the corresponding pin. E .
12. The power pulse generator for a non-real-time system according to claim 9, characterized in that, The sampling period is T. S =100us, sampling rate F S It is 10k.
13. The power pulse generator for a non-real-time system according to claim 9, characterized in that, The value is 80ms.
14. The power pulse generator for a non-real-time system according to claim 9, characterized in that, If the condition is not met for multiple consecutive sampling periods If the synchronous counting calculation fails, the interrupt handling will end.
15. The power pulse generator for a non-real-time system according to any one of claims 9 to 14, characterized in that, The remaining accumulated electrical energy for: in, This represents the accumulated energy value during the (i-1)th sampling period; T is the power in the i-th sampling period; S The sampling period is the sampling pulse.
16. The power pulse generator for a non-real-time system according to claim 9, characterized in that, The accumulated energy value in the i-th sampling period is less than or equal to the threshold value generated by the energy pulse. When the interruption occurs, the current interruption process ends.
Citation Information
Patent Citations
Sampling and calculating separated type electric energy meter calibrating method and electric energy meter site parameter recorder
CN101957439A
Electric energy meter prediction type pulse output method, system and device and storage medium
CN116381330A
