An ac-dc sampling method based on a linux platform

By using an ADC AC/DC sampling method based on the Linux platform, the problems of numerous PCB traces and large layout space in the MCU+SOC metering scheme were solved, achieving effective cost reduction and ensuring data integrity.

CN115078811BActive Publication Date: 2026-02-27SHENZHEN CLOU ELECTRONICS
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210490251.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-05-07
Publication Date
2026-02-27
Estimated Expiration
2042-05-07

AI Technical Summary

Technical Problem

In existing technologies, metering solutions based on MCU+SOC require numerous PCB traces and large layout space, resulting in high product costs.

Method used

An ADC AC/DC sampling method based on the Linux platform is adopted. By configuring the notification mode of ADC sampling data, registering the character device driver and configuring the timer driver, and combining the cycle queue alternating buffering technology, the sampling and calculation of AC voltage and DC voltage data are realized.

Benefits of technology

It reduces PCB traces and layout space, lowers product costs, and ensures data sampling integrity and frequency synchronization, making it suitable for environments that do not support DMA functionality.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115078811B_ABST
    Figure CN115078811B_ABST
Patent Text Reader

Abstract

The application discloses an ADC AC-DC sampling method based on a Linux platform and belongs to the technical field of data sampling. The method comprises the following steps: configuring a notification mode of ADC sampling data, wherein the notification mode is configured as one of a polling mode, a blocking mode, a SIGIO mode and an interrupt mode; configuring an ADC sampling frequency; registering a character device driver for providing an API access interface of a system to a Linux application layer; configuring a timer driver; sampling AC voltage data and DC voltage data; when the AC voltage data or the DC voltage data is sampled, notifying the Linux application layer; and calculating actual values of the AC voltage data and the DC voltage data in the Linux application layer according to the AC voltage data and the DC voltage data. Through the technical scheme, the technical problem of a large number of wirings and a large layout space of a PCB in the prior art design is solved, and the problem of high cost of a product designed by the prior art is further solved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The application belongs to the technical field of data sampling and relates to an ADC AC / DC sampling method based on a linux platform. BACKGROUND

[0002] After the State Grid Marketing Department releases the object-oriented electricity information data exchange protocol ''DL / T698.45'', the current linux terminal type metering product adopts the MCU+SOC metering scheme, such as the commonly used metering scheme adopting NUC977DK51Y+RN8208. However, the metering scheme has the following defects: the PCB has many wirings and needs a large layout space when the scheme is designed, and the product designed has a high cost. SUMMARY

[0003] The application aims to provide an ADC AC / DC sampling method based on a linux platform, which solves the technical problems of the MCU+SOC metering scheme in the prior art, such as many wirings of the PCB and a large layout space when the scheme is designed, and further solves the problem of a high cost of the product designed.

[0004] To solve the above technical problems, the technical scheme of the application is as follows:

[0005] The application provides an ADC AC / DC sampling method based on a linux platform, which comprises the following steps:

[0006] Configuring a notification mode of ADC sampling data, wherein the notification mode is configured as one of a polling mode, a blocking mode, a SIGIO mode and an interrupt mode;

[0007] Configuring an ADC sampling frequency;

[0008] Registering a character device driver, which is used to provide an API access interface of a system to a linux application layer;

[0009] Configuring a timer driver, which is used to sample AC voltage data and DC voltage data;

[0010] Notifying the linux application layer when the AC voltage data or the DC voltage data is sampled;

[0011] According to the AC voltage data and the DC voltage data, calculating actual values of the AC voltage data and the DC voltage data in the linux application layer.

[0012] In some embodiments, before the step of configuring the notification mode of the ADC sampling data, the method further comprises the following steps:

[0013] The linux driver layer initializes the notification mode, the ADC sampling frequency, the character device driver and the timer driver.

[0014] In some embodiments, the step of configuring the notification mode of the ADC sampling data further comprises:

[0015] When the notification mode is configured as the polling mode or the blocking mode, the linux driver layer initializes a linux wait queue.

[0016] In some embodiments, the step of configuring the timer driver comprises:

[0017] Registering a timer interrupt request callback function;

[0018] Setting the interrupt frequency and the interrupt period of the timer;

[0019] Setting the comparison register of the timer, for correcting the interrupt frequency of the timer by changing the value of the comparison register, so that the interrupt frequency of the timer is synchronized with the grid frequency.

