You are on page 1of 14

Programming Counters

Week 08
Typical examples of PLC counters include the
following:
straight counting in a process,
 two counters
used to give the sum of two counts, and
used to give the difference between two counts.
 combinations of counters and timers to process
control.

Block-formatted
Coil-formatted counter counter instruction.
and reset instructions.
1. Counter Instructions
All PLC manufacturers offer some form of counter instruction as part of
their instruction set. One common counter application is keeping track
of the number of items moving past a given point.

Counters are similar to timers except that they do not operate on an


internal clock but are dependent on external or program sources for
counting. The two methods used to represent a counter within a PLC’s
ladder logic program are the coil format and the block format.

Transitions on counter input


rung causes the counter to
count up (or down)

The counter reset instruction


must be used in conjunction
with the counter instruction.
The counter will either increment (up-counter[CTU]) or decrement
(down-counter[CTD]) whenever the count input transfers from an off
state to an on state.
PLC counters are normally retentive; that is, whatever count was
contained in the counter at the time of a processor shutdown will be
restored to the counter on power-up. The accumulated count is
retained until cleared by a reset (RES) instruction.
2. Up-Counter
The up-counter is an output instruction whose function is to increment
its accumulated value on false-to-true transitions of its instruction. The
up-counter output instruction will increment by 1 each time the
counted event occurs.
Counter Status Bits
• /CU: count up
• /CD: count down
• /DN: counter done
• /OV: counter overflow
• /UN: counter underflow
Each of the three data words
shares the same base
address, which is the
address of the counter itself.
There can be up to 256
counter elements. Addresses
for counter fi le 5, counter
element 3 (C5:3),

This bit Is Set When And remains set until


Count Up Overflow Accumulated value becomes A (RES) instruction with the same
Bit (OV) wraps around to -32768 address as the CTU instruction is enabled
(from+32767) OR the count is decremented less than or
equal to +32767 with a count down
(CTD) instruction
Done Bit (DN) Accumulated value is equal to or Accumulated value becomes less than the
greater than the preset value preset value
Count Up Enable Bit Rung conditions are true Rung conditions go false or a (RES)
(CU) instruction with the same address as the
CTU instruction is enabled
Siemens Counter operations

STEP 7 automatically creates the DB when you insert


the instruction. The number of counters that you can use
in your user program is limited only by the amount of
memory in the CPU. Counters use the following amount
of memory:
● For SInt or USInt ,the counter uses 3 bytes.
● For Int or UInt, the counter uses 6 bytes.
● For DInt or UDInt, the counter uses 12 bytes.
This control application
is designed to turn the
red pilot light on and
the green pilot light off
after an accumulated
count of 7.
or

is often used to automatically clear or reset a counter. The one-shot is


perfect for resetting both counters and timers since it stays on for one
scan only.

B:0/0 M0.1
The conveyor motor PLC program of Figure 8-17 illustrates the application of an up-
counter along with a programmed one-shot (OSR) transitional contact instruction. The
counter counts the number of cases coming off the conveyor. When the total number of
cases reaches 50, the conveyor motor stops automatically. The trucks being loaded will
take a total of only 50 cases of this particular product; however, the count can be
changed for different product lines. The operation of the program can be summarized as
follows:
• The momentary start button is
pressed to start the conveyor motor
M1.
• The passage of cases is sensed by
the proximity switch.
• Cases move past the proximity
switch and increment the counter’s
accumulated value with each false-
to-true transition of the switch.
• After a count of 50, the done bit of
the counter changes state to stop the
conveyor motor automatically and
reset the counter’s accumulated
value to zero.
• The conveyor motor can be
stopped and started manually at
any time without loss of the
accumulated count.
• The accumulated count of the
counter can be reset manually at any
time by means of the count reset
button.
3. Down-Counter
The down-counter instruction will count down or decrement by 1 each
time the counted event occurs. Normally the down-counter is used in
conjunction with the up-counter to form an up/down-counter.

One application for an up/down-counter is to keep count of the cars


that enter and leave a parking garage. Figure 8-22 shows a typical
PLC program that could be used to implement this.
Siemens Counter operations

• If the value of parameter CV (current count value) is equal to or less than 0, the
counter output parameter Q = 1.
• If the value of parameter LOAD changes from 0 to 1, the value at parameter PV
(preset value) is loaded to the counter as the new CV (current count value).
4. Cascading Counters
Depending on the application, it may be necessary to count events
that exceed the maximum number allowable per counter instruction.
One way of accomplishing this count is by interconnecting, or
cascading, two counters. The program of Figure 8-26 illustrates the
application of the technique
when an extremely long time-delay period is required. For example, if
you require a timer to time to 1,000,000 s, you can achieve this by
using a single timer and counter. Figure 8-36 shows how the timer and
counter would be programmed for such a purpose.
5. Combining Counter and Timer Functions
Lab. EXPERIMENT 6
Figure 8-34 shows a motor
lock-out program. This
program is designed to
prevent a machine operator
from starting a motor that
has tripped off more than 5
times in an hour.

You might also like