You are on page 1of 162

Logic Control

What is Logic control


Logic control is a control based on a logic
concept, that is the on-off state of variable
and/or equipment
Logic control is often used to control
combinational and/or sequential events such as
lift control, automatic production line, engine
start-up, etc.
Originally used device such as switches, relay,
timer, drum, and any other mechanism to enable
changes of the on-off state

SWITCHES

Toggle Hand Switches

~
Single pole single throw (SPST)

Toggle Hand Switches

~
Single pole double throw SPDT switches

Toggle Hand Switches


DPST

DPDT

Hand Switches
3PST

Rotary
Swtich

Push button Hand Switches

Normally open
NO

Normally close
NC

Push-Push Switch
This looks like a momentary action push switch but
it is a standard on-off switch:
push once to switch on,
push again to switch off.

This is called a latching action.

Microswitch
usually SPDT
Microswitches are designed
to switch fully open or
closed in response to small
movements.
They are available with
levers and rollers attached.

Keyswitch
A key operated
switch.
The example shown
is SPST.

Reed Switch
Usually SPST
The contacts of a reed switch
are closed by bringing a small
magnet near the switch.
They are used in security
circuits, for example to check
that doors are closed.
Standard reed switches are
SPST (simple on-off) but SPDT
(changeover) versions are also
available.
reed switches have a glass
body which is easily broken!

DIP Switch
DIP = Dual In-line Parallel
This is a set of miniature
SPST on-off switches, the
example shown has 8
switches.
The package is the same
size as a standard DIL
(Dual In-Line) integrated
circuit.
This type of switch is
used to set up circuits,
e.g. setting the code of a
remote control.

Multi-pole Switch
The picture shows a 6pole double throw switch,
also known as a 6-pole
changeover switch.
It can be set to have
momentary or latching
action.
Latching action means it
behaves as a push-push
switch, push once for the
first position, push again
for the second position
etc.

Multi-way Switch
Multi-way switches have 3 or more conducting positions.
They may have several poles (contact sets). A popular
type has a rotary action and it is available with a range of
contact arrangements from 1-pole 12-way to 4-pole 3
way.
The number of ways (switch positions) may be reduced
by adjusting a stop under the fixing nut. For example if
you need a 2-pole 5-way switch you can buy the 2-pole
6-way version and adjust the stop.

Process Operated Switches


These switches is constructed using one of the
above switches. A process variable will initiate a
displacement to switch the switch

Limit switch
Proximity switch
Pressure switch
Level switch
Temperature switch
Flow switch
etc

SWITCH CAPACITY
On a switch usually there is a label informing the voltage
and current capacity, e.g.:
250 V
5A
It means that:
the maximum current allowed to pass the switch is 5 A.
The maximum voltage across its terminal allowed is 250 volt
I<5 A

~V<250 V

RELAY

Relay
NC contact
NO contact
coil

RELAY

A relay is an electrically
operated switch.
Current flowing through the coil
of the relay creates a magnetic
field which attracts a lever and
changes the switch contacts.
The coil current can be on or off
so relays have two switch
positions and they are double
throw (changeover) switches.
Relay consist of coil and contact
Usually a relay has 1 coil and
many contacts both NO and NC

Relay

Picture is downloaded from www.kpsec.freeuk.com/components/relay.htm

Relay

In electrical diagram relay is symbolized as shown


A relay can have many contacts both NO and NC
The coil of a relay typically passes 30mA for a 12V relay,
The contacts can drive 5A or more depending on the size of
relay
contacts
coil

NO

NO

NO

NO

NC

NC

RELAY SYMBOL WITH 8 CONTACTS

NC

NC

Relay
30 mA
R11

R1

12 V

R12

5A
~ 220V

Relays allow one circuit to switch a second circuit


which can be completely separate from the first.
For example a low voltage battery circuit can use a
relay to switch a 220V AC mains circuit.
There is no electrical connection inside the relay
between the two circuits, the link is magnetic and
mechanical. N

Ladder diagram

Ladder Diagram
To make such as previous diagram easier
to read a ladder diagram is used
+

S
R1

R11

Basic logic
+

AND LOGIC

s1

s2
L

Lamp L will light if switch s1 and s2 are on.


In logic on usually symbolized as 1 and off as 0.

s1
0

s2
0

L
0

Mathematically written as
L = S1 AND S2

Basic logic
+

OR LOGIC

s1
L

s2

Lamp L will light if switch s1 OR s2 are on.

s1
0