[0020] In some embodiments, when the timer generates an interrupt, the timer interrupt request callback function comprises:

[0021] Clearing the timer interrupt identification, for making the timer perform the interrupt according to the interrupt period;

[0022] Sampling the AC voltage data and the DC voltage data.

[0023] In some embodiments, when the timer generates an interrupt, the timer interrupt request callback function further comprises:

[0024] When the notification mode is the polling mode or the blocking mode, waking up the linux wait queue;

[0025] When the notification mode is the SIGIO mode, sending an asynchronous notification to the linux application layer.

[0026] In some embodiments, the DC voltage data comprises:

[0027] RTC battery voltage data, system power failure detection voltage data, super capacitor voltage data;

[0028] In some embodiments, the step of sampling the AC voltage data and the DC voltage data comprises:

[0029] The first AC cycle queue and the second AC cycle queue of the linux driver layer alternately cache the AC voltage data, the data cached by the first AC cycle queue or the second AC cycle queue is alternated every N times, and the first AC cycle queue and the second AC cycle queue are arranged in the first channel.

[0030] The first battery cycle queue and the second battery cycle queue of the Linux driver layer alternately cache the RTC battery voltage data, the data cached by the first battery cycle queue or the second battery cycle queue is alternated every N times, and the first battery cycle queue and the second battery cycle queue are arranged in the second channel.

[0031] The first power-off cycle queue and the second power-off cycle queue of the Linux driver layer alternately cache the system power-off detection voltage data, the data cached by the first power-off cycle queue or the second power-off cycle queue is alternated every N times, and the first power-off cycle queue and the second power-off cycle queue are arranged in the third channel.

[0032] The first capacitor cycle queue and the second capacitor cycle queue of the Linux driver layer alternately cache the super capacitor voltage data, the data cached by the first capacitor cycle queue or the second capacitor cycle queue is alternated every N times, and the first capacitor cycle queue and the second capacitor cycle queue are arranged in the fourth channel.

[0033] In some embodiments, when sampling the alternating current voltage data or the direct current voltage data, the step of notifying the Linux application layer includes:

[0034] The Linux kernel layer is notified when the first alternating current cycle queue or the second alternating current cycle queue alternates, and the Linux kernel layer notifies the Linux application layer.

[0035] The Linux kernel layer is notified when the first battery cycle queue or the second battery cycle queue alternates, and the Linux kernel layer notifies the Linux application layer.

[0036] The Linux kernel layer is notified when the first power-off cycle queue or the second power-off cycle queue alternates, and the Linux kernel layer notifies the Linux application layer.

[0037] The Linux kernel layer is notified when the first capacitor cycle queue or the second capacitor cycle queue alternates, and the Linux kernel layer notifies the Linux application layer.

[0038] In some embodiments, according to the alternating current voltage data and the direct current voltage data, the step of calculating the actual value of the alternating current voltage data and the actual value of the direct current voltage data in the Linux application layer includes:

[0039] Import the alternating current calibration coefficient;

[0040] Cycle to read the alternating current voltage data cached by the first alternating current cycle queue or the second alternating current cycle queue;

[0041] According to the order of reading, the root mean square value of the alternating current voltage data cached by at least one of the first alternating current cycle queue or the second alternating current cycle queue is calculated, and the average value of the root mean square value is calculated.

[0042] The effective value of the AC voltage data is calculated according to the AC calibration coefficient and the average of the root mean square values.

[0043] In some embodiments, the step of calculating the actual value of the AC voltage data and the actual value of the DC voltage data according to the AC voltage data and the DC voltage data at the Linux application layer further comprises:

[0044] The RTC battery voltage data cached in the first battery cycle queue or the second battery cycle queue is read cyclically, and the average of at least one RTC battery voltage data cached in the first battery cycle queue or the second battery cycle queue is calculated according to the reading sequence.

[0045] The system power-off voltage data cached in the first power-off cycle queue or the second power-off cycle queue is read cyclically, and the average of at least one system power-off voltage data cached in the first power-off cycle queue or the second power-off cycle queue is calculated according to the reading sequence.

