• 沒有找到結果。

l Set and Reset with Input Downward Differentiation Specification

在文檔中 Instructions Reference Manual (頁 142-153)

When the master control is reset, the execution condition changes to FALSE. If the previous execution

condition was TRUE, then the input downward differentiation condition is met. However, during the

master control reset, the previous output value is retained, so as a result the value of the output is

retained.

A

0 0

MC In ENO MCNo

MCR EN ENO MCNo

MC_ON

A

B MC_ON

TRUE FALSE TRUE FALSE TRUE FALSE TRUE FALSE

Master control reset

Output from LD instruction B

NS

The input downward differentiation condition is met, but master control is reset, so the output is retained.

A

0 0

MC In ENO MCNo

MCR EN ENO MCNo

MC_ON

A

B MC_ON

TRUE FALSE TRUE FALSE TRUE FALSE TRUE FALSE

Master control reset

Output from LD instruction B

NR

The input downward differentiation condition is met, but master control is reset, so the output is retained.

l CTU, CTD, and CTUD

When the master control is reset, the value of the counter input changes to FALSE. If the value of the counter input is TRUE when the master control reset is cleared, the input upward differentiation condi-tion is met and the instruccondi-tion counts.

A

0 0

B

B MC

In ENO MCNo

MCR EN ENO MCNo MC_ON

CTU CU Q Reset CV PV

CTU_instance

MC_ON

A

TRUE FALSE TRUE FALSE TRUE FALSE

Master control reset

Output from LD instruction

Input upward differentiation condition met.

Always use the MC and MCR instructions as a pair in the same POU. The same value is used for master control number MCNo for both of the paired MC and MCR instructions. The user does not set the value of MCNo. It is automatically registered by the Sysmac Studio.

The MC and MCR instructions can be nested to up to 15 levels.

Sequence Control Instructions

2

MC and MCR

0

0 1

1

MCR EN ENO MCNo

MCR EN ENO MCNo

MC In ENO MCNo

MC In ENO MCNo

The following figure shows a programming example.

If the value of bit A is FALSE, the master control region is reset. While the master control region is in a reset state, the TON instruction is reset. The MOVE instruction is not executed. Also the Out instruc-tion and OutNot instrucinstruc-tion will output FALSE to bits D and E.

These are not executed.

FALSE is output.

A

0 0

B abc T#10ms def

C

TON In Q PT ET

TON_instance

INT#0 array[position]

Reset.

UINT#0 UINT#10 UINT#1

position FOR

EN ENO InitVal Index EndVal StepVal

NEXT EN ENO

D

E MOVE EN ENO In Out

MC In ENO MCNo

MCR EN ENO MCNo

Precautions for Correct Use

• These instructions must be used in a ladder diagram. They cannot be used in ST. They also cannot

be used in inline ST in a ladder diagram.

• Always connect In directly to the left bus bar. You cannot pass a variable or constant to In.

• Always use the MC and MCR instructions as a pair in the same POU.

• Always place the MCR instruction after the MC instruction.

• Do not nest the MC and MCR instructions to more than 15 levels.

• If there is inline ST in the master control region, the inline ST is not executed when the master con-trol region is reset.

• If you use the MC and MCR instructions and the JMP instruction together, the operation is as fol-lows:

a) The following figure shows an MC-MCR pair inside a JMP-Label pair. Here, the jump is executed regardless of the value of In.

Label Flow of processing

JMP instruction executed.

Not executed due to JMP instruction.

Instructions after the label are executed.

Label 0

0

MCR EN ENO MCNo

MC In ENO MCNo

b) The following figure shows a JMP-Label pair inside an MC-MCR pair. Here, operation is as given in the following table.

Value of In Operation

TRUE Master control region is not reset.

The jump is made.

FALSE Master control region is reset.

The jump is not made.

Sequence Control Instructions

2

MC and MCR

Label

Label 0

0

0

0 MCR

EN ENO MCNo

MC In ENO MCNo

Label

Label

MCR EN ENO MCNo

MC In ENO MCNo Flow of processing

l In = TRUE l In = FALSE

MC instruction not executed.

MCR instruction not executed.

Instructions after the label are executed.

Not executed due to JMP instruction.

JMP instruction executed.

Flow of processing MC instruction

executed.

MCR instruction executed.

Master control reset

JMP instruction not executed.

c) In the following figure, the JMP instruction, the MC instruction, a Label, and the MCR instruction are arranged in the stated order. First, the JMP instruction is executed. As a result, the MC in-struction is not executed. Therefore, inin-structions can be executed after the Label. If the value of

In is FALSE, the MCR instruction is executed, but nothing changes.

Flow of processing

l In = TRUE l In = FALSE

JMP instruction executed.

MCR instruction not executed.

Instructions after the label are executed.

Not executed due to JMP instruction.

MC instruction not executed.

Instructions after the label are executed.

Flow of processing JMP instruction

executed.

MCR instruction executed, but nothing changes.

