Main ↔ ↔ subprogram switching (CHG) ↔ ↔

Một phần của tài liệu type acpu (common instructions) programming manual ib-66250c (Trang 182 - 195)

Available Device

Bit device Word (16-bit) device Constant Pointer Level Carry flag Error flag

X Y M L S B F T C D W R A0 A1 Z V K H P I N

Digit specification Index

M9012 (M9010, M9011)

Functions (1) Executes switching between the main program and subprogram after the timer/

counter processing and self-diagnostic check, general data processing, data link/network refresh processing, and I/O processing.

AnS AnN AnSH

An A1FX A3H

A3M A3V AnA AnU

A2AS A0J2H A2C

A52G A73 A3N boad Applicable

CPU

X O O X X O O

Remark *1: A3N only *3: A3A only

*2: A3 only *4: A3U and A4U only

Switching command Interlock contact

CHG

*1 *2 *3 *4

CHG

END

CHG

Sequence program

END

Sequence program Timer, counter processing Self-diagnostic check,

l d t i d t li k/ t k

Sequence program

Sequence program

(2) For further information on functions and applications, refer to the use of subprograms given in the ACPU Programming Manual (Fundamentals).

POINTS

(1) A4U's CHG instruction is used to switch subsequence programs 1, 2, and 3 which are set in the main sequence program.

When up to subsequence program 2 has been set, programs are switched as the main sequence program

→ subsequence program1 → subsequence program 2

→ main sequence program.

(2) To switch specified programs, use a ZCHG dedicated instruction.

The AnACPU/AnUCPU Programming Manual (Dedicated Instructions) Execution (1) When the A3 is used, the CHG instruction is only executed on the leading edge Conditions of its input condition. Since operation result of the input condition changes with status of M9050, execution contents of the CHG instruction change with status

of M9050.

Status of M9050

OFF ON

Ladder example

The following program is written before END or FEND of the main and subsequence programs.

Timing chart

OFF No switching between the main and subsequence programs. (4), 5), 11))

No switching between the main and subsequence programs (4), 5), 11))

ON

CHG instruction is executed every scan and switches between the main and subsequence programs.

(2), 3), 7), 8), 9), 10))

The main sequence program is only switched to the subsequence program, then back to the main sequ-ence program on the first leading edge of the CHG instruction execution command (X0). (2)) Operation

depending on ON/OFF of

X0

OFF

↓ ON

Switched between the main and subsequence prog-rams ( 1), 6), 12))

Switched between the main and subsequence prog-rams ( 1), 6), 12))

Remarks When the CHG instruction is executed, END processing (e.g. timer timing, counter counting, WDT reset) is performed for the current program and operation is started from step 0 of the other program.

X0

CHG instruction execution in main sequence program Main sequence program

OFF

ON 1) 2) 3) 4) 5) 6) 7) 8) 9) 10) 11) 12) X0

CHG instruction execution in main sequence program Main sequence program

OFF

ON 1) 2) 3) 4) 5) 6) 7) 8) 9) 10) 11) 12) X000 Inter lock

CHG Input condition

Main sequence program

Subsequence Program 1

Subsequence Program 2

CHG

CHG

CHG 0 0

0

gives details of the ZCHG instruction.

(2) When the A3N, A73, A3V and A3N board are used, the CHG instruction is only executed on the leading edge of its input condition. Since M9050 is not

provided, execution contents of the CHG instruction are always same.

Ladder example

The following program is written before END or FEND of the main and subsequence programs.

Timing chart

OFF No switching between the main and subsequence programs. (4), 5), 11))

ON The main sequence program is only switched to the subsequence program, then back to the main sequence program on the first leading edge of the CHG instruction execution command (X0). (2))

Operation depending on ON/OFF

of X0 OFF

↓ ON

Switched between the main and subsequence programs ( 1), 6), 12))

Remarks When the CHG instruction is executed, END processing (e.g. timer timing, counter counting, WDT reset) is performed for the current program and operation is started from step 0 of the other program.