[0046] The super capacitor voltage data cached in the first capacitor cycle queue or the second capacitor cycle queue is read cyclically, and the average of at least one super capacitor voltage data cached in the first capacitor cycle queue or the second capacitor cycle queue is calculated according to the reading sequence.

[0047] In some embodiments, the step of calculating the actual value of the AC voltage data and the actual value of the DC voltage data according to the AC voltage data and the DC voltage data at the Linux application layer further comprises calculating the interrupt frequency of the timer following the power grid frequency:

[0048] Q continuous AC cycle queues meeting the zero-crossing detection are obtained, and the AC cycle queues include the first AC cycle queue and / or the second AC cycle queue.

[0049] The number of the AC voltage data cached in the Q continuous AC cycle queues meeting the zero-crossing detection is obtained.

[0050] The power grid following frequency is calculated according to the number of the ADC AC voltage data.

[0051] The power grid following frequency deviation is calculated, the power grid following frequency deviation is the difference between the power grid standard frequency and the power grid following frequency, and the power grid standard frequency is 50 Hz.

[0052] The value of the timer comparison register is changed according to the power grid following frequency deviation, which is used to correct the interrupt frequency of the timer, so that the interrupt frequency of the timer follows the power grid frequency.

[0053] The beneficial effects of the present application are:

[0054] The technical scheme of the application adopts a top-down layered framework design, and respectively comprises a Linux user layer, a Linux kernel layer and a Linux driver layer. The Linux driver layer is responsible for ADC sampling of AC voltage data and DC voltage data of the MCU; the Linux kernel layer is responsible for providing a system API access interface to the Linux application layer, switching task scheduling, and notifying and transmitting ADC sampled AC voltage data and DC voltage data; the Linux user layer is responsible for calculation of actual values of the ADC sampled AC voltage data and DC voltage data, and calculation of frequency following synchronization. In the technical scheme, ADC AC voltage data and ADC DC voltage data are alternately sampled through a cycle queue, so that the integrity of the sampled data is ensured when DMA function is not supported, and the problem that the timer high-frequency interrupt is easily interrupted by other high-priority interrupts is avoided. The calculation of the ADC AC sampling data and the calculation of the frequency following synchronization are based on pure algorithm implementation, and can be used as a template and applied to other platforms. The measurement scheme of the MCU avoids the technical problems of a large number of PCB layout lines and a large layout space during design, and further solves the problem of high cost of the designed product. BRIEF DESCRIPTION OF DRAWINGS

[0055] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings needed to be used in the embodiments. Obviously, the drawings in the following description only constitute some embodiments of the present application, and for those skilled in the art, other drawings can also be obtained based on these drawings without creative labor.

[0056] Figure 1 The timing diagram of the embodiments of the present application.

[0057] Figure 2 The system block diagram of the embodiments of the present application.

[0058] Figure 3 The schematic diagram of the cycle queue buffer sampling data of the embodiments of the present application. DETAILED DESCRIPTION

[0059] The technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. It should be clear that the described embodiments are only some of the embodiments of the present application, not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor are within the scope of protection of the present application.

[0060] The embodiment of the present application provides an ADC AC / DC sampling method based on a linux platform, the ADC AC / DC sampling method is designed based on a product of an MCU NUC975DK61Y measurement scheme, like Figure 1 As shown in a timing diagram of the embodiment of the present application, the AC / DC sampling method of the embodiment of the present application is as follows:

[0061] A notification mode of the ADC sampling data is configured, and the notification mode supported by the embodiment of the present application includes a polling mode (poll), a blocking mode (block), a SIGIO mode and an interrupt mode; specifically, when the notification mode of the embodiment of the present application is configured as the polling mode or the blocking mode, a linux waiting queue is initialized by a linux driver layer; the reason for selecting the linux waiting queue in the embodiment of the present application is that it does not occupy the CPU usage rate during the delay sleep, and the ADC sampling frequency is high in the embodiment of the present application, so the CPU can be effectively vacated by sleep, so as to improve the stability of the system and the switching frequency of task scheduling.

[0062] An ADC sampling frequency is configured; in the embodiment of the present application, the ADC sampling frequency is configured as 1MHz, and it should be clear that the ADC sampling frequency in the embodiment of the present application is not limited to 1MHz, and can also be configured as other frequencies, as long as the sampled data can make the cycle queue alternate when the timer triggers the interrupt, and the number of data required for the cycle queue to alternate can also be set by itself.

