Direct memory access (DMA)-based alternating current sampling method and application thereof
By adopting the DMA-based AC current sampling method in the power monitoring system, using a control period four times the sampling period for synchronous sampling, and processing the sampling data in combination with data association and sine wave characteristics, the omission of sampling data and calculation deviations are solved. problems and improve the reliability and stability of the power monitoring system.
Patent Information
- Application Number
- CN202411422153.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-12
- Publication Date
- 2025-01-24
AI Technical Summary
In the prior art, the DMA control module is responsible for sampling and SPI communication at the same time, which may lead to untimely sampling, resulting in missed sampling data and inconsistent sampling data with memory locations, affecting the accuracy of power monitoring and the stability of the power system.
The DMA -based AC power current sampling method is used to synchronize sampling by four times the control cycle of the sampling cycle. Combined with data association and sinological wave characteristics, the sampling data is selected or discarded to reduce the calculation deviation of the average current.
It effectively reduces the calculation deviation of the average current and improves the reliability of the power monitoring system and the stability of the power supply equipment.
Smart Images

Figure CN119355353A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the field of electrical digital data processing, and in particular to an alternating current sampling method based on DMA and an application thereof. Background Art
[0002] The power data acquisition system is a system that integrates automation, information and intelligent technologies. It is mainly used to monitor the operating status of the power system and collect and analyze power data. Through this system, the operating status of the power system can be understood in real time, power problems can be discovered and solved in time, and the stability and reliability of the power system can be improved. DMA (Direct Memory Access) data sampling is a data acquisition technology. Its working principle is to open a direct data transmission path for RAM and I / O devices based on hardware, allowing peripheral devices to manage data transmission through DMA controllers, and directly store the sampled data in the preset storage unit of the memory in a cyclic input manner without CPU intervention, thereby improving the efficiency of data acquisition and reducing the CPU load. However, since the DMA control module is responsible for sampling and SPI communication at the same time, there may be situations where sampling is not timely due to SPI communication, sampling data is omitted, and the sampling data does not correspond to the memory location. Ultimately, the average current based on the sampled data deviates greatly from the actual value, affecting the accuracy of power monitoring, and affecting the subsequent automation control strategy based on the average current, affecting the stability and reliability of the power system.
[0003] Therefore, it is necessary to design a current sampling method that can reduce the inaccurate calculation caused by missing sampling data. Summary of the invention
[0004] The purpose of the present invention is to provide an alternating current sampling method based on DMA and its application, which aims to overcome the above-mentioned problems existing in the prior art.
[0005] To achieve the above object, the present invention provides the following technical solutions:
[0006] A DMA-based AC current sampling method comprises the following steps:
[0007] Step (1), performing the following operations with a control period four times the sampling period: synchronously sampling the current and voltage of the sinusoidal alternating current; at the same time, storing the current sampling value and the voltage sampling value obtained by each synchronous sampling in a preset storage unit of the memory in a data-associated manner; each time the current sampling value is written into the preset storage unit, the value N is increased by one; wherein the value range of the value N is 0, 1, 2, 3, 4;
[0008] Step (2), after a control cycle ends, determine whether the value N reaches 4, if not, jump to step (1); if yes, execute step (3);
[0009] Step (3), reading four synchronously sampled voltage sampling values from a preset storage unit, and comparing the numerical values of the four voltage sampling values;
[0010] Step (4), when the four synchronous samplings are in the rising half cycle of the voltage sine wave, the four voltage sampling values are arranged in order from small to large according to the numerical value; the current sampling value that is data-associated with the voltage sampling value of the second rank is read, and the current sampling value that is data-associated with the voltage sampling value of the fourth rank is read; the two read current sampling values are used as the calculated values of the average current; and the process jumps to the step (1);
[0011] Step (5), when the four synchronous samplings are in the falling half cycle of the voltage sine wave, the four voltage sampling values are arranged in order from large to small according to the numerical value; the current sampling value that is data-associated with the second-rank voltage sampling value and the current sampling value that is data-associated with the fourth-rank voltage sampling value are read; the two read current sampling values are used as the calculated values of the average current; and the process jumps to the step (1).
[0012] Furthermore, the control period is 55us.
[0013] Furthermore, the data association method in step (2) is specifically to store the current sampling values and voltage sampling values at the same sampling time point in the same preset storage unit in the form of an array or a matrix.
[0014] Furthermore, the method for reading the current sampling value in step (4) and step (5) is specifically to first determine the memory address of the preset storage unit where the voltage sampling value is located through the voltage sampling value, and then read the current sampling value in the preset storage unit according to the memory address.
[0015] Furthermore, in step (4) and step (5), based on the characteristics of the voltage sine wave of the alternating current, it is known in advance whether the sampling time points of the four sampling periods within the control period are all in the falling half-period, or all in the falling half-period; if all are in the falling half-period, step (4) is executed; if all are in the falling half-period, step (5) is executed; if neither all are in the falling half-period nor all are in the falling half-period, no judgment is made and the process directly jumps to step (1).
[0016] The present invention also discloses the application of the above-mentioned DMA-based AC current sampling method, including the following:
[0017] A computer storage medium stores a computer-readable program for executing any of the DMA-based alternating current sampling methods described above.
[0018] A power supply device comprises a processor and a memory, wherein the memory stores instructions, and when the instructions are executed by the processor, the processor executes any of the above-mentioned DMA-based alternating current sampling methods.
[0019] A power monitoring device comprises a processor and a memory, wherein the memory stores instructions, and when the instructions are executed by the processor, the processor executes any of the above-mentioned DMA-based alternating current sampling methods.
[0020] Compared with the prior art, the present invention has the following beneficial effects:
[0021] The present invention is based on DMA technology and synchronously samples current and voltage with a control period four times the sampling period; the sampled data is stored in a preset storage unit of the memory in a cyclic input manner, and the sampled data is selected or discarded in combination with data association and sinusoidal wave characteristics, so as to reduce the calculation deviation of the average current, thereby improving the reliability of the power monitoring system and the stability of the power supply equipment. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] Figure 1 This is a simplified flowchart of an AC current sampling method based on DMA in the present invention.
[0023] Figure 2 Figure 1 is a schematic diagram of the sampling time point, current and voltage on the time axis, where the voltage is in the falling half cycle of the sine wave.
[0024] Figure 3 To sample the current individually, the sampled data is cyclically entered into the data table during normal operation.
[0025] Figure 4 In order to sample the current separately, the sampling data is input into the data table in the abnormal state cyclically. For example, the sampling data at sampling time point 3 is omitted, which causes the sampling data at sampling time points 5-8 to not correspond to the memory location.
[0026] Figure 5 In the present invention, the current and voltage are sampled synchronously, and the sampled data are cyclically input into the data table when abnormality occurs. DETAILED DESCRIPTION
[0027] The specific implementation of the present invention is described below with reference to the accompanying drawings. In order to fully understand the present invention, many details are described below, but for those skilled in the art, the present invention can be implemented without these details.
[0028] like Figure 1 As shown, a DMA-based AC current sampling method includes the following steps:
[0029] Step (1) performs the following operations with a control period four times the sampling period: synchronously sampling the current and voltage of the sinusoidal alternating current; at the same time, storing the current sampling value and the voltage sampling value obtained by each synchronous sampling in a preset storage unit of the memory in a data-associated manner; each time the current sampling value is written to the preset storage unit, the value N is increased by one; wherein the value range of the value N is 0, 1, 2, 3, 4.
[0030] In other words, in step (1), the synchronously sampled current and voltage are directly input into the preset storage unit of the memory by using DMA technology, providing a data basis for the calculation of the average current. It should be noted that at the beginning of each control cycle, the value of the value N is 0.
[0031] Taking the sampling period of 13.75us as an example, the control period is 55us.
[0032] Preferably, the data association method is as follows: the current sampling value and the voltage sampling value at the same sampling time point are stored in the same preset storage unit in an array or matrix. In other words, the memory needs to have four preset storage units to store all the sampling data in one control cycle.
[0033] Step (2): After a control cycle is completed, determine whether the value N reaches 4. If not, jump to step (1); if so, execute step (3).
[0034] Step (3), reading four synchronously sampled voltage sampling values from a preset storage unit, and comparing the numerical values of the four voltage sampling values.
[0035] Step (4), when the four synchronous samplings are in the rising half cycle of the voltage sine wave, the four voltage sampling values are arranged in order from small to large according to the numerical value; the current sampling value that is data-associated with the voltage sampling value in the second rank is read, and the current sampling value that is data-associated with the voltage sampling value in the fourth rank is read; the two read current sampling values are used as the calculated values of the average current; and jump to step (1).
[0036] Step (5), when the four synchronous samplings are in the falling half cycle of the voltage sine wave, the four voltage sampling values are arranged in order from large to small according to the numerical value; the current sampling value that is data-associated with the second-rank voltage sampling value and the current sampling value that is data-associated with the fourth-rank voltage sampling value are read; the two read current sampling values are used as the calculated values of the average current; jump to step (1).
[0037] Specifically, in step (4) and step (5), the method for reading the current sampling value is: first determine the memory address of the preset storage unit where the voltage sampling value is located through the voltage sampling value, and then read the current sampling value in the preset storage unit according to the memory address.
[0038] Specifically, in step (4) and step (5), according to the characteristics of the voltage sine wave of the alternating current, it is known in advance whether the sampling time points of the four sampling periods within the control period are all in the falling half-period, or all in the falling half-period; if all are in the falling half-period, step (4) is executed; if all are in the falling half-period, step (5) is executed; if neither all are in the falling half-period nor all are in the falling half-period, no judgment is made and the process jumps directly to step (1).
[0039] Preferably, in step (2), step (4) and step (5), before jumping to step (1), it is first determined whether the condition for ending sampling is met; if so, the sampling is ended; if not, the process jumps to step (1). The condition for ending sampling includes but is not limited to receiving an interrupt instruction, an end instruction, etc.
[0040] The present invention also discloses the application of the above-mentioned DMA-based AC current sampling method, including the following:
[0041] A computer storage medium stores a computer readable program for executing the DMA-based alternating current sampling method as described above.
[0042] A power supply device includes a processor and a memory, wherein the memory stores instructions, and when the instructions are executed by the processor, the processor executes the DMA-based alternating current sampling method as described above.
[0043] A power monitoring device includes a processor and a memory, wherein the memory stores instructions, and when the instructions are executed by the processor, the processor executes the DMA-based alternating current sampling method as described above.
[0044] In order to facilitate the understanding of the present invention, the following is an example of a power supply device providing sinusoidal alternating current to the outside and performing power monitoring on its power supply end, for illustration:
[0045] like Figure 2-Figure 5 As shown in the figure, a control cycle four times the sampling cycle is used to sample the current individually and input it into the memory cyclically:
[0046] When sampling is normal, it is only necessary to sample the output current of the sinusoidal alternating current separately at the nine sampling time points 1, 2, 3, ... 9 corresponding to the time axis. And, with every four consecutive sampling time points as a cycle, the current sampling values of the sinusoidal alternating current are directly stored in the memory in a cyclic input manner. That is, the software of the power monitoring system enters an interrupt at sampling time points 1, 5, and 9. When entering the interrupt at 5, the DMA controller stores the data sampled at the previous sampling time points 1-4 in the preset storage unit of the memory in a cyclic input manner (such as Figure 3 Combined with Figure 3 As shown, in this control cycle, the current sampling values at sampling time points 2 and 4 should be used as the calculated values of the average current. The current sampling values at sampling time points 1 and 3 deviate too much from the average current and should be discarded. Therefore, in this control cycle, the average current = (I2+I4) / 2.
[0047] Similarly, when the interrupt is entered at 9, the memory data and the value N are cleared, and then the data sampled at the previous sampling time points 5-8 are stored in the preset storage unit of the memory in a cyclic input manner (such as Figure 3 Combined with Figure 2 As shown, in this control cycle, the current sampling values at sampling time points 6 and 8 should be used as the calculated values of the average current, while the current sampling values at sampling time points 5 and 7 deviate too much from the average current and should be discarded. Therefore, in this control cycle, the average current = (I6 + I8) / 2.
[0048] However, since the DMA control module is responsible for sampling and SPI communication at the same time, the sampling may be delayed due to SPI communication, resulting in omission of sampled data, and the sampled data may not correspond to the memory location (such as Figure 4 This is inconsistent with the previous situation, resulting in a large deviation between the average current calculated based on the sampled data and the actual current, affecting the accuracy of power monitoring, and affecting the subsequent automation control strategy based on the average current, affecting the stability and reliability of the power system.
[0049] Therefore, the present invention synchronously samples the current and voltage with a control period four times the sampling period, and stores the sampled data into a preset storage unit (such as Figure 5 As shown), the sampled data is selected or discarded in combination with data association and sine wave characteristics to reduce the calculation deviation of the average current, which is roughly as follows:
[0050] Under the effect of the present invention, when the sampling data at the sampling time point 3 is omitted, the value N is only accumulated to 3 in the control cycle, but not to 4, which indicates that the sampling data is omitted, and all the sampling data in the control cycle are discarded, and the average current value is not calculated. Figure 5 As shown, I3 is omitted, and the sampling data at sampling time points 1, 2, and 4 are all discarded. Only when the value N reaches 4 in a control cycle, and all sampling time points are in the rising half cycle of the voltage sine wave or in the falling half cycle of the voltage sine wave, the following steps will be performed: using the characteristics that the voltage sampling value gradually increases in the rising half cycle of the voltage sine wave and gradually decreases in the falling half cycle of the voltage sine wave, the order of the four voltage sampling values on the time axis is determined. Then, by using data association, the two current sampling values closer to the actual average current value (i.e., the current sampling values at sampling time points 6 and 8) are selected, and the average current value is calculated, and the other two current sampling values (i.e., the current sampling values at sampling time points 5 and 7) that deviate greatly from the actual average current value are discarded, so as to achieve the purpose of accurate calculation of the average current value.
[0051] The above is only a specific implementation of the present invention, but the design concept of the present invention is not limited thereto. Any non-substantial changes to the present invention using this concept shall be deemed as an infringement of the protection scope of the present invention.
Claims
1. A DMA-based AC current sampling method, characterized in that: The following steps are involved: Step (1), performing the following operations at a control period four times the sampling period: synchronously sampling the current and voltage of the sinusoidal alternating current; and storing the current sampling value and the voltage sampling value obtained by each synchronous sampling in a preset storage unit of the memory in a data-associated manner; Each time the current sampling value is written into the preset storage unit, the value N is incremented by one; wherein the value range of the value N is 0, 1, 2, 3, 4; Step (2), after a control cycle ends, determine whether the value N reaches 4, if not, jump to step (1); if yes, execute step (3); Step (3), reading four synchronously sampled voltage sampling values from a preset storage unit, and comparing the numerical values of the four voltage sampling values; Step (4), when the four synchronous samplings are in the rising half cycle of the voltage sine wave, the four voltage sampling values are arranged in order from small to large according to the numerical value; the current sampling value that is data-associated with the voltage sampling value of the second rank is read, and the current sampling value that is data-associated with the voltage sampling value of the fourth rank is read; the two read current sampling values are used as the calculated values of the average current; and the process jumps to the step (1); Step (5), when the four synchronous samplings are in the falling half cycle of the voltage sine wave, the four voltage sampling values are arranged in order from large to small according to the numerical value; the current sampling value that is data-associated with the second-rank voltage sampling value and the current sampling value that is data-associated with the fourth-rank voltage sampling value are read; the two read current sampling values are used as the calculated values of the average current; and the process jumps to the step (1).
2. The method for sampling alternating current based on DMA according to claim 1, characterized in that: The control period is 55us.
3. The method for sampling alternating current based on DMA according to claim 1, characterized in that: In the step (1), the data association method is specifically to store the current sampling values and voltage sampling values at the same sampling time point in the same preset storage unit in the form of an array or a matrix.
4. The method for sampling alternating current based on DMA according to claim 3, characterized in that: The method for reading the current sampling value in step (4) and step (5) is specifically to first determine the memory address of the preset storage unit where the voltage sampling value is located through the voltage sampling value, and then read the current sampling value in the preset storage unit according to the memory address.
5. The method for sampling alternating current based on DMA according to claim 1, characterized in that: In step (4) and step (5), according to the characteristics of the voltage sine wave of the alternating current, it is known in advance whether the sampling time points of the four sampling periods in the control period are all in the falling half period, or all in the falling half period; if all are in the falling half period, step (4) is executed; if all are in the falling half period, step (5) is executed; If neither is in the falling half cycle nor is both in the rising half cycle, no judgment is made and the process directly jumps to step (1).
6. A computer storage medium, characterized in that: A computer-readable program for executing the DMA-based AC current sampling method as described in any one of claims 1 to 5 is stored therein.
7. A power supply device, characterized in that: The invention comprises a processor and a memory, wherein the memory stores instructions, and when the instructions are executed by the processor, the processor executes the DMA-based AC current sampling method according to any one of claims 1 to 5.
8. An electric power monitoring device, characterized in that: The invention comprises a processor and a memory, wherein the memory stores instructions, and when the instructions are executed by the processor, the processor executes the DMA-based AC current sampling method according to any one of claims 1 to 5.