(3) When the A3H, A3M, AnA, A3U and A4U are used, the CHG instruction is executed repeatedly while its input condition is on.

Ladder example

The following program is written before END or FEND of the main and subsequence programs.

Timing chart

OFF No switching between the main and subsequence programs. (4), 5), 11))

ON CHG instruction is executed every scan and switches between the main and subsequence programs. (2), 3), 7), 8), 9), 10))

Operation depending on ON/OFF

of X0 OFF ON

Switched between the main and subsequence programs (1), 6), 12))

Remarks When the CHG instruction is executed, END processing (e.g. timer timing, counter counting, WDT reset) is performed for the current program and operation is started from step 0 of the other program.

X000 Interlock

CHG Input condition

X0

CHG instruction execution in main sequence program

Main sequence program OFF

ON

1) 2) 3) 4) 5) 6) 7) 8) 9) 10) 11) 12) X000 Inter lock

CHG

X0

CHG instruction execution in main sequence program Main sequence program

OFF ON

1) 2) 3) 4) 5) 6) 7) 8) 9) 10) 11) 12)

Execution of PLS Instruction Used with CHG Instruction

(1) When the A3 is used, execution contents of the PLS instruction change with status of M9050 when other input conditions are same.

Status of M9050

OFF ON

Ladder example

The following program is written at step 0 of the main and subsequence programs.

Timing chart

OFF M0 is not switched on. M0 is not switched on.

ON M0 is only switched on during the first scan after switched by the CHG instruction.

M0 is only switched on during the first scan of the subsequence program selected by the CHG instruction executed after X0 is switched on.

Operation

X0 status

OFF

↓ ON

M0 is only switched on during 1 scan. M0 is only switched on during 1 scan.

(2) When the A3N, A73 and A3V are used, execution contents are always same.

Ladder example

The following program is written at step 0 of the main and subsequence programs.

Timing chart

OFF M0 is not switched on.

ON M0 is only switched on during the first scan of the subsequence program selected by the CHG instruction executed after X0 is switched on.

Operation

X0 status

OFF

↓ ON

M0 is only switched on during 1 scan.

X000

PLS M0

Input condition

Main sequence program run

Subsequence program run

OFF ON

OFF ON

CHG instruction execution CHG instruction execution

1 scan

Main sequence program run

Subsequence program run

OFF ON

OFF ON

CHG instruction execution

CHG instruction execution 1scan

CHG instruction execution

OFF ON

OFF ON Main sequence program run

Subsequence program run

1 scan

CHG instruction execution

X000

PLS M0

Input condition 0

0

(3) When the A3H, A3M, A3A, A3U and A4U are used, the CHG instruction is executed repeatedly while its input condition is on.

Ladder example

The following program is written before END or FEND of the main and subsequence programs.

Timing chart

OFF M0 is not switched on.

ON M0 is only switched on during the first scan of the subsequence program selected by the CHG instruction executed after X0 is switched on.

Operation

X0 status

OFF

↓ ON

M0 is only switched on during 1 scan.

X000

PLS M0 Input condition

Main sequence program run

Subsequence program run

OFF ON

OFF ON

CHG instruction execution

CHG instruction execution 1 scan

0

Execution of P Instruction Used with CHG Instruction

(1) When the A3 is used, execution contents of the PLS instruction change with status of M9050 when other input conditions are same.

Status of M9050

OFF ON

Ladder example

The following program is written at step 0 of the main and subsequence programs.

Timing chart

OFF MOVP instruction is not executed. MOVP instruction is not executed.

ON The MOVP instruction is executed during the first scan after switched by the CHG instruction.

MOVP instruction is only executed during the first scan of the subsequence program selected by the CHG instruction executed after X0 is switched on.

Operation depending on X0 ON/OFF

status OFF

↓ ON

MOVP instruction is only executed once. MOVP instruction is only executed once.

