Browse
(440) 299-7778
Menu
(440) 299-7778
One-year parts and labor warranty30-day money-back guaranteeContact

The text of a manual · part 32 of 60

C200HX/C200HG/C200HE Programmable Controllers Operation Manual, pages 304 to 313

Pages 304 to 313 of 586

The original document is the PDF (3.4 MB). This is its text as extracted, unedited; tables and drawings read best in the PDF, and each page heading opens it at that page.

For the Omron C200HE-CPU42-E

Page 304

Section 5-23

Subroutines and Interrupt Control

The following diagram illustrates program execution flow for various execution conditions for two SBS(91). A SBS(91)

000

A

B Main program

SBS(91)

OFF execution conditions for subroutines 000 and 001

B

C

001 ON execution condition for subroutine 000 only

A

C

SBN(92)

000

D

B

C

ON execution condition for subroutine 001 only

A

B

E

C

D

Subroutines

RET(93) SBN(92)

001

ON execution conditions for subroutines 000 and 001

A

D

B

E

C

E

RET(93) END(001)

Note A non-fatal error (error code 8B) will be generated if a subroutine’s execution time exceeds 10 ms. Flags

ER:

A subroutine does not exist for the specified subroutine number. A subroutine has called itself. An active subroutine has been called.

! Caution

SBS(91) will not be executed and the subroutine will not be called when ER is ON.

5-23-4 SUBROUTINE DEFINE and RETURN – SBN(92)/RET(93) Ladder Symbols SBN(92) N

Definer Data Areas N: Subroutine number 000 to 255

RET(93)

Limitations

Each subroutine number can be used in SBN(92) once only.

Description

SBN(92) is used to mark the beginning of a subroutine program; RET(93) is used to mark the end. Each subroutine is identified with a subroutine number, N, that is programmed as a definer for SBN(92). This same subroutine number is used in any SBS(91) that calls the subroutine (see 5-23-3 SUBROUTINE ENTER – SBS(91)). No subroutine number is required with RET(93).

286

Page 305

Section 5-23

Subroutines and Interrupt Control

All subroutines must be programmed at the end of the main program. When one or more subroutines have been programmed, the main program will be executed up to the first SBN(92) before returning to address 00000 for the next cycle. Subroutines will not be executed unless called by SBS(91). END(01) must be placed at the end of the last subroutine program, i.e., after the last RET(93). It is not required at any other point in the program. Precautions

If SBN(92) is mistakenly placed in the main program, it will inhibit program execution past that point, i.e., program execution will return to the beginning when SBN(92) is encountered. If either DIFU(13) or DIFU(14) is placed within a subroutine, the operand bit will not be turned OFF until the next time the subroutine is executed, i.e., the operand bit may stay ON longer than one cycle.

Flags

There are no flags directly affected by these instructions.

5-23-5 MACRO – MCRO(99) Operand Data Areas N: Subroutine number

Ladder Symbols

000 to 255 MCRO(99)

@MCRO(99)

N

N

I1

I1

O1

O1

I1: First input word IR, SR, AR, DM, HR, TC, LR O1: First output word IR, SR, AR, DM, HR, LR

Limitations

I1 through I1+3 must be in the same data area, as must O1 through O1+3.

Description

The MACRO instruction allows a single subroutine to replace several subroutines that have identical structure but different operands. There are 4 input words, SR 290 to SR 293, and 4 output words, SR 294 to SR 297, allocated to MCRO(99). These 8 words are used in the subroutine and take their contents from I1 to I1+3 and O1 to O1+3 when the subroutine is executed. When the execution condition is OFF, MCRO(99) is not executed. When the execution condition is ON, MCRO(99) copies the contents of I1 to I1+3 to SR 290 to SR 293, copies the contents of O1 to O1+3 to SR 294 to SR 297, and then calls and executes the subroutine specified in N. When the subroutine is completed, the contents of SR 294 through SR 297 are then transferred back to O1 to O1+3 before MCRO(99) is completed.

287

Page 306

Section 5-23

Subroutines and Interrupt Control

