Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Jack H.Automating manufacturing systems with PLCs.2005.pdf
Скачиваний:
261
Добавлен:
23.08.2013
Размер:
5.34 Mб
Скачать

plc basic functions - 15.15

FAL

A Control R6:0 length 5 position 0 Mode all

Destination #N7:5 Expression #N7:0 + 5

FAL

B Control R6:1

length 5

position 0

Mode 2

Destination #N7:5

Expression N7:0 + 5

FAL

C Control R6:2 length 5 position 0

Mode incremental Destination N7:5 Expression #N7:0 + 5

Figure 15.14 File Algebra Example

file to file

element to file file to element

file to element

15.3 LOGICAL FUNCTIONS

15.3.1 Comparison of Values

Comparison functions are shown in Figure 15.15. Previous function blocks were outputs, these replace input contacts. The example shows an EQU (equal) function that compares two floating point numbers. If the numbers are equal, the output bit B3:5/1 is true, otherwise it is false. Other types of equality functions are also listed.

plc basic functions - 15.16

 

EQU

 

B3:5

 

 

 

 

 

A F8:01

 

 

 

 

 

 

 

 

B F8:02

01

 

 

 

 

 

EQU(value,value) - equal NEQ(value,value) - not equal LES(value,value) - less than LEQ(value,value) - less than or equal GRT(value,value) - greater than GEQ(value,value) - greater than or equal

CMP(expression) - compares two values for equality MEQ(value,mask,threshold) - compare for equality using a mask LIM(low limit,value,high limit) - check for a value between limits

Figure 15.15 Comparison Functions

The example in Figure 15.16 shows the six basic comparison functions. To the right of the figure are examples of the comparison operations.

plc basic functions - 15.17

 

 

 

O:012

 

EQU

 

 

 

 

 

 

A N7:03

 

 

 

 

 

 

 

 

B N7:02

00

 

 

 

O:012

 

 

 

 

NEQ

 

 

 

 

 

 

A N7:03

 

 

 

 

 

 

 

 

B N7:02

01

 

 

 

O:012

 

 

 

 

LES

 

 

 

 

 

 

A N7:03

 

 

 

 

 

 

 

 

B N7:02

02

 

 

 

O:012

 

 

 

 

LEQ

 

 

 

 

 

 

A N7:03

 

 

 

 

 

 

 

 

B N7:02

03

 

 

 

O:012

 

 

 

 

GRT

 

 

 

 

 

 

A N7:03

 

 

 

 

 

 

 

 

B N7:02

04

 

 

 

O:012

 

 

 

 

GEQ

 

 

 

 

 

 

A N7:03

 

 

 

 

 

 

 

 

B N7:02

05

 

 

 

 

 

Figure 15.16 Comparison Function Examples

O:012/0=0

O:012/1=1

N7:3=5 O:012/2=0 N7:2=3 O:012/3=0 O:012/4=1 O:012/5=1

O:012/0=1

O:012/1=0

N7:3=3 O:012/2=0 N7:2=3 O:012/3=1 O:012/4=0 O:012/5=1

O:012/0=0

O:012/1=1

N7:3=1 O:012/2=1 N7:2=3 O:012/3=1 O:012/4=0 O:012/5=0

The ladder logic in Figure 15.16 is recreated in Figure 15.17 with the CMP function that allows text expressions.

plc basic functions - 15.18

 

CMP

 

O:012

 

 

 

 

 

 

 

 

 

 

expression

 

 

 

 

 

 

 

 

 

 

N7:03 = N7:02

00

 

 

 

 

O:012

 

 

 

 

 

 

CMP

 

 

 

 

 

 

 

expression

 

 

 

 

 

 

 

 

 

 

N7:03 <> N7:02

01

 

 

 

 

O:012

 

 

 

 

 

 

CMP

 

 

 

 

 

 

 

expression

 

 

 

 

 

 

 

 

 

 

N7:03 < N7:02

02

 

 

 

 

O:012

 

 

 

 

 

 

CMP

 

 

 

 

 

 

 

expression

 

 

 

 

 

 

 

 

 

 

N7:03 <= N7:02

03

 

 

 

 

O:012

 

 

 

 

 

 

CMP

 

 

 

 

 

 

 

expression

 

 

 

 

 

 

 

 

 

 

N7:03 > N7:02

04

 

 

 

 

O:012

 

 

 

 

 

 

CMP

 

 

 

 

 

 

 

expression

 

 

 

 

 

 

 

 

 

 

N7:03 >= N7:02

05

 

 

 

 

 

 

 

Figure 15.17 Equivalent Statements Using CMP Statements

Expressions can also be used to do more complex comparisons, as shown in Figure 15.18. The expression will determine if F8:1 is between F8:0 and F8:2.

 

 

 

O:012

 

 

CMP

 

 

 

 

 

 

 

 

expression

 

 

 

 

 

 

 

 

 

 

(F8:1 > F8:0) & (F8:1 < F8:2)

04

 

 

 

 

 

 

 

 

 

 

 

 

 

Figure 15.18 A More Complex Comparison Expression

The LIM and MEQ functions are shown in Figure 15.19. The first three functions will compare a test value to high and low limits. If the high limit is above the low limit and the test value is between or equal to one limit, then it will be true. If the low limit is above

plc basic functions - 15.19

the high limit then the function is only true for test values outside the range. The masked equal will compare the bits of two numbers, but only those bits that are true in the mask.

LIM

low limit N7:0 test value N7:1 high limit N7:2

LIM

low limit N7:2 test value N7:1 high limit N7:0

LIM

low limit N7:2 test value N7:3 high limit N7:0

MEQ source N7:0 mask N7:1

compare N7:2

MEQ source N7:0 mask N7:1

compare N7:4

N7:5/0

N7:5/1

N7:5/2

N7:5/3

N7:5/4

Addr.

 

before (decimal)

before (binary)

 

after (binary)

 

 

 

 

 

 

N7:0

 

1

0000000000000001

 

0000000000000001

N7:1

 

5

0000000000000101

 

0000000000000101

N7:2

 

11

0000000000001011

 

0000000000001011

N7:3

 

15

0000000000001111

 

0000000000001111

N7:4

 

 

0000000000001000

 

0000000000001000

N7:5

 

0

0000000000000000

 

0000000000001101

 

 

Figure 15.19 Complex Comparison Functions

plc basic functions - 15.20

Figure 15.20 shows a numberline that helps determine when the LIM function will

be true.

high limit

 

 

low limit

 

 

 

 

low limit

high limit

Figure 15.20 A Number Line for the LIM Function

File to file comparisons are also permitted using the FSC instruction shown in Figure 15.21. The instruction uses the control word R6:0. It will interpret the expression 10 times, doing two comparisons per logic scan (the Mode is 2). The comparisons will be

F8:10<F8:0, F8:11<F8:0 then F8:12<F8:0, F8:13<F8:0 then F8:14<F8:0, F8:15<F8:0 then F8:16<F8:0, F8:17<F8:0 then F8:18<F8:0, F8:19<F8:0. The function will continue until a false statement is found, or the comparison completes. If the comparison completes with no false statements the output A will then be true. The mode could have also been All to execute all the comparisons in one scan, or Increment to update when the input to the function is true - in this case the input is a plain wire, so it will always be true.

 

FSC

 

A

 

Control R6:0

 

 

 

Length 10

 

 

 

 

 

 

Position 0

 

 

 

Mode 2

 

 

 

Expression #F8:10 < F8:0

 

 

 

 

 

 

Figure 15.21 File Comparison Using Expressions