s2
0

L
0

Mathematically written as
L = S1 OR S2

Basic logic
NOT LOGIC

s1
R1
R11
L

Lamp L will light if not R1 is on

R1
0

L
1

Mathematically written as
L = NOT(R1)

Combinational logic
Suppose you want to design a safe car with the following criteria:
The gear box (GB) will not engage unless:
1. The safety belt (SB) is fastened and the doors (D1-D4) are locked or
2. The safety system is disable by switching on override switch (OS) for
maintenance purpose
Mathematically the above logic is written as
GB = (SB AND D1 AND D2 AND D3 AND D4) OR OS

SB

D1

D2

D3

D4
GB

OS

Motor Start Stop (sequential logic)


The following ladder diagram is used to
switch a motor on and off
S1

S2
R1

start

stop

R11

R12

R13

motor
Latching action

R14

Auto start of water pump


Suppose that the motor is
used to drive water pump
and we want that the
pump can run or stop
automatically depending
on the water level
In addition we also want
to override the automatic
control using manual start
and sop control

LS

Auto start of water pump


Off, manual and auto motor control
O
M
A

S2

S1

R1
start

stop

motor
R11
LS

Permissive circuits
Often it is desired that a piece of equipment is
allowed to start if several conditions are met.
For example overload switch and over
temperature switch must be closed in order the
motor can be started
Each process condition is called a permissive,
and each permissive switch contact is wired in
series, so that if any one of them detects an
unsafe condition, the circuit will be opened.

Auto start of water pump with


protection
Suppose we want to protect the motor against over load
and over temperature
O
S0

S2

S1

Permissive
circuits
R1

start

stop

OL

R11
LS

motor

OT

Interlock circuits
Often it is desired that only one piece of
equipment is allowed to start if all other
equipments are in off condition.
For example push button circuit used in Quiz
show program where several contestant have to
answer a question.
The first one who pushes the push button will
disable the others push button switch
This circuit is called interlock since acting one
circuit will lock the others to function

Push Button In Quiz Show program


A
B

R12

R22
R13
R23

R21

R11

R1

R2

LA

LB

Push Button In Quiz Show program


A

R21

R31

R11

R31

R14

R24

R12
R22
R32
R13
R23
R33

R1
R2
R3

LA
LB
LC

Push Button In Quiz Show program


Instead of pushing
the PB continually
it is desired that
just pushing once
is enough for the
contestant to claim
that they are the
first team pushing
the button
The presenter must
push the reset
button to reset the
system back to
original state

Reset

R21

R11

R1

R12

R2

R22
R13
R23
R14
R23

LA
LB

Interlock
Another example of interlock is the forward circuit of motor
must prevent the reverse circuit, otherwise the motor will
damage

Note:
Motor contactor (or "starter") coils are typically designated by the letter "M"
in ladder logic diagrams.

Time delay relay

If the motor is carry a high inertia load it is dangerous to reverse the


direction of the motor instantaneously.
Time delay relay can be installed to prevent such occurrence to
happen

Fail safe design


Consider an alarm system
as shown.
It can be design in 2 ways
Both ways work exactly in
the same manner
The second design
however gives fail save
design.
Murphys law is true. If
something can go wrong
it will.

PLC

Programmable logic controllers


Before the advent of solid-state logic circuits, logical
control systems were designed and built exclusively
around electromechanical relays.
Relays are far from obsolete in modern design, but have
been replaced in many of their former roles as logic-level
control devices, relegated most often to those
applications demanding high current and/or high voltage
switching.
Systems and processes requiring "on/off" control abound
in modern commerce and industry, but such control
systems are rarely built from either electromechanical
relays or discrete logic gates. Instead, digital computers
fill the need, which may be programmed to do a variety
of logical functions.

Programmable logic controllers


In the late 1960's an American company named Bedford
Associates released a computing device they called the
MODICON. As an acronym, it meant Modular Digital
Controller, and later became the name of a company
division devoted to the design, manufacture, and sale of
these special-purpose control computers.
Other engineering firms developed their own versions of
this device, and it eventually came to be known in nonproprietary terms as a PLC, or Programmable Logic
Controller.
The purpose of a PLC was to directly replace
electromechanical relays as logic elements with a solidstate digital computer with able to emulate the
interconnection of many relays to perform certain logical
tasks.

Programmable logic controllers


~220VAC

A PLC has many "input" terminals


