You are on page 1of 20

Chapter - Ladder Logic Function

Combinatorial Logic
Events
Data Handling
Numerical Logic
Lists
Program Control
Input and Output
Data Handling - Moves

A M O V
S o u r c e t e s t _ r e a l_ 1
D e s t in a t io n t e s t _ r e a l_ 2

B M O V
S o u r c e t e s t _ r e a l_ 1
D e s t in a t io n t e s t _ in t

C M O V
S o u rc e 1 2 3
D e s t in a t io n t e s t _ in t

N O T E : w h e n a f u n c t io n c h a n g e s a v a lu e , e x c e p t f o r in p u t s a n d o u t p u t s , t h e v a lu e is
c h a n g e d im m e d ia t e ly . C o n s id e r F ig u r e 1 5 . 2 , if A , B a n d C a r e a ll t r u e , t h e n t h e
v a lu e in t e s t _ r e a l _ 2 w ill c h a n g e b e f o r e t h e n e x t in s t r u c t io n s t a r t s . T h is is d if fe r e n t
t h a n t h e in p u t a n d o u t p u t s c a n s t h a t o n ly h a p p e n b e f o r e a n d a f t e r t h e lo g ic s c a n .
A
M O V
Example so u rc e 1 3 0
d e s t in t _ 0

M O V
s o u r c e in t _ 1
d e s t in t _ 2

M V M
s o u r c e in t _ 3
m a s k in t _ 4
d e s t in t _ 5

M V M
s o u r c e in t _ 3
m a s k in t _ 4
d e s t in t _ 6

b e fo r e a fte r
b in a r y d e c im a l b in a r y d e c im a l
in t _ 0 0000000000000000 0 0000000010000010 130
in t _ 1 1101101101010111 -9385 1101101101010111 -9385
in t _ 2 1000000000000000 -32768 1101101101010111 -9385
in t _ 3 0101100010111011 22715 becom es 0101100010111011 22715
in t _ 4 0010101010101010 10922 0010101010101010 10922
in t _ 5 0000000000000001 1 0000100010101011 2219
in t _ 6 1101110111111111 1101110111111111

N O T E : t h e c o n c e p t o f a m a s k is v e r y u s e f u l, a n d it w ill b e u s e d in o t h e r f u n c t io n s .
M a s k s a llo w in s t r u c t io n s t o c h a n g e a c o u p le o f b it s in a b in a r y n u m b e r w it h o u t h a v
in g t o c h a n g e t h e e n t ir e n u m b e r . Y o u m ig h t w a n t t o d o t h is w h e n y o u a r e u s in g b it s in
a n u m b e r to r e p r e s e n t s ta te s , m o d e s , s ta tu s , e tc .
Math Functions

A
A D D
s o u r c e A in t _ 1
s o u r c e B r e a l_ 1
d e s t in a t io n r e a l_ 2

A D D ( v a lu e , v a lu e , d e s t in a t io n ) - a d d t w o v a lu e s
S U B ( v a lu e , v a lu e , d e s t in a t io n ) - s u b t r a c t
M U L ( v a lu e , v a lu e , d e s t in a t io n ) - m u lt ip ly
D I V ( v a lu e , v a lu e , d e s t in a t io n ) - d iv id e
N E G ( v a lu e , d e s t in a t io n ) - r e v e r s e s ig n f r o m p o s it iv e / n e g a t iv e
C L R ( v a lu e ) - c le a r t h e m e m o r y lo c a t io n

