5 Basics of PLC Programming (1)
5 Basics of PLC Programming (1)
Basics of PLC
Programming
Lecture 5
Contents
Contents
1
2/19/25
Memory organization
Memory Organization
2
2/19/25
Memory Organization
Program files
Program files
3
2/19/25
Data files
Data files
• These files are organized by the type of data they
contain and may include:
• Output (file 0) —This file stores the state of the
output terminals for the controller.
• Input (file 1) —This file stores the status of the input
terminals for the controller.
• Status (file 2) —This file stores controller operation
information and is useful for troubleshooting
controller and program operation.
• Bit (file 3) —This file is used for internal relay logic
storage.
• Timer (file 4) —This file stores the timer
accumulated and preset values and status bits.
Data files
Data files
4
2/19/25
Data files
Data files
Scanning
Program Scan
• When a PLC executes a program, it must know—in real time—when external devices
controlling a process are changing.
• During each operating cycle, the processor reads all the inputs, takes these values,
and energizes or de-energizes the outputs according to the user program.
• This process is known as a program scan cycle.
• Figure illustrates a single PLC operating cycle consisting of the input scan, program
scan, output scan, and housekeeping duties.
• Because the inputs can change at any time, it constantly repeats this cycle as long as
the PLC is in the RUN mode.
10
5
2/19/25
Scanning
Program Scan
• The time it takes to complete a scan cycle is called the scan cycle time and indicates how
fast the controller can react to changes in inputs.
• The time required to make a single scan can vary from about 1 millisecond to 20
milliseconds. If a controller has to react to an input signal that changes states twice during
the scan time, it is possible that the PLC will never be able to detect this change.
• For example, if it takes 8 ms for the CPU to scan a program, and an input contact is opening
and closing every 4 ms, the program may not respond to the contact changing state.
• The CPU will detect a change if it occurs during the update of the input image table file, but
the CPU will not respond to every change.
• The scan time is a function of the following:
• The speed of the processor module
• The length of the ladder program
• The type of instructions executed
• The actual ladder true/false conditions
11
Scanning
Program Scan
• The scan is normally a continuous and sequential process of reading the status of
inputs, evaluating the control logic, and updating the outputs.
• There are two basic scan patterns that different PLC manufacturers use to
accomplish the scan function.
• Allen-Bradley PLCs use the horizontal scan by rung method. In this system, the
processor examines input and output instructions from the first command, top left
in the program, horizontally, rung by rung.
• Modicon PLCs use the vertical scan by column method. In this system, the processor
examines input and output instructions from the top left command entered in the
ladder diagram, vertically, column by column and page by page.
• Pages are executed in sequence. Both methods are appropriate; however,
misunderstanding the way the PLC scans a program can cause programming bugs.
12
6
2/19/25
PLC Language
13
PLC Language
14
7
2/19/25
PLC Language
15
PLC Language
16
8
2/19/25
Relay Instructions
Relay-Type Instructions
• Representations of contacts and coils are the basic symbols of the logic ladder diagram instruction set.
• The three fundamental symbols that are used to translate relay control logic to contact symbolic logic
are Examine If Closed (XIC), Examine If Open (XIO), and Output Energize (OTE).
• Each of these instructions relates to a single bit of PLC memory that is specified by the instruction’s
address.
• The symbol for the Examine If Closed (XIC) instruction is shown in Figure. The XIC instruction, which is
also called the Examine-on instruction, looks and operates like a normally open relay contact.
• Associated with each XIC instruction is a memory bit linked to the status of an input device or an
internal logical condition in a rung. This instruction asks the PLC’s processor to examine if the contact
is closed.
17
Relay Instructions
Relay-Type Instructions
• It does this by examining the bit at the memory location
specified by the address in the following manner:
i. The memory bit is set to 1 or 0 depending on the status
of the input (physical) device or internal ( logical) relay
address associated with that bit.
ii. A 1 corresponds to a true status or on condition.
iii. A 0 corresponds to a false status or off condition.
iv. When the Examine-on instruction is associated with a
physical input, the instruction will be set to 1 when a
physical input is present (voltage is applied to the input
terminal), and 0 when there is no physical input present
(no voltage applied to the input terminal).
18
9
2/19/25
Relay Instructions
Relay-Type Instructions
v. When the Examine-on instruction is associated by
address with an internal relay, then the status of the
bit is dependent on the logical status of the internal
bit with the same address as the instruction.
vi. If the instruction memory bit is a 1 (true) this
instruction will allow rung continuity through itself,
like a closed relay contact.
vii. If the instruction memory bit is a 0 (false) this
instruction will not allow rung continuity through
itself and will assume a normally open state just like
an open relay contact.
19
Relay Instructions
Relay-Type Instructions
• The symbol for the Examine If Open (XIO) instruction is shown in Figure.
20
10
2/19/25
Relay Instructions
Relay-Type Instructions
• When the Examine-off instruction is used to examine a physical input, then
the instruction will be interpreted as false when there is a physical input
(voltage) present (the bit is 1) and will be interpreted as true when there is
no physical input present (the bit is 0).
• If the Examine-off instruction were associated by address with an internal
relay, then the status of the bit would be dependent on the logical status of
the internal bit with the same address as the instruction.
• Like the Examine-on instruction, the status of the instruction (true or false)
determines if the instruction will allow rung continuity through itself, like a
closed relay contact.
• The memory bit always follows the status (true = 1 or false = 0) of the input
address or internal address assigned to it. The interpretation of that bit,
however, is determined by which instruction is used to examine it.
• Examine-on instructions always interpret a 1 status as true and a 0 status as
false, while Examine-off instructions interpret a 1 status as false and a 0
status as true.
21
Relay Instructions
Relay-Type Instructions
• The symbol for the Output Energize (OTE) instruction is shown in Figure.
• The OTE instruction looks and operates like a relay coil and is associated with a
memory bit.
• This instruction signals the PLC to energize (switch on) or de-energize (switch off )
the output.
• The processor makes this instruction true (analogous to energizing a coil) when
there is a logical path of true XIC and XIO instructions in the rung.
• The operation of the Output Energize instruction can be summarized as follows:
22
11
2/19/25
Relay Instructions
Relay-Type Instructions
• The status bit of the addressed Output
Energize instruction is set to 1 to energize the
output and to 0 to de-energize the output.
• If a true logic path is established with the input
instructions in the rung, the OTE instruction is
energized and the output device wired to its
terminal is energized.
• If a true logic path cannot be established or
rung conditions go false, the OTE instruction is
de-energized and the output device wired to it
is switched off.
23
Relay Instructions
Relay-Type Instructions
• The main function of the ladder logic diagram program is to
control outputs based on input conditions, as illustrated in
Figure.
• This control is accomplished through the use of what is referred
to as a ladder rung.
• In general, a rung consists of a set of input conditions,
represented by contact instructions, and an output instruction at
the end of the rung, represented by the coil symbol.
• Each contact or coil symbol is referenced with an address that
identifies what is being evaluated and what is being controlled.
• The same contact instruction can be used throughout the
program whenever that condition needs to be evaluated.
• The number of ladder logic relays and input and output
instructions is limited only by memory size.
• Most PLCs allow more than one output per rung.
24
12
2/19/25
Relay Instructions
Relay-Type Instructions
• For an output to be activated or energized, at least
one left-to-right true logical path must exist, as
illustrated in Figure.
• A complete closed path is referred to as having
logical continuity. When logical continuity exists in
at least one path, the rung condition and Output
Energize instruction are said to be true.
• The rung condition and OTE instruction are false if
no logical continuity path has been established.
• During controller operation, the processor
evaluates the rung logic and changes the state of
the outputs according to the logical continuity of
rungs.
25
1. Seal-in Circuit
• A Seal-in circuit is a method of maintaining current flow
after a momentary switch has been pressed and
released.
• Consider a Relay is used to control the power supply to a
motor. Here we are calling this relay as “Motor Starter
Coil”. This Relay another NO contact is used to seal-in or
latch the start signal.
• As start push button is a push & release type i.e., signal
will be available for some time say momentarily and
then signal will be lost.
• So, we have to latch this circuit in order to make motor
run continuously even after release of start push button.
• For this purpose, we are using Relay (M) NO contact
across Start push button such that it will take care of
start signal after start button is released.
26
13
2/19/25
1. Seal-in Circuit
• The seal-in auxiliary contact (NO Contact) of the
starter (M) is connected in parallel with the start
button to keep the starter coil (M) energized when
the start button released.
• After Start Push button pressed : The Motor starter
coil energized, and its NO contact becomes NC as
shown in below figure.
• During Starting, Start push button will give the
signal to energize the coil (M), after that coil NO
contact which is connected across.
• Start Push button will be used to latch the start
signal as start push button will be released after
pressing ( start button are momentary type ).
27
2. State/fault coil
• The State Coil (sometimes called a Memory Coil) is an
extension to the Sealed in Coil pattern.
• The pattern consists of a trigger condition, a coil, with a
contact from the coil branching around the trigger
condition to “seal itself in”, and then some other
condition to “break the seal”.
• Like the Sealed in Coil, the State Coil will always revert
to a de-energized state if the PLC loses power or the
program is reset.
• However, unlike the Sealed in Coil, the State Coil turns
on and off during normal operation of the program.
• The purpose of this pattern is to remember a single
true/false condition representing internal state of the
machine.
28
14
2/19/25
2. State/fault coil
• You will commonly see the State Coil pattern to represent a
“Fault” condition. Let’s say you have a “fault” with the
machine (i.e. something that must cause the machine to
stop, and the condition must be reported to the operator,
and they must acknowledge it).
• In this example, the “fault condition” is the “Trigger”
contact in the logic above.
• For example, it might be an over-temperature sensor on a
motor.
• When the over-temperature sensor indicates a fault, it
energizes the Fault (State Coil), and the Fault stays
energized.
• A contact from this Fault coil is typically used to stop the
machine (or at least the motor) to prevent damage to the
machine.
29
2. State/fault coil
• Another contact from this coil might be used to drive
an alarm light, or a message on a screen to notify the
operator of the problem.
• Finally, a “fault reset button” would act as the Break
Condition to break the seal and reset the fault.
• Notice that if the fault condition is still “active” (i.e.
the over-temperature switch is still indicating an
over-temperature condition) then the Fault will stay
sealed in.
• This is what someone means when they say that “a
fault must be cleared before it can be reset.”
30
15
2/19/25
3. Start/Stop Circuit
• This pattern is an extension to the Sealed in Coil pattern
and is similar to the State Coil.
• However, where the State Coil is “trigger dominant” (i.e.
the Trigger condition takes priority over the Break
Condition), the Start/Stop Circuit is “stop dominant”.
• Like the Sealed in Coil, the Run coil will always revert to a
de-energized (off) state if the PLC is turned off, or if the
ladder logic program is reset.
• That’s a useful property because when starting up the
machine we likely want motors, etc., to be in the off
state until the logic decides to start them.
• If the operator pushes the Start button, then the Run coil
will turn on, and it seals itself in until the operator
pushes the Stop button.
31
3. Start/Stop Circuit
• The reason that this pattern is “stop dominant” is that we
want the Stop condition to take priority over the Start
condition in the case where both signals are active.
• Imagine a case where the Start condition was stuck on for
some reason.
• At least the operator could stop the motor, etc., by holding
the Stop button on until they can turn the machine off with
the main switch.
• The reason the buttons are wired this way is so that if the
wire to the Stop button becomes disconnected or power to
the Stop button is lost, then the machine will act as if the
Stop button has been pressed, and the motor, etc., will
stop.
• This is presumably a safer condition than allowing the
motor to continue running without the ability to stop it.
32
16
2/19/25
4. Set/Reset Circuit
• The Set/Reset pattern, also known as the Latch/Unlatch
pattern or simply “Latch Bit” is for remembering some
on/off state of the machine that has to survive a power
outage.
• Note that in an Allen-Bradley PLC, you will see the terms
Latch (L) and Unlatch (U) used instead of Set and Reset.
• In the logic shown above, this is a “reset dominant”
Set/Reset.
• That’s because if both the Set and Reset conditions are
active at the same time, the memory will be reset.
• Of course, you can make this “set dominant” by simply
reversing the logic.
33
4. Set/Reset Circuit
• The Set/Reset pattern is often used for part tracking in a machine.
• Imagine you have a machine where a robot places a part into a fixture, and
then some manufacturing operation is performed to that part (like a
grinding or milling operation), and then another robot removes the part
from the fixture, moving it to the next station.
• Ideally there will be a sensor in the fixture to indicate if a part is present.
• You will need some way to “remember” the status of the manufacturing
operation performed on that part.
34
17
2/19/25
4. Set/Reset Circuit
• First, you will need a Set/Reset to remember that the manufacturing
operation has been started, and secondly you will need another Set/Reset
to remember that the manufacturing operation has been completed.
• In the event of a power outage, the machine can then recover: if neither
memory is on, then you still need to perform the manufacturing operation
on the part, and if both are on then you just need to remove the part from
the fixture.
• If the Started memory is on but the Finished memory is off, then you may
need to scrap the part, or you may be able to continue the operation.
35
5. Step Circuit
• The logic for each Step is simple:
• You can combine any number of steps to form a
Sequence.
• The steps will execute sequentially. When the Step
In Progress, coil turns on, this should be the signal
to actuate a mechanism somewhere else in the
program.
• For instance, if the Step is “Extend Cylinder” then
a contact from the Step In Progress coil could be
used to turn on the pneumatic valve to extend the
cylinder.
• The Step stays active (i.e. the Step In Progress coil
stays on) until the Step Done condition is true.
• In the example of extending the cylinder, the Step
Done condition could be the Cylinder Extended
input.
36
18
2/19/25
5. Step Circuit
• Here is an example of a two step sequence. Step 1 is
“Extend Cylinder” and Step 2 is “Retract Cylinder”:
• The Sequence Start condition is what initiates the
sequence.
• This should be something like “the machine is in Auto
Mode, an Auto Cycle is running, a part is present, and the
part hasn’t been processed yet”.
• When the sequence is complete, then the Sequence
Complete coil turns on.
• This can be used in combination with the Set/Reset pattern
to latch a memory bit to indicate that the part has been
processed.
• Presumably this causes another sequence to begin, such as
an Unload Part sequence.
• Alternatively we might just wait for the operator to remove
the part.
37
6. Mission Circuit
• The Mission Ladder Logic Programming Pattern is
used for higher level decision making in a
machine.
• While many machines are so simple that they only
have one sequence of steps for their Automatic
Mode, some are more complex.
• A good example of such a complex machine is
an Automated Storage and Retrieval System or
AS/RS.
• This type of machine can perform several tasks,
such as storing incoming bins of material in the
storage racks, or picking up bins from storage and
bringing them to an outgoing station.
• It’s typical to break these kinds of problems into
smaller tasks, such as:
38
19
2/19/25
6. Mission Circuit
• Pick up bin from incoming station
• Place bin in storage location X
• Retrieve bin from storage location X
• Place bin in outgoing station
• In the Mission pattern, each of these higher level
tasks is called a “Mission”.
• The logic is responsible for choosing the
appropriate mission to perform next, and monitor
for the completion of that mission, or abort the
mission if appropriate.
39
7. Mode Circuit
• Most machines have a mode selection mechanism,
and the most common modes are Auto(matic) and
Manual:
• The Auto/Manual Mode pattern above has two useful
properties:
• At program start, since the Auto Mode coil will default
to Off, Manual Mode will be on
• The system can never be in both Auto Mode and
Manual Mode at the same time
• The first property is important because we never want
a system to start up in Automatic Mode. It’s always
safer to start in Manual Mode and have the operator
request Auto Mode.
• The second property is one we want for all Mode
systems: only one mode can be active at a time
40
20