Chapter 4.1 Basics of PLC Programming - A - Siemens

You might also like

You are on page 1of 92

Chapter 4

Basics of PLC
Programming
Section 4.1

Processor Memory Organization


SIMATIC
S7-1500.
• Load memory:
Load memory is
non-volatile
memory for code
blocks, data blocks,
technology objects
and the hardware
configuration. This
load memory is
located on the
SIMATIC memory
card.

http://phenikaa-
uni.edu.vn
• Work memory: The
work memory is volatile
memory that contains
the code and data
blocks. The work
memory is integrated
into the CPU and cannot
be extended. Work
memory includes Code
work memory and Data
work memory.

http://phenikaa-
uni.edu.vn
• Retentive memory:
The retentive memory
is non-volatile
memory for saving a
limited amount of
data in the event of
power failure

http://phenikaa-
uni.edu.vn
• Additional memory areas include process images
and temporary local data.

http://phenikaa-
uni.edu.vn
 How to access to
data memory?

http://phenikaa-
uni.edu.vn
 How to access to
data memory?

http://phenikaa-
uni.edu.vn
An address is a label or number that
indicates where a certain piece of
information is located in memory.

Physic-based addressing
schemes are used with
Siemens SIMATIC S7.
Tag-based addressing is used with
SIMATIC S7 controllers.
SIMATIC S7 1500
addressing format.
SIMATIC S7 1500
addressing format.

Bit address: XXX.X

Byte address: XBX

IBa
Memory
Byte number
areas(I, Q, M…)
SIMATIC S7 1500
addressing format.

IWa

Word address: XWX

Memory
High byte number
areas(I, Q, M…)
SIMATIC S7 1500
addressing format.
ID a

IB a IB a+1 IB a+2 IB a+3

IW a IW a+2

Word address: XDX

Memory
High byte number
areas(I, Q, M…)
SIMATIC controllers consist of operating
system and user program
Code Blocks
Organization blocks
(OBs) forms the
interface between the
operating system of
the CPU and the user
program. The
organization blocks
determine the order
in which the user
program is executed.
Code Blocks
Functions (FCs) are
blocks without cyclic
data storages.
Code Blocks
Function block (FB)
is a code block with
static data. An FB
allows you to pass
parameters in the
user program.
Code Blocks
Data blocks (DBs) are
data areas in the user
program that contain
user data.
Section 5.2

Program Scan
During each program scan cycle, the processor
reads all the inputs, takes these values, and
energizes or de-energizes the outputs according to
the user program.
The time it takes to complete a scan cycle is a
measure of how fast the controller can react to
changes in inputs.

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.
The scan time is a function of:
• The speed of the processor module
• The length of the ladder program
• The type of instructions executed
• The actual ladder true/false conditions

The PLC computes the scan time each


time the END instruction is executed.

Typical scan time data include the


maximum scan time and the last scan time.
In a rung of a hardwired circuit there must
be electrical continuity in order for the load
to energize.

The rung has electrical continuity only when the


current flows is established in a path from one
side of the power rail to the other.
A PLC ladder logic rung is evaluated
in terms of logical continuity.

When there is a continuous path of true conditional


instructions in a rung, logical continuity exists;
accordingly the output instruction is true and the
status bit will be set 1 (ON).
Overview of the data flow during
the scan process.
Scan process applied to a single rung program.

I0.0 I0.0 Q0.0 Q0.0

I0.0 Q0.0
Scan process
applied to a
multiple rung
program.
Vertical versus horizontal scan patterns.
Section 4.3

PLC Programming Languages


PLC programming language refers to the method
by which the user communicates information to
the PLC.

Standard PLC programming languages


Ladder Diagram programming is a symbolic
depiction of instructions arranged in rungs
similar to ladder-formatted schematic diagrams.

Hardwired relay
control circuit

Equivalent ladder
diagram program
Instruction list programming language consists
of a series of instructions that refer to the basic
AND, OR, and NOT logic gate functions.

Hardwired relay
control circuit

Equivalent instruction
list program
Functional block diagram programming uses
instructions that are programmed as blocks wired
together to accomplish certain functions.
Ladder diagram and functional block diagram
programming used to produce the same logical
output.

Ladder diagram

