COUNTERS IN PLC - Portal PDF

Download as pdf or txt
Download as pdf or txt
You are on page 1of 88

Programmable Logic

Controller
(Counters)
Introduction
• Counters used in PLC’s serve the same function as
mechanical counters.
• Counters compare an accumulated value to a preset
value to control circuit functions.
• Control applications that commonly use counters
include the following:
- Count to a preset value and cause an event to occur
- Cause an event to occur until the count reaches a
preset value
COUNTER
• Electronic counters can count up, count
down, or be combined to count up and
down.
• They are dependent on external sources,
such as parts traveling past a sensor or
actuating a limit switch for counting.
COUNTER APPLICATIONS
Industrial Application
• A bottling machine, for example, may use a
counter to count bottles into groups of six for
packaging
Counter Speed

The maximum speed of transitions you can count is


determined by your program's scan time. Any
counter
input signal must be fixed for one scan time to be
counted reliably.
If the input changes faster than one
scan period, the count value will
become unreliable because counts
will be missed. When this is the case
you need to use a high-speed
counter.
Basic Operation of Counter
• Counters are represented by boxes in
ladder logic.
• Counters increment/decrement one count
each time the input transitions from off
(logic 0) to on (logic 1).
• The counters are reset when a RESET
instruction is executed
Counter symbol
CNT XXX
Count input

Reset # XXXX

PLC counters operate or count on the leading edge of


the input signal. The counter will either increment or
decrement whenever the count input transfers from an
"off" state to an "on" state. The counter will not operate
on the trailing edge, or on-to-off transition of the input
condition.
OMRON Counter
• There are 256 counters in the CPM1A,
numbered CNT000 through CNT255.
• The same number cannot be assigned to
more than one counter or timer.
• For example, if an up counter is assigned
number 45, a timer cannot also be
assigned number 45.
• The maximum count value of a counter is
9999
How it works?
• Count input
• Reset input
• Counter number (000-255)
• Set value (0000-9999)
Up-counter

PB1
CNT 001

PB2
#0010

CNT001 Y0

CNT001 Y1

END
Up-counter Program Timing Diagram

PB1

Y0

Y1

PB2
Counter Counting Sequence
The up-counter is incremented by 1 each time the
rung containing the counter is energized.

The counter will increment until the accumulated value is


equal to or greater than the preset value, at which time an
output will be produced.
Down-counter

The down-counter output 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. Normally the
down-counter is used in conjunction with the up
counter to form an up/down counter.
DOWN-COUNTER

Generic up/down
counter program
Up/Down Counter Timing diagram

Preset Value = 3
Counter Example
• A counter might be used to keep track of the
number of vehicles in a parking lot.
• As vehicles enter the lot through an entrance
gate, the counter counts up.
• When the lot is full a sign at the entrance gate
turns on indicating the lot is full
Counter Example
Counter Example
• In this ladder diagram, we wait for the sensor
0000 to turn on.
• Each pulse transition change form logic 0 to
1, will count as 1
• When 10 pulse transition has achieved, the
CNT000 contact close and output 1002 turns
on.
• When input 0002 turns on, the counter
CNT000 will reset back to 0 causing its
contact to turn off (open), thereby making
output 1002 turn back off.
Counter Example
Example 1

00000
CNT 001

00002
#0010

CNT001 01002

END
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 is
by interconnection, or
cascading, two counters.
Cascading Counters
Example 2: Count to 20,000 counts
Example 3
Packaging line control

• When PB1 (START push


button) is pressed, the
box conveyor moves.
• Upon detection of box
present, the conveyor
stops and the apple
conveyor starts moving.
• Part sensor, SE1 will
count for 10 apples.
• Then, apple conveyor
stops and box conveyor
starts again.
• Counter will be reset and
operation repeats until
PB2 (STOP push button)
is pressed.
Example 3 (cont..)
Input/output assignments
Example 3 (cont..)
Timing diagram
Example 3 (cont..)
Initial condition
Example 3 (cont..)
PB1 pressed – internal relay turn ON and box conveyor starts moving
Example 3 (cont..)
PB1 released – internal relay remains ON and box conveyor keep moving
Example 3 (cont..)
box sensor (SE2) turn ON – box conveyor stops and apple conveyor starts moving
Example 3 (cont..)
Part sensor (SE1) detects apple
Example 3 (cont..)
Upon 10 apples have been counted, CNT 000 will activated – apple
conveyor stops and box conveyor moves again
Example 3 (cont..)
Sensor SE2 will reset CNT 000 and the process repeats until PB2 is pressed
Example 3 (cont..)
PB2 is pressed – the process stops
Counter Used For Length Measurement