N O T E : T o s a v e s p a c e t h e f u n c t io n t y p e s a r e s h o w n in t h e s h o r t e n e d n o t a t io n a b o v e .
F o r e x a m p le t h e f u n c t io n A D D ( v a l u e , v a l u e , d e s t i n a t i o n ) r e q u ir e s t w o s o u r c e v a l
u e s a n d w ill s t o r e it in a d e s t in a t io n . I t w ill u s e t h is n o t a t io n in a f e w p l a c e s t o
r e d u c e t h e b u l k o f t h e f u n c t io n d e s c r ip t io n s .
A D D
s o u r c e A in t _ 0
Math Function Examples s o u r c e B in t _ 1
d e s t . in t _ 2
A D D a d d r. b e fo r e a fte r
so u rc e A 1
s o u r c e B in t _ 3 in t _ 0 10 10
d e s t . in t _ 3 in t _ 1 25 25
in t _ 2 0 35
SU B in t _ 3 0 1
s o u r c e A in t _ 1 in t _ 4 0 -10
s o u r c e B in t _ 2 in t _ 5 0 250
d e s t . in t _ 4 in t _ 6 0 3
M U LT in t _ 7 0 10
s o u r c e A in t _ 0 in t _ 8 100 0
s o u r c e B in t _ 1
d e s t . in t _ 5 f lt _ 0 1 0 .0 1 0 .0
f lt _ 1 2 5 .0 2 5 .0
D IV f lt _ 2 0 2 .5
s o u r c e A in t _ 1 f lt _ 3 0 2 .5
s o u r c e B in t _ 0
d e s t . in t _ 6
N EG
s o u r c e A in t _ 4 N o t e : r e c a ll, in t e g e r
d e s t . in t _ 7 v a lu e s a r e lim it e d
to r a n g e s b e tw e e n -
C LR 32768 and 32767,
d e s t . in t _ 8 a n d th e r e a re n o
D IV f r a c t io n s .
s o u r c e A f lt _ 1
s o u r c e B f lt _ 0
d e s t . f lt _ 2
D IV
s o u r c e A in t _ 1
s o u r c e B in t _ 0
d e s t . f lt _ 3
Other Math Functions
A C S ( v a lu e , d e s t in a t io n ) - in v e r s e c o s in e
C O S ( v a lu e , d e s t in a t io n ) - c o s in e
A S N ( v a lu e , d e s t in a t io n ) - in v e r s e s in e
S I N ( v a lu e , d e s t in a t io n ) - s in e
A T N ( v a lu e , d e s t in a t io n ) - in v e r s e t a n g e n t
T A N ( v a lu e , d e s t in a t io n ) - t a n g e n t
X P Y ( v a lu e , v a lu e , d e s t in a t io n ) - X t o t h e p o w e r o f Y
L N ( v a lu e , d e s t in a t io n ) - n a t u r a l lo g
L O G ( v a lu e , d e s t in a t io n ) - b a s e 1 0 lo g
S Q R ( v a lu e , d e s t in a t io n ) - s q u a r e r o o t
C P T ( d e s t in a t io n , e x p r e s s io n ) - d o e s a c a lc u la t io n

OR

go
C PT
D e s t. A
E x p r e s s io n
S Q R (L N (B )+ X P Y (2 .7 1 8 ,C )* A C S (D ))
Example - Implement ladder logic for the function below
given
C
A = ln B + e acos D
Conversions

A FRD
S o u r c e A D 1 0 :5
D e s t . F 8 :2

T O D ( v a lu e , d e s t in a t io n ) - c o n v e r t fr o m B C D t o 2 s c o m p lim e n t
F R D ( v a lu e , d e s t in a t io n ) - c o n v e r t fr o m 2 s c o m p lim e n t t o B C D
D E G ( v a lu e , d e s t in a t io n ) - c o n v e r t fr o m r a d ia n s t o d e g r e e s
R A D ( v a lu e , d e s t in a t io n ) - c o n v e r t fr o m d e g r e e s t o r a d ia n s
FRD
Example S o u rc e b c d _ 1
D e s t . in t _ 0

TO D
S o u r c e in t _ 1
D e s t. b c d _ 0

D EG
S o u r c e r e a l_ 0
D e s t . r e a l_ 2

RA D
S o u r c e r e a l_ 1
D e s t . r e a l_ 3

A d d r. B e fo r e a fte r

in t _ 0 0 1 793
in t _ 1 5 48 5 48
r e a l_ 0 3 .1 4 1 3 .1 4 1
r e a l_ 1 4 5 4 5
r e a l_ 2 0 1 80
r e a l_ 3 0 0 .7 8 5
bcd_0 0 000 0000 0000 0000 0 000 0101 0100 1000 t h e s e a r e s h o w n in
bcd_1 0 001 0111 1001 0011 0 001 0111 1001 0011 b in a r y B C D f o r m
Advanced Functions

A AV E
F ile w e ig h t [ 0 ]
D e s t w e ig h t _ a v g
C o n t r o l w e ig h t _ c o n t r o l
le n g t h 4
p o s it io n 0

