Sie sind auf Seite 1von 20

Chapter - Ladder Logic Function

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

Data Handling - Moves

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

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

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
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
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
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

o u t p u t s , t h e v a lu e is
C a r e a ll t r u e , t h e n t h e
s t a r t s . T h is is d if
fe r e n t
a f t e r t h e lo g ic s c a n .

M O V
so u rc e 1 3 0
d e s t in t _ 0

Example

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 in a r y
in t _
in t _
in t _
in t _
in t _
in t _
in t _

0
1
2
3
4
5
6

b e fo r e

0000000000000000
1101101101010111
1000000000000000
0101100010111011
0010101010101010
0000000000000001
1101110111111111

a fte r

d e c im a l

b in a r y

0
-9385
-32768
22715
10922
1

0000000010000010
1101101101010111
1101101101010111
0101100010111011
0010101010101010
0000100010101011
1101110111111111

becom es

d e c im a l
130
-9385
-9385
22715
10922
2219

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 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 .

Math Function Examples

A D D
s o u r c e A in t _ 0
s o u r c e B in t _ 1
d e s t . in t _ 2
A D D
so u rc e A 1
s o u r c e B in t _ 3
d e s t . in t _ 3
SU B
s o u r c e A in t _ 1
s o u r c e B in t _ 2
d e s t . in t _ 4
M U LT
s o u r c e A in t _ 0
s o u r c e B in t _ 1
d e s t . in t _ 5
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 . in t _ 6
N EG
s o u r c e A in t _ 4
d e s t . in t _ 7
C LR
d e s t . in t _ 8
D IV
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

a d d r.

b e fo r e

a fte r

in t _
in t _
in t _
in t _
in t _
in t _
in t _
in t _
in t _

10
25
0
0
0
0
0
0
100

10
25
35
1
-10
250
3
10
0

1 0 .0
2 5 .0
0
0

1
2
2
2

f lt _
f lt _
f lt _
f lt _

0
1
2
3
4
5
6
7
8
0
1
2
3

0 .0
5 .0
.5
.5

N o t e : r e c a ll, in t e g e r
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 32768 and 32767,
a n d th e r e a re n o
f r a c t io n s .

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
A =

ln B + e acos D

Conversions

T O D ( v a lu e , d e s t in a t io n )
F R D ( v a lu e , d e s t in a t io n )
D E G ( v a lu e , d e s t in a t io n )
R A D ( v a lu e , d e s t in a t io n )

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

c o n v e r t fr o m
c o n v e r t fr o m
c o n v e r t fr o m
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
2 s c o m p lim e n t t o B C D
r a d ia n s t o d e g r e e s
d e g r e e s t o r a d ia n s

FRD
S o u rc e b c d _ 1
D e s t . in t _ 0

Example

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
in t _ 1
r e a l_ 0
r e a l_ 1
r e a l_ 2
r e a l_ 3
bcd_0
bcd_1

0
5
3
4
0
0
0
0

1
5
3
4
1
0
0
0

48
.1 4 1
5
000 0000 0000 0000
001 0111 1001 0011

793
48
.1 4 1
5
80
.7 8 5
000 0101 0100 1000
001 0111 1001 0011

t h e s e a r e s h o w n in
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

Example

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 tr o l c _ 1
le n g t h 4
p o s it io n 0

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

S RT
F ile w e ig h t [ 0 ]
C o n tr o l c _ 3
le n g t h 4
p o s it io n 0

A d d r.

b e fo r e

a fte r A

a fte r B

a fte r C

w
w
w
w
w
w

3
1
2
4
0
0

3
1
2
4
2 .5
0

3
1
2
4
2 .5
1 .2 9

1
2
3
4
2 .5
1 .2 9

e ig h t [ 0 ]
e ig h t [ 1 ]
e ig h t [ 2 ]
e ig h t [ 3 ]
e ig h t _ a v g
e ig h t _ s t d

Array Functions

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
A

FA L
C o n tr o l c _ 0
le n g t h 5
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

a rra y to a rra y

FA L
C o n t r o l R 6 :1
le n g t h 5
p o s it io n 0
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

e le m e n t t o a r r a y
a r r a y t o e le m e n t

FA L
C o n t r o l R 6 :2
le n g t h 5
p o s it io n 0
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

a r r a y t o e le m e n t

Logical Functions

EQ U
A
B

lig h t

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

EQ U
A in t _ 3
B in t _ 2
N EQ
A in t _ 3
B in t _ 2
LES
A in t _ 3
B in t _ 2
LEQ
A in t _ 3
B in t _ 2
G RT
A in t _ 3
B in t _ 2
GEQ
A in t _ 3
B in t _ 2

O _0

O _1

O _2

O _3

O
O
in t _ 3 = 5 O
in t _ 2 = 3 O
O
O

_0=0
_1=1
_2=0
_3=0
_4=1
_5=1

O
O
in t _ 3 = 3 O
in t _ 2 = 3 O
O
O

_0=1
_1=0
_2=0
_3=1
_4=0
_5=1

O
O
in t _ 3 = 1 O
in t _ 2 = 3 O
O
O

_0=0
_1=1
_2=1
_3=1
_4=0
_5=0

O _4

O _5

Comparison with Expressions


C M P
e x p r e s s io n
in t _ 3 = in t _ 2
C M P
e x p r e s s io n
in t _ 3 < > in t _ 2
C M P
e x p r e s s io n
in t _ 3 < in t _ 2
C M P
e x p r e s s io n
in t _ 3 < = in t _ 2
C M P
e x p r e s s io n
in t _ 3 > in t _ 2
C M P
e x p r e s s io n
in t _ 3 > = in t _ 2

O _0

O _1

O _2

O _3

O _4

O _5

Limit Functions

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

in t _ 5 . 0

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

in t _ 5 . 1

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

in t _ 5 . 2

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

in t _ 5 . 3

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

in t _ 5 . 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 )

in t _
in t _
in t _
in t _
in t _
in t _

1
5
11
15

0
0
0
0
0
0

0
1
2
3
4
5

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

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

a f t e r ( b in a r y )
0
0
0
0
0
0

0001
0101
1011
1111
1000
0000

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

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

0
0
0
0
0
0

0
0
0
0
0
0

0001
0101
1011
1111
1000
1101

Boolean Functions

A
O
N
X

N
R
O
O

D ( v a lu e , v a lu e , d e s t in a t io n )
( v a lu e , v a lu e , d e s t in a t io n ) T ( v a lu e , v a lu e , d e s t in a t io n )
R ( v a lu e , v a lu e , d e s t in a t io n )

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
B
-

B in a r y a n d f u n c t io n
in a r y o r f u n c t io n
B in a r y n o t f u n c 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 fte r

a d d r.
n [0 ]
n [1 ]
n [2 ]
n [3 ]
n [4 ]
n [5 ]

d a ta
0011
1010
0010
1011
1001
1100

( b in a r y )
010111011011
010011101010
010011001010
010111111011
000100110001
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

Das könnte Ihnen auch gefallen