In the following example, the contents of DM 0010 through DM 0013 are copied to SR 290 through SR 293, the contents of DM 0020 through DM 0023 are copied to SR 294 through SR 297, and subroutine 010 is called and executed. When the subroutine is completed, the contents of SR 294 through SR 297 are copied back to DM 0020 to DM 0023.

Main program MCRO(99)

010 DM 0010 DM 0020

Main program

SBN(92)

010

Subroutine RET(93) END(01)

Note

1. Subroutines for macros are programmed just like other subroutines, except that SR 290 to SR 297 contents are transferred in from the designated input and output words. 2. Not only external I/O words, but internal I/O words can be used for I1 and O1. 3. SR 290 to SR 297 can be used as work bits when not used for macro programs. 4. MCRO(99) instructions can be nested, but be sure to preserve I/O data since the instructions use the same 8 I/O words (SR 290 to SR 297).

Precautions

MCRO(99) can be used only for program sections that can be written using four or fewer consecutive input words and/or four or fewer consecutive output words. It is thus generally necessary to consider system and program design together to take full advantage of macro programming. Be careful that the input and output words properly correspond to the macro input and output words.

Flags

ER:

A subroutine does not exist for the specified subroutine number. An operand has exceeded a data area boundary. Indirectly addressed DM word is non-existent. (Content of word is not BCD, or the DM area boundary has been exceeded.) A subroutine has called itself. An active subroutine has been called.

288

Page 307

Section 5-23

Subroutines and Interrupt Control Example

The following examples shows the use of four MCRO(99) instructions that access the same subroutine. The program section on the left shows the same program without the use of MCRO(99).

25313 00000

10001

MCRO(99) 10000

090

Always ON Flag 10000

000 100

00001

00002 10001

MCRO(99) 090

00200

002

10501 10500

105

10500 MCRO(99) 00201

090

00202

005

10501

120 00500

MCRO(99)

12001 12000

090

12000

010 150

00501

00502 12001

01000

SBN(92)

29000

15001

29401 29400

15000 29400

15000

01001

090

29001

01002

29002 29401

15001

RET(93)

5-23-6 INTERRUPT CONTROL – INT(89) Operand Data Areas C: Control code

Ladder Symbols

# (000, 001, 002, 100, or 200)

Limitations

INT(89)

@INT(89)

C

C

N

N

D

D

N: Interrupt type # (000, 001, or 004) D: Control data IR, AR, DM, HR, TC, LR, #

D must be between #0000 and #00FF when N=000 and C=000 or 001. D must be BCD between #0001 and #9999 when N=004 and C=000 or 001.

289

Page 308

Section 5-23

Subroutines and Interrupt Control Description

INT(89) is used to control interrupts and performs one of 11 functions depending on the values of C and N. As shown in the following tables, six of the functions act on input interrupts, three act on the scheduled interrupt, and the other two mask or unmask all interrupts. Interrupt Input interrupts from Interrupt Input Unit 0 (N=000) Input interrupts from Interrupt Input Unit 1 (N=001) Scheduled (N=004)

C 000 001 002 000 001 002 000 001 002

INT(89) Function

Comments Mask/unmask input interrupts Bits 00 to 07 of D indicate inputs 00 to 07. Clear input interrupts Read current mask status Status written to D. Mask/unmask input interrupts Bits 00 to 07 of D indicate inputs 00 to 07. Clear input interrupts Read current mask status Set interrupt interval Set time to first interrupt Read interrupt interval

Status written to D. -------

The following 2 functions depend on the value of C only. Value of C

INT(89) Function

100

Mask all interrupts

200

Unmask all interrupts

Mask/unmask Input Interrupts (N=000 or 001, C=000)

Set N=000 for Interrupt Input Unit 0 and N=001 for Interrupt Input Unit 1. This function is used to mask and unmask input interrupts 00 to 07.Masked inputs are recorded, but ignored. When an input is masked, the interrupt program for it will be run as soon as the bit is unmasked (unless it is cleared beforehand by executing INT(89) with C=001 and N=000). Set the corresponding bit in D to 0 to unmask or to 1 to mask an I/O interrupt input. Bits 00 to 07 correspond to 00 to 07.

Clear Input Interrupts (N=000 or 001, C=001)