[0063] A character device driver is registered; specifically, the registration of the character device driver includes: registering a character device driver name; registering a major and minor number of the character device; binding a member function of a struct file_operation structure, and the member function at least includes an open function, a read function, an ioctl function, a close function, a fasync function, a poll function, the function of the member function is to provide an API access interface of the system to the linux application layer, and it should be clear that the technical solution of the present application is only applied to these member functions, so the function of the member function is not described in detail; as an optimization, after the character device driver is registered, a sysfs device class can also be registered, and the purpose is also to provide an API access interface of the system to the linux application layer.

[0064] A timer driver is configured; wherein the configuration of the timer driver includes the following steps:

[0065] A timer interrupt request callback function is registered, which is used for sampling the ADC AC voltage data and the ADC DC voltage data, wherein the execution time of the timer interrupt function must be less than the interrupt frequency of the timer, otherwise abnormal problems such as interrupt nesting and kernel crash will be caused;

[0066] The interrupt frequency and interrupt period of the timer are set, in the embodiment of the application, the interrupt frequency of the timer is 50Hz multiplied by N multiplied by 4 (Hz), wherein N represents the number of data in a cycle queue cache, and 4 represents that 4-way data are sampled in the embodiment of the application, preferably, N is set to 32 in the embodiment of the application, that is, the interrupt frequency is 6400Hz at this time, and the interrupt period is about 0.156ms;

[0067] The comparison register of the timer is set, which aims to correct the interrupt frequency of the timer by changing the value of the comparison register, so that the interrupt frequency of the timer is synchronized with the grid frequency, it should be clear that, since the grid frequency is prone to fluctuation, the interrupt frequency needs to be changed to synchronize the fluctuation of the grid frequency, at the same time, the change of the interrupt frequency will also affect the interrupt period.

[0068] Specifically, when the timer interrupt triggers, the timer interrupt request callback function performs the following operations:

[0069] The timer interrupt identifier is cleared, which aims to make the timer perform the interrupt according to the interrupt period;

[0070] The AC voltage data and DC voltage data are sampled, since the ADC sampling does not support the DMA function, the cycle sampling is adopted in the embodiment of the application, wherein the AC voltage data, the RTC battery voltage data, the system power failure detection voltage data and the super capacitor voltage data each have a corresponding two cycle queues for caching the sampled data, the cycle queue corresponding to each voltage data is arranged in the corresponding channel, for example, the AC voltage data is cached in the first AC cycle queue and the second AC cycle queue, the two AC cycle queues are arranged in the AC voltage channel (the first channel), the RTC battery voltage data is cached in the first battery cycle queue and the second battery cycle queue, the two battery cycle queues are arranged in the DC battery voltage channel (the second channel), the power failure detection voltage data is cached in the first power failure cycle queue and the second power failure cycle queue, the two power failure cycle queues are arranged in the DC power failure detection voltage channel (the third channel), and the super capacitor voltage data is cached in the first capacitor cycle queue and the second capacitor cycle queue, the two capacitor cycle queues are arranged in the DC super capacitor voltage channel (the fourth channel), specifically, the caching process is as follows:

[0071] The first AC cycle queue and the second AC cycle queue of the linux driver layer alternately cache the AC voltage data, the data cached in the first AC cycle queue or the second AC cycle queue is alternated when N is 1, and the first AC cycle queue and the second AC cycle queue are arranged in the first channel;

[0072] The first battery cycle queue and the second battery cycle queue of the linux driver layer alternately cache RTC battery voltage data, the data cached by the first battery cycle queue or the second battery cycle queue is alternated every N times, and the first battery cycle queue and the second battery cycle queue are arranged in the second channel.

[0073] The first power-off cycle queue and the second power-off cycle queue of the linux driver layer alternately cache system power-off detection voltage data, the data cached by the first power-off cycle queue or the second power-off cycle queue is alternated every N times, and the first power-off cycle queue and the second power-off cycle queue are arranged in the third channel.

[0074] The first capacitor cycle queue and the second capacitor cycle queue of the linux driver layer alternately cache super capacitor voltage data, the data cached by the first capacitor cycle queue or the second capacitor cycle queue is alternated every N times, and the first capacitor cycle queue and the second capacitor cycle queue are arranged in the fourth channel.

