Up counter
The function block CTU (count up) allows you to program counting procedures.
Counting up starts at zero until the maximum value 32767 is reached. Each rising edge at count up CU increases the value at current value CV by 1.
Input
count up
the value 1 is added to CV for each rising edge at CU, except when R is set
Reset
A rising edge at R resets the currrent value CV to zero and counting stops. The output Q is set to FALSE.
The next falling edge at R restarts counting.
Preset value
if CV is equal/greater than PV, Q is set to TRUE
If no preset value is set or the preset value is zero, the output Q is set to TRUE immediately after counting starts.
Output
signal output
is set to TRUE if CV is greater than/equal to PV
is set to FALSE if a rising edge is detected at R
Current value
contains the addition result
If CV reaches the preset value PV, the output Q is set to TRUE, but counting continues until the maximum limit 32767 is reached.
The value can be changed during counting operation by writing to the variable from the programming editor.
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
CTU1: CTU;
bReset: BOOL:=FALSE;
(*sets CV to zero if TRUE*)
iPresetValue: INT:=3;
(*if CV reaches this value,
output Q is set*)
bUpCounting_PV_reached: BOOL:=FALSE;
(*is set, if CV reaches PV*)
iCurrentValue: INT:=0;
(*contains the current value*)
END_VAR
If bReset is set (status = TRUE), iCurrentValue (CV) will be reset. If a rising edge is detected at CU, the value 1 will be added to iCurrentValue. If a rising edge is detected at CU, this procedure will be repeated until iCurrentValue is greater than/equal to iPresetValue. Then, bUpCounting_PV_reached will be set to TRUE.
BODY
WORKSPACE
NETWORK_LIST_TYPE := NWTYPELD ;
END_WORKSPACE
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 8 ;
NETWORK_BODY
B(B_CONTACT,,sys_bPulse1s,5,2,7,4,);
B(B_FB,CTU!,CTU1,12,1,17,6,,?BCU?BR?BPV?AQ?ACV);
B(B_COIL,,bUpCounting_PV_reached,23,2,25,4,);
B(B_CONTACT,,bReset,5,4,7,6,);
B(B_VAROUT,,iCurrentValue,18,4,20,6,);
B(B_VARIN,,iPresetValue,7,6,9,8,);
L(1,0,1,8);
L(1,3,5,3);
L(7,3,12,3);
L(17,3,23,3);
L(9,4,12,4);
L(9,4,9,5);
L(17,4,17,5);
L(1,5,5,5);
L(7,5,9,5);
L(10,5,12,5);
L(17,5,18,5);
L(10,5,10,7);
L(9,7,10,7);
END_NETWORK_BODY
END_NET_WORK
END_BODY
CTU1(CU := sys_bPulse1s, R := bReset, PV := iPresetValue,
Q => bUpCounting_PV_reached,
CV => iCurrentValue);