The text of a manual · part 9 of 27
SYSMAC C20P/C28P/C40P/C60P P-type Programmable Controllers Operation Manual: SECTION 5, pages 53 to 62
Pages 53 to 62 of 211, from SYSMAC C20P/C28P/C40P/C60P P-type Programmable Controllers Operation Manual
The original document is the PDF (2.2 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 C28P
Page 53
SECTION 5 Instruction Set 5–1 5–2 5–3 5–4 5–5
5–6
5–7 5–8 5–9 5–10 5–11
5–12
5–13
5–14 5–15
5–16
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Instruction Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Data Areas, Definer Values, and Flags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Ladder Diagram Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5–5–1 Load, Load NOT, AND, AND NOT, OR, and OR NOT . . . . . . . . . . . 5–5–2 AND Load and OR Load . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Bit Control Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5–6–1 Output and Output NOT – OUT and OUT NOT . . . . . . . . . . . . . . . . . 5–6–2 Differentiate Up and Down – DIFU(13) and DIFD(14) . . . . . . . . . . . . 5–6–3 Keep – KEEP(11) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Interlock and Interlock Clear – IL(02) and ILC(03) . . . . . . . . . . . . . . . . . . . . . . . Jump and Jump End – JMP(04) and JME(05) . . . . . . . . . . . . . . . . . . . . . . . . . . . . End – END(01) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . No Operation – NOP(00) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Timer and Counter Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5–11–1 Timer – TIM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5–11–2 High-speed Timer – TIMH(15) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5–11–3 Analog Timer Unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5–11–4 Counter – CNT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5–11–5 Reversible Counter – CNTR(12) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5–11–6 High-speed Counter – HDM(98) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Data Shifting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5–12–1 Shift Register – SFT(10) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5–12–2 Word Shift – WSFT(16) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Data Movement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5–13–1 Move – MOV(21) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5–13–2 Move NOT – MVN(22) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Data Compare – CMP(20) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Data Conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5–15–1 BCD to Binary – BIN(23) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5–15–2 Binary to BCD – BCD(24) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5–15–3 4-to-16 Decoder – MLPX(76) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5–15–4 16-to-4 Encoder – DMPX(77) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . BCD Calculations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5–16–1 BCD Add – ADD(30) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5–16–2 BCD Subtract – SUB(31) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5–16–3 Set Carry – STC(40) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5–16–4 Clear Carry – CLC(41) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
46 46 46 47 47 48 49 49 49 50 51 53 55 56 56 56 57 61 61 64 67 68 77 78 80 81 81 82 82 84 84 85 85 87 89 90 92 93 93
45
Page 54
Section 5–3
Instruction Format
5–1
Introduction The P-type PCs have large programming instruction sets that allow for easy programming of complicated control processes. This section explains each instruction individually and provides the ladder diagram symbol, data areas, and flags used with each. Basic application examples are also provided as required in describing the instructions. The many instructions provided by the P-type PCs are described in following subsections by instruction group. These groups include Ladder Diagram Instructions, Bit Control Instructions, Timer and Counter Instructions, Data Shifting, Data Movement, Data Comparison, Data Conversion, BCD Calculations, Subroutines, Step Instructions, and Special Instructions. Some instructions, such as Timer and Counter instructions, are used to control execution of other instructions, e.g., a TIM Completion Flag might be used to turn ON a bit when the time period set for the timer has expired. Although these other instructions are often used to control output bits through the Output instruction, they can be used to control execution of other instructions as well. The Output instructions used in examples in this manual can therefore generally be replaced by other instructions to modify the program for specific applications other than controlling output bits directly.
5–2
Notation In the remainder of this manual, all instructions will be referred to by their mnemonics. For example, the Output instruction will be called OUT; the AND NOT instruction, AND NOT. If you’re not sure of what instruction a mnemonic is used for, refer to Appendix B Programming Instructions. If an instruction is assigned a function code, it will be given in parentheses after the mnemonic. These function codes, which are 2-digit decimal numbers, are used to input most instructions into the CPU and are described briefly below and in more detail in 7–5 Inputting, Modifying and Checking the Program. A table of instructions listed in order of function codes is also provided in Appendix B Programming Instructions.
5–3
Instruction Format Most instructions have at least one or more operands associated with them. Operands indicate or provide the data on which an instruction is to be performed. These are sometimes input as the actual numeric values (i.e., as constants), but are usually the addresses of data area words or bits that contain the data to be used. A bit whose address is designated as an operand is called an operand bit; a word whose address is designated as an operand is called an operand word. In some instructions, the word address designated in an instruction indicates the first of multiple words containing the desired data. Each instruction requires one or more words in Program Memory. The first word is the instruction word, which specifies the instruction and contains any definers (described below) or operand bits required by the instruction. Other operands required by the instruction are contained in following words, one operand per word. Some instructions require up to four words. A definer is an operand associated with an instruction and contained in the same word as the instruction itself. These operands define the instruction rather than telling what data it is to be used. Examples of definers are TC numbers, which are used in timer and counter instructions to create timer and counter. Bit operands are also contained in the same word as the instruction itself, although these are not considered definers.
46
Page 55
Section 5–5
Ladder Diagram Instructions
5–4
Data Areas, Definer Values, and Flags Each instruction is introduced with the ladder diagram symbol(s), the data areas that can be used with any operand(s), and the values that can be used for definers. With the data areas is also specified the operand names and the type of data required for each operand (i.e., word or bit and, for words, hexadecimal or BCD). Not all addresses in a specified data area are necessarily allowed in an operand, e.g., if an operand requires two words, the last word in a data area cannot be designated because all words for a single operand must be in the same data area. Unless a limit is specified, any bit/word in the area can be used. Specific limitations for operands and definers are specified in a Limitations subsection. Refer to Section 3 Memory Areas for addressing conventions and the addresses of flags and control bits. Note The IR and SR areas are considered as separate areas and both are not necessarily allowed for an operand just because one of them is. The boarder between the IR and SR area can, however, be crossed for a single operand, i.e., the last bit in the IR area may be specified for an operand that requires more than one word as long as the SR area is also allowed for that operand. The Flags subsection lists flags that are affected by execution of the instruction. These flags include the following SR area flags. Abbreviation
Name
Bit
ER
Instruction Execution Error Flag
1903
CY
Carry Flag
1904
EQ
Equals Flag
1906
GR
Greater Than Flag
1905
LE
Less Than Flag
1907
ER is the flag most often used for monitoring an instruction’s execution. When ER goes ON, it indicates that an error has occurred in attempting to execute the current instruction. The Flags subsection of each instruction lists possible reasons for ER being ON. ER will turn ON for any instruction if operands are not input within established parameters. Instructions are not executed when ER is ON. A table of instructions and the flags they affect is provided in Appendix D Error and Arithmetic Flag Operation.
Designating Constants
5–5
Although data area addresses are most often given as operands, many operands can be input and all definers are input as constants. The range in which a number can be specified for a given definer or operand depends on the particular instruction that uses it. Constants must also be input in the form required by the instruction, i.e., in BCD or in hexadecimal.
Ladder Diagram Instructions Ladder diagram instructions include ladder instructions and logic block instructions. Ladder instructions correspond to the conditions on the ladder diagram. Logic block instructions are used to relate more complex parts of the diagram that cannot be programmed with ladder instructions alone.
47
Page 56
Section 5–5
Ladder Diagram Instructions
5–5–1
Load, Load NOT, AND, AND NOT, OR, and OR NOT
Load – LD
Ladder Symbol
Operand Data Areas
B
B: Bit IR, SR, HR, TC, TR
Load NOT – LD NOT
Ladder Symbol
Operand Data Areas
B
B: Bit IR, SR, HR, TC, TR
AND – AND
Ladder Symbol
Operand Data Areas
B
B: Bit IR, SR, HR, TC, TR
AND NOT – AND NOT
Ladder Symbol
Operand Data Areas
B
B: Bit IR, SR, HR, TC, TR
OR – OR
Ladder Symbol
Operand Data Areas B: Bit
B
OR NOT – OR NOT
Ladder Symbol
IR, SR, HR, TC, TR
Operand Data Areas B: Bit
B
IR, SR, HR, TC, TR
Limitations
There is no limit in the number of any of these instructions or in the order in which they must be used as long as the capacity of the PC is not exceeded.
Description
These six basic instructions correspond to the conditions on a ladder diagram. As described in Section 4 Programming, the status of the bits assigned to each instruction determines the execution conditions for all other instructions. Each of these instructions can be used as many times and a bit address can be used in as many of these instructions as required. The status of the bit operand (B) assigned to LD or LD NOT determines the first execution condition. AND takes the logical AND between the execution condition and the status of its bit operand; AND NOT, the logical AND between the execution condition and the inverse of the status of its bit operand. OR takes the logical OR between the execution condition and the status of its bit operand; OR NOT, the logical OR between the execution condition and the inverse of the status of its bit operand. The ladder symbol for loading TR bits is different from that shown. See 4–3–2 Ladder Instructions for details.
Flags
48
There are no flags affected by these instructions.
Page 57
Section 5–6
Bit Control Instructions
5–5–2
AND Load and OR Load
AND Load – AND LD Ladder Symbol
0000
0002
0001
0003
OR Load – OR LD 0000
0001
0002
0003
Ladder Symbol
Description
When the above instructions are combined into blocks that cannot be logically combined using only OR and AND operations, AND LD and OR LD are used. Whereas AND and OR operations logically combine a bit status and an execution condition, AND LD and OR LD logically combine two execution conditions, the current one and the last unused one. AND LD and OR LD instruction are not necessary to draw ladder diagrams, nor are they necessary when inputting ladder diagrams directly, as is possible from the GPC. They are required, however, to convert the program to and input it in mnemonic form. The procedures for these, limitations for different procedures, and examples are provided in 7–5 Inputting, Modifying and Checking the Program. In order to reduce the number of programming instruction required, a basic understanding of logic block instructions is required. For an introduction to logic blocks, refer to 7–2–3 Logic Block Instructions.
Flags
5–6
There are no flags affected by these instructions.
Bit Control Instructions There are five instructions that can be used generally to control individual bit status. These are OUT, OUT NOT, DIFU(13), DIFD(14), and KEEP(11). These instructions are used to turn bits ON and OFF in different ways.
5–6–1
Output and Output NOT – OUT and OUT NOT
Output – OUT
Ladder Symbol
Operand Data Areas B: Bit B
Output NOT – OUT NOT
Ladder Symbol
IR, HR, TR
Operand Data Areas B: Bit B
IR, HR, TR
Limitations
Any output bit can be used in only one instruction that controls its status. See 3–3–1 I/O Words for details.
Description
OUT and OUT NOT are used to control the status of the designated bit according to the execution condition.
49
Page 58
Section 5–6
Bit Control Instructions
OUT turns ON the designated bit for a ON execution condition, and turns OFF the designated bit for an OFF execution condition. OUT with a TR bit appears at a branching point rather than at the end of an instruction line. Refer to 4–3–4 Branching Instruction Lines for details. OUT NOT turns ON the designated bit for a OFF execution condition, and turns OFF the designated bit for an ON execution condition. OUT and OUT NOT can be used to control execution by turning ON and OFF bits that are assigned to conditions on the ladder diagram, thus determining execution conditions for other instructions. This is particularly helpful when a complex set of conditions can be used to control the status of a single work bit, and then that work bit can be used to control other instructions. The length of time that a bit is ON or OFF can be controlled by combining the OUT or OUT NOT with TIM. Refer to Examples under 5–11–1 Timer – TIM for details. There are no flags affected by these instructions.
Flags
5–6–2
Differentiate Up and Down – DIFU(13) and DIFD(14) Ladder Symbol DIFU(13)
B
Operand Data Areas B: Bit IR, HR
Ladder Symbol DIFD(14)
B
Operand Data Areas B: Bit IR, HR
Limitations
Any output bit can be used in only one instruction that controls its status. See 3–3–1 I/O Words for details.
Description
DIFU(13) and DIFD(14) are used to turn the designated bit ON for one scan only. Whenever executed, DIFU(13) compares its current execution with the previous execution condition. If the previous execution condition was OFF and and current one is ON, DIFU(13) will turn ON the designated bit. If the previous execution condition was ON and the current execution condition is either ON or OFF, DIFU(13) will turn the designated bit OFF or do nothing (i.e., if the designated bit is already OFF). The designated bit will thus never be ON for longer than one scan assuming it is executed each scan (see Precautions, below). Whenever executed, DIFD(14) compares its current execution with the previous execution condition. If the previous execution condition was ON and the current one is OFF, DIFD(14) will turn ON the designated bit. If the previous execution condition was OFF and the current execution condition is either ON or OFF, DIFD(14) will turn the designated bit OFF or do nothing (i.e., if the designated bit is already OFF). The designated bit will thus never be ON for longer than one scan. These instructions are used when a single-scan execution of a particular instruction is desired. Examples of these are shown below.
50
Page 59
Section 5–6
Bit Control Instructions
DIFU(13) and DIFD(14) operation can be tricky when used in programming between IL and ILC, between JMP and JME, or in subroutines. Refer to 5–7 Interlock and Interlock Clear – IL(02) and ILC(03) and 5–8 Jump and Jump End – JMP(04)/JME(05) for details. A total of 48 DIFU(13)/DIFD(14) can be used in a program. If more than 48 are used in a program only the first 48 will be executed and all others will be ignored. DIFU(13)/DIFD(14) are useful when used in conjunction with CMP(20) or MOV(21), see Example below. Flags
There are no flags affected by these instructions.
Example
In diagram A, below, CMP(20) will compare the contents of the two operand words (HR 1 and DM 00) whenever it is executed with an ON execution condition and set the arithmetic flags (GR, EQ, and LE) accordingly. If the execution condition remains ON, flag status may be changed each scan if the contents of one or both operands change. Diagram B, however, shows how DIFU(13) can be used to ensure that CMP(20) is executed only once each time the desired execution condition goes ON.
0000 CMP(20) HR 1
Diagram A
DM 00
0000 DIFU(13) 1000 1000 CMP(20) HR 1
Diagram B
5–6–3
DM 00
Keep – KEEP(11) Ladder Symbol
Operand Data Areas KEEP(11)
B: Bit
B
S
IR, HR R
Limitations
Any output bit can be used in only one instruction that controls its status. See 3–3–1 I/O Words for details.
Description
KEEP(11) is used to maintain the status of the designated bit based on two execution conditions. These execution conditions are labeled S and R. S is the set input; R, the reset input. KEEP(11) operates like a latching relay that is set by S and reset by R. When S turns ON, the designated bit will go ON and stay ON until reset, regardless of whether S stays ON or goes OFF. When R turns ON, the designated bit will go OFF and stay OFF until reset, regardless of whether R stays ON or goes OFF. The relationship between execution conditions and KEEP(11) bit status is shown below.
51
Page 60
Section 5–6
Bit Control Instructions S execution condition R execution condition
Status of B
Notice that KEEP(11) operates like a self-maintaining bit. The following two diagrams would function identically, though the one using KEEP(11) requires one less instruction to program and would maintain status even in an interlocked program section.
0002
0003 0500
0500
0002
S KEEP 0500
0003
R
Flags
There are no flags affected by this instruction.
Precautions
Never use an input bit in an inverse condition on the reset (R) for KEEP(11) when the input device uses an AC power supply. The delay in shutting down the PC’s DC power supply (relative to the AC power supply to the input device) can cause the designated bit of KEEP(11) to be reset. This situation is shown below. Input Unit A S
NEVER
A
KEEP HR 000 R
Bits used in KEEP are not reset in interlocks. Refer to the 5–7 Interlock – IL(02) and ILC(03) for details. Example
52
If a HR bit is used, bit status will be retained even during a power interruption. KEEP(11) can thus be used to program bits that will maintain status after restarting the PC following a power interruption. An example of this that can be used to produce a warning display following a system shutdown for an emergency situation is shown below. Bits 0002, 0003, and 0004 would be turned ON to indicate some type of system error. Bit 0005 would be turned ON to reset the warning display. HR 000, which is turned ON for any of the three bits which indicates emergency situation, is used to turn ON the warning indicator through 0500.
Page 61
Section 5–7
Interlock and Interlock Clear 0002
0003
S
KEEP HR 000 R
Indicates emergency situation
0004 Reset input 0005
HR 000 0500
Activates warning display
KEEP(11) can also be combined with TIM to produce delays in turning bits ON and OFF. Refer to 5–11–1 Timer – TIM for details.
5–7
Interlock and Interlock Clear – IL(02) and ILC(03) Ladder Symbol
IL(02)
Ladder Symbol
ILC(03)
Description IL(02) is always used in conjunction with ILC(03) to create interlocks. Interlocks are used to enable branching in the same way as can be achieved with TR bits, but treatment of instructions between IL(02) and ILC(03) differs from that with TR bits when the execution condition for IL(02) is OFF. If the execution condition of IL(02) is ON, the program will be executed as written, with an ON execution condition used to start each instruction line from the point where IL(02) is located through ILC(03). Refer to 4–3–4 Branching Instruction Lines for basic descriptions of both methods. If the execution condition for IL(02) condition is OFF, the interlocked section between IL(02) and ILC(03) will be treated as shown in the following table: Instruction
Treatment
OUT and OUT NOT
Designated bit turned OFF.
TIM and TIMH(15)
Reset.
CNT, CNTR(12)
PV maintained.
KEEP(11)
Bit status maintained.
DIFU(13) and DIFD(14)
Not executed (see below).
All others
Not executed.
IL(02) and ILC(03) do not necessarily have to be used in pairs. IL(02) can be used several times in a row, with each IL(02) creating an interlocked section through the next ILC(03). ILC(03) cannot be used unless there is at least one IL(02) between it and any previous ILC(03). DIFU(13) and DIFD(14) in Interlocks
Changes in the execution condition for a DIFU(13) or DIFD(14) are not recorded if the DIFU(13) or DIFD(14) is in an interlocked section and the exe-
53
Page 62
Section 5–7
Interlock and Interlock Clear cution condition for the IL(02) is OFF. When DIFU(13) or DIFD(14) is executed in an interlocked section immediately after the execution condition for the IL(02) has gone ON, the execution condition for the DIFU(13) or DIFD(14) will be compared to the execution condition that existed before the interlock became effective (i.e., before the interlock condition for IL(02) went OFF). The ladder diagram and bit status changes for this are shown below. The interlock is in effect while 0000 is OFF. Notice that 1000 is not turned ON at the point labeled A even though 0001 has turned OFF and then back ON.
0000 IL(02) 0001 DIFU(13) 1000 ILC(03)
A ON
0000
OFF ON
0001
OFF ON
1000
Precautions
OFF
There must be an ILC(03) following any one or more IL(02). Although as many IL(02) as necessary can be used with one ILC(03), ILC(03) cannot be used consecutively without at least one IL(02) in between, i.e., nesting is not possible. Whenever a ILC(03) is executed, all interlocks are cleared. When more than one IL(02) is used with a single ILC(03), an error message will appear when the program check is performed, but execution will proceed normally.
Flags
There are no flags affected by these instructions.
Example
The following diagram shows IL(02) being used twice with one ILC(03).
0000 IL(02) 0001 TIM 11 0002 IL(02) 0003 0100
0004
CP R
CNT 01 10
0005 0502
ILC(03)
54
001.5 s