You are on page 1of 8

CIM & Automation Technology

Lecture 8 PLC Programming


Programming Methods

The three most commonly used methods for programming PLCs are:

Ladder diagram: A graphical programming language derived from the electrical


circuit diagrams for relay control systems.

S1 S2 Y1

S3

Instruction List: A textual programming language with mnemonic codes similar


to assembly language programs used in the programming of microprocessor
systems.

STR S1
OR S2
AND S3
OUT Y1

Function block diagram: A graphical programming language based on logic


gates derived from the logic diagrams for electronic circuits.

S1
S2
Y1
S3

Ladder Diagram

The ladder diagram is composed of a series of horizontal lines which resemble


the rungs of a ladder. The rungs are placed between two vertical power lines or
rails (e.g. 24V and 0V) which resemble the sides of a ladder. The next diagram
shows the electrical circuit for indirect control of a solenoid using a relay and
its implementation as a ladder diagram.

Rudie Coppieters Page 1 of 8


CIM & Automation Technology

S1 K1

K1 Y1

Electrical Diagram Ladder Diagram

The following conventions are used in drawing ladder diagrams:

The ladder diagram is read from left to right and from top to bottom (this is also
how it is scanned by the PLC).

Each rung must start with one or more inputs and must end with one output.

Inputs are shown in their normal or rest position e.g. a n/o switch is shown open
in the ladder diagram.

The same input contact may appear in several rungs of the ladder.

All the inputs and outputs are identified in the ladder diagram by their addresses.

Ladder Symbols

N/O Contact N/C Contact Output Coil Special Function

Instruction Lists

Some smaller PLCs require that the program be entered by a hand-held device
using commands similar to instruction lists. Typical mnemonics for the logic
instructions are:

STR : Start a new rung of logic NOT: N/C contact


AND: Contacts in series OR: Contacts in parallel
OUT: End a rung of logic

Rudie Coppieters Page 2 of 8


CIM & Automation Technology

Instruction Matsushita Siemens

STR ST A or O
STR NOT ST/ AN or ON
AND AN A
AND NOT AN/ AN
OR OR O
OR NOT OR/ ON
OUT OT =

Logic Functions

The basic logic functions examined previously using relays will now be
considered using PLCs. Ladder diagrams and instruction lists for the following
logic functions are shown using symbols for the inputs and outputs instead of
I/O addresses:

Identity function NOT function


OR function AND function
NAND function NOR function

S1 Y1
STR S1
OUT Y1

Identity function

S1 Y1
STR NOT S1
OUT Y1

NOT function

Rudie Coppieters Page 3 of 8


CIM & Automation Technology

S1 Y1
STR S1
OR S2
S2 OUT Y1

OR function

S1 S2 Y1
STR S1
AND S2
OUT Y1

AND function

S1 Y1

STR NOT S1
S2 OR NOT S2
OUT Y1

NAND function

S1 S2 Y1 STR NOT S1
AND NOT S2
OUT Y1

NOR function

Rudie Coppieters Page 4 of 8


CIM & Automation Technology

Latch

A PLC output may be latched or held on using a hold-on contact. The next
diagram shows the electrical circuit for indirect control of a solenoid using a
relay and its implementation as a ladder diagram. The relay is held on by the
hold-on contact K1 when S1 is pressed and the latch can be broken by pressing
S2. Note that in the ladder diagram the relay coil and contact K1 are not needed.

S1 S2 Y1

Y1

The previous ladder diagram for the latch is shown again together with a
modified version of the latching circuit. The instruction list for each of the
circuits has been added. An alternative version of the latching circuit is also
shown using a retentive coil with set (S) and reset (R) inputs.

S1 S2 Y1
STR S1
OR Y1
Y1 AND NOT S2
OUT Y1

Latch 1

S1 Y1
STR S1
OR ( Y1 AND
Y1 S2 NOT S2)
OUT Y1

Latch 2

Rudie Coppieters Page 5 of 8


CIM & Automation Technology

S1 Y1

S STR S1
S2 Y1 SET Y1
STR S2
RST Y1
R
Set and Reset

Internal Relays

Internal relays (or internal coils) are bits or memory locations within the PLC
which behave like relays. These can be switched on and off in the ladder
diagram like normal relays but do not produce external outputs from the PLC.
They are assigned addresses like real outputs and may be used to indirectly
control external devices connected to the PLC.

S1 IR1
STR S1
OUT IR1
STR IR1
IR1 Y1 OUT Y1

Internal Relay

Timers

Most PLCs have delay-on timers and some also have delay-off timers. Examples
of both delay-on and delay-off timers with timing diagrams are shown. The
delay-on timer starts timing when switch S1 closes. After 10 seconds the timer
contact TMR1 closes switching on the output Y1. The timer resets when switch
S1 opens. With the delay-off timer the output switches on and the timer starts
timing when switch S1 closes. After 10 seconds the timer contact TMR1 opens
switching off the output Y1. The timer resets itself when the contact TMR1
opens.

Rudie Coppieters Page 6 of 8


CIM & Automation Technology

Delay-on Timer Delay-off Timer

S1 TMR1
STR S1
TMR1
10s
K 10
TMR1 Y1 STR TMR1
OUT Y1

Delay-on Timer

S1 TMR1 Y1
STR S1
OR Y1
AND NOT TMR1
Y1 TMR1 OUT Y1
TMR1
K 10
10s

Delay-off Timer

Counters

Most PLCs have up counters and some also have down counters. An example of
an up counter with timing diagram is shown. The counter counts up by one each
time switch S1 closes and reopens. When the count reaches five the contact
CNT1 closes and switches on output Y1. The counter is reset by closing switch
S2.

Rudie Coppieters Page 7 of 8


CIM & Automation Technology

CNT1 5
S1

STR S1
S2 STR S2
CNT1
K 5
CNT1 Y1 STR CNT1
OUT Y1

Rudie Coppieters Page 8 of 8

You might also like