Count input pulses are generated by the magnetic sensor, which


detects passing teeth on a conveyor drive sprocket. If 10 teeth per foot
of conveyor motion pass the sensor, the accumulated count of the
counter would indicate feet in tenths.

The photoelectric sensor monitors a reference point on the


conveyor. When activated, it prevents the unit from counting, thus
permitting the counter to accumulate counts only when bar stock is
moving.
Prolong time to range 1000hour
00000 TIM 001

TIM 001
#6000

TIM 001

00001 CNT 002


#6000

CNT 002 01000

END
Combining Counter And Timer Functions

• Many PLC applications use both the counter and the


timer function.
• Example 4 illustrates an automatic stacking program that
requires both a timer and counter.
• In this process, conveyor M1 is used to stack metal
plates onto conveyor M2.
• The photoelectric sensor provides an input pulse to the
PLC counter each time a metal plate drops from
conveyor M1 to M2.
• When 15 plates have been stacked, conveyor M2 is
activated for 5 seconds by the PLC timer.
• The operation of the program can be summarized as
follows:
Combining Counter And Timer Functions
Example 4 When the start button is pressed,
conveyor M1 begins running.

After 15 plates have been


stacked, conveyor M1 stops and
conveyor M2 begins running.

After conveyor M2 has been


operated for 5 s, it stops and the
sequence is repeated
automatically.

The done bit of the timer resets


the timer and counter, and
provides a momentary pulse to
Automatic Stacking Process
automatically restart conveyor
M1.
Example 5
• When input push button 00000 being pressed 2
times, then output 01000 will ON. Then when
input push button 00000 being pressed another
2 times, output 01001 will ON. Then when input
00000 being pressed another 2 times, output
01002 will ON. Then when input 00000 being
pressed another 1 times, output 01000 will OFF,
another 1 times output 01001 will OFF and
another 1 time output 01002 will OFF. Use input
00001 as the reset button for the counter.
SHIFT REGISTER
Shift Registers
A shift register can be used to simulate the movement or
track the flow of parts and information.

We use the shift register whenever we need to store the


status of an event that had previously happened so that
we can act upon it at a later time. This is accomplished by
shifting either status or values through data files.

Common applications include:


• Tracking parts through an assembly line
• Controlling machine or process operations
• Inventory control
• System diagnostics
OMRON Shift Registers

Shift register shifts a 16-bit data in specified channel by 1


bit. Although this instruction shift data within channel,
both a start channel and an end channel must be specified
as the data.
Basic Concept Of A Shift Register

A shift data or clock pulse causes each bit in the shift


register to move 1 position to the right. When the register's
storage capacity is exceeded shift data are lost at the end of
the shift register.
Basic Concept Of A Shift Register
Typically, data in the shift register could represent :
▪Part types, quality, and size
▪The order in which events occur
▪Identification numbers or locations
▪A fault condition that caused a shutdown
Bit Shift Right And Bit Shift Left Registers
When tracking parts on a status basis, bit shift registers
are used.

Bit shift instructions will shift bit status from a source bit
address, through a data file, and out to an unload bit, one
bit at a time.

There are two bit shift instructions: bit shift left (BSL),
which shifts bit status from a lower address number to a
higher address number through a data file; and bit shift
right (BSR), which shifts data from a higher address
number to a lower address number. Some PLCs provide a
circulating shift register function, which allows you to
repeat a pattern again and again.
Bit Shift Right And Bit Shift Left Registers

When working with a bit shift register, each bit is


