PLC Counting Instructions
PLC Counting Instructions
UP Counting Counters
Up counters increase their current count output variable “ CV” each time their
trigger inputs experience a transition from logic zero to logic one. The instruction output
Boolean variable Q toggles from zero to one when CV reaches the preset count value “ PV”
and stay so unless reset by the reset input R. The upper counting level depends upon the
counting instruction type. Table 1 lists the upper limits for the various up counting
instructions . Figure 1 shows the instruction function block and timing chart.
CTU_XXXXX R
CU Q
CU
R
Q
CV
PV CV
PV
CV=0 CV=PV
CV=1 CV=Max Count
books each time preset number of books have been passed ( say 12 books).
BooksSensors
BooksSensors C1.Q ResetC1
ResetC1
P
Switches
Switches Switches Switches
Switches
C1
Swi
BooksSensors CTU_INT
tch Swit
N
Switches
es
IN ches Q
Swit ResetC1
R
che
Switches
s
Req.Quantity PV CV
Switches Switches
Down counters decrease their current count output variable labeled CV , starting from
the preset value "PV" loaded by the load input "LD", each time their trigger inputs
experience transition from logic zero to logic one. The instruction output Boolean
variable Q toggles from zero to one the time CV reaches zero and stay one unless reset by
the load input LD . The minimum counting level depends upon the counting instruction
type. Table 2 lists the lower limits for the various down counting instructions . Figure 2
shows the instruction function block and details its timing chart.
LD Q
PV CV
PV CV 0
CV=PV CV=0
CV=PV-1 CV=Mini Count
Example 2: Write ladder diagram to track the number of remaining items in a store
previously loaded with 100 items.
Swit Load t
LD
che c
Switches
s 100 PV CV h
C1.Q e
StoreEmpty
Switches
s
Switches Switches
UP / Down counters can be considered as two counters (up counter and down counter)
sharing the same preset value input variable PV and current value output variable CV. The
up counting part has its own unshared terminals or variables represented by the triggering
input CU, reset input R, and the output QU. The down counter unshared variables are
the triggering input CD, the load input LD, and the output variable QD. The upper and
lower counting levels for these counters depend upon the instruction used type. Table 3 list
down these limits.
Table 3: MAXIMUM /Minimum counting values of up/down counting instructions
Example 3: Draw ladder diagram for Parking Garage Controller with N car capacity
Start
LT
Switches IN ENO
CarInside SpaceOK
Swit IN1
OUT
che Switches Switches
Capacity IN2 GarageFull
S
s
Switches w
Switches
h wi
NS PV
e tc
wi
s he
S
tc
wi s
he
tc
Figure 5: Parking Garage Controller
s
he
s
Ring Counter
Ring counter CTR is an up counting instruction with inherent reset strobe facility. Here
the current value CV increases as the rung connected to CD experiences a transition from
zero to one and CV is less than PV. When CV equals PV the Q output becomes "1". The
next positive transition on CD ( after CV=PV) resets the Q output and forces CV to take a
value of one and new cycle starts. The ring counter supports only integer data types for its
CV and PV variables. Figure 6 displays the ladder symbol and the timing chart of the ring
counter.
RST
CTR1
CTR CD
CD Q
PV Q
PV CV
RST CV
Example 4: Y is one dimensional array. It consists of 10 word type elements. Write PLC
Program segment to continuously copy the contents of this array one after the other to the
PLC output terminals. Let the copy process time span equals to 30sec.
tch MOVE es
Switches EN ENO
es
Pattern[J] IN OUT Lamp
Swit
che s
s