(2) When the A3N, A73 and A3V are used, execution contents are always same.

Ladder example

The following program is written at step 0 of the main and subsequence programs.

Timing chart

OFF MOVP instruction is not executed.

ON MOVP instruction is only executed duing the first scan of the subsequence program selected by the CHG instruction executed after X0 is switched on.

Operation depending on X0 ON/OFF

status

OFF

↓ ON

MOVP instruction is only executed once.

CHG instruction execution 1 scan

Main sequence program run

Subsequence program run

CHG instruction execution

CHG instruction execution 1 scan

Main sequence program run

Subsequence program run

CHG instruction execution

CHG instruction execution 1scan

Main sequence program run

Subsequence program run

CHG instruction execution MOV

X000 P

X000

MOV 0 D0 P K

(3) When the A3H, A3M, A3A, A3U and A4U are used, the CHG instruction is executed repeatedly while its input condition is on.

Ladder example

The following program is written at step 0 of the main and subsequence programs.

Timing chart

OFF MOVP instruction is not executed.

ON MOVP instruction is only executed duing the first scan of the subsequence program selected by the CHG instruction executed after X0 is switched on.

Operation depending on X0 ON/OFF

status

OFF

↓ ON

MOVP instruction is only executed once.

CHG instruction execution 1scan

Main sequence program run

Subsequence program run

CHG instruction execution X000

MOV 0 D0 P K

Counting of Counter Used with CHG Instruction

(1) When the A3 is used, execution contents of the counter change with status of M9050 when other input conditions are same.

Status of M9050

OFF ON

Ladder example

The following program is written at step 0 of the main and subsequence programs.

Timing chart

OFF C0 count value remains unchanged. C0 cont value remains unchanged.

ON

C0 count value is incremented by 1 after END (FEND, CHG) is executed during the first scan of the program selected by the CHG instruction.

C0 count value is incremented by 1 after END (FEND, CHG) is executed during the first scan of the program selected by the CHG instruction executed after X0 is switched on.

Operation depending on

X0 ON/OFF status

OFF

↓ ON

C0 count value is incremented by 1 after END (FEND, CHG) is executed.

C0 count value is incremented by 1 after END (FEND, CHG) is executed.

(2) When the A3N, A73 and A3V are used, execution contents are always same.

Ladder example

The following program is written at step 0 of the main and subsequence programs.

Timing chart

OFF C0 count value remains unchanged.

ON C0 count value is incremented by 1 after END (FEND, CHG) is executed during the first scan of the program selected by the CHG instruction executed after X0 is switched on.

Operation depending on

X0 ON/OFF status OFF

↓ ON

C0 count value is incremented by 1 after END (FEND, CHG) is executed.

( )

X000 K10

C0

1 scan

Main sequence program run

CHG instruction execution

Subsequence program run X0 OFF

ON

C0 coil OFF ON

C0 count value 0 31 2 4

CHG instruction execution

1 scan

Main sequence program run

CHG instruction execution

Subsequence program run X0 OFF

ON

C0 coil OFF ON

C0 count value 0 1 2

CHG instruction execution

( )

X000 K10

C0

1 scan

CHG instruction execution Main sequence

program run Subsequence program run

CHG instruction execution X0 OFF

ON

C0 coil OFF 0 1

ON

2

(3) When the A3H, A3M, A3A, A3U and A4U are used, execution contents are always same.

Ladder example

The following program is written at step 0 of the main and subsequence programs.

Timing chart

OFF C0 count value remains unchanged.

ON C0 count value is incremented by 1 after END (FEND, CHG) is executed during the first scan of the program selected by the CHG instruction executed after X0 is switched on.

Operation depending on

X0 ON/OFF status OFF

↓ ON

C0 count value is incremented by 1 after END (FEND, CHG) is executed.

( )

X000 K10

C0

1 scan

Main sequence program run

CHG instruction execution

Subsequence program run X0 OFF

ON

C0 coil OFF ON