identified by its position in the register. Therefore,
working with any bit in the register becomes a matter of
identifying the position it occupies rather than the
conventional word number/bit number addressing
scheme.
Bit Shift Right And Bit Shift Left Registers

The shift register function enables a programmer to


move digital bits within and through the PLC
registers. A data array is a collection of more than
one data word (more than 16 bits) in memory. Since
data in the BSL and BSR instruction is shifted one
bit at a time, the data, which is shifted is stored in a
binary or bit file. When more than one word is
grouped together, the grouping is identified as a
data array. The data files or arrays used with shift
registers generally contain more than 16 bits.
Example circuit
MASTER
CONTROLLER
RELAY
Hardwired Master Control Relay Circuit

Hardwired master control relays are used in relay


circuitry to provide input/output power shutdown of
an entire circuit.
Hardwired Master Control Relay Circuit
MCR Instruction MCR

The master control reset (MCR) instruction can be programmed


to control an entire circuit or to control only selected rungs of a
circuit. When the MCR instruction is false, or de-energized, all
nonretentive (nonlatched) rungs below the the MCR will be de-
energized even if the programmed logic for each rung is true. All
retentive rungs will remain in their last state. The MCR
instruction establishes a zone in the user program in which all
nonretentive outputs can be turned off simultaneously.
Therefore, retentive instructions should not normally be placed
within an MCR zone because the MCR zone maintains retentive
instructions in the last active state when the instruction goes
false.
MCR Instruction Programmed To Control An
Entire Circuit
MCR Instruction Programmed To Control A
Fenced Zone

The Master Control


Reset (MCR) instruction
is used in pairs to disable
or enable a zone within a
ladder program and has
Fenced
Zone
no address. You program
the first MCR with input
instructions in the rung
and the ending MCR
without any other
instructions in the rung.
MCR Instruction Programmed To Control A
Fenced Zone
MCR Zone True
MCR Instruction Programmed To Control A
Fenced Zone
MCR Zone False
Programming MCR Instructions
If you start instructions such as timers and counters
in an MCR zone, instruction operation ceases when the
zone is disabled.

The TOF timer will activate when placed inside a false


MCR zone.

When troubleshooting a program that contains an MCR zone


you need to be aware of which rungs are within zones in
order to correctly edit the circuit.

MCR controlled areas must contain only two MCR


instructions – one to define the start and one to define the
end.
JUMP
INSTRUCTION
Jump Instruction JMP

As in computer programming, it is sometimes desirable


to be able to jump over certain program instructions.
The jump instruction (JMP) is an output instruction used for
this purpose. The advantages to the jump instruction include:
▪ the ability to reduce the processor scan time by jumping over
instructions not pertinent to the machines operation at that
instant
▪ The PLC can hold more than one program and scan only the
program appropriate to operator requirements
▪ Sections of a program can be jumped when a production
fault occurs
Jump Operation
By using the jump instruction, you can branch or
skip to different portions of a program and freeze all
affected outputs in their last state.

Jumps are normally allowed in


both the forward and backward
directions.

Jumping over counters and


timers will stop them from being
incremented.
Jump-To-Label
With Allen-Bradley PLCs the jump (JMP) instruction and
the label (LBL) instruction are employed together so the
scan can jump over a portion of the program.

The label is a target for the jump, it is the first


instruction in the rung, and it is always true.

A jump jumps to a label with the same address. The area


that the processor jumps over is defined by the
locations of the jump and label instructions in the
program.
If the jump coil is energized, all logic between the jump
and label instructions is bypassed and the processor
continues scanning after the LBL instruction.
Jump
To Label Timers should
Program be
programmed
outside the
jumped section

Input conditions
are not examined Jumped program
and outputs rungs (5,6,7) are
remain in their
not scanned by
last state
the processor
Jump-To-Label From Two Locations
20

20

20
FORCE
INSTRUCTION
Forcing External I/O Addresses
The forcing capability of a PLC allows the user to
turn an external input or output "on" or "off" from the
keyboard of the programmer.

L1 L2
Program

Input False Output