(X), many output terminals (Y).
The input-output relation is
programmable
To make PLCs easy to program,
their programming language was
designed to resemble ladder logic
diagrams.
Thus, an industrial electrician or
electrical engineer accustomed to
reading ladder logic schematics
would feel comfortable
programming a PLC to perform
the same control functions.

Programmable logic controllers


+

A
S1
S2

B
C

Suppose that the PLC is wired as shown and we


want that :
Lamp A will light if S1 AND S2 is pushed
Lamp B will light if S1 OR S2 is pushed
Lamp C will light if S1 EXOR S2 is pushed

Programmable logic controllers


+

A
S1

S2

X3

X4
Y1

LA=X3 AND X4

Y3

LB =X3 OR X4

X3
X4

Programmable logic controllers


+

A
S1

S2

X3

X4
Y5

X4

X3

LC=X3 EXOR X4

Processors Structure
Display block

Proc

RAM
memory

Digital
Processing

Flash
EPROM

COMM

IO MODULES

Processors TSX 37-10

RU
N
TER
I/O
ER
R
Terminal port TER
BAT
RESET button
Power Supply
Optional Battery

Processors TSX 37-21/22


MINI extension
rack

BASE

Standard
format
module

Half format
module

Application Memory Structure on TSX 3710/21/22


Using PCMCIA
Without Memory Card
Memory Card
Data
Program

Protected
Internal RAM

Data

Constants
Backup copy
of Program
and
Constants

Internal
Flash
EPROM

Program
PCMCI
A card

Constants

TSX Micro
Discrete I/O
12 I
8I
ter. blk. HE10

64 I/O
HE10

28 I/O 28 I/O
ter. blk. HE10

8O
8O
ter. blk. HE10

8I
ter. blk.

4O
ter. blk.

TSX Micro
Remote discrete I/O on TSX 07 link
Exchanges between Applications
%IW,
%QW
addr. 1
ATS05

ATS05

%I
%Q
remote I/O
200 m. max.

ATS05

ATS05

TSX Micro
"TELEFAST" I/O Interface

TELEFAST I/O

TSX Micro
Analog I/O

Analog I/O in
module

8 Inp
12 bits
0-10 V 4-20 mA
or
+ 10 V 0-20 mA

4 Inp
4 Outp
2 Outp
16 bits
11 bits + sign
11 bits + sign
differential
+ 10 V
+ 10 V
multirange
0-20 mA or 4-20 mA

TSX
Premium

FIELDBUS

Controllers / Gateways / Masters

MACHINE
Standard sensors
Man-machine interface
Interfaces

7 8 9
4 5 6
1 2 3
+ 0

Interfaces

ENCLOSURE

1
2
3
4

Intelligent sensors

Motor starters

Power
supply

Software

PL7 Junior Main Screen

PL7 Junior File Menu

PL7 Junior Tools Menu

PL7 Junior PLC Menu

PL7 Junior Toolbar


NEW FILE
OPEN FILE

SAVE FILE

PRINT

Creating or Editing a File

PL7 Junior Hardware Configuration

PL7 Junior Hardware Configuration

PL7 Junior - Configuring Power Supply

PL7 Junior - Configuring Processor

PL7 Junior I/O Configuration

Single Task Software Structure


Watchdog time

Periodic Execution

Period time

I.P

I.P

I.P

%I

%I

%I

Program
Processing

Program
Processing

%Q

%Q

Program
Processing

I.P

I.P

Elapsed
time
Scan n
Elapsed
time
Scan n+1
Elapsed time
Scan n+2
%Q

%S19 set

Single Task Software Structure


Watchdog time

I.P

I.P

I.P

%I

%I

%I

Program
Processing

Program
Processing

%Q

%Q

I.P

I.P

Program
Processing

Watchdog with periodic


execution

Elapsed
time
Scan n
Elapsed
time
Scan n+1
PLC STOP
IMMEDIATELY
OVERRUN
OCCURED

Multitask Software Structure


PL7 Junior software has multitask structure
with different priority and execution.

Master task

Fast task
priority

MAST

FAST

Event-triggered
task

EVTi

Multitask Software Structure


Example of Single Task
processing.
Simple Single task processing
Cyclic Master task
time

MAST
SYSTEM

%I
I.P

Program
Processing

%Q

%I
I.P

Program
Processing

%Q

Multitask Software Structure


Example of Multitask
Simple Multitask processing processing.
Cyclic Master task (MAST)
Fast task (FAST) with 20 ms period

Event
detecte
d 20 ms

20 ms

20 ms