Set N=000 for Interrupt Input Unit 0 and N=001 for Interrupt Input Unit 1. This function is used to clear I/O interrupt inputs 00 to 07. Since interrupt inputs are recorded, masked interrupts will be serviced after the mask is removed unless they are cleared first. Set the corresponding bit in D to 1 to clear an interrupt input. Bits 00 to 07 correspond to 00 to 07.

Read Current Mask Status (N=000 or 001, C=002)

Set N=000 for Interrupt Input Unit 0 and N=001 for Interrupt Input Unit 1. This function is used to write the current mask status for input interrupts 00 to 07 to word D. The corresponding bit will be ON if the input is masked. (Bits 00 to 07 correspond to 00 to 07.)

Set Interrupt Interval (N=004, C=000)

This function is used to set the interval between scheduled interrupts. The content of D (BCD: 0001 to 9999) is multiplied by the scheduled interrupt time unit (1 ms or 10 ms) to obtain the scheduled interrupt interval. The scheduled interrupt time unit is set in DM 6622 of the PC Setup. Refer to 3-6-4 PC Setup for details on setting this time unit.

Set Time to First Interrupt (N=004, C=001)

This function is used to set the time to the first scheduled interrupt. The content of D (BCD: 0000 to 9999) is multiplied by the scheduled interrupt time unit (1 ms or 10 ms) to obtain the time to the first scheduled interrupt. The scheduled interrupt time unit is set in DM 6622 of the PC Setup. Refer to 3-6-4 PC Setup for details on setting this time unit. Be sure to set the time to the first interrupt. If this setting is not made, the interval to the first interrupt (set with N=004, C=000) will be uncertain. Use the First Cycle Flag (SR 25315) for the execution condition to INT(89) when setting the time to the first interrupt (C=001). The scheduled interrupt might never occur if the C=001 setting is made continuously.

290

Page 309

Section 5-23

Subroutines and Interrupt Control Read Interrupt Interval (N=004, C=002)

This function is used to write the current setting for the scheduled interrupt interval to word D.

Mask/Unmasking All Interrupts (C=100/200)

This function is used to mask or unmask all interrupt processing. Masked inputs are recorded, but ignored. The masked inputs will be serviced as soon as they are unmasked. This function masks or unmask all interrupts at the same time and is independent of the masks created with other functions. The control data, D, and interrupt type, N, are not used for this function. Set them to #0000.

Flags

ER:

Indirectly addressed DM word is non-existent. (Content of word is not BCD, or the DM area boundary has been exceeded.) C, and/or N are not within specified values. All interrupts within the subroutine are masked or unmasked.

Example 1: Input Interrupt

This example shows how to unmask a particular interrupt input. Input interrupt subroutines will be executed when the CPU Unit receives the corresponding interrupt input, regardless of the location in the CPU Unit’s cycle. These interrupts are useful when using program sections of uncertain length, such as event programs. All input interrupts are masked at the start of operation, and the desired interrupt input is unmasked using INT(89) with N=000 and C=000. As shown in the following diagram, the subroutine would be executed if there were an input from input interrupt 00 of Interrupt Input Unit 0 when that interrupt input was unmasked.

Main program LD

25315

INT(89)

000 000 #00FE

First Cycle Flag Only interrupt input 00 is unmasked.

Main program

SBN(92) Interrupt from interrupt input 00

00

Subroutine RET(93) END(01)

Note Depending on the setting of DM 6621 in the PC Setup, Host Link servicing, Remote I/O servicing, Special I/O Unit servicing, and individual instruction execution will be completed before the subroutine is executed. Refer to page 282 for details. Example 2: Scheduled Interrupt

This example shows how to set the interval between scheduled interrupts. Scheduled interrupt subroutines will be executed at fixed intervals, regardless of the location in the CPU Unit’s cycle. This interrupt is useful for program sections such as regular monitoring programs.

291

Page 310

Section 5-23

Subroutines and Interrupt Control

The scheduled interrupt is disabled at the start of operation (the scheduled interrupt interval is 0), so the time to the first interrupt and scheduled interrupt interval must be set using INT(89) with N=004 and C=001/000. In the following diagram, the subroutine would be executed every 20 ms if the scheduled interrupt time unit is set to 10 ms in DM 6622 of the PC Setup.

