Vector measurement and power calculation of least square filter in microcontroller

Publisher:知识的海洋Latest update time:2006-05-07 Source: 电子技术应用 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

    Abstract: A least squares filter with four-point sampling per week is provided. Through optimization algorithms such as integer transformation and table lookup root finding, fast measurement of phasors can be achieved in a single-chip microcomputer. The phase relationship of the phasors in the filter is analyzed, and the calculation method of the two-wire power is provided.

    Keywords: least squares filter vector microcontroller power

At present, digital electrical measurement and protection devices based on microcontrollers have become the mainstream form. Direct sampling of AC signals has also become a common method. The fast Fourier algorithm is the main algorithm, and the least squares algorithm requires a large amount of calculation. Especially when the processing power of the microcontroller is limited, it is necessary to ensure both real-time performance and calculation speed without careful design and calculation. Program optimization makes it difficult to ensure the unification of the two.

By reducing the number of sampling times, using a fitting filter that filters four sampling points every week, and a set of optimization measures, the calculation speed of this algorithm is greatly improved, and it is capable of real-time measurement of power frequency vectors, so it can be used for overcurrent, rapid interruption, Directional protection and many other aspects. This article analyzes the vector phase relationship in the filter and gives an example of two-wire power calculation based on this. This method has been tested in practical applications.

1 Construction of least square filter

According to the research results in literature [1~3], for each signal, the input voltage function can be expressed as:

    In the formula:

P0——DC component value

Pk——The amplitude of the Kth harmonic component K=1,…,N

θk ——The relative starting phase angle of the Kth harmonic K=1,…,N

ω ——Fundamental angular frequency, ω=2πf, f=50Hz

λ ——constant, equal to the DC component attenuation time constant

In general measurement and protection applications, only the fundamental wave component is of concern. To reduce the amount of computation, the number of samples should be minimized. According to the sampling theorem, the number of discrete sampling times for a sine function is at least 3 times per wave. For convenience, the number of sampling times per week is set to 4, that is, the sampling period is 5ms. Then only DC and power frequency components can be included in formula (1). Expand the DC component according to Taylor series and take the first two terms, then equation (1) becomes:

u(t)=P0-P0 λt+P1sin(ωt)cos(θ1)+P1cos(ωt)sin(θ1) (2)

Among them, P0 is the DC component value, P1 is the peak-peak value of the fundamental wave, and θ1 is the phase angle of the fundamental wave component relative to the zero point at the sampling time.

If the last four consecutive sampling values ​​are used as samples, four sampling equations can be obtained. For example, if P0, -P0 λ and P1cos( θ1)P1sin(θ1) are used as unknown variables to be measured, the four sampling equations can be expressed as the following matrix:

    If the symbol A is used to represent the coefficient matrix, X represents the unknown parameter vector, and U represents the sampled value, then:

X=A -1U (3)

Where A-1 represents the inverse matrix of A, that is, the least square filter of the vector X. According to the literature [3], this filter is:

    therefore,

P1cos( θ1)= ∑A-1[3][I]U[I] I=1,4 (4)

P1sin( θ1)= ∑A-1[4][I]U[I] I=1,4 (5)

cos( θ1)=P1cos(θ1)/P1 (6)

sin(θ1)=P1sin(θ1)/P1 (7)

P0= ∑A-1[1][I]U[I] I=1,4 (8)

P0 λ= ∑A-1[2][I]U[I] I=1,4 (9)

    In practical applications, in order to reduce the calculation error caused by the time delay caused by the sequential sampling of the microcontroller, the hardware circuit should have a synchronous sampling function. Its function is to hold all electrical signals separately at the sampling moment.

2 Relationship between instantaneous phasors in digital filters

If ua, ub, and uc are used to represent the three-phase voltage phasors respectively, Ua, Ub, and Uc represent their effective values, the initial phase angles are represented by θua , θub , and θuc respectively ; ia, ib, and ic are used to represent the three-phase current phasors respectively. , Ia, Ib, and Ic represent their effective values, and the initial phase angles are θia , θib , and θic respectively . Then equation (4) is the projection of the corresponding phasor on the X-axis, that is, the real part of the vector; equation (5) is the projection of the corresponding phasor on the Y-axis, that is, the imaginary part of the vector, (4) and (5) θ1 in the formula is the phase angle of the above phasor relative to the beginning of the 20ms time window.