EVTi
FAST

MAST
SYSTEM

I
I

Addressing I/O module objects in TSX 57


Addressing of the main word and bit objects
in I/O modules is defined as follows :
EXAMPLE :
%I03.3

%I05.1

RACK 0

%Q15.1
RACK 1

Addressing Fault Information in I/O module


objects in TSX 57-10/20/30
EXAMPLE :
%I3.MOD.ERR

Information on fault in
the module in position
3 in rack at address 0

RACK 0

%I105.1.ERR

Information on fault in
channel 1 of the module in
position 5 in rack at address
1

RACK 1

Addressing I/O module objects in TSX 57


Addressing of the main word and bit objects
in I/O modules is defined as follows :
%

I or Q

Symbo Type of
l
object
I = Input
Q=
Output

X, W, or D

Format
X=
Boolean
W = Word
D = Double
Word

Rack
Module
Addres Position
s
(00 to
(0 to 7)
10)

Channel
Number
(0 to
127)

Addressing I/O module objects


Addressing of the main word and bit
objects in I/O modules is defined as
follows :
%

I or Q

Symbo Type of
l
object
I = Input
Q=
Output

X, W, or D

Format
X=
Boolean
W = Word
D = Double
Word

Rack
Module
Addres Position
s
(00 to
(0 to 7)
10)

Channel
Number
(0 to
127)

Memory Addressing
Words objects can be addressed by PL7
Software using four different formats :

Byte (B)
Floating Point (F)
Words (W)
Double Words (D)

Memory Addressing
Byte (B) is used exclusively or operations on
character strings.
Example : B, c, , $, etc.
Floating Point (F) format used is that of IEEE
Std 754-1985 (equivalent to IEC 559). Words
are 32 bits long, which corresponds to single
length floating point numbers.
Example : 1285.28
12.8528E2.

Memory Addressing
Words single length (W), these 16-bit
words can contain an algebraic value
between
-32.768 and 32.767
W (WORD) are stored in the memory on two consecutive single length
bytes.
16-bit word
15

14

13

12

11

10

Memory Addressing
Words double length (D), these 32-bit
words can contain an algebraic value
between
-2.147.483.648 and 2.147.483.647
D (DOUBLE WORD) are stored in the memory on two consecutive
single length words
15

14

13

12

11

10

31

30

29

28

27

26

25

24

23

22

21

20

19

18

17

16

32-bit word

Symbolization Example
If %I001.0 has Tacho_meter as its symbol
Then
%I001.0

Tacho_meter

%Q002.1

Can be symbolized
by

%Q002.1

Symbolization
All PL7 objects can be symbolized, but
there are an exception for table type
structured objects and indexed objects.
EXAMPLE :
If %MW0 has Temperature as its symbol
Then %MW0:10 can be symbolized by :
Temperature:10

Animation Tables
All variables of the application to be
monitored or modified can be done by
creating animation tables.
EXAMPLE :
The value of %MW0 want to be monitored.

%MW0

PL7 Junior Software Language


PL7 Junior software offers :

A Graphic language (Ladder Diagram)


A Boolean language (Instruction list)
A Structured text
A Grafcet (Sequential)

PL7 Junior Software Language


A Boolean language

A Boolean language, Instruction List, which is a machine language for writing


logical and numerical processing operations.

PL7 Junior Software Language


A Graphic language

A Graphic language, Ladder language, is especially for combinational processing


and offers basic graphic elements.

PL7 Junior Software Language


A Structured text language

A Structured text language which is a data processing type language enabling the
structured writing of logical and numerical.

PL7 Junior Software Language


A Grafcet language

A Grafcet language which is used to represent the operation of a sequential control


system in a graphic and structured way.

Principle of Ladder Language


Program written in Ladder language consist of a
series of rungs which are executed sequentially
by the PLC
A rung consists of a set of graphic elements
bounded on the left and right by power rails.
Example of a rung

Graphic Elements
Power Rails

Principle of Ladder Language


Each rung
consists of a
maximum of 7
lines and 11
columns. Rungs
are executed
rung by rung,
and each rung is
executed from
left to right.

Principle of Ladder Language


Structure of a
rung. are used to identify a rung within a
Labels
program entity (main program, subroutine,
etc.), but are not compulsory.
Labels take the syntax %Li (i being 0 to 999) and
are located at the top left before the power rail..

LABELS

Principle of Ladder Language