Equivalent
function block
diagram.
Sequential
function chart
programming
language is
similar to a
flowchart of
your process.

The program is split into


steps with multiple
operations happening in
parallel branches.
Structured text is a high level language primarily
used to implement more complex procedures.

Ladder diagram

Equivalent
structured text
program.
Section 4.4

Bit-Level Logic Instructions


Section 4.4.1

Bit-Level Logic Instructions


The ladder diagram language is a symbolic set
of instructions used to create the controller
program.

Representations of contacts and coils are the basic


symbols of the logic ladder diagram instruction set.
Each symbolic instruction is a command to
perform a specific operation.

The symbols are arranged to obtain the


desired control logic that is to be entered
into the memory of the PLC.
The normally open contact (NO) instruction looks
and operates like a normally open relay contact.

Normally open contact

Associated with each NO


instruction is a memory bit
linked to the status of an
input device or an internal
logical condition in a rung.
The memory bit is set to 1 or 0 depending on the
status of the input.
A 1 corresponds to a true status or on condition.

I0.4

I0.4

If the instruction memory bit is a 1 (true) this


instruction will allow rung continuity through itself,
like a closed relay contact.
A 0 corresponds to a false status or off condition.

I0.4

I0.4

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.
Normally Open Contact

The normally open


(NO) contact is closed
(ON) when the assigned I0.4

bit value in memory is


equal to 1 I0.4

I0.4

I0.4

http://phenikaa-
uni.edu.vn
Normally Open Contact

The normally open


(NO) contact is
closed (ON) when
the assigned bit
value in memory is
equal to 1

http://phenikaa-
uni.edu.vn
Simulated NO instruction operation.
The Normally Closed Contact (NC)
instruction looks and operates like
a normally closed relay contact.

Normally Closed Contact

This instruction asks the PLC’s processor to examine


if the contact is open.

The normally closed (NC) contact is open (ON) when the


assigned bit value is equal to 1.
As with any other input the memory bit is set to 1 or 0
depending on the status of the input. A 1 corresponds to
a true status or on condition.

I0.4

I0.4

The instruction is interpreted as false when the bit is


1 and will not allow rung continuity through itself.
A 0 corresponds to a off condition.

I0.4

I0.4

The instruction is interpreted as true when the bit is


0 and will not allow rung continuity through itself.
The normally closed
(NC) contact is open
(ON) when the
assigned bit value is
equal to 1

http://phenikaa-
uni.edu.vn
Simulated NC instruction operation.
Quiz
For the input module of
beside figure, the data
stored in the bit
corresponding to the open
switch would be ___ and
that for the closed switch
would be ___ respectively.

a) 1, 1
b) 0, 1
c) 0, 0
d) 1, 0
http://phenikaa-
uni.edu.vn
The Output instruction looks and operates like
a relay coil.

This instruction signals the PLC to energize


(switch on) or de-energize (switch off ) the output.

 If power flows through the output coil, then that output-


coil memory bit is set to 1.
 If power will not flow through that output coil, then
that output coil memory bit is set to 0.
Output
instruction is set
to 1 to energize
I0.1 I0.4 Q0.1 Q0.1
the output.

A true logic
path is
I0.1
established by
I0.4
the input
instructions in
the rung.
Simulated Output instruction
operation.
Action of the field device and PLC bit.
A signal
present
makes the
NO bit (1)
true; a signal
absent makes
the NO bit
(0) false. The
reverse is
true for an
NC bit.
Simulated operation of the field input
device and the PLC bit.
The main function of the ladder logic diagram
program is to control outputs based on input
conditions.
Each contact or coil symbol is referenced with an
address that identifies what is being evaluated and
what is being controlled.

The same contact I0.1 I0.2 I0.3 Q0.1

instruction can be
used throughout the Q0.1

program whenever
I0.2 I0.4 Q0.2
that condition needs
to be evaluated.
For an output to be activated or energized, at least
one left-to-right true logical path must exist.

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 instruction are said to be
true.
Simulated operation of logic continuity.
Section 4.4.2

Branch Instructions
Branch instructions are used to create parallel
paths of input condition instructions.

The rung will be


true if either
instruction
A or B is true.
Simulated branch instructions.
Parallel branches can be used to allow more than
one combination of input conditions.