Main program

First Cycle Flag Sets the time to first interrupt to 20 ms.

LD

25315

INT(89)

001 004 #0002 000

INT(89)

004 #0002 Sets the scheduled interrupt interval to 20 ms. Main program

SBN(92)

99

Scheduled interrupt every 10 ms.

Subroutine RET(93)

Return to program address before interrupt.

END(01)

Note Depending on the setting of DM 6621 in the PC Setup, Host Link servicing, Remote I/O servicing, Special I/O Unit servicing, and individual instruction execution will be completed before the subroutine is executed. Refer to page 282 for details.

5-23-7 Processing the Same Memory Locations with the Main Program and Interrupt Subroutines If a memory location is manipulated both by the main program and an interrupt subroutine, an interrupt mask must be set to disable interrupts. When an interrupt occurs, execution of the main program will be interrupted immediately, even during execution of an instruction. The intermediate processing results is saved for use after completing the interrupt subroutine, i.e., when the interrupt subroutine has been executed, execution of the main program is started from the same position with data restored to the previous condition. If any of the memory locations being used by the main program are changed in the interrupt subroutine, the changes will be lost when data is restored to the previous state when restarting execution of the main program. It is thus necessary to disable interrupts before and enable interrupts after any instructions that should be executed to completion even if an interrupt occurs. Processing Interrupted between 1st and 3rd Operands

292

Page 311

Subroutines and Interrupt Control

Section 5-23

Flow of Processing

When the interrupt occurs while processing ADD, the addition result, 1235, is saved temporarily in memory and not stored in DM 0000. Although #0010 is moved to DM 0000 in the interrupt program, the addition result that was saved is written to DM 0000 as soon as processing returns to the main program, effectively undoing the results of the interrupt program. Countermeasure for Above Problem

Interrupting Writing Multiple Words of Data

293

Page 312

Subroutines and Interrupt Control

Section 5-23

Flow of Processing

Processing was interrupted for BSET when #1234 was not yet written to DM 0010. Therefore, in the comparison at point *1, the contents of DM 0000 and DM 0001 are not equal and processing stops with A in the OFF state. As a result, although the contents of DM 0000 and DM 0010 agree at the value 1234, an incorrect comparison result is reflected in comparison result output A. Countermeasure for Above Problem

294

Page 313

Section 5-24

Step Instructions

5-24 Step Instructions The step instructions STEP(08) and SNXT(09) are used in conjunction to set up breakpoints between sections in a large program so that the sections can be executed as units and reset upon completion. A section of program will usually be defined to correspond to an actual process in the application. (Refer to the application examples later in this section.) A step is like a normal programming code, except that certain instructions (e.g., IL(02)/ILC(03), JMP(04)/JME(05)) may not be included.

5-24-1 STEP DEFINE and STEP START–STEP(08)/SNXT(09) Ladder Symbols STEP(08) B

Definer Data Areas STEP(08)

B: Control bit IR, SR, AR, HR, LR

SNXT(09) B

B: Control bit IR, SR, AR, HR, LR

Limitations

All control bits must be in the same word and must be consecutive. IR 29800 to IR 29915 cannot be used for B.

Description

STEP(08) uses a control bit in the IR or HR areas to define the beginning of a section of the program called a step. STEP(08) does not require an execution condition, i.e., its execution is controlled through the control bit. To start execution of the step, SNXT(09) is used with the same control bit as used for STEP(08). If SNXT(09) is executed with an ON execution condition, the step with the same control bit is executed. If the execution condition is OFF, the step is not executed. The SNXT(09) instruction must be written into the program so that it is executed before the program reaches the step it starts. It can be used at different locations before the step to control the step according to two different execution conditions (see example 2, below). Any step in the program that has not been started with SNXT(09) will not be executed. Once SNXT(09) is used in the program, step execution will continue until STEP(08) is executed without a control bit. STEP(08) without a control bit must be preceded by SNXT(09) with a dummy control bit. The dummy control bit may be any unused IR or HR bit. It cannot be a control bit used in a STEP(08).

295