Structure of a
rung.
The
Comments is integrated into the rung and
contains up to 222 alphanumeric character. It
facilitates interpretation of the rung to which it is
assigned, but it is not compulsory.

COMMENTS

Principle of Ladder Language


Graphic Elements.
Graphic Elements can be grouped into :
Contacts
Coils
Function Blocks
Comparison Blocks
Operate Blocks
Connector Lines
Jump, Call, Return, Halt

Normally Open/Closed Contacts

NORMALLY OPEN

NORMALLY CLOSED

Transitional Contacts
POSITIVE
TRANSITIONAL
CONTACTS

NEGATIVE
TRANSITIONAL
CONTACTS

Positive Transitional Contacts


POSITIVE
TRANSITIONAL
CONTACTS
Positive
Transitional
Contacts
Power Flow

OFF

OFF

ON

ON
one scan time

ON
OFF
ON
OFF

Negative Transitional Contacts


NEGATIVE
TRANSITIONAL
CONTACTS
Negative
Transitional
Contacts
Power Flow

ON

OFF

N
OFF

ON
one scan time

ON
OFF
ON
OFF

Normally Open/Close, Latch/Unlatch Coils


NORMALLY-OPEN COIL
NORMALLY-CLOSE COIL
LATCH COIL
UNLATCH COIL

S
R

Normally Open Coils

NORMALLY-OPEN COIL

Power Flow

Normally Open
Coils

OFF

OFF

ON

ON

OFF

OFF

ON
OFF
ON
OFF

Normally Closed Coils

NORMALLY-CLOSE COIL

Power Flow

Normally Close
Coils

OFF

ON

ON

OFF

OFF

ON

ON
OFF
ON
OFF

Latch Coils
LATCH COIL

Power Flow

Normally Open
Coils

OFF

OFF

ON

OFF

ON
Coils Set

ON
OFF
ON
OFF

Unlatch Coils
UNLATCH COIL

Power Flow

Normally Open
Coils

OFF

ON

ON

OFF

OFF
Coils Reset

ON
OFF
ON
OFF

Simple Contact-Coil Logic Example


CONTACT-COIL USES PLC
AND LADDER LOGIC
PHYSICAL INPUT

PHYSICAL OUTPUT

Simple Contact-Coil Logic Example

%I001.0

%I001.1

%I003.0

%Q002.0

Simple Logical AND Circuit

Simple Contact-Coil Logic Example


%I101.0

%Q102.0

%I103.0

Simple Logical OR Circuit

Simple Contact-Coil Logic Example


%I001.0

%I003.0

%I001.0

%I003.0

%Q002.0

Simple Logical XOR Circuit

Simple Contact-Coil Logic Example


Contact-Coil using Memory Bit
%I001.0

%M1

%M1

%Q002.1

Is the same with


%I001.0

%Q002.1

Simple Contact-Coil Logic Example


Contact-Coil using Word
Bit
%MW10:X12

15

14

13

12

%Q002.0

%MW10:X5

11

10

%MW10

Common Control Technique


Building A Seal Circuit
Start

Stop

%I101.0

%I101.1

%Q102.0

%Q102.0

%Q102.0

Running Lamp (Red)


%Q102.1

%Q102.0

%Q102.2

Running Lamp (Green)

Common Control Technique


A Start/Stop Program
Cycle
Start

End of
Cycle

Cycle
Stop

%I101.0

%Q102.1

%I101.1

%Q102.0

%Q102.0

Auto Single
Cycle

Common Control Technique


A Start/Stop Program with AntiRepeat
Cycle
Start

End of
Cycle

Cycle
Stop

%I101.0

%Q102.1

%I101.1

%Q102.0

%Q102.0

Auto Single
Cycle

INPUT
MODE OF
TIMERS

IN
Q

Timers
%TM0
TM

MODE : TON
TB : 1s

OUTPUT

TIME BASE

PRESET TIME

TIME
ACCUMULATED

TM.P : 15
MODIF : Y
TM.V : 13

MODIFICATION

Timers (Mode TON - On Delay)


%TM0
IN

TM
Q
MODE : TON
TB : 1s
TM.P : 15
MODIF : Y
TM.V : 13

Input Timer

Output Timer

OFF

ON

OFF

OFF

ON
preset time

OFF

ON
OFF
ON
OFF

Timers (Mode TP - Monostable)


%TM0
IN

TM
Q
MODE : TP
TB : 1s
TM.P : 15
MODIF : Y
TM.V : 13

Input Timer

Output Timer

OFF

OFF

ON

ON