[0075] In the embodiment of the application, the ADC sampling data is cached by two cycle queues, the number of data cached by each cycle queue can be set, when the number of data cached by one cycle queue reaches the set value, the data is cached by the other cycle queue, so that the task scheduling delay when the data is read by the linux application layer is avoided, the sampling value loss is avoided, and the integrity of the sampling data is ensured.

[0076] Preferably, the number N of data cached by each cycle queue in the embodiment of the application is 32, as shown in Figure 1 and Figure 3 Taking the sampling AC voltage data as an example, after 32 data are cached by the cycle queue A, the linux application layer is informed to process the data in the cycle queue A, at the same time, the data is cached by the cycle queue B, after 32 data are cached, the linux application layer is informed to process the data in the cycle queue B, and the data is cached by the cycle queue A again, and the cycle is repeated.

[0077] It should be clear that the "AC cycle queue", "battery cycle queue", "capacitor cycle queue", "power-off cycle queue", "AC voltage channel", "DC battery voltage channel", "DC power-off detection voltage channel" and "DC super capacitor voltage channel" are only a kind of naming in the embodiment of the application, and in actual application, they can be named arbitrarily.

[0078] After the AC and DC data are sampled, if the notification mode is set to the polling mode or the blocking mode, the linux waiting queue is woken up; if the notification mode is set to the SIGIO mode, an asynchronous notification is sent to the linux application layer.

[0079] After sampling the AC voltage data or DC voltage data, the Linux application layer needs to be notified. Specifically, for AC voltage data, when two AC cycle queues alternate, that is, the number of data cached by the current AC cycle queue reaches the set value, preferably, in the embodiment of the application, when the set value is 32, that is, when the number of data cached by the cycle queue is 32, the Linux kernel layer is notified, and the Linux application layer is notified by the Linux kernel layer; for three kinds of DC voltage data, the same applies, such as for RTC battery voltage data, when the first battery cycle queue or the second battery cycle queue alternates, that is, the number of data cached by the current cycle queue is 32, the Linux kernel layer is notified, and the Linux application layer is notified by the Linux kernel layer; for system power failure detection voltage data, when the first power failure cycle queue or the second power failure cycle queue alternates, that is, the number of data cached by the current cycle queue is 32, the Linux kernel layer is notified, and the Linux application layer is notified by the Linux kernel layer; for super capacitor voltage data, when the first capacitor cycle queue or the second capacitor cycle queue alternates, that is, the number of data cached by the current cycle queue is 32, the Linux kernel layer is notified, and the Linux application layer is notified by the Linux kernel layer.

[0080] The Linux application layer calculates the actual value of the AC voltage data and the actual value of the DC voltage data according to the AC voltage data and the DC voltage data. Specifically, the steps of the Linux application layer include:

[0081] The AC calibration coefficient is imported. In the application, single-point calibration is adopted, that is, the calculation of the effective value of the AC voltage data is performed by the function y=kx+b, where x is the actual voltage, in the calculation of the embodiment of the application, x represents the average value of the root mean square value of the data in the cycle queue (the root mean square value of each cycle queue is calculated, and then the average value of the root mean square value is calculated), y is the effective value of the AC voltage data, k and b are the imported AC calibration coefficients; the AC calibration coefficient can be selected from standard calibration data; preferably, in the embodiment of the application, the AC calibration coefficient can also be selected from the calibration data calculated by itself, compared with selecting standard calibration data, selecting calibration data calculated by itself is more accurate, because the calibration coefficient calculated by itself needs to be calculated by the standard calibration coefficient, so it is necessary to first complete the calculation of the ADC AC / DC data according to the standard calibration data, and then calculate the new calibration coefficient, generally, the standard calibration data is selected before the new standard data is calculated, and then the new calibration coefficient is selected;

[0082] The AC voltage data cached by the first AC cycle queue or the second AC cycle queue is read in a loop;

[0083] According to the order of reading, the root mean square values of the alternating voltage data cached by at least one first alternating cycle queue or second alternating cycle queue are calculated, and the average of the root mean square values is calculated, for example, 20 alternating cycle queues of data are read continuously, and the root mean square of the data cached by each cycle queue is calculated, and the average of 20 root mean square values is calculated, or only the root mean square value of one cycle queue of data is calculated, but the accuracy of the actual value of the alternating voltage data obtained is low;