Figure 1 shows the phase relationship between phase A voltage and phase A current, and the others are similar.

The phase relationship of the above phasors is the basis for further operations of the phasors.

3 Two-wire power calculation

At present, the power measurement of high-voltage lines generally uses three-phase voltage and two sets of current, that is, the two-wire power meter method. Line active power and reactive power can be measured using equations (4), (5), (6), (7) and (10). The specific process is as follows:

The forward drop of the two-wire system assumes that the three-phase current is balanced, that is:

ia+ib+ic=0 (11)

If there is no B-phase current transformer, then B-phase current:

ib=-(ia+ic) (12)

The active power of the line is:

P=Pa+Pb+Pc=ua×ia+ub×ib+uc×ic

=ua×ia-ub×(ia+ic)+uc×ic

=uab×ia+ucb×ic

=Uab×Ia×cos( θuab-θia)+Ucb×Ic×cos(θucb-θic) (13)

According to the trigonometric function formula:

cos( θuab-θia)=con(θuab)×cos(θia)+sin(θuab)×sin(θia) (14)

cos(θucb-θic)=cos(θucb)×cos(θic)+sin(θucb)×sin(θic) (15)

Among them, uab is the line voltage between phase A and phase B; ucb is the line voltage between phase C and phase B.

Combine the results of equations (6) and (7) with equations (14), (15) and (13) to measure the active power of the three-phase balanced line.

If the input voltage is phase voltage, then:

P=Pa+Pb+Pc=ua×ia+ub×ib+uc×ic

=ua×ia-ub×(ia+ic)+uc×ic

=Ua×Ia×cos( θua-θia)-Ub×Ia×cos(θub-θia)

-Ub×Ic×cos(θub-θic)+Uc×Ic×cos(θuc-θic)      (16)

After expanding the cosine function in the above formula, then substitute the corresponding results in formulas (6) and (7) respectively.

The calculation of reactive power only requires changing the cosine operation in equations (14), (15) and (16) to the corresponding sine operation.

4 Optimization measures based on microcontroller applications

Judging from the current market situation, although the performance of microcontrollers is constantly improving, such as INTEL microcontrollers continue to introduce new ones from 8-bit, 16-bit to 32-bit, the products that are truly widely adopted are not the products with the best performance. From a practical application point of view, sometimes a restricted objective reality must be faced. For this application, the calculation speed of the program can be greatly improved by adopting the following measures.

4.1 Convert floating point operations to integer operations

For equations (4) to (10), it is convenient and highly accurate to use C or PL/M high-level language to perform floating-point operations. But compared to integer operations, floating point operations are much slower. Therefore, in order to improve calculation speed, integer operations should be used as much as possible. From an engineering practical point of view, the result after A/D conversion is generally a double-byte integer, which can be directly operated with a 10-bit amplified least squares filter, then equation (4) becomes:

X[3]=5×U[2]-10×U[3]+5×U[4] (17)

(5) The formula becomes:

X[4]=5×U[1]-10×U[2]+5×U[3] (18)

Equations (17) and (18) only have 6 multiplications and 4 additions of 4-byte long integers. Even for 12-bit A/D, the calculation results of equations (17) and (18) will not overflow. Since the filter is an integer when expanded by 10 times, there is no rounding, so there is no additional error in the calculation process.

4.2 Quick square root method

Judging from equations (4) to (10), equation (10) takes the most time, that is, finding the square root operation to obtain the peak-to-peak value of the fundamental wave.

If you directly use the square root function provided by the standard floating point library, the 16MHz 80196KC takes about 3ms. If the integer look-up table method in literature [4] is used, or the bisection method with an accuracy of 1% provided in literature [5], the time required to find the root under the same conditions is generally between 100 and 300 μs , and the calculation speed is increased by 10 times. above.

The least square filter with 4 sampling points per wave proposed in this article can realize real-time phasor measurement of power frequency signals in a general microcontroller. After the algorithm is further optimized, it can reflect multi-channel signals in real time within a cycle time window, meeting the technical requirements of general protection. The algorithm also enables other protection and measurement functions.

Reference address:Vector measurement and power calculation of least square filter in microcontroller

Previous article:Low voltage, time adjustable voice recording/playback circuit ISD1810
Next article:Using ISD devices to realize segmented recording and random combination playback of live speech

Latest Embedded Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号