ON
preset time

OFF

OFF

ON
OFF
ON
OFF

Timers (Mode TOF - Off Delay)


%TM0
IN

TM
Q
MODE : TOF
TB : 1s
TM.P : 15
MODIF : Y
TM.V : 13

Preset time
Input Timer

Output Timer

OFF

OFF

ON

ON

ON

OFF

OFF

ON
OFF
ON
OFF

Timer Programming Example


Normally Open On-Delay Program
%I001.0

%Q002.0

%TM0
IN

TM
Q
MODE : TON
TB : 1s
TM.P : 15
MODIF : Y
TM.V : 0

%I100.0

OFF

ON

OFF

15 s
%Q200.0

OFF

ON

OFF

Timer Programming Example


Normally Open Off-Delay Program
%I001.0

%Q002.0

%TM0
IN

TM
Q
MODE : TOF
TB : 1s
TM.P : 15
MODIF : Y
TM.V : 0

%I100.0

OFF

%Q200.0

OFF

15 s

ON

ON

OFF

OFF

COUNTER
RESET
COUNTER

SET
COUNTER

UP-COUNTER

DOWN-COUNTER

%C0
C

C.P : 15
CU
MODIF : Y
C.V : 13
CD

COUNTER EMPTY

COUNTER DONE

COUNTER PRESET

COUNTER FULL
MODIFICATION
COUNTS
ACCUMULATED

Counter Programming Example


Simple Up-Counter Program
Counter
%I001.1
Reset

%C0
R

C
E

Up-Counter
%I001.0

S
D
C.P : 15
CU
F
MODIF : Y
C.V : 0
CD

Indicator Lamp
%Q002.0

Counter Programming Example


Simple Down-Counter Program

%C0

Counter
%I001.1
Set

C
E

S
D

Down%I001.0
Counter
P

C.P : 15
CU
F
MODIF : Y
C.V : 0
CD

Indicator
%Q002.0
Lamp

Timer-Counter Programming Example


Time Interval Driven Lube
Program
Lube Pump

Auto Reset
%I001.0%Q002.1

%TM0
IN

TM

%TM1
IN

%Q002.0

TM

MODE : TON
TB : 1min
TM.P : 24
MODIF : Y
TM.V : 0

MODE : TP
TB : 1min
TM.P : 6
MODIF : Y
TM.V : 0

Reset
%Q002.1

Timer-Counter Programming Example


Event Driven Lube Program
Reset
%Q002.1

%C0
R

End
Auto
Of
%I001.0%Q100.0
Cycle
P

Lube Pump

%TM0
IN

S
D
C.P : 100
CU
F
MODIF : Y
C.V : 0
CD

%Q002.0

TM
Q
MODE : TP
TB : 1s
TM.P : 60
MODIF : Y
TM.V : 0

Reset
%Q002.1

Timer-Counter Programming Example


Simple 24 Hour Clock
%M0

%M1
R
S

%M0

P
%M2
%M1

%M0

%TM0
IN TM
Q
MODE : TON
TB : 1s
TM.P : 60

CU
CD
R
S
CU
CD

%C0
C
C.P : 60

Minute

E
D
F

%C1
C
C.P : 24

%M1

Hour
%M2

E
D
F

day

Comparison in PL7 Junior

Comparison instructions are used to


compare two operands
There are 2 types of comparison
Horizontal Comparison Block
Vertical Comparison Block

Horizontal Comparison Block


COMPARE

OP1 OPERATORS OP2

OP1
OPERATORS
<,<=,>,>=,<>,=
OP2

OPERANDS 1
OPERANDS 2

PL7 Junior uses four types of operands.


Indexed Words
- %MWi, %KWi
Non-Indexed Words
- Immediate Value, %IWxy.i, %QWxy.i,
%SWi,
%NWi, Function Block, Numeric
Expression
Indexed Double Words
- %MDi, %KDi
Non-Indexed Double Words
- Immediate Value, %IDxy.i, %QDxy.i, %SDi,
Numeric Expression

OPERATORS

<
<=

Test if operand 1 is less than operand 2


Test if operand 1 is less than or equal
to operand 2

>
>=

Test if operand 1 is greater than operand 2


Test if operand 1 is greater than or
equal to operand 2

=
<>

Test if operand 1 is equal to operand 2


Test if operand 1 is different from operand 2

The result is 1 when the comparison block is


true

Comparison Instruction Example


Simple Comparison Program
%Q002.0

COMPARE
%MW10>%MW20

