Disclosure of Invention
In view of the foregoing, it is necessary to provide a method and apparatus for calculating a true effective value.
A method of computing a true valid value, comprising the steps of: setting an analog-to-digital converter to be in an automatic continuous conversion mode, and setting a corresponding conversion frequency; according to the Nyquist sampling theorem, high-speed sampling is carried out on a detected signal and an internal signal through an analog-to-digital converter, and an external alternating current signal and an internal voltage signal are obtained; calculating according to the external alternating current signal and the internal voltage signal to obtain an alternating current signal value; and (4) integrating and calculating according to the alternating current signal value by combining a thermal equivalent principle to obtain a voltage true effective value.
In one embodiment, the obtaining an external ac signal and an internal voltage signal by performing high-speed sampling on a signal to be measured and an internal signal through an analog-to-digital converter according to the nyquist sampling theorem specifically includes: according to the Nyquist sampling theorem, the highest frequency in the signals is set to be Fmax, the sampling frequency is F, F is larger than 2Fmax, and the tested signals and the internal signals are sampled at high speed by the sampling frequency F to obtain external alternating current signals and internal voltage signals.
In one embodiment, the calculating according to the external ac signal and the internal voltage signal to obtain an ac signal value specifically includes:
u=(Rac*k)/Rcore; (1)
wherein, Rcore is the sampling value of the internal voltage signal, Rac is the sampling value of the external alternating current signal, k is the conversion constant, and u is the alternating current signal value.
In one embodiment, the obtaining the voltage true effective value by performing an integral calculation according to an alternating current signal value in combination with a thermal equivalent principle specifically includes:
wherein, U is the voltage true effective value, and T is the cycle.
In one embodiment, the period is calculated by the formula:
F=(k*Tn)/Np; (3)
and calculating the acquisition period according to the inverse relation between the period and the frequency, wherein k is a frequency deviation value, Np is the total sampling point number, and Tn is the total period number.
In one embodiment, after the integration calculation is performed according to the ac signal value in combination with the thermal equivalent principle to obtain the true effective voltage value, the method further includes: calculating a true effective value of the check voltage and a check frequency deviation value according to the alternating voltage standard source; and verifying the voltage true effective value and the frequency deviation value according to the verification voltage true effective value and the verification frequency deviation value.
An apparatus for computing a true valid value, comprising: the device comprises a microcontroller, a sampling circuit, a key, a display and a resistance-capacitance voltage reduction power supply; the sampling circuit, the key, the display and the resistance-capacitance voltage reduction power supply are all electrically connected with the microcontroller; the sampling circuit and the resistance-capacitance voltage reduction power supply are connected with an external signal; the sampling circuit is internally provided with an analog-to-digital converter which is used for sampling an external signal and an internal signal of the microcontroller, acquiring an external alternating current signal and an internal voltage signal and transmitting the external alternating current signal and the internal voltage signal to the microcontroller; the microcontroller is used for calculating and acquiring a voltage true effective value according to the external alternating current signal and the internal voltage signal and transmitting the voltage true effective value to the display; the display is used for displaying the voltage true effective value; the key is used for controlling the on-off of the device.
In one embodiment, the display is a four-bit LED display.
Compared with the prior art, the invention has the advantages and beneficial effects that: the invention can process the analog signal transmitted by the sampling circuit and acquire the true effective value of the voltage according to the integral algorithm, and has the advantages of good stability, high precision, wide applicable frequency range and small influence of harmonic wave.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is described in further detail below with reference to the accompanying drawings by way of specific embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
In one embodiment, as shown in FIG. 1, there is provided a method of computing a true valid value, comprising the steps of:
step S101, setting the analog-to-digital converter to be in an automatic continuous conversion mode, and setting a corresponding conversion frequency.
Specifically, the analog-to-digital converter is set to an automatic continuous conversion mode, and a corresponding conversion frequency is set, for example, the conversion frequency is 12.5kHz, so that the measured signal can be continuously sampled subsequently.
And S102, according to the Nyquist sampling theorem, carrying out high-speed sampling on the detected signal and the internal signal through an analog-to-digital converter to obtain an external alternating current signal and an internal voltage signal.
Specifically, according to the nyquist sampling theorem, when the sampling frequency is greater than 2 times the highest frequency in the signal, the digital signal after sampling completely retains the information in the original signal. Therefore, the sampling frequency of the analog-to-digital converter can be set to be 2 times higher than the highest frequency, and the tested signal and the internal signal are sampled at high speed to obtain the external alternating current signal and the internal voltage signal.
According to the Nyquist sampling theorem, the highest frequency in the signals is set to be Fmax, the sampling frequency is F, F is larger than 2Fmax, and the tested signals and the internal signals are sampled at high speed by the sampling frequency F to obtain external alternating current signals and internal voltage signals.
For example, when the actual signal is ac 50Hz, F is 250Fmax, and 250 points are sampled per cycle, which is far beyond the requirement of nyquist sampling theorem. The conversion period T is 1/F is 80 μ s, that is, 80 μ s is converted once, and the conversion is completed and the interrupt is automatically generated.
And step S103, calculating and acquiring an alternating current signal value according to the external alternating current signal and the internal voltage signal.
Specifically, the analog-to-digital converter samples the external alternating current signal and the internal voltage signal respectively in sequence, and the alternating current signal value can be calculated and obtained according to the external alternating current signal and the internal voltage signal because the sampling interval time of two times is short, the fluctuation value of a power supply during two times of sampling can be ignored, and the signal sampled by using the same reference is determined.
The formula for calculating and obtaining the alternating current signal value is as follows:
u=(Rac*k)/Rcore; (1)
wherein, Rcore is the sampling value of the internal voltage signal, Rac is the sampling value of the external alternating current signal, k is the conversion constant, and u is the alternating current signal value.
For example, assuming that the power supply is 5V at a certain time, the internal voltage is 2.5V, and 12BITS ADC, k can be decreased to 2048, and the value calculated by equation (1) is the accurate ac signal value, which is not changed regardless of the power supply variation.
And step S104, integrating and calculating according to the alternating current signal value by combining a thermal equivalent principle to obtain a voltage true effective value.
Specifically, in a sinusoidal alternating current, according to the thermal equivalent principle, the effective value of the voltage is defined as its instantaneous value, and the root mean square value in one period is equivalent to squaring and averaging the real-time sampling value of the measured signal, and then squaring, that is, an integration process. Therefore, the voltage true effective value can be obtained by performing the integral calculation based on the ac signal value.
The formula for calculating the true effective value of the voltage is as follows:
wherein, U is the voltage true effective value, and T is the cycle.
Since averaging is an operation that tends to stabilize the varying signal, since its period may vary, the result is a stable value as long as its complete period is evaluated, where the time T of averaging goes to 50 complete periods T of the periodic signal, i.e. 1 second.
When performing the integration, a complete cycle needs to be recorded, a start signal and an end signal are needed. And setting a descending threshold and an ascending threshold, starting to detect the ascending threshold when detecting that the descending threshold is lower for 10 times, and identifying that the period starts and ending the signal in the same way when the ascending threshold is higher for 10 times.
Because of adopting the 1 second average method, after the signal is started, the time interval of each sampling point is the same, the sampling stops until a certain point number, the effective value can be calculated according to the integral and the root mean square, the frequency F can be calculated according to the total point number and the total period number of the sampling, and the formula is as follows:
F=(k*Tn)/Np; (3)
and calculating the acquisition period according to the inverse relation between the period and the frequency, wherein k is a frequency deviation value, Np is the total sampling point number, and Tn is the total period number.
In one embodiment, after step S104, the method further includes: and calculating a true effective value of the check voltage and a check frequency deviation value according to the alternating voltage standard source, and checking the true effective value of the voltage and the frequency deviation value according to the true effective value of the check voltage and the check frequency deviation value to ensure the precision.
In this embodiment, set up analog-to-digital converter for automatic continuous conversion mode, and set up corresponding conversion frequency, according to the nyquist sampling theorem, carry out high-speed sampling to measured signal and internal signal through analog-to-digital converter, obtain outside alternating current signal and internal voltage signal, calculate according to outside alternating current signal and internal voltage signal and obtain the alternating signal value, combine the thermal equivalence principle, carry out integral calculation according to the alternating signal value, obtain the true virtual value of voltage, can handle analog signal, calculate through the integral algorithm and obtain the true virtual value of voltage, have the stability good, applicable frequency range is wide and receive the advantage that the harmonic influences are little.
As shown in fig. 2, there is provided an apparatus for calculating a true valid value, including: the microcontroller 10, the sampling circuit 20, the keys 30, the display 40 and the resistance-capacitance voltage reduction power supply 50; the sampling circuit 20, the key 30, the display 40 and the resistance-capacitance voltage reduction power supply 50 are all electrically connected with the microcontroller 10; the sampling circuit 20 and the resistance-capacitance voltage reduction power supply 50 are connected with external signals; an analog-to-digital converter is arranged in the sampling circuit 20, and is used for sampling an external signal and an internal signal of the microcontroller 10, acquiring an external alternating current signal and an internal voltage signal, and transmitting the external alternating current signal and the internal voltage signal to the microcontroller 10; the microcontroller 10 is configured to calculate and obtain a true effective voltage value according to the external ac signal and the internal voltage signal, and transmit the true effective voltage value to the display 40; the display 40 is used for displaying the true effective value of the voltage; the keys 30 are used to control the switching of the device.
In this embodiment, the external signal and the internal signal of the microcontroller 10 are sampled by the analog-to-digital converter of the sampling circuit 20 to obtain the external ac signal and the internal voltage signal, and the external ac signal and the internal voltage signal are transmitted to the microcontroller 10, the external ac signal and the internal voltage signal are calculated by the microcontroller 10 to obtain the true effective value of the voltage, the true effective value of the voltage is transmitted to the display 40, the true effective value of the voltage is displayed by the display 40, the analog signal transmitted by the sampling circuit 20 can be processed by controlling the on/off of the device through the key 30, and the true effective value of the voltage is obtained according to the integral algorithm.
The resistance-capacitance voltage reduction power supply 50 is only provided with one voltage stabilizing diode, when the resistance-capacitance voltage reduction power supply is directly used as a power supply of the device, the power supply has larger ripples, and because the analog-digital converter is fixed by adopting the power supply voltage as a sampling reference power supply, when the power supply has larger fluctuation, if the sampling result is directly adopted, the instability and the error are large. The 2.5V voltage used by the core logic of the microcontroller 10 is very stable and the analog to digital converter can sample this signal as well.
Therefore, the external signal and the internal signal can be respectively sampled at high speed to obtain an external alternating current signal and an internal voltage signal; because the interval time of the two times of sampling is short, the fluctuation value of the power supply during the two times of sampling can be ignored, the signal is determined as a signal of unified reference sampling, and the true effective value of the voltage can be obtained by calculation according to the external alternating current signal and the internal voltage signal.
Wherein, the display adopts the four-digit LED display.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by a computer program, which can be stored in a computer-readable storage medium, and when executed, can include the processes of the embodiments of the methods described above. The storage medium may be a magnetic disk, an optical disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), or the like.
It will be apparent to those skilled in the art that the modules or steps of the invention described above may be implemented in a general purpose computing device, they may be centralized on a single computing device or distributed across a network of computing devices, and optionally they may be implemented in program code executable by a computing device, such that they may be stored on a computer storage medium (ROM/RAM, magnetic disks, optical disks) and executed by a computing device, and in some cases, the steps shown or described may be performed in an order different than that described herein, or they may be separately fabricated into individual integrated circuit modules, or multiple ones of them may be fabricated into a single integrated circuit module. Thus, the present invention is not limited to any specific combination of hardware and software.
The foregoing is a more detailed description of the present invention that is presented in conjunction with specific embodiments, and the practice of the invention is not to be considered limited to those descriptions. For those skilled in the art to which the invention pertains, several simple deductions or substitutions can be made without departing from the spirit of the invention, and all shall be considered as belonging to the protection scope of the invention.