Either A and not B, or C provides logical


continuity and energizes output D.
Simulated program, either A and not B, or C
provides logical continuity and energizes output D.
Output branching allows a true logic path to
control multiple outputs.

Either A or B provides a
true logical path to all
three output instructions:
C, D, and E.

Additional input
instructions can be
programmed in the
output branches.
Simulated program, either A or B provides a true
logical path to all three output instructions: C, D,
and E.
Input and output branches can be nested to avoid
redundant instructions and to speed up processor
scan time.

A nested branch starts or ends within another branch.


In some PLC models, the
programming of a nested
branch cannot be done
directly.

It is possible, however,
to program a logically
equivalent branching
condition.
There may be limitations to the number of series
contact instructions that can be included in one
rung of a ladder diagram as well as limitations to
the number of parallel branches.
The PLC will not allow
for programming of
vertical contacts.

Boolean equation: Y = (AD) + (BCD) + (BE) + (ACE)

Reprogrammed to eliminate
vertical contact.
The processor examines the ladder logic rung for logic
continuity from left to right.

If programmed as shown,
contact combination
FDBC would be ignored.

Boolean equation: Y = (ABC) + (ADE) + (FE) + (FDBC)

Reprogrammed circuit.
Section 4.4.3

Internal Relay Instructions


An internal output does not directly
control an output field device.

M0.3

The advantage of using internal outputs is that there


are many situations in which an output instruction is
required in a program but no physical connection to a
field device is needed.
Internal relay used for a program that requires
more series contacts than the rung allows.

M0.3

M0.3

This PLC allows for only 7 series contacts when 12


are actually required for the programmed logic.
Simulated internal relay program.
Section 4.4.4

Programming
Normally Open Contact and
Normally Closed Contact
Instructions
Normally Open Contact instruction

Both the NO and the NC pushbuttons are represented in


the program by the Normally Open Contact instruction.
The normal state of the field input device (NO
or NC) does not matter to the controller.

What matters is that contacts need to closed to energize


the output.
Simulated Normally Open Contact instruction
Normally Closed Contact instruction

The pushbutton is represented in the user program


by an Normally Closed Contact instruction.

This is because the rung must be true when the


external pushbutton is open and false when the
pushbutton is closed.
Simulated Normally Closed Contact instruction
The logic states (0 or 1) indicate whether an instruction
is true or false and is the basis of controller operation.

Normally Open Normally Closed Output Coil


Contact Contact
The time aspect relates to the repeated scans of the
program, wherein the input table is updated with
the most current status bits.
Section 4.4.4

Other Bit Logic Instructions


NOT logic inverter

The LAD NOT contact inverts the logical state of


power flow input.
 If there is no power flow into the NOT contact,
then there is power flow out.
 If there is power flow into the NOT contact, then
there is no power flow out.
Set and Reset Instructions

 When S (Set) is activated, then the data value at


the OUT address is set to 1. When S is not
activated, OUT is not changed.

 When R (Reset) is activated, then the data value


at the OUT address is set to 0. When R is not
activated, OUT is not changed.
Set and Reset Bit Field

 When SET_BF is activated, a data value of 1 is


assigned to "n“ bits starting at address OUT. When
SET_BF is not activated, OUT is not changed.

 RESET_BF writes a data value of 0 to "n" bits


starting at address OUT. When RESET_BF is not
activated, OUT is not changed.
Set and Reset Bit Field

 RS is a set dominant latch where the set dominates.


If the set (S1) and reset (R) signals are both true,
the output address OUT will be 1.

 SR is a reset dominant latch where the reset


dominates. If the set (S) and reset (R1) signals are
both true, the output address OUT will be 0.
Positive and Negative edge Instructions

The state of this contact is TRUE when a positive


transition (OFFto-ON) is detected on the assigned "IN"
bit. The contact logic state is then combined with the
power flow in state to set the power flow out state. The P
contact can be located anywhere in the network except
the end of a branch.
Positive and Negative edge Instructions

The state of this contact is TRUE when a negative


transition (ONto-OFF) is detected on the assigned
input bit. The contact logic state is then combined
with the power flow in state to set the power flow out
state. The N contact can be located anywhere in the
network except the end of a branch.

You might also like