If %MW10 is greater than %MW20 then %Q002.0 is on


Else %Q002.0 is off

Comparison Instruction Example


Simple Air Conditioning Program
%IW300.0 - Input Analog Temperature
COMPARE
%IW300.0>24

%Q004.0

COMPARE
%IW300.0<=24

%Q004.0

COMPARE
%IW300.0<21

%Q004.1

COMPARE
%IW300.0>=21

%Q004.1

Cooler
On
Cooler
Off
Heater
On
Heater
Off

Timer-Counter-Comparison Example
Time Interval Driven Lube Program
Reset

Auto Reset
%I001.0%Q002.1

%Q002.1

%TM1
IN

TM
Q
MODE : TON
TB : 1min
TM.P : 30
MODIF : Y
TM.V : 0

COMPARE
%TM1.V>=24

COMPARE
%TM1.V<=30

Lube Pump
%Q002.0

Timer-Counter-Comparison Example
Event Driven and Time Interval Driven Lube Program
%TM1

%I001.0 %Q002.1
%C0

%Q002.2

IN MODE : TON Q
TB : 1min
TM.P : 30

R
C
E
S C.P : 100 D
%I001.0 %Q100.0
P

%Q002.1

%Q002.2

CU
F
CD C.V : 0

Auto
%Q002.2
P

COMPARE
%TM1.V>=24

%TM0
IN MODE : TP Q
TB : 1s
TM.P : 60
COMPARE
%TM1.V<=30

%Q002.0

Vertical Comparison Block


COMPARE

EN

>

OP1

OP2

<
<>

OP1
OP2

OPERANDS 1
OPERANDS 2

Vertical Comparison Instruction Example


Simple Vertical Comparison Program
EN

COMPARE

%MW10

%MW20

<

%Q002.0

>

%Q002.1

<>

If %MW10 is greater than %MW20 then %Q002.0 is on, else


%Q002.0 is off.
If %MW10 is less than %MW20 then %Q002.1 is on, else %Q002.1 is
off.

Drum Controller

RESET

STEP UP

TIME
ACCUMULATED

%DR0
R
DR
TB : 1mn
U
LEN : 6
DR.V : 4
DR.S : 2

FULL
TIME BASE

DRUM
LENGTH

STEP
ACCUMULATED

Drum Controller - Operation

The table on the right


summarizes the main
characteristics of the
drum controller
(configured with 7
steps).

bit

Example :

0
1
2
3
4
5
6
7
8
A
B
C
D
E
F

0
1
0
0
0
0
0
1
0
0
0
0
0
0
0
0

1
0
1
0
0
0
1
0
0
0
0
0
0
0
0
0

steps
2 3 4
0 0 0
0 0 0
1 0 1
0 1 0
1 0 1
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0

5
0
1
0
0
0
1
0
0
0
0
0
0
0
0
0

6
1
0
0
0
0
0
1
0
0
0
0
0
0
0
0

address
%Q002.0
%Q002.2
%M1
%M2
%M3
%Q002.3
%Q002.1

Drum Controller Example


Simple Running Lamp Program
%I001.0

DR
F
TB : 1s

U
LEN : 4
DR.V : 4
DR.S : 0

%I001.0

steps
address
0 1 2 3
0 1 0 0 0 %Q002.0
1 0 1 0 0 %Q002.1
2 0 0 1 0 %Q002.2
3 0 0 0 0
4 0 0 0 0
5 0 0 0 0
6 0 0 0 0
Step 0 Step 1 Step 2

bit

%DR0

%Q002.0%Q002.1%Q002.2

Drum Controller Example


Simple Running Lamp Program ver.2
%I001.0

DR
F
TB : 1s

U
LEN : 4
DR.V : 4
DR.S : 0

%I001.0

steps
address
0 1 2 3
0 1 0 1 0 %Q002.0
1 0 1 1 0 %Q002.1
2 1 0 1 0 %Q002.2
3 0 0 0 0
4 0 0 0 0
5 0 0 0 0
6 0 0 0 0
Step 0 Step 1 Step 2

bit

%DR0

%Q002.0%Q002.1%Q002.2

Drum Controller Example


Simple Running Lamp Program with Time Interval
Start / Reset
%I001.0

%DR0

DR
F
TB : 1s

Step Up
%M1

U
LEN : 4
DR.V : 4
DR.S : 2
COMPARE

%DR0.V>=6

Step Up
%M1

Numerical Processing on Integers