Not executed due to JMP instruction.

Label

Label 0

0

MCR EN ENO MCNo

MC In ENO MCNo

Label

Label 0

0

MCR EN ENO MCNo

MC In ENO MCNo MC instruction

not executed.

d) The instructions are in the following order in the following figure: MC instruction, JMP instruction, MCR instruction, and Label. Here, operation is as given in the following table.

Value of In Operation

TRUE Master control region is not reset.

The jump is made.

FALSE Master control region is reset.

The jump is not made.

Flow of processing

l In = TRUE l In = FALSE

MC instruction not executed.

MCR instruction not executed.

Instructions after the label are executed.

Not executed due to JMP instruction.

JMP instruction executed.

MCR instruction executed.

Flow of processing

MC instruction executed.

JMP instruction not executed.

Label

Label 0

0

MCR EN ENO MCNo

MC In ENO MCNo

Label

Label 0

0

MCR EN ENO MCNo

MC In ENO MCNo Master control

reset

• If you use the MC and MCR instructions and the FOR and NEXT instructions together, the operation is as follows:

a) The following figure shows an MC-MCR pair inside a FOR-NEXT pair. Here, operation is as giv-en in the following table.

Value of In Operation

TRUE Master control region is not reset.

The FOR loop is executed.

FALSE

Master control region is reset.

The FOR loop is executed, but the instructions between the MC and MCR instructions are not executed.

Flow of processing

l In = TRUE l In = FALSE

Flow of processing

NEXT FOR

0

0

MCR EN ENO MCNo

MC In ENO MCNo

NEXT FOR

0

0

MCR EN ENO MCNo

MC In ENO MCNo MC instruction

not executed.

MCR instruction

not executed. MCR instruction

executed.

MC instruction executed.

Master control reset

FOR instruction executed. FOR instruction

executed.

b) The following figure shows a FOR-NEXT pair inside an MC-MCR pair. Here, operation is as giv-en in the following table.

Value of In Operation

TRUE Master control region is not reset.

The FOR loop is executed.

Sequence Control Instructions

2

MC and MCR

Value of In Operation FALSE Master control region is reset.

The FOR loop is not executed.

Flow of processing

l In = TRUE l In = FALSE

Flow of processing

NEXT FOR 0

0

MCR EN ENO MCNo

MC In ENO MCNo

NEXT FOR 0

0

MCR EN ENO MCNo

MC In ENO MCNo MC instruction

not executed.

MCR instruction not executed.

MCR instruction executed.

MC instruction executed.

Master control reset

FOR instruction executed. FOR instruction

not executed.

c) A building error occurs if the FOR, NEXT, MC, and MCR instructions are used in either of the following orders.

FOR, MC, NEXT, MCR, or MC, FOR, MCR, NEXT

JMP

The JMP instruction moves processing to the specified jump destination.

Instruction Name FB/

FUN Graphic expression ST expression

JMP Jump FUN Label None

Variables

None

Function

When the execution condition is TRUE, the JMP instruction moves processing to the jump destination specified by a Label in a ladder diagram. The label can be any text string.

The following figure shows a programming example. This example uses the text string STEP1 as the label. When the JMP instruction is executed, processing moves to the location marked STEP1. In this example, the Out instruction between the JMP instruction and the Label is not executed, and the value of variable B is retained.

LD

A B

STEP1

Not executed and value of variable B retained.

STEP1 C D

Additional Information

• You can also jump to a Label instruction above the JMP instruction in the section.

• You can use the same Label instruction as the jump destination for more than one JMP instruction.

Precautions for Correct Use

• You cannot omit labels. If you omit a label, a building error will occur.

Sequence Control Instructions

2

JMP

• Place the JMP and Label instructions in the same POU and in the same section.

• Do not set the same Label instruction more than once in the same section.

• You cannot jump into a FOR-NEXT loop from outside the loop.

• The following restrictions apply to the characters that can be used as labels.

Item Specification

Maximum number of bytes

127 bytes

127 characters when converted to ACSII

31 characters when converted to Japanese characters (including single-byte kana) Character code UTF-8

Applicable char-acters

Not case sensitive.

English alphanumeric characters and other language characters.

Symbols: _ (underbar) and ~ (tilda)

Prohibited text strings

