Down counter
Counters realized with the CT_FB function block are down counters. The count area SV (set value) is 1 to 32767.
Input
count contact (down)
each time a rising edge is detected at Count, the value 1 is subtracted from the elapsed value EV until the value 0 is reached
reset contact
each time a rising edge is detected at Reset, the value 0 is assigned to EV and the signal output C is reset; each time a falling edge is detected at Reset, the value at SV is assigned to EV
Set value
value of EV after a reset procedure
Output
signal output
is set when EV becomes 0
Elapsed value
current counter value
The value can be changed during counting operation by writing to the variable from the programming editor.
In order to work correctly, the CT_FB function block needs to be reset each time before it is used.
The number of available counters is limited and depends on the settings in the system registers 5 and 6. The compiler assigns a NUM* address to every counter instance. The addresses are assigned counting downwards, starting at the highest possible address.
The basic function CT (down counter) uses the same NUM* address area (Num input). In order to avoid errors (address conflicts), the CT function and the CT_FB function block should not be used together in a project.
Time chart
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
copy_name: CT_FB;
set_value: INT:=10;
signal_output: BOOL:=FALSE;
count_contact: BOOL:=FALSE;
Reset_CT: BOOL:=FALSE;
machine_error: BOOL:=FALSE;
number_error: INT:=0;
END_VAR
This example uses variables. You may also use constants for the input variables. Each rising edge detected at count_contact the value 1 is subtracted from the elapsed value EV. Signal_output is set to TRUE if the elapsed value EV becomes zero.
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_FB,CT_FB!,copy_name,9,1,15,6,,?BCount?BReset?BSV?AC?AEV);
B(B_VARIN,,count_contact,7,2,9,4,);
B(B_VARIN,,Reset_CT,7,3,9,5,);
B(B_VARIN,,set_value,7,4,9,6,);
B(B_VAROUT,,signal_output,15,2,17,4,);
L(1,0,1,6);
END_NETWORK_BODY
END_NET_WORK
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 6 ;
NETWORK_BODY
B(B_F,E_MOVE!,Instance,10,1,16,5,,?DEN?D?AENO?C);
B(B_VARIN,,copy_name.EV,8,3,10,5,);
B(B_VAROUT,,number_error,16,3,18,5,);
B(B_CONTACT,,machine_error,4,2,6,4,);
L(1,3,4,3);
L(6,3,10,3);
L(1,0,1,6);
END_NETWORK_BODY
END_NET_WORK
END_BODY
If you want to call the function block in an instruction list, enter the following: