Calculate deviation from data table
This FP instruction calculates the deviation from the values in a data table.
Input
Beginning of data table
Number of values
Output
Variance, deviation2
Standard deviation, square root of variance
All input and output variables used for programming this function have been declared in the POU header.The same POU header is used for all programming languages.
VAR
arrData: ARRAY [0..31] OF INT:=[0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1];
rDeviation: REAL:=0.0;
rVariance: REAL:=0.0;
iNumberOfData: INT:=8;
bStart: BOOL:=FALSE;
END_VAR
When the variable bStart is set to TRUE, the function is carried out.
BODY
WORKSPACE
NETWORK_LIST_TYPE := NWTYPELD ;
ACTIVE_NETWORK := 0 ;
END_WORKSPACE
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 5 ;
NETWORK_BODY
B(B_F,FP_DATA_DEVIATION!,,15,0,26,5,,?DEN?Ds1_Start?Dn_Number?AENO?Cd1_Variance?Cd2_Deviation);
B(B_VARIN,,arrData[0],13,2,15,4,);
B(B_VARIN,,iNumberOfData,13,3,15,5,);
B(B_VAROUT,,rVariance,26,2,28,4,);
B(B_VAROUT,,rDeviation,26,3,28,5,);
B(B_CONTACT,,bStart,4,1,6,3,);
L(1,2,4,2);
L(6,2,15,2);
L(1,0,1,5);
END_NETWORK_BODY
END_NET_WORK
END_BODY
IF bStart then
FP_DATA_DEVIATION(s1_Start := arrData[0],
n_Number := iNumberOfData,
d1_Variance => rVariance,
d2_Deviation => rDeviation);
END_IF;