Any text string that starts with ASCII characters 0 to 9 (character codes 16#30 to 16#39)

A text string that consists of only a single _ (underbar) ASCII character

Any text string that includes two or more consecutive _ (underbar) ASCII characters

Any text string that starts with an _ (underbar) ASCII character

Any text string that ends with an _ (underbar) ASCII character

Any text string that starts with P_

Prohibited

charac-ters Blank space ! " # $ & ' ( ) * + , - . / : ; < = > ? @ [ ] ^ ` %

• Variable names cannot be used as labels.

FOR and NEXT

FOR : Marks the starting position for repeat processing and specifies the repeat condition.

NEXT : Marks the ending position for repeat processing.

Instruction Name FB/

FUN Graphic expression ST expression

FOR Repeat Start FUN

FOR EN ENO InitVal Index EndVal StepVal

FOR Index:=InitVal TO EndVal BY StepVal DO expression END_FOR*;

* In ST, do not use NEXT to mark the ending position of repeat proc-essing. Use END_FOR instead.

NEXT Repeat End FUN

NEXT EN ENO

Variables

Meaning I/O Description Valid range Unit Default

InitVal Initial value

Input

Value to set the Index to when repetition is

started. Depends on

da-ta type.*1

---*2

EndVal End value Value of Index where

repetition is stopped

StepVal Increment

Value to add to Index each time processing is repeated

Depends on

da-ta type.*3 *4

Index Control variable Output Loop index Depends on

da-ta type. ---

---*1. When using a ladder diagram, set InitVal so that it is less than EndVal.

*2. If you omit an input parameter, the default value is not applied. A building error will occur.

*3. When using a ladder diagram, 0 and negative numbers are not included. When using an ST program, 0 is not included.

*4. If you omit the input parameter in a ladder diagram, the default value is not applied. A building error will occur. If you omit the input parameter in ST, a default value of 1 is applied.

Boo

lean Bit strings Integers

Real num-bers

Times, durations, dates, and text strings

BOOL BYTE WORD DWORD LWORD USINT UINT UDINT ULINT SINT INT DINT LINT REAL LREAL TIME DATE TOD DT STRING

InitVal OK OK OK OK OK OK OK OK

An enumeration, array element or structure member can also be specified.*1

EndVal OK OK OK OK OK OK OK OK

An array element or structure member can also be specified.

StepVal OK OK OK OK OK OK OK OK

An array element or structure member can also be specified.

Sequence Control Instructions

2

FOR and NEXT

Boo

lean Bit strings Integers

Real num-bers

Times, durations, dates, and text strings

BOOL BYTE WORD DWORD LWORD USINT UINT UDINT ULINT SINT INT DINT LINT REAL LREAL TIME DATE TOD DT STRING

Index OK OK OK OK OK OK OK OK

An array element or structure member can also be specified.

*1. You cannot specify enumerations in ladder diagrams.

Function

The FOR and NEXT instructions repeat the processing that you place between them. (FOR and END_FOR are used in ST.)

The processing procedure for a FOR-NEXT loop is as follows:

1 The value of InitVal is set in control variable Index.

2 The values of StepVal, Index, and EndVal are checked to see if the conditions in the following table are met. If the conditions are met, processing moves to step 3. If the conditions are not met, repeat processing is not performed, and processing moves to the next process after the NEXT instruction (or END_FOR in ST).

Programming language Conditions to start repeat processing Ladder diagram StepVal ≥ 0 and Index ≤ EndVal

ST StepVal ≥ 0 and Index ≤ EndVal

StepVal < 0 and Index ≥ EndVal

3 The values of Index and EndVal are checked to see if the conditions in the following table are met. If the conditions are met, processing moves to step 4. If the conditions are not met, repeat processing is ended, and processing moves to the next process after the NEXT instruction (or END_FOR in ST).

Programming language Conditions to continue repeat processing

Ladder diagram Index ≤ EndVal

ST If StepVal ≥ 0, Index must be ≤ EndVal

If StepVal < 0, Index must be ≥ EndVal

4 The processing between the FOR instruction and the NEXT instruction (or the END_FOR in-struction in ST) is executed once.

5 The value of StepVal is added to Index.

6 Processing returns to step 3.

The following example is for when InitVal is INT#0, EndVal is INT#9, and StepVal is INT#1. The MOVE

instruction is executed 10 times and INT#0 is assigned to array variables AryOut[0] to AryOut[9].

FOR position:=INT#0 TO INT#9 BY INT#1 DO AryOut[position]:=INT#0;

END_FOR;

LD ST

INT#0 AryOut[position]

INT#0 INT#9 INT#1

position FOR

EN ENO InitVal Index EndVal StepVal

NEXT EN ENO

MOVE EN ENO In Out

INT#0 → InitVal INT#9 → EndVal INT#1 → StepVal

INT#0 INT#0 is assigned in order to AryOut[0] to AryOut[9].

InitVal → Index

* For ST: InitVal ≤ EndVal Index + StepVal → Index

INT#0 → AryOut[Index]

Index ≤ EndVal TRUE

TRUE

FALSE

END

FALSE

INT#0 INT#0 INT#0 INT#0 INT#0 INT#0 INT#0 INT#0 INT#0 INT#0 AryOut[0]

AryOut[1]

AryOut[2]

AryOut[3]

AryOut[4]

AryOut[5]

AryOut[6]

AryOut[7]

AryOut[8]

AryOut[9]

StepVal ≥ 0 and Index < EndVal *

START

ST Programming Example That Uses Expressions or Functions for

在文檔中 Instructions Reference Manual (頁 142-153)