C0 count value 0 1 2

CHG instruction execution

Timing of Timer Used with CHG Instruction

Each of the CPUs with which the CHG instruction can be used has two timer set value storage areas; one for the main sequence program and the other for the subsequence program.

In these areas, the set value of the timer not in use is 0. The set value of 0 is regarded as infinite and the timer does not time out.

When the main (sub) sequence program is switched to the sub (main) sequence program by the CHG instruction after the timer in the main (sub) sequence program has started timing, the timer does not time out during execution of the sub (main) program because the timer set value specified in the main (sub) program is 0 in the sub (main) program timer set value storage area.

Ladder example

The following program is written after the main sequence program and the same timer number is not used in the subsequence program.

Timing chart

Operation

T200 started by the main sequence program does not time out while the subsequence program is running.

It times out on the following condition when the main sequence program is run again:

(Present value) < 0 or (set value) < (present value)

( )

X000 K15

T200

Main sequence program run Subsequence program run

X0 T200 coil

The timer does not time out as the set value in the sub-sequence program is 0.

The timer times out as the set value is greater than the present value. In this case, the value monitored is 15.

T200 contact

T200 coil is not switched off as OUT T200 is not executed when X0 is switched off.

10ms timer tim-ing value T200 present value

Execution of OUT Instruction Used with CHG Instruction

When the CPUs with which the CHG instruction can be used are used, the coil switched on/off in the main (sub) sequence program remains unchanged during sub (main) sequence program run even if its input condition changes.

Ladder example

The following program is written after the main sequence program and the same coil is not used in the subsequence program.

Timing chart

Operation Y70 is switched on/off when X0 is switched on/off during main sequence program run.

Y70 remains unchanged if X0 is switched on/off during subsequence program run.

( )

X000

Main sequence program run Subsequence program run X0

Y70

Y070

Program Examples CHG

The following programs are used with the A3CPU and other types of CPUs to output pulses in accordance with the input condition of the PLS instruction while alternately running the main and subprograms.

(1) For A3CPU

It is necessary to compare the operation result of a scan with that of the previous scan to allow correct output of the PLS instruction. M9050 must therefore be turned ON when the CHG instruction is executed to save the operation result of the previous scan, which has been stored in the operation result storage memory, in the save area.

Since the CHG instruction for the A3CPU is executed only when input conditions are turned ON, programs must be written in the forms shown below.

(2) For A3N, A73 and A3V CPUs

Since the CHG instruction for the A3NCPU is executed only when input conditions are turned ON, programs must be written in the forms shown below.

( )

( )

Main sequence program Sub sequence program

( )

( )

( )

( )

M9036 M0 M0 M0 M0 M0 P0 P1

M9051 M9051 M9051

M9057 M9057

M9050 M0 CJ P1

CHG CHG CJ P0 FEND Always on

M9036 M1 M1 M1 M1 M1 P0 P1

M9051 M9051 M9051

M9056 M9056

M9050 M1 CJ P1

CHG CHG CJ P0 FEND Always on

M0 M0 M0 M0 M0 P0 P1

M9051 M9051 M9051

M9057 M9057

M0 CJ P1

CHG

CHG CJ P0

FEND

M1 M1 M1 M1 M1 P0 P1

M9051 M9051 M9051

M9056 M9056

M1 CJ P1

CHG

CHG CJ P0

FEND

(3) For A3H, A3M, A3A, A3U and A4U program

CAUTION

When modifying a subprogram during main program run or vice versa, M9051, M9056 and M9057 contacts should be used to disable the CHG instruction so that the CHG instruction may not switch the currently running program to the program currently being corrected.

Always on

M9036 M9056 M9051 CHG FEND Always on

M9036 M9057 M9051 CHG FEND

Main sequence program Subsequence program

Một phần của tài liệu type acpu (common instructions) programming manual ib-66250c (Trang 182 - 195)

Tải bản đầy đủ (PDF)

(451 trang)