• 沒有找到結果。

Differences between the Set and Reset Instructions and the Out and OutNot Instructions

在文檔中 Instructions Reference Manual (頁 84-91)

The OutNot instruction takes the inverse of the logical result from the previous instruction and outputs it to a specified BOOL variable.

Logic processing result from previous instruction Output

TRUE FALSE

FALSE TRUE

The following figure shows a programming example and timing chart.

TRUE FALSE TRUE FALSE A

B4

Instruction executed

A B4

Additional Information

Differences between the Set and Reset Instructions and the Out and OutNot Instructions

• The Set and Reset instructions operate only when the input value changes to TRUE. They do not operate when the input value is FALSE. When the input value is FALSE, the output does not change.

• The Out and OutNot instructions affect the output whether the logical result of the previous

instruc-tion is TRUE or FALSE.

Precautions for Correct Use

• In the following case, an error occurs and nothing is output.

a) You specify an array element for the variable value and the element does not exist.

Example: A BOOL array a[0..5] is defined, but the instruction is executed using a[10] as the vari-able.

• The following connections are possible.

a) You can connect another Out instruction after the Out instruction.

A B C

b) You can connect the LD instruction and Out instruction after the Out instruction.

A B C D

• The following connections are not possible.

a) You cannot connect only the LD instruction after the Out instruction.

A B C

b) Functions and function blocks cannot be connected after the Out instruction.

C D

A B

MOVE EN ENO In Out

c) Branches and joins cannot be used after Out instructions.

A B

A B

C D

Ladder Diagram Instructions

2

Out and OutNot

ST Statement Instructions

Instruction Name Page

IF If page 2-28

CASE Case page 2-32

WHILE While page 2-36

REPEAT Repeat page 2-39

EXIT Break Loop page 2-42

RETURN Return page 2-45

FOR Repeat Start page 2-46

2

IF

The IF construct selects one of two statements to execute, based on the evaluation result of a speci-fied condition expression.

Instruction Name FB/

FUN Graphic expression ST expression

IF If --- None

IF condition expression THEN statement;

ELSIF condition expression THEN statement;

ELSE statement;

END_IF;

Variables

None

Function

The IF construct selects one of two statements to execute, based on the evaluation result of a speci-fied condition expression. Use a condition expression that evaluates to TRUE or FALSE as shown in the table below.

Item used for condition

expression Example Evaluation result

Logic expression

a > 3 If the value of variable a is greater than 3, the result is TRUE. Other-wise, the result is FALSE.

a = b If the values of variables a and b are equal, the result is TRUE. Other-wise, the result is FALSE.

BOOL variable abc If the value of variable abc is TRUE, the result is TRUE. If it is FALSE, the result is FALSE.

BOOL constant TRUE TRUE

Function with a BOOL

re-turn value FUN name If the function returns TRUE, the result is TRUE. If it returns FALSE, the result is FALSE.

You can use the following operators in the logic expression.

Opera-tor Meaning Example Evaluation result

= Equals a = b If the values of variables a and b are equal, the result is TRUE. Other-wise, the result is FALSE.

<> Not equals a <> b If the values of variables a and b are not equal, the result is TRUE. Other-wise, the result is FALSE.

Opera-tor Meaning Example Evaluation result

<

Comparison

a < b If the value of variable a is less than the value of variable b, the result is TRUE. Otherwise, the result is FALSE.

<= a <= b If the value of variable a is less than or equal to the value of variable b, the result is TRUE. Otherwise, the result is FALSE.

> a > b If the value of variable a is greater than the value of variable b, the result is TRUE. Otherwise, the result is FALSE.

>= a >= b If the value of variable a is greater than or equal to the value of variable b, the result is TRUE. Otherwise, the result is FALSE.

AND (&) Logical AND a AND b

a & b The result is the logical AND of BOOL variables a and b.

OR Logical OR a OR b The result is the logical OR of BOOL variables a and b.

XOR Exclusive OR a XOR b The result is the logical exclusive OR of BOOL variables a and b.

NOT NOT NOT a The result is the NOT of BOOL variable a

In the following flowchart, the IF construct is executed based on the evaluation results of condition ex-pressions 1 and 2. More than one statement can be used in a IF construct, as shown below.

IF condition expression 1 THEN statement 1;

ELSIF condition expression 2 THEN statement 2;

ELSE

statement 3;

END_IF;

FALSE

TRUE FALSE

TRUE Condition expression 1

Condition expression 2 Statement 1

Statement 3 Statement 2

Additional Information

• IF statements can be nested. The following example executes statement 11 if the evaluation results of both condition expression 1 and condition expression 11 are TRUE.

IF condition expression 1 THEN IF condition expression 11 THEN

ST Statement Instructions

2

IF

statement 11;

ELSIF condition expression 12 THEN statement 12;

ELSE

statement 13;

END_IF;

ELSIF condition expression 2 THEN statement 2;

ELSE

statement 3;

END_IF;

You can use ELSIF more than once. The following processing flow is for this example.

IF condition expression 1 THEN statement 1;

ELSIF condition expression 2 THEN statement 2;

ELSIF condition expression 3 THEN statement 3;

ELSE

statement 4;

END_IF;

FALSE

TRUE FALSE

TRUE FALSE

TRUE Condition expression 1

Statement 1

Statement 3 Statement 4 Statement 2

Condition expression 2

Condition expression 3

• ELSIF is not needed if the IF construct has only one condition expression. ELSE is not needed ei-ther if no processing is required when none of the condition expressions evaluate to TRUE. The fol-lowing processing flow is for this example.

IF condition expression THEN statement;

END_IF;

FALSE TRUE Statement

Condition expression

• There are no restrictions on the statements that you can use. You can use any statements for the IF construct as you do for other instructions, such as function block calls and FOR statements.

Precautions for Correct Use

• You must always use IF and END_IF. IF and END_IF must be paired.

• You can nest statement constructs up to a maximum of 15 levels, including IF, CASE, FOR, WHILE,

and REPEAT statements.

在文檔中 Instructions Reference Manual (頁 84-91)