In Ladder language, numerical instructions


are entered in :
Comparison Blocks
Operation Blocks

Numerical Processing on Integers

Numerical processing using operation


block can contain :
Simple expression, eg :
OP3:=OP1+OP2
Complex expression, eg :
OP5:=(OP1+OP2)*OP3-OP4
OP : Operand

Assignment Instructions

Assignment instructions are used to load


an OP2 operand into an OP1 operand.
Syntax :
OP1:=OP2
Example :

OP2
OP1
OPERATE

%MW10:=%IW003.0

Assignment of Bit tables

The operations on bit tables can be


performed :
Bit table
bit table
Bit table
word or double word
Word or double word
bit
table

Assignment of Bit tables

Example :
OPERATE
%Q002.0:8:=%M1:8
OPERATE
%MW10:=%I003.0:16
OPERATE
%M20:16:=%IW003.0

Arithmetic Instructions on Integers

These instructions are used to


perform arithmetic operations
between two operands or one operand
:

+
*
/

SQRT
INC
DEC
ABS
REM

Arithmetic Instructions on Integers

Example :
%M0

OPERATE
%MW0:=%MW10+100

%I001.0

OPERATE
%MW0:=SQRT(%MW10)

%I001.1

OPERATE
INC(%MW100)

Logic Instructions

These instructions are used to perform a


logic operation between two operands or
on one operand.

AND
OR
XOR
NOT

Logic Instructions

Example :
%M0

OPERATE

%MW0:=%MW10 AND
16#FF00
%I001.0

OPERATE

%MW0:=%KW5 OR %MW10
%I001.1

OPERATE

%MW0:=NOT %MW100

Execution Priority of Instructions

In numerical expressions, priority of


different instructions is observed.They
are executed in the order described
below :
Instruction
to an
operand
OR

*
/
REM
XO
R

+
-

AN
D

<,>
<=,>=
=
<>

Execution Priority of Instructions

Example :
SQRT(%MW3)+%MW5*7 AND %MW8 OR %MW5 XOR %MW10
5
1

3
4

Shift Instruction
16 bit (single word) or
32 bit (double word)

Shift Left

Last bit
stored in
%S17

result:=SHL(OP1,i)

Shift Right

result:=SHR(OP1,i)

Shift Instruction
Example of Shift Left :
OPERATE

%MW3:=SHL(%MW0,3)
%MW0
15

14

13

12

11

10

Store in bit
%S17
4
3
2
1

15

14

13

12

11

10

%MW3

Fill with bit


0

Shift Circular Instruction


16 bit (single word) or
32 bit (double word)

Rotate Left

Last bit
stored in
%S17

result:=ROL(OP1,i)

Rotate Right

result:=ROR(OP1,i)

Shift Circular Instruction


Example of Rotating Left :
OPERATE

%MW3:=ROL(%MW0,1)
%MW0

15

14

13

12

11

10

Store in bit
%S17
4
3
2
1

15

14

13

12

11

10

%MW3

Subroutine

In the master task (MAST), besides main


processing, there are subroutines to
perform a task and can be called from
main processing or from another
subroutine.
Main
Processing
MAIN

Subroutine
Subroutine
SRi
SRi
Subroutine
SR1
Subroutine
SR0

Subroutine Call

Subroutine call instructions are used to call


a subroutine module located in the same
task.
SRi

C
SRi : subroutine module number (0 to 253)

Subroutine Call

A subroutine can call another subroutine.


The number of cascaded calls is limited
to 8.
Main Processing

Call SR 10

Subroutine module
SR 10

Call SR 12

Subroutine module
SR 12

Subroutine Return

Subroutine return instructions are used to


return to the calling module.

RETURN

Program Jumps

Jump instructions allow connection to a line


of programming identified by a label %Li.
%Li

%Li : represent the label of the line to which


the connection is made (i numbered from 1
to 999 with up to 256 labels)

Jumps Example

Simple Jump Example


%L0

%I001.0

%L20

%I001.1

%Q002.0

%L20

%I001.0

%Q002.1

Stop Program

Execution of an application program can


be stopped using the instruction HALT
(stops all tasks).

HALT

Stop Program Example


A Start/Stop Program with Time Error Detecting
Cycle
Start

End of
Cycle

Cycle
Stop

%I101.0

%Q102.1

%I101.1

%Q102.0

P
%Q102.0

%Q102.1
P

%TM0
IN MODE : TOF
Q
TB : 1min
TM.P : 30

HALT

You might also like