FB_PMA_Harmonics_1Ph
The function block FB_PMA_Harmonics_1Ph calculates the RMS bands of the individual current and voltage harmonics. In addition, the calculated RMS bands are used to calculate the THD of the input variables.
The input buffer is provided via the function block FB_PMA_Source_1Ph. The size of the input buffer is half the window length.
By way of example, possible FFT and window lengths are shown in the following table:
FFT length | Window length | Buffer length | |
---|---|---|---|
512 | 29 | 400 | 200 |
1024 | 210 | 800 | 400 |
2048 | 211 | 1600 | 800 |
4096 | 212 | 3200 | 1600 |
8192 | 213 | 6400 | 3200 |
16384 | 214 | 12800 | 6400 |
Memory properties
Since the Welch method is used, in each case the current input buffer together with the last transferred buffer is used for the calculation.
The frequency analysis takes step changes in the time series into account. In order to achieve a correct result, the last two input buffers should therefore be consecutive without step changes.
Syntax
Definition:
FUCNTION BLOCK FB_PMA_Harmonics_1Ph
VAR_INPUT
nOwnID : UDINT;
tTransferTimeout : LTIME := LTIME#500US;
stInitPars : ST_PMA_Harmonics_InitPars;
END_VAR
VAR_OUTPUT
bError : BOOL;
ipResultMessage : I_TcMessage;
bNewResult : BOOL;
nCntResults : ULINT;
fTHD_U : LREAL;
fTHD_U_Min : LREAL;
fTHD_U_Max : LREAL;
fTHD_I : LREAL;
fTHD_I_Min : LREAL;
fTHD_I_Max : LREAL;
bValidStatistics : BOOL;
END_VAR
Inputs
The input parameters of this function block represent initialization parameters and must be assigned when declaring the function block instance (alternative: Init method). They may only be assigned once. A change at runtime is not possible.
Name | Type | Description |
---|---|---|
tTransferTimeout | LTIME | Setting of the synchronous timeout for internal multi-array forwardings. See Parallel Processing in Transfer Tray. |
stInitPars | Function-block-specific structure with initialization parameters. The parameters must match the definition of the input and output buffers. | |
nOwnID | UDINT | Identifies the function block instance with a unique ID. This must always be greater than zero. A proven approach is to define an enumeration for this purpose. |
Outputs
Name | Type | Description |
---|---|---|
bError | BOOL | TRUE if an error occurs. |
ipResultMessage | I_TcMessage | The interface offers detailed information about the return value. |
bNewResult | BOOL | TRUE once new results have been calculated. |
nCntResults | ULINT | Count value is incremented with new output data. |
fTHD_U | LREAL | THD of the voltage. The output is in percent. |
fTHD_U_Min | LREAL | Smallest value of fTHD_U that has occurred. Can be reset via bResetStatistics of the Call method. |
fTHD_U_Max | LREAL | Largest value of fTHD_U that has occurred. Can be reset via bResetStatistics of the Call method. |
fTHD_I | LREAL | THD of the current. The output is in percent. |
fTHD_U_Min | LREAL | Smallest value of fTHD_U that has occurred. Can be reset via bResetStatistics of the Call method. |
fTHD_U_Max | LREAL | Largest value of fTHD_U that has occurred. Can be reset via bResetStatistics of the Call method. |
bValidStatistics | BOOL | TRUE if the Min, Max and Hold value calculation has been performed. These values are valid. |
Methods
Name | Description |
---|---|
The method is called in each cycle to execute the calculations from the input buffer when new data is present. | |
Alternative to the function block initialization | |
As an alternative to the Call method, the method can be called in each cycle if no calculation is to take place. The incoming input buffer is then forwarded accordingly. | |
The method is called in order to reconfigure the function block during the runtime. | |
This method deletes all the data sets already added. In addition, the calculated output values are reset. |
Sample
VAR CONSTANT
cOversamples : UDINT := 10;
cFFT_Length : UDINT := 4096;
cWindowLength : UDINT := 3200;
cSourceInitPars: ST_PMA_Source_InitPars := (
nBufferLength := cWindowLength/2);
cHarmonicsInitPars : ST_PMA_Harmonics_InitPars := (
nFFT_Length := cFFT_Length,
nWindowLength := cWindowLength,
fSampleRate := cOversamples * 1000,
fBaseFreq := 50.0,
nNumBands := 40,
fBandwidth := 20.0,
eWindowType := E_PMA_WindowType.HannWindow,
bTransformToDecibel := FALSE,
fDecibelThreshold := GVL_PMA.cMinArgLog10,
bTransformToPercent := TRUE);
END_VAR
VAR
aVoltage AT%I* : ARRAY[1..cOversamples] OF LREAL;
aCurrent AT%I* : ARRAY[1..cOversamples] OF LREAL;
fbSource : FB_PMA_Source_1Ph := (nOwnID := 1, aDestIDs := [2], stInitPars := cSourceInitPars);
fbHarmonics : FB_PMA_Harmonics_1Ph := (nOwnID := 2, stInitPars := cHarmonicsInitPars);
aHarmonicsVoltage : ARRAY[1..40] OF LREAL;
aHarmonicsCurrent : ARRAY[1..40] OF LREAL;
END_VAR
// Call source
fbSource.Call(ADR(aVoltage), ADR(aCurrent), SIZEOF(aVoltage), 0);
// Call algorithm
fbHarmonics.Call(ADR(aHarmonicsVoltage), ADR(aHarmonicsCurrent), SIZEOF(aHarmonicsVoltage), FALSE);
Requirements
Development environment | Target platform | PLC libraries to include |
---|---|---|
TwinCAT v3.1.4024.0 | PC or CX (x86, x64) | Tc3_PowerMonitoring |