A V E ( s t a r t v a lu e , d e s t in a t io n , c o n t r o l, le n g t h ) - a v e r a g e o f v a lu e s
S T D ( s t a r t v a lu e , d e s t in a t io n , c o n t r o l, le n g t h ) - s t a n d a r d d e v ia t io n o f v a lu e s
S R T ( s t a r t v a lu e , c o n t r o l, le n g t h ) - s o r t a lis t o f v a lu e s
A AV E
Example F ile w e ig h t [ 0 ]
D e s t w e ig h t _ a v g
C o n tr o l c _ 1
le n g t h 4
p o s it io n 0

B STD
F ile w e ig h t [ 0 ]
D e s t w e ig h t _ s t d
C o n tr o l c _ 2
le n g t h 4
p o s it io n 0

C S RT
F ile w e ig h t [ 0 ]
C o n tr o l c _ 3
A d d r. b e fo r e a fte r A a fte r B a fte r C le n g t h 4
p o s it io n 0
w e ig h t [ 0 ] 3 3 3 1
w e ig h t [ 1 ] 1 1 1 2
w e ig h t [ 2 ] 2 2 2 3
w e ig h t [ 3 ] 4 4 4 4
w e ig h t _ a v g 0 2 .5 2 .5 2 .5
w e ig h t _ s t d 0 0 1 .2 9 1 .2 9
Array Functions

A
C O P
S o u rc e n [5 0 ]
D e st n [4 0 ]
L e n g th 1 0

C O P ( s t a r t v a lu e , d e s t in a t io n , le n g t h ) - c o p ie s a b lo c k o f v a lu e s
F A L ( c o n t r o l, le n g t h , m o d e , d e s t in a t io n , e x p r e s s io n ) - w ill p e r f o r m b a s ic m a t h
o p e r a t io n s t o m u lt ip le v a lu e s .
F S C ( c o n t r o l, le n g t h , m o d e , e x p r e s s io n ) - w ill d o a c o m p a r is o n t o m u lt ip le v a lu e s
F L L ( v a lu e , d e s t in a t io n , le n g t h ) - c o p ie s a s in g le v a lu e t o a b lo c k o f m e m o r y
Example FA L
A C o n tr o l c _ 0
le n g t h 5 a rra y to a rra y
p o s it io n 0
M o d e a ll
D e s t in a t io n n [ c _ 0 . P O S + 5 ]
E x p r e s s io n n [ c _ 0 . P O S ] + 5

FA L
B C o n t r o l R 6 :1
le n g t h 5 e le m e n t t o a r r a y
p o s it io n 0 a r r a y t o e le m e n t
M ode 2
D e s t in a t io n n [ c _ 0 . P O S + 5 ]
E x p r e s s io n n [ 0 ] + 5

FA L
C C o n t r o l R 6 :2
le n g t h 5
p o s it io n 0 a r r a y t o e le m e n t
M o d e in c r e m e n t a l
D e s t in a t io n n [ 5 ]
E x p r e s s io n n [ c _ 0 . P O S ] + 5
Logical Functions

lig h t
EQ U
A
B

E Q U ( v a lu e , v a lu e ) - e q u a l
N E Q ( v a lu e , v a lu e ) - n o t e q u a l
L E S ( v a lu e , v a lu e ) - le s s t h a n
L E Q ( v a lu e , v a lu e ) - le s s t h a n o r e q u a l
G R T ( v a lu e , v a lu e ) - g r e a t e r t h a n
G E Q ( v a lu e , v a lu e ) - g r e a t e r t h a n o r e q u a l
C M P ( e x p r e s s io n ) - c o m p a r e s t w o v a lu e s f o r e q u a lit y
M E Q ( v a lu e , m a s k , t h r e s h o ld ) - c o m p a r e f o r e q u a lit y u s in g a m a s k
L I M ( lo w lim it , v a lu e , h ig h lim it ) - c h e c k f o r a v a lu e b e t w e e n lim it s
Example O _0 O _0=0
EQ U O _1=1
A in t _ 3 in t _ 3 = 5 O _2=0
B in t _ 2 in t _ 2 = 3 O _3=0
O _1 O _4=1
N EQ O _5=1
A in t _ 3
B in t _ 2
O _2
LES O _0=1
A in t _ 3 O _1=0
B in t _ 2 in t _ 3 = 3 O _2=0
O _3 in t _ 2 = 3 O _3=1
LEQ O _4=0
A in t _ 3 O _5=1
B in t _ 2
O _4
G RT
O _0=0
A in t _ 3
O _1=1
B in t _ 2
in t _ 3 = 1 O _2=1
O _5 in t _ 2 = 3 O _3=1
GEQ
O _4=0
A in t _ 3
B in t _ 2 O _5=0
Comparison with Expressions
O _0
C M P
e x p r e s s io n
in t _ 3 = in t _ 2
O _1
C M P
e x p r e s s io n
in t _ 3 < > in t _ 2
O _2
C M P
e x p r e s s io n
in t _ 3 < in t _ 2
O _3
C M P
e x p r e s s io n
in t _ 3 < = in t _ 2
O _4
C M P
e x p r e s s io n
in t _ 3 > in t _ 2
O _5
C M P
e x p r e s s io n
in t _ 3 > = in t _ 2
Limit Functions L IM
lo w lim it in t _ 0 in t _ 5 . 0
t e s t v a lu e in t _ 1
h ig h l im it in t _ 2

