Counter Instructions
• Programmed counters serve the same function as mechanical counters.
• Every time the actuating lever is moved over, the counter adds one
number.
• Resetting to zero is done with a pushbutton located on the side of the
unit.
Counter Instructions
• Electronic counters can count up, count down, or be combined to
count up and down.
• Although the majority of counters
used in industry are up-counters,
numerous applications require the
implementation of down-counters or
of combination up/down-counters.
1
Counter Instructions
• All PLC manufacturers offer some form of counter instruction.
• One common counter application is
keeping track of the number of items
moving past a given point.
• PLC counter instructions are similar
to timers except that they do not
operate on an internal clock but are
dependent on external or program
sources for counting.
Counter Instructions
• Generic coil-formatted
up-counter instruction.
2
Counter Instructions
• The counter reset instruction must be used in conjunction with the
counter instruction.
• The counter reset coil
is given the same
address as the counter
that it is to reset.
• Up-counters are always
reset to zero.
Counter Instructions
• Generic block-formatted counter.
• The counter reset coil
is given the same
address as the counter
that it is to reset.
• Up-counters are always
reset to zero.
3
Counter Instructions
• All PLC counters operate, or count, on the leading edge or off-to-on
transition of the input condition.
• PLC counters can be programmed to count up to a preset value or to
count down to a preset value.
Counter Instructions
• The up-counter is incremented • The down-counter decrements
by 1 each time the rung by 1 each time the rung
containing the counter is containing the counter is
energized. energized
4
Up Counter
The up-counter is used to count false-to-true transitions of an input
instruction and then trigger an event after a required number of counts
or transitions.
The up-counter count value will increment by 1 each time the counted
event occurs.
Up Counter: SLC 500 Count-Up Counter
10
5
Up Counter: SLC 500 Count-Up Counter
Allen-Bradley counter takes three data table words: the control word,
preset word, and accumulated word.
Word 0 is the control word
Word 1 stores the preset value
Word 2 stores the accumulated value
11
Up Counter: SLC 500 Count-Up Counter
Count-Up (CU) Enable Bit — used with the CU counter.
— true whenever the CU counter instruction is true.
Count-Down (CD) Enable Bit — used with the CD counter.
— true whenever the CD counter instruction is true.
Done (DN) Bit — true whenever the accumulated value is equal to or greater
than the preset value, for either the count-up or the count-down counter.
12
6
Up Counter: SLC 500 Count-Up Counter
Overflow (OV) Bit—is true whenever the counter counts past its maximum value,
which is 32,767. On the next count, the counter will wrap around to –32,768 and
will continue counting from there toward 0 on successive false-to-true transitions
of the count-up counter.
Underflow (UN) Bit—The underflow bit will go true when the counter counts below
–32,768. The counter will wrap around to +32,767 and continue counting down
toward 0 on successive false-to-true rung transitions of the count-down counter.
13
Up Counter: SLC 500 Count-Up Counter
Update Accumulator (UA) Bit—The update accumulator bit is used only in
conjunction with an external HSC (high-speed counter).
14
7
Up Counter: SLC 500 Count-Up Counter
Preset value (PRE) word specifies the value that the counter must
count to before it changes the state of the done bit.
The accumulated value (ACC) word is the current count based on the
number of times the rung goes from false to true.
• The accumulated value either increments with a false-to-true
transition of the count-up counter instruction or decrements with a
false-to-true transition of the count-down counter instruction.
• The accumulated value will continue to count past the preset value
instead of stopping at the preset like a timer does.
SLC 500: preset value (-32768 to 32767)
ControlLogix: preset value (-2.147.438.648 to 2.147.438.647)
15
Up Counter: SLC 500 Count-Up Counter
16
8
Example: stop a motor from running
17
Example: Can-counting program
18
9
Example: Alarm monitor program
19
Up Counter: ControlLogix Count-Up Counter
Logix processors use a tag name,
such as Package_Count, instead of a
counter number
20
10
Down Counter
• The down-counter instruction will count down or decrement by 1
each time the counted event occurs.
• Each time the down-count event occurs, the accumulated value is
decremented.
21
Down Counter
Normally the down-counter is used in conjunction with the up-counter
to form an up/down-counter
22
11
Down Counter
• Some up-counters count only to their preset values, and additional
counts are ignored. Other up-counters keep track of the number of
counts received above the counter’s preset value.
• Conversely, some down-counters will simply count down to zero and
no further. Other down-counters may count below zero and begin
counting down from the largest preset value that can be set for the
PLC’s counter instruction
23
Example: Parking garage counter
24
12
Example: count up/down program
25
Example: count up/down program
26
13
Cascading counters: Counting Beyond the Maximum Count
27
Cascading counters: Extremely Large Count
28
14
Cascading counters: 24-hour clock program
29
Cascading counters: Monitoring the time of an event
30
15
31
16