Detect changes in data
This FP instruction detects changes in a value at input s_Current by comparing it with its former value that is stored at input/output d1_Previous. If the new input value at s_Current is not equal to the former value, the function assigns the new value to the input/output d1_Previous. To signal the change, the system output d2 is set to TRUE.
Input
Data area for detecting data changes
Input/output
Data area where the data from the previous execution is stored.
Output
Set to TRUE if a change is detected
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
bStart: BOOL:=FALSE;
(*activates the function*)
diCurrent_value: DINT:=101;
(*value whose status
should be monitored*)
diPrevious_value: DINT:=0;
(*dummy value for storing
the former present value*)
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 := 6 ;
NETWORK_BODY
B(B_CONTACT,,bStart,6,2,8,4,);
B(B_VARIN,,diCurrent_value,10,3,12,5,);
B(B_VARIN,,diPrevious_value,10,4,12,6,);
B(B_F,FP_DETECT_CHANGE!,,12,1,24,6,,?DEN?Ds_Current?Dd1_Previous?Ad1_Previous?AENO?Cd2);
B(B_VAROUT,,bValueChanged,24,3,26,5,);
L(1,3,6,3);
L(8,3,12,3);
L(1,0,1,6);
END_NETWORK_BODY
END_NET_WORK
END_BODY
IF bStart then
FP_DETECT_CHANGE(s_Current := diCurrent_value, d_Previous := diPrevious_value);
END_IF;