L IM
lo w lim it in t _ 2 in t _ 5 . 1
t e s t v a lu e in t _ 1
h ig h l im it in t _ 0

L IM
lo w lim it in t _ 2 in t _ 5 . 2
t e s t v a lu e in t _ 3
h ig h l im it in t _ 0

M EQ
s o u r c e in t _ 0 in t _ 5 . 3
m a s k in t _ 1
c o m p a r e in t _ 2

M EQ
s o u r c e in t _ 0 in t _ 5 . 4
m a s k in t _ 1
c o m p a r e in t _ 4

A d d r. b e f o r e ( d e c im a l) b e f o r e ( b in a r y ) a f t e r ( b in a r y )

in t _ 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0001 0 0 0 0 0 0 0 0 0 0 0 0 0001
in t _ 1 5 0 0 0 0 0 0 0 0 0 0 0 0 0101 0 0 0 0 0 0 0 0 0 0 0 0 0101
in t _ 2 11 0 0 0 0 0 0 0 0 0 0 0 0 1011 0 0 0 0 0 0 0 0 0 0 0 0 1011
in t _ 3 15 0 0 0 0 0 0 0 0 0 0 0 0 1111 0 0 0 0 0 0 0 0 0 0 0 0 1111
in t _ 4 0 0 0 0 0 0 0 0 0 0 0 0 1000 0 0 0 0 0 0 0 0 0 0 0 0 1000
in t _ 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0000 0 0 0 0 0 0 0 0 0 0 0 0 1101
Boolean Functions

A A N D
s o u r c e in t _ A
s o u r c e in t _ B
d e s t . in t _ X
A N D ( v a lu e , v a lu e , d e s t in a t io n ) - B in a r y a n d f u n c t io n
O R ( v a lu e , v a lu e , d e s t in a t io n ) - B in a r y o r f u n c t io n
N O T ( v a lu e , v a lu e , d e s t in a t io n ) - B in a r y n o t f u n c t io n
X O R ( v a lu e , v a lu e , d e s t in a t io n ) - B in a r y e x c lu s iv e o r f u n c t io n
Example A N D
so u rc e A n [0 ]
so u rc e B n [1 ]
d e s t. n [ 2 ]
O R
so u rc e A n [0 ]
so u rc e B n [1 ]
d e s t. n [ 3 ]
X O R
so u rc e A n [0 ]
so u rc e B n [1 ]
d e s t. n [ 4 ]
N O T
so u rc e A n [0 ]
d e s t. n [ 5 ]
a d d r. d a ta ( b in a r y )
n [0 ] 0011 010111011011
n [1 ] 1010 010011101010
n [2 ] 0010 010011001010
a fte r
n [3 ] 1011 010111111011
n [4 ] 1001 000100110001
n [5 ] 1100 101000100100
Example
Create a ladder logic program that will start when input A is turned
on and calculate the series below. The value of n will start at 0 and
with each scan of the ladder logic n will increase by 2 until n=20.
While the sequence is being incremented, any change in A will be
ignored.

x = 2 log n 1 A = B3/10
n = N7:0
x = F8:15

You might also like