The text of a manual · part 37 of 68
Programmable Controllers C200HX-CPU-ZE, C200HG-CPU-ZE, C200HE-CPU-ZE Operation Manual: SECTION 5 Instruction Set, pages 334 to 343
Pages 334 to 343 of 613, from Programmable Controllers C200HX-CPU-ZE, C200HG-CPU-ZE, C200HE-CPU-ZE Operation Manual
The original document is the PDF (3.8 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.
Filed in the catalog under the Omron C200H-SP001 and Omron C200HW-PA204
Page 334
Section 5-24
Subroutines and Interrupt Control
The following diagram illustrates program execution flow for various execution conditions for two SBS(091). A SBS(091)
000
A
B Main program
SBS(091)
OFF execution conditions for subroutines 000 and 001
B
C
001 ON execution condition for subroutine 000 only
A
C
SBN(092)
000
D
B
C
ON execution condition for subroutine 001 only
A
B
E
C
D
Subroutines
RET(093) SBN(092)
001
ON execution conditions for subroutines 000 and 001
A
D
B
E
C
E
RET(093) 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(091) will not be executed and the subroutine will not be called when ER is ON.
5-24-4 SUBROUTINE DEFINE and RETURN – SBN(092)/RET(093) Ladder Symbols SBN(092) N
Definer Data Areas N: Subroutine number 000 to 255
RET(093)
Limitations
Each subroutine number can be used in SBN(092) once only.
Description
SBN(092) is used to mark the beginning of a subroutine program; RET(093) is used to mark the end. Each subroutine is identified with a subroutine number, N, that is programmed as a definer for SBN(092). This same subroutine number is used in any SBS(091) that calls the subroutine (see 5-24-3 SUBROUTINE ENTER – SBS(091)). No subroutine number is required with RET(093).
322
Page 335
Section 5-24
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(092) before returning to address 00000 for the next cycle. Subroutines will not be executed unless called by SBS(091). END(001) must be placed at the end of the last subroutine program, i.e., after the last RET(093). It is not required at any other point in the program. Precautions
If SBN(092) 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(092) is encountered. If either DIFU(013) or DIFU(014) 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-24-5 MACRO – MCRO(099) Operand Data Areas N: Subroutine number
Ladder Symbols
00 to 255 MCRO(099)
@MCRO(099)
N
N
I1
I1
O1
O1
I1: First input word IR, SR, AR, DM, EM, HR, TC, LR O1: First output word IR, SR, AR, DM, EM, 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(099). 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(099) is not executed. When the execution condition is ON, MCRO(099) 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(099) is completed.
323
Page 336
Section 5-24
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(099)
010 DM 0010 DM 0020
Main program
SBN(092)
010
Subroutine RET(093) END(001)
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(099) 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(099) 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. The content of an word containing an indirect DM/EM address is not BCD or the DM/EM area boundary has been exceeded. A subroutine has called itself. An active subroutine has been called.
324
Page 337
Section 5-24
Subroutines and Interrupt Control Example
The following examples shows the use of four MCRO(099) instructions that access the same subroutine. The program section on the left shows the same program without the use of MCRO(099).
25313 00000
10001
MCRO(099) 10000
090
Always ON Flag 10000
000 100
00001
00002 10001
MCRO(099) 090
00200
002
10501 10500
105
10500 MCRO(099) 00201
090
00202
005
10501
120 00500
MCRO(099)
12001 12000
090
12000
010 150
00501
00502 12001
01000
SBN(092)
29000
15001
29401 29400
15000 29400
15000
01001
090
29001
01002
29002 29401
15001
RET(093)
5-24-6 INTERRUPT CONTROL – INT(089) Operand Data Areas C: Control code
Ladder Symbols
# (000, 001, 002, 100, or 200)
Limitations
INT(089)
@INT(089)
C
C
N
N
D
D
N: Interrupt type # (000, 001, or 004) D: Control data IR, AR, DM, EM, HR, TC, LR, #, SR
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. INT(089) is an expansion instruction. A Programming Device can be used to reassign function code 089 to another expansion instruction.
325
Page 338
Section 5-24
Subroutines and Interrupt Control Description
INT(089) 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(089) 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(089) 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(089) 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: 0000 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-5 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-5 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(089) when setting the time to the first interrupt (C=001). The scheduled interrupt might never occur if the C=001 setting is made continuously.
326
Page 339
Section 5-24
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:
The content of an word containing an indirect DM/EM address is not BCD or the DM/EM 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(089) 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(089)
000 000 #00FE
First Cycle Flag Only interrupt input 00 is unmasked.
Main program
SBN(092) Interrupt from interrupt input 00
00
Subroutine RET(093) END(001)
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 318 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.
327
Page 340
Section 5-24
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(089) 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(089)
001 004 #0002 000
INT(089)
004 #0002 Sets the scheduled interrupt interval to 20 ms. Main program
SBN(092)
99
Scheduled interrupt every 10 ms.
Subroutine RET(093) END(001)
Return to program address before interrupt.
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 318 for details.
328
Page 341
Section 5-25
Step Instructions
5-25 Step Instructions The step instructions STEP(008) and SNXT(009) 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(002)/ILC(003), JMP(004)/ JME(005)) may not be included.
5-25-1 STEP DEFINE and STEP START–STEP(008)/SNXT(009) Ladder Symbols STEP(008) B
Definer Data Areas STEP(008)
B: Control bit IR, SR, AR, HR, LR
SNXT(009) 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(008) uses a control bit in the IR or HR areas to define the beginning of a section of the program called a step. STEP(008) does not require an execution condition, i.e., its execution is controlled through the control bit. To start execution of the step, SNXT(009) is used with the same control bit as used for STEP(008). If SNXT(009) 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(009) 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(009) will not be executed. Once SNXT(009) is used in the program, step execution will continue until STEP(008) is executed without a control bit. STEP(008) without a control bit must be preceded by SNXT(009) 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(008).
329
Page 342
Section 5-25
Step Instructions
Execution of a step is completed either by execution of the next SNXT(009) or by turning OFF the control bit for the step (see example 3 below). When the step is completed, all of the IR and HR bits in the step are turned OFF. All timers in the step except TTIM(087) are reset to their SVs. TTIM(087), counters, shift registers, bits set or reset with SET or RSET, and bits used in KEEP(011) maintain status. Two simple steps are shown below.
00000 SNXT(009) LR 2000
Starts step execution
STEP(008) LR 2000
Step controlled by LR 2000
1st step
00001 SNXT(009) LR 2001
STEP(008) LR 2001
Step controlled by LR 2001
2nd step
00002 SNXT(009) LR 2002
STEP(008)
Address
Instruction
00000 00001 00002
LD SNXT(009) STEP(008)
Operands 00000 LR 2000 LR 2000
Step controlled by LR 2000 00100 00101
LD SNXT(009)
00001 LR 2001
Address
Instruction
00102
STEP(008)
Ends step execution
Operands LR 2001
Step controlled by LR 2001 00200 00201 00202
LD SNXT(009) STEP(008)
00002 LR 2002 ---
Steps can be programmed in consecutively. Each step must start with STEP(008) and generally ends with SNXT(009) (see example 3, below, for an exception). When steps are programmed in series, three types of execution are possible: sequential, branching, or parallel. The execution conditions for, and the positioning of, SNXT(009) determine how the steps are executed. The three examples given below demonstrate these three types of step execution. Precautions
Interlocks, jumps, SBN(092), and END(001) cannot be used within step programs. Bits used as control bits must not be used anywhere else in the program unless they are being used to control the operation of the step (see example 3, below). All control bits must be in the same word and must be consecutive. If IR or LR bits are used for control bits, their status will be lost during any power interruption. If it is necessary to maintain status to resume execution at the same step, HR bits must be used.
330
Page 343
Section 5-25
Step Instructions Flags
25407: Step Start Flag; turns ON for one cycle when STEP(008) is executed and can be used to reset counters in steps as shown below if necessary.
00000 Start
SNXT(009) 01000 01000 STEP(008) 01000 00100
CP CNT 01 25407
25407
R
Address
Instruction
00000 00001 00002 00003
LD SNXT(009) STEP(008) LD
Operands 00000 01000 01000 00100
#0003
Address 00004 00005
1 cycle
Instruction
Operands
LD CNT
25407 01 #0003
Examples The following three examples demonstrate the three types of execution control possible with step programming. Example 1 demonstrates sequential execution; example 2, branching execution; and example 3, parallel execution. Example 1: Sequential Execution
The following process requires that three processes, loading, part installation, and inspection/discharge, be executed in sequence with each process being reset before continuing on the the next process. Various sensors (SW1, SW2, SW3, and SW4) are positioned to signal when processes are to start and end.
SW 1 SW 4
SW 2 SW 3
Loading
Part installation
Inspection/discharge
331