[0084] The effective value of the alternating voltage data is calculated according to the average of the root mean square values and the alternating calibration coefficient, that is, the effective value is calculated according to the calibration function y=kx+b of the embodiment of the application, x is the average of the root mean square values, and thus the calculation of one ADC alternating sampling is completed.

[0085] For the sampling of the direct current voltage data, the calibration coefficient is not required for calculation, specifically, the RTC battery voltage data cached by the first battery cycle queue or the second battery cycle queue is read in a loop, and the average of the RTC battery voltage data cached by at least one first battery cycle queue or second battery cycle queue is calculated according to the order of reading;

[0086] The system power-off voltage data cached by the first power-off cycle queue or the second power-off cycle queue is read in a loop, and the average of the system power-off voltage data cached by at least one first power-off cycle queue or second power-off cycle queue is calculated according to the order of reading;

[0087] The super capacitor voltage data cached by the first capacitor cycle queue or the second capacitor cycle queue is read in a loop, and the average of the super capacitor voltage data cached by at least one first capacitor cycle queue or second capacitor cycle queue is calculated according to the order of reading.

[0088] For the direct current voltage data, only the average of one cycle queue of data is required for calculation; in order to make the accuracy of the direct current voltage data higher, the average of multiple cycle queues of data can also be calculated.

[0089] In the embodiment of the application, since the grid frequency is prone to fluctuation, the interruption frequency needs to be changed to synchronize the fluctuation of the grid frequency, that is, frequency following calculation is also required, specifically, including:

[0090] Q consecutive alternating cycle queues meeting the zero-crossing detection are obtained, and if there are alternating cycle queues not meeting the zero-crossing detection in the middle, the alternating cycle queues are reacquired;

[0091] The number M of the alternating voltage data cached by the Q consecutive alternating cycle queues meeting the zero-crossing detection is obtained, Q represents that once Q consecutive cycle queues meeting the zero-crossing detection are sampled, frequency following synchronization calculation is performed, and preferably, in the embodiment of the application, Q is set to 256;

[0092] The grid following frequency is calculated according to the number M of the AC voltage data of the continuous AC cycle queue detected by the zero-crossing detection; preferably, in the embodiment of the present application, when Q is set as 256 and the number N of the cycle queue cache is 32, the grid following frequency is calculated according to the equation "8192 multiplied by the grid following frequency = M multiplied by 50Hz"; wherein 8192 represents that when the grid frequency is 50Hz, 256 cycle queues have 8192 data in total;

[0093] The grid following frequency deviation is calculated, which is the difference between the grid standard frequency and the grid following frequency, and the grid standard frequency is 50Hz;

[0094] It should be clear that, taking Q as 256 and N as 32 as an example, the data of each cycle queue cache in the embodiment of the present application is 32, and the number M of the continuous AC cycle queue cache of the AC voltage data detected by the zero-crossing detection here conforms to the principle of the waveform anomaly near the zero-crossing detection point, so the cycle queue calculated by the frequency following synchronization must be the cycle queue detected by the zero-crossing detection and continuous.

[0095] The value of the timer comparison register is changed according to the grid following frequency deviation, which is used to correct the interrupt frequency of the timer, so that the interrupt frequency of the timer follows the grid frequency synchronously; it should be clear that, in the embodiment of the present application, the number N of the cycle queue cache and the number Q of the cycle queue detected by the zero-crossing detection are not limited to N being 32 and Q being 256.

[0096] In the embodiment of the present application, when the imported AC calibration coefficient is the calibration data calculated by itself, a new AC calibration coefficient needs to be calculated according to the standard AC calibration coefficient.

[0097] Specifically, after setting the timer interrupt frequency and the grid frequency following in the linux application layer, the AC calibration coefficient is calculated through the configuration software, including the following steps:

[0098] The sampling calibration is started through the configuration software;

[0099] The configuration software transmits the standard calibration data to the linux application layer through the protocol;

[0100] The linux application layer calculates the calibration coefficient according to the received standard calibration data and the actually sampled data; specifically, the calibration coefficient value is calculated according to the equation "actual voltage / standard voltage = actual sampling value / calibration coefficient value"; wherein the actual voltage is the average value of the root mean square value of the data in the cycle queue read in this calculation, the standard voltage is the voltage of the ADC sampled hardware device specified by the grid, and the actual sampling value is the effective value of the AC voltage data calculated this time;

