UP/DOWN counter
DOWN counting if the trigger UpDirection is in the OFF state. UP counting if the trigger UpDirection is in the ON state.
Input
sets counter to count up (ON) or down (0FF)
starts counter
resets counter
16-bit area or equivalent constant for counter preset value
Output
16-bit area for counter elapsed value
The area for the elapsed value d becomes 0 when the rising edge of the trigger is detected (OFF ® ON). The value in s_PresetValue is transferred to d when the falling edge of the trigger is detected (ON ® OFF).
The variables s_PresetValue and d have to be of the same data type.
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
up: BOOL:=FALSE;
(*declares, if the counter
counts up or down*)
count: BOOL:=FALSE;
(*at a rising edge on count
the counter counts*)
reset: BOOL:=FALSE;
(*resets the counter to
set_value if TRUE*)
set_value: INT:=0;
(*the starting value*)
output_value: INT:=0;
(*the actual value*)
END_VAR
A rising edge at the input Count_Trigger activates the counter. The boolean variable at the input UpDirection sets the direction of the counter (TRUE = up, FALSE =down). TRUE at the input Reset_Preset resets the counter to the starting value.
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,F118_UDC!,Instance,8,0,17,6,,?DUpDirection?DCountTrigger?DReset_Preset?Ds_PresetValue?Cd);
B(B_VARIN,,up,6,1,8,3,);
B(B_VARIN,,count,6,2,8,4,);
B(B_VARIN,,reset,6,3,8,5,);
B(B_VARIN,,set_value,6,4,8,6,);
B(B_VAROUT,,output_value,17,1,19,3,);
L(1,0,1,6);
END_NETWORK_BODY
END_NET_WORK
END_BODY
output_value:=F118_UDC( UpDirection:= up, Count_Trigger:= count, Reset_Preset:= reset, s_PresetValue:= set_value);
(* output_value contains the count value *)