"off"
Forced
"on"
Forcing Inputs
Overriding of physical inputs on conventional relay
control systems can be accomplished by installing
hardwire jumpers. With PLC control this is not
necessary as the input data table values can be
forced to an "on" or "off" state.

Forcing inputs manipulates the input image table file bits


and thus affects all areas of the program that uses those
bits.

The forcing of inputs is done just after the input scan.


Forcing An Input Address On

10
Forcing An Input Address On

Force> ON

Forcing inputs affects all areas of the program that


uses that bit.
Forcing Outputs
Forcing outputs affects only the addressed output terminal.
When we force an output address we are forcing only the
output terminal to an on or off state.

The output image table file bits are unaffected, therefore,


your program will be unaffected.

The forcing of outputs is done just before the output


image table file is updated.

By forcing outputs "off" you can prevent the controller


from energizing those outputs, even though the ladder
logic, which normally controls them, may be true.
Forcing An Output Address On
Forcing An Output Address On

Forcing outputs affects only the addressed


output terminal.
Using Forcing Functions

The Force function can not be applied when the


processor is in the run mode.

An understanding of the potential effect that forcing


given inputs or outputs will have on the machine
operation is essential to avoid possible personal injury
and equipment damage.

Most programming terminals provide some visible


means of alerting the user that a force is in effect.
Temporary
End (TND)
Instruction

Switch SW 13 is closed to
energize the TND
Normal program scan
instruction and stop all
scanning beyond this point.
MATH
INSTRUCTION
PLC math instructions allow you to perform arithmetic
functions on values stored in memory words.

For example, assume you are


using a counter to keep track of
the numbers of parts
manufactured and you would
like to display how many more
must be produced in order to
reach a certain quota. This
would require the data in the
accumulated value of the
counter to be subtracted from
the quota required.
ADD Instruction
The ADD instruction is an output instruction that
performs the addition of two values stored in the
referenced memory locations.

This instruction adds the value stored at Source A to


the value stored at Source B and stores the answer at
the Destination.
OMRON ADD Instruction
• ADD totals the data in 2 different
channels, or 1 channel and a constant and
then outputs the sum to a third channel.
• Therefore, 3 data parameters must be
specified; an augend, an addend and a
result channel.
OMRON ADD Instruction
• Au - augend,
• Ad - addend
• R - result
channel.
OMRON ADD Instruction
SUBTRACT Instruction
The SUBTRACT instruction is an output
instruction that subtracts one value from another
and stores the result in the destination address.

When rung conditions are true, the subtract instruction


subtracts source B from source A and stores the result
in the destination.
OMRON SUB Instruction
• SUB finds the difference between the data
in 1 channel and the data in another
channel or a constant, and then outputs
the result to a third channel.
• Therefore, 3 data must be specified: an
minuend, an subtrahend and a result
channel.
OMRON SUB Instruction
• Mi – minuend
• Su – subtrahend
• R – result
OMRON SUB Instruction
MULTIPLY Instruction
The MULTIPLY instruction is an output instruction
that multiplies two values and stores the result in
the destination address.

When rung conditions are true, the multiply instruction


multiplies source A by source B and stores the result
in the destination.
MULTIPLY Instruction
When the rung is true, the data in source A (the constant, 20) will
be multiplied by the data in source B (the accumulated value of
counter C5:10), with the result being placed in the destination
N7:2.

As with previous math instructions, sources A and B can be


values (constants) or addresses that contain values.
Simple MULTIPLY Program
DIVIDE Instruction
The DIVIDE instruction divides the value in source A
by the value in source B and stores the result in the
destination and math register.

If the reminder is 0.5 or greater, a round-up occurs in the


integer destination. The value stored in the math register
consists of the unrounded quotient (placed in the most
significant word) and the remainder (placed in the least
significant word). Some larger PLC's support the use of
floating-decimal as well as integer values.
DIVIDE Instruction
When the rung is true, the data in source A (the
accumulated value of counter C5:5) will be divided by
the data in source B (the constant 2), with the result
being placed in the destination N7:3.
Simple DIVIDE Program

You might also like