[0101] The Linux application layer stores the calibration coefficient into a database, and the calibration coefficient is a new AC calibration coefficient required, which can be imported when calculating the ADC AC voltage data next time;

[0102] Stopping sampling calibration;

[0103] The configuration software reads the effective value of the AC / DC data calculated by the Linux application layer and compares it with the standard source value to determine whether the deviation of the effective value of the AC / DC data and the standard voltage meets the national grid regulation; the reason for comparison is that the national grid determines the deviation of the voltage value of the detection equipment to be-0.5% to 0.5%.

[0104] It should be clear that in the embodiments of the present application, sampling calibration generally only needs to be performed once, but performing multiple times will not affect the technical solutions in the embodiments of the present application.

[0105] In the technical solutions of the present application, as shown in Figure 2 a top-down layered framework design is adopted, including a Linux user layer, a Linux kernel layer, and a Linux driver layer. The Linux driver layer is responsible for the ADC sampling of the AC voltage data and the DC voltage data of the MCU; the Linux kernel layer is responsible for providing a system API access interface to the Linux application layer, simultaneously performing task scheduling switching, and responsible for the notification and transmission of the ADC sampled AC / DC voltage data; and the Linux user layer is responsible for the calculation of the actual value of the ADC sampled AC voltage data and the DC voltage data, the calculation of frequency following synchronization, and other functions.

[0106] The above is a further detailed description of the present application in combination with specific embodiments, and the specific implementation of the present application cannot be limited to these descriptions. For ordinary skilled persons in the technical field to which the present application belongs, without departing from the concept of the present application, a number of simple deductions or substitutions can be made, which should be regarded as the protection scope of the present application.

Claims

1. An ADC AC / DC sampling method based on the Linux platform, characterized in that, include: Configure the notification mode for ADC sampling data, wherein the notification mode is configured as one of polling mode, blocking mode, SIGIO mode and interrupt mode; Configure the ADC sampling frequency; Register the character device driver to provide the system's API access interface to the Linux application layer; Configure the timer driver; Used for sampling AC voltage data and DC voltage data; When the AC voltage data or the DC voltage data is sampled, a notification is sent to the Linux application layer; Based on the AC voltage data and the DC voltage data, the actual values ​​of the AC voltage data and the actual values ​​of the DC voltage data are calculated at the Linux application layer. The step of configuring the timer driver includes: Register the timer interrupt request callback function; Configure the interrupt frequency and interrupt period of the timer; The timer's comparison register is configured to correct the timer's interrupt frequency by changing the value of the comparison register, so that the timer's interrupt frequency is synchronized with the power grid frequency; When the timer is interrupted, the timer interrupt request callback function includes: Clear the interrupt flag of the timer to enable the timer to execute the interrupt according to the interrupt cycle; Sample the AC voltage data and the DC voltage data; The DC voltage data includes: RTC battery voltage data, system power failure detection voltage data, supercapacitor voltage data; The step of sampling the AC voltage data and the DC voltage data includes: The first AC frequency queue and the second AC frequency queue of the Linux driver layer alternately buffer the AC voltage data. The alternation occurs when the first AC frequency queue or the second AC frequency queue buffers N data items. The first AC frequency queue and the second AC frequency queue are located in the first channel. The first battery cycle queue and the second battery cycle queue of the Linux driver layer alternately cache the RTC battery voltage data. The alternation occurs when the first battery cycle queue or the second battery cycle queue caches N data items. The first battery cycle queue and the second battery cycle queue are located in the second channel. The first power-down frequency queue and the second power-down frequency queue of the Linux driver layer alternately cache the system power-down detection voltage data. The alternation occurs when the first power-down frequency queue or the second power-down frequency queue caches N data items. The first power-down frequency queue and the second power-down frequency queue are located in the third channel. The first and second capacitor frequency queues of the Linux driver layer alternately buffer the supercapacitor voltage data. The alternation occurs when the first or second capacitor frequency queue buffers N data items. The first and second capacitor frequency queues are located in the fourth channel.

