Define buffer area for moving average and total values
This FP instruction specifies a special buffer to compute the average value and the total of all contained values. The starting address is set by d_Start and the size by n_Words. The buffer has a particular structure, which is shown in the programming example, where the number of array elements of the last element iArrData corresponds to the size defined by n_words. Use the instruction FP_AVERAGE_BUFFER_WRITE for writing into the buffer.
Input
Specifies the memory size of the buffer
Values: 1–30000
Output
Starting data area of the buffer
We recommend using a user-defined DUT as shown in the programming example.
if a value specified for a parameter is outside the permissible range.
if a value specified for a parameter is outside the permissible range.
Elements of the DUT (identifiers):
Size of buffer
Number of stored data
Total sum of stored data
Moving average
Position of writing pointer
Contains the values of the buffer. The number of integer values (10 in this example) must be equal to the size of the buffer defined with iNumberOfIntegerValues.
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
bDefine: BOOL:=FALSE;
bWrite: BOOL:=FALSE;
iCounter: INT:=0;
END_VAR
VAR CONSTANT
iNumberOfIntegerValues: INT:=10;
(*number of integers values must be equal to average buffer size*)
END_VAR
VAR
dutAverageBufferInt10: DUT_FP_AVERAGE_BUFFER_INT_10;
(*Average Buffer for integer numbers of size 10*)
END_VAR
When the variable bDefine 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 := 6 ;
NETWORK_BODY
B(B_F,FP_AVERAGE_BUFFER_DEFINE!,,13,2,28,6,,?DEN?Dn_Words?AENO?Cd_Start);
B(B_VARIN,,iNumberOfIntegerValues,11,4,13,6,);
B(B_VAROUT,,dutAverageBufferInt10,36,4,38,6,);
B(B_CONTACT,,bDefine,4,1,6,3,);
B(B_F,Adr_Of_Var_O!,,28,4,36,6,,?D?C);
L(1,2,4,2);
L(6,2,6,4);
L(6,4,13,4);
L(1,0,1,6);
END_NETWORK_BODY
END_NET_WORK
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 8 ;
NETWORK_BODY
B(B_CONTACT,,bWrite,2,1,4,3,);
B(B_CONTACT,,bDefine,6,1,8,3,N);
B(B_F,FP_AVERAGE_BUFFER_WRITE!,,14,2,28,6,,?DEN?D@'s'?AENO?Cd_Start);
B(B_VARIN,,sys_iRingCounter_2ms5,12,4,14,6,);
B(B_F,Adr_Of_Var_O!,,28,4,36,6,,?D?C);
B(B_VAROUT,,dutAverageBufferInt10,36,4,38,6,);
B(B_CONTACT,,sys_bPulse1s,11,1,13,3,R);
L(1,2,2,2);
L(4,2,6,2);
L(8,2,11,2);
L(13,2,13,4);
L(13,4,14,4);
L(1,0,1,8);
END_NETWORK_BODY
END_NET_WORK
END_BODY
IF (bDefine) then
FP_AVERAGE_BUFFER_DEFINE(n_Words := iNumberOfIntegerValues,
d_Start => Adr_Of_Var(dutAverageBufferInt10));
END_IF;
If (bWrite) AND NOT (bDefine) AND DF(sys_bPulse1s) then
FP_AVERAGE_BUFFER_WRITE(s := sys_iRingCounter_2ms5,
d_Start => Adr_Of_Var(dutAverageBufferInt10));
End_if;