PLC Lab 6
PLC Lab 6
Lab 6 : Counter
OBJECTIVES
To study the operation of different types of counters.
To use the PLC counters and timers in a process control.
COUNTER INSTRUCTION
1. CTU: Count up
Description
You can use the "Count up" instruction to increment the value at output CV. When the
signal state at the CU input changes from "0" to "1" (positive signal edge), the
instruction executes and the current counter value at the CV output is incremented by
one. When the instruction executes for the first time, the current counter value at the
CV output is set to zero. The counter value is incremented each time a positive signal
edge is detected, until it reaches the high limit for the data type specified at the CV
output. When the high limit is reached, the signal state at the CU input no longer has
an effect on the instruction.
You can scan the counter status at the Q output. The signal state at the Q output is
determined by the parameter PV. If the current counter value is greater than or equal to
the value of the PV parameter, the Q output is set to signal state "1". In all other cases,
the Q output has signal state "0".
The value at the CV output is reset to zero when the signal state at input R changes to
"1". As long as the R input has signal state "1", the signal state at the CU input has no
effect on the instruction.
Note
Only use a counter at a single location in the program to avoid risk of counting errors
Each call of the "Count up" instruction must be assigned an IEC counter in which the
instruction data is stored. An IEC counter is a structure with one of the following data
types:
For S7-1200 CPU
Data block of system data type IEC_counter
Local tag
(global DB)
CTU_SINT / CTU_USINT
CTU_INT / CTU_UINT
IEC_SCOUNTER /
CTU_DINT / CTU_UDINT
IEC_USCOUNTER
IEC_SCOUNTER /
IEC_COUNTER / IEC_UCOUNTER
IEC_USCOUNTER
IEC_DCOUNTER /
IEC_COUNTER / IEC_UCOUNTER
IEC_UDCOUNTER
IEC_DCOUNTER /
IEC_UDCOUNTER
When you insert the instruction in the program, the "Call options" dialog opens in
which you can specify whether the IEC counter is stored in its own data block (single
instance) or as a local tag (multiple instance) in the block interface. If you create a
separate data block, you will find it in the project tree in the "Program resources"
folder under "Program blocks > System blocks". For additional information on this
topic, refer to "See also".
The execution of the "Count up" instruction requires a preceding logic operation. It
can be placed within or at the end of the network.
Parameter
The following table shows the parameters of the "Count up" instruction:
I, Q, M, T, C, D,
R Input BOOL Reset input
L, P or constant
Value at which
I, Q, M, D, L, P
PV Input Integers the output Q is
or constant
set.
Q Output BOOL I, Q, M, D, L Counter status
Integers, CHAR, Current counter
CV Output I, Q, M, D, L, P
DATE value
You can select the data type for the instruction from the "<???>" drop-down list of the
instruction box.
For additional information on valid data types, refer to "See also".
Example
The following example shows how the instruction works:
When the signal state of the "TagIn_1" operand changes from "0" to "1", the "Count
up" instruction executes and the current counter value of the operand "Tag_CV" is
incremented by one. With each additional positive signal edge, the counter value is
incremented until the high limit value of the data type (INT = 32767) is reached.
The value of the PV parameter is adopted as the limit for determining the "TagOut"
output. The "TagOut" output has signal state "1" as long as the current counter value is
greater than or equal to the value of the "Tag_PV" operand. In all other cases, the
"TagOut" output has signal state "0".
Each call of the "Count down" instruction must be assigned an IEC counter in which
the instruction data is stored. An IEC counter is a structure with one of the following
data types:
For S7-1200 CPU
Data block of system data type IEC_counter
Local tag
(global DB)
CTD_SINT / CTD_USINT
CTD_INT / CTD_UINT
IEC_SCOUNTER /
CTD_DINT / CTD_UDINT
IEC_USCOUNTER
IEC_SCOUNTER /
IEC_COUNTER / IEC_UCOUNTER
IEC_USCOUNTER
IEC_DCOUNTER /
IEC_COUNTER / IEC_UCOUNTER
IEC_UDCOUNTER
IEC_DCOUNTER /
IEC_UDCOUNTER
When you insert the instruction in the program, the "Call options" dialog opens in
which you can specify whether the IEC counter is stored in its own data block (single
instance) or as a local tag (multiple instance) in the block interface. If you create a
separate data block, you will find it in the project tree in the "Program resources"
folder under "Program blocks > System blocks". For additional information on this
topic, refer to "See also".
The execution of the "Count down" instruction requires a preceding logic operation. It
can be placed within or at the end of the network
Parameter
The following table shows the parameters of the "Count down" instruction:
I, Q, M, T, C, D,
LD Input BOOL Load input
L, P or constant
Value at which
I, Q, M, D, L, P
PV Input Integers the output Q is
or constant
set.
Q Output BOOL I, Q, M, D, L Counter status
Integers, CHAR, Current counter
CV Output I, Q, M, D, L, P
DATE value
You can select the data type for the instruction from the "<???>" drop-down list of the
instruction box.
For additional information on valid data types, refer to "See also".
Example
The following example shows how the instruction works:
When the signal state of the "TagIn_1" operand changes from "0" to "1", the "Count
down" instruction is executed and the value at the "Tag_CV" output is decremented by
one. With each additional positive signal edge, the counter value is decremented until
the low limit of the specified data type (INT = -32768) is reached.
The "TagOut" output has signal state "1" as long as the current counter value is less
than or equal to zero. In all other cases, the "TagOut" output has signal state "0".
Each call of the "Count up and down" instruction must be assigned an IEC counter in
which the instruction data is stored. An IEC counter is a structure with one of the
following data types:
For S7-1200 CPU
CTUD_SINT / CTUD_USINT
CTUD_INT / CTUD_UINT
IEC_SCOUNTER /
CTUD_DINT / CTUD_UDINT
IEC_USCOUNTER
IEC_SCOUNTER /
IEC_COUNTER / IEC_UCOUNTER
IEC_USCOUNTER
IEC_DCOUNTER /
IEC_COUNTER / IEC_UCOUNTER
IEC_UDCOUNTER
IEC_DCOUNTER /
IEC_UDCOUNTER
When you insert the instruction in the program, the "Call options" dialog opens in
which you can specify whether the IEC counter is stored in its own data block (single
instance) or as a local tag (multiple instance) in the block interface. If you create a
separate data block, you will find it in the project tree in the "Program resources"
folder under "Program blocks > System blocks". For additional information on this
topic, refer to "See also".
The execution of the "Count up and down" instruction requires a preceding logic
operation. It can be placed within or at the end of the network.
Parameter
The following table shows the parameters of the "Count up and down" instruction:
I, Q, M, T, C, D,
R Input BOOL Reset input
L, P or constant
I, Q, M, T, C, D,
LD Input BOOL Load input
L, P or constant
Value at which
I, Q, M, D, L, P
PV Input Integers the output QU is
or constant
set.
Status of the
QU Output BOOL I, Q, M, D, L
counter up
Status of the
QD Output BOOL I, Q, M, D, L
down-counter
Integers, CHAR, Current counter
CV Output I, Q, M, D, L, P
DATE value
You can select the data type for the instruction from the "<???>" drop-down list of the
instruction box.
For additional information on valid data types, refer to "See also".
Example
The following example shows how the instruction works:
If the signal state at the "TagIn_1" or "TagIn_2" input changes from "0" to "1"
(positive signal edge), the "Count up and down" instruction is executed. When there is
a positive signal edge at the "TagIn_1" input, the current counter value is incremented
by one and stored at the "Tag_CV" output. When there is a positive signal edge at the
"TagIn_2" input, the counter value is decremented by one and stored at the "Tag_CV"
output. When there is a positive signal edge at the CU input, the counter value is
incremented until it reaches the high limit of 32767. If input CD has a positive signal
edge, the counter value is decremented until it reaches the low limit value of INT = -
32768.
The "TagOut" output has signal state "1" as long as the current counter value is greater
than or equal to the value at the "Tag_PV" input. In all other cases, the "TagOut"
output has signal state "0".
The "TagOut_QD" output has signal state "1" as long as the current counter value is
less than or equal to zero. In all other cases, the "TagOut_QD" output has signal state
"0".
EXPERIMENTAL WORK
A PLC-controlled system operates as follows. If the Start button is pressed, MV1 will be opened and
dye starts to fill the tank. At the same time mixing-motor begins to run. As the level of the dye passes
TBL2 and reaches to TBL1, MV1 will be closed and mixing-motor will stop. Then MV2 will be opened
and dye begins to run out of the container. After the level of the dye reaches to the below of TBL2, MV2
will be closed. The operator will determine the number of operation times will be repeated by using HMI
interface. Then the system will stop.
We can observe the stopping of the system with the lamp and the buzzer.
After the system stops, buzzer will continue to run for 2 sec and then it stops. But the lamp continues to
light until the reset button is pressed. When the reset button is pressed, the system will be ready to
begin the same process again. Use the HMI interface to show which process is applied. Construct a
LAD diagram and HMI interface for this system.