2. The ADC AC / DC sampling method based on the Linux platform as described in claim 1, characterized in that, Before the step of configuring the notification mode for ADC sampling data, the method further includes: The Linux driver layer initializes the notification mode, the ADC sampling frequency, the character driver device, and the timer driver.

3. The ADC AC / DC sampling method based on the Linux platform as described in claim 1, characterized in that, The step of configuring the notification mode for ADC sampling data further includes: When the notification mode is configured as polling mode or blocking mode, the Linux driver layer initializes the Linux wait queue.

4. The ADC AC / DC sampling method based on the Linux platform as described in claim 1, characterized in that, When the timer is interrupted, the timer interrupt request callback function further includes: When the notification mode is polling mode or blocking mode, wake up the Linux waiting queue; When the notification mode is SIGIO mode, an asynchronous notification is sent to the Linux application layer.

5. The ADC AC / DC sampling method based on the Linux platform as described in claim 1, characterized in that, The step of notifying the Linux application layer when the AC voltage data or the DC voltage data is sampled includes: The Linux kernel layer is notified when the first AC cycle queue or the second AC cycle queue alternates, and the Linux kernel layer notifies the Linux application layer. The Linux kernel layer is notified when the first battery cycle queue or the second battery cycle queue alternates, and the Linux kernel layer notifies the Linux application layer. The Linux kernel layer is notified when the first power-down cycle queue or the second power-down cycle queue alternates, and the Linux kernel layer notifies the Linux application layer. The Linux kernel layer is notified when the first capacitor cycle queue or the second capacitor cycle queue alternates, and the Linux kernel layer notifies the Linux application layer.

6. The ADC AC / DC sampling method based on the Linux platform as described in claim 5, characterized in that, The step of calculating the actual values ​​of the AC voltage data and the DC voltage data at the Linux application layer based on the AC voltage data and the DC voltage data includes: Import AC calibration coefficients; The AC voltage data buffered in the first AC cycle queue or the second AC cycle queue is read in a loop. Calculate the root mean square value of at least one AC voltage data buffered in the first AC cycle queue or the second AC cycle queue according to the reading order, and calculate the average value of the root mean square value. The effective value of the AC voltage data is calculated based on the average of the AC calibration coefficient and the root mean square value.

7. The ADC AC / DC sampling method based on the Linux platform as described in claim 6, characterized in that, The step of calculating the actual values ​​of the AC voltage data and the DC voltage data at the Linux application layer based on the AC voltage data and the DC voltage data further includes: The RTC battery voltage data cached in the first battery cycle queue or the second battery cycle queue is read in a loop, and the average value of at least one RTC battery voltage data cached in the first battery cycle queue or the second battery cycle queue is calculated according to the reading order. The system power-down voltage data cached in the first power-down frequency queue or the second power-down frequency queue is read in a loop, and the average value of at least one system power-down voltage data cached in the first power-down frequency queue or the second power-down frequency queue is calculated according to the reading order. The supercapacitor voltage data buffered in the first capacitor cycle queue or the second capacitor cycle queue is read in a loop, and the average value of at least one supercapacitor voltage data buffered in the first capacitor cycle queue or the second capacitor cycle queue is calculated according to the reading order.

8. The ADC AC / DC sampling method based on the Linux platform as described in claim 7, characterized in that, The step of calculating the actual values ​​of the AC voltage data and the DC voltage data at the Linux application layer based on the AC voltage data and the DC voltage data also includes calculating the timer interrupt frequency to synchronize with the power grid frequency. Obtain Q consecutive AC frequency queues that meet the zero-crossing detection, wherein the AC frequency queues include the first AC frequency queue and the second AC frequency queue; Obtain the number of AC voltage data buffered in the Q consecutive AC cycle queues that meet the zero-crossing detection; Calculate the power grid following frequency based on the number of AC voltage data from the ADC; Calculate the grid following frequency deviation, which is the difference between the grid standard frequency and the grid following frequency, where the grid standard frequency is 50Hz; The value of the timer comparator register is changed according to the power grid following frequency deviation to correct the interrupt frequency of the timer, so that the interrupt frequency of the timer follows the power grid frequency synchronously.

Citation Information

Patent Citations

  • Low cost rapid high precision alternating voltage signal sampling system

    CN103424608A

  • Bay-orient intelligent substation multifunctional secondary device and sampling platform

    CN103675522A