The text of a manual · part 13 of 27
SYSMAC C20P/C28P/C40P/C60P P-type Programmable Controllers Operation Manual: SECTION 5, pages 93 to 101
Pages 93 to 101 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 93
Section 5–15
Data Conversion Flags
ER:
The content S is not BCD
EQ:
ON when 0000 is placed in R.
5–15–2 Binary to BCD – BCD(24) Ladder Symbol
Operand Data Areas S : Source word (binary)
BCD(24) IR, SR, DM, HR, TC S R : Result word R
IR, DM, HR
Limitations
If the content of S exceeds 270F, the converted result would exceed 9999 and BCD(24) will not be executed. When the instruction is not executed, the content of R remains unchanged.
Description
BCD(24) converts the binary (hexadecimal) content of S into the numerically equivalent BCD bits, and outputs the BCD bits to R. Only the content of R is changed; the content of S is left unchanged. BCD(24) can be used to convert binary to BCD so that displays on the Programming Console or any other programming device will appear in decimal rather than hexadecimal. It can also be used to convert to BCD to perform BCD arithmetic operations rather than binary arithmetic operations, e.g., when BCD and binary values must be added.
Flags
ER:
S is greater than 270F.
EQ:
ON when 0000 is placed in R.
5–15–3 4-to-16 Decoder – MLPX(76) Operand Data Areas Ladder Symbol
S : Source word IR, SR, DM, HR, TC
MLPX(76) Di : Digit designator S Di R
Limitations
IR, DM, HR, TC, # R : First result word IR, DM, HR
The rightmost two digits of Di must each be between D and 3. All result words must be in the same data area.
Description
When the execution condition is OFF, MLPX(76) is not executed and the next instruction is moved to. When the execution condition is ON, MLPX(76) converts up to four, four-bit hexadecimal digits from S into decimal values from 0 to 15, each of which is used to indicate a bit position. The bit whose number corresponds to each converted value is then turned ON in a result word. If more than one digit is specified, then one bit will be turned ON in each of consecutive words beginning with R. (See examples, below.)
85
Page 94
Section 5–15
Data Conversion
The following is an example of a one-digit decode operation from digit number 1 of S, i.e., here Di would be 0001. S C
Bit C (i.e., bit number 12) turned ON. R 0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
The first digit and the number of digits to be converted are designated in Di. If more digits are designated than remain in S (counting from the designated first digit), the remaining digits will be taken starting back at the beginning of S. The final word required to store the converted result (R plus the number of digits to be converted) must be in the same data area as R, e.g., if two digits are converted, the last word address in a data area cannot be designated; if three digits are converted, the last two words in a data area cannot be designated. Digit Designator
The digits of Di are set as shown below. Digit numbers: 0 1 2 3
Specifies the first digit to be converted (0 to 3) Number of digits to be converted (0 to 3) 0: 1 digits 1: 2 digits 2: 3 digits 3: 4 digits Not used.
Some example Di values and the digit-to-word conversions that they produce are shown below. Di : 0010
Di : 0030
S
S
0
R
0
R
1
R+1
1
R+1
2
2
R+2
3
3
R+3
Di : 0031
Di : 0023
S
86
S
0
R
0
R
1
R+1
1
R+1
2
R+2
2
R+2
3
R+3
3
Page 95
Section 5–15
Data Conversion Flags
ER:
Undefined digit designator, or R plus number of digits exceeds a data area.
Example
The following program converts three digits of data from DM 20 to bit positions and turns ON the corresponding bits in three consecutive words starting with HR 1. 0000 MLPX(76) DM 20 #0021 HR 1
S : DM 20
R : HR 1
DM 00
20
DM 01
21
DM 02
22
DM 03
R+1 : HR 2
R+2 : HR 3
HR 100
0
HR 200
0
HR 300
1
HR 101
0
HR 201
0
HR 301
0
HR 102
0
HR 202
0
HR 302
0
23
HR 103
0
HR 203
0
HR 303
0
1
20
HR 104
0
HR 204
0
HR 304
0
DM 05
1
21
HR 105
0
HR 205
0
HR 305
0
DM 06
1
22
HR 106
0
HR 206
1
HR 306
0
1
23
HR 107
0
HR 207
0
HR 307
0
DM 08
0
20
DM 09
1
21
DM 10
1
DM 11
DM 04
DM 07
Not Converted
1
15
HR 108
0
HR 208
0
HR 308
0
HR 109
0
HR 209
0
HR 309
0
22
HR 110
0
HR 210
0
HR 310
0
0
23
HR 111
0
HR 211
0
HR 311
0
0
20
HR 112
0
HR 212
0
HR 312
0
DM 13
0
21
HR 113
0
HR 213
0
HR 313
0
DM 14
0
22
HR 114
0
HR 214
0
HR 314
0
0
23
HR 115
1
HR 215
0
HR 315
0
DM 12
DM 15
6
2
3
0
5–15–4 16-to-4 Encoder – DMPX(77) Operand Data Areas Ladder Symbol
S : First source word IR, SR, DM, HR, TC
DMPX(77) R : Result word S R Di
Limitations
IR, DM, HR Di : Digit designator IR, DM, HR, TC, #
The rightmost two digits of Di must each be between 0 and 3. All source words must be in the same data area.
87
Page 96
Section 5–15
Data Conversion Description
When the execution condition is OFF, DMPX(77) is not executed and the next instruction is moved to. When the execution condition is ON, DMPX(77) determines the position of the highest ON bit in S, encodes it into single-digit hexadecimal value corresponding to the bit number of the highest ON bit number, then transfers the hexadecimal value to the specified digit in R. The digits to receive the results are specified in Di, which also specifies the number of digits to be encoded. The following is an example of a one-digit encode operation to digit number 1 of R, i.e., here Di would be 0001.
S 0
0
0
1
0
0
0
1
0
0
0
1
0
1
1
0
C transferred to indicate bit number 12 as the highest ON bit. R C
Up to four digits from four consecutive source words starting with S may be encoded and the digits written to R in order from the designated first digit. If more digits are designated than remain in R (counting from the designated first digit), the remaining digits will be placed at digits starting back at the beginning of R. The final word to be converted (S plus the number of digits to be converted) must be in the same data area as SB.
Digit Designator
The digits of Di are set as shown below.
Digit Numbers: 0 1 2 3
Specifies the first digit to receive converted data (0 to 3). Number of words to be converted (0 to 3) 0: 1 word 1: 2 words 2: 3 words 3: 4 words Not used.
Some example Di values and the word-to-digit conversions that they produce are shown below.
88
Page 97
Section 5–16
BCD Calculations Di : 0011
Di : 0030 R
R
S
0
S
0
S+1
1
S+1
1
2
S+2
2
3
S+3
3
Di : 0013
Di : 0032 R
Flags
S
0
S
R 0
S+1
1
S+1
1
2
S+2
2
3
S+3
3
ER:
Undefined digit designator, or S plus number of digits exceeds a data area. Content of a source word is 0000.
Example
When 0000 is ON, the following diagram encodes IR words 10 and 11 to the first two digits of HR 2 and then encodes DM 10 and 11 to the last two digits of HR 2. Although the status of each source word bit is not shown, it is assumed that the bit with status 1 (ON) shown is the highest bit that is ON in the word. 0000 DMPX(77) 10 HR 2 #0010
DMPX(77) DM10 HR 2 #0012
IR 010
IR 011
1000
1100
:
:
1011
1
1109
1
1012
0
1110
0
: 1015
: 0
: 1115
: 0
HR 2 Digit 0
B
Digit 1
9
DM 10
DM 11
Digit 2
1
DM1000
DM1100
Digit 3
8
:
:
DM1001 1
DM1108 1
DM1002 0
DM1109 0
:
:
DM1015 0
:
:
DM1115 0
5–16 BCD Calculations The BCD calculation instructions perform mathematic operations on BCD data.
89
Page 98
Section 5–16
BCD Calculations
These instructions change only the content of the words in which results are placed, i.e., the contents of source words are the same before and after execution of any of the BCD calculation instructions. STC(40) and CLC(41), which set and clear the Carry Flag, are included in this group because most of the BCD operations make use of the Carry Flag (CY) in their results. Binary arithmetic and shift operations also use CY. The addition and subtraction instructions use CY in the calculation as well as in the result. Be sure to clear CY if its previous status is not required in the calculation, and to use the result placed in CY, if required, before it is changed by execution of any other instruction.
5–16–1 BCD Add – ADD(30) Operand Data Areas Au : Augend word (BCD)
Ladder Symbol
IR, SR, DM, HR, TC, # ADD(30) Ad : Addend word (BCD) Au
IR, SR, DM, HR, TC, #
Ad
R : Result word
R
Description
When the execution condition is OFF, ADD(30) is not executed and the next instruction is moved to. When the execution condition is ON, ADD(30) adds the contents of Au, Ad, and CY, and places the result in R. CY will be set if the result is greater than 9999. Au and Ad should not be designated as constants. This instruction will be executed every scan as long as the execution condition remains ON. If the instruction is to be executed only once for a given ON execution condition then it must be used in conjunction with DIFU(13) or DIFD(14).
Au + Ad + CY
Flags
Example
90
IR, DM, HR
CY
ER:
Au and/or Ad is not BCD.
CY:
ON when there is a carry in the result.
EQ:
ON when the result is 0.
R
If 0002 is ON, the following diagram clears CY with CLC(41), adds the content of IR 02 to a constant (6103), places the result in DM 01, and then moves either all zeros or 0001 into DM 02 depending on the status of CY (1904). This ensures that any carry from the last digit is preserved in R + 1 so that the entire result can be later handled as eight-digit data.
Page 99
Section 5–16
BCD Calculations TR 0 0002 CLC(41)
ADD(30) 02 #6103 DM 01 1904 MOV(21) #0001 DM 02 1904 MOV(21) #0000 DM 02
Consecutive ADD(30)s can be used to perform eight-digit BCD addition. By using two ADD(30)s and combining the augend and the addend words of one ADD(30) with those of the other, two 8-digit values can be added. The result may or may not be 9 digits depending on whether a carry is generated. 0002 DIFU(13) 1000
TR 0 1000 CLC(41)
ADD(30) DM 00 DM 02 DM 04 ADD(30) DM 01 DM 03 DM 05 1904 MOV(21) #0001 DM 06 1904 MOV(21) #0000 DM 06
In the above program the 8 digit augend consists of two words: DM 00 and DM 01, with DM 01 being used for the 4 left digits and 00 for the 4 right digits. Similarly the 8-digit addend consist of DM 02 and 03. Three words are used to hold the results of the addition: DM 04, DM 05, and DM 06. In this case DM 05 and DM 04 are used to represent the intermediate 4 digits and the 4 right digits respectively. DM 06 represents the leftmost digit, the 9th digit.
91
Page 100
Section 5–16
BCD Calculations
If a carry is generated, SR 1904 (CY) is turned ON and the constant 0001 is transferred to DM 06. If a carry is not generated SR 1904 remains OFF and the constant 0000 is transferred to DM 06.
5–16–2 BCD Subtract – SUB(31) Operand Data Areas Mi : Minuend word (BCD)
Ladder Symbol
IR, SR, DM, HR, TC, # SUB(31) Su : Subtrahend word (BCD) Mi
IR, SR, DM, HR, TC, #
Su
R : Result word
R
Description
When the execution condition is OFF, SUB(31) is not executed and the next instruction is moved to. When the execution condition is ON, SUB(31) subtracts the contents of Su and CY from Mi and places the result in R. If the result is negative, CY is set and the 10’s complement of the actual result is placed in R. To convert the 10’s complement to the true result, subtract the content of R from zero (see example below).. This instruction will be executed every scan as long as the execution condition remains ON. If the instruction is to be executed only once then it must be used in conjunction with DIFU(13) or DIFD(14).
Mi – Su – CY
Flags
IR, DM, HR
CY
R
ER:
Mi and/or Su is not BCD.
CY:
ON when the result is negative, i.e., when Mi is less than Su plus CY.
EQ:
ON when the result is 0.
Caution Be sure to clear the Carry Flag (CY) with CLC(41) before executing SUB(31) if its previous status is not required, and check the status of CY after doing a subtraction with SUB(31). If CY is ON as a result of executing SUB(31) (i.e., if the result is negative), the result is output as the 10’s complement of the true answer. To convert the output result to the true value, subtract the value in R from 0. Example
When 0002 is ON, the following diagram clears CY, subtracts the contents of DM 01 and CY from the content of IR 10 and places the result in HR 2. If CY is set by executing SUB(31), the result in HR 2 is subtracted from zero (note that CLC(41) is again required to obtain an accurate result), the result is placed back in HR 2, and HR 300 is turned ON to indicate a negative result. If CY is not set by executing SUB(31), the result is positive, the second subtraction is not performed and HR 300 is not turned ON. HR 300 is programmed as a self-maintaining bit so that a change in the status of CY will not turn it OFF when the program is rescanned.
92
Page 101
Section 5–16
BCD Calculations TR 0 0002 CLC(41)
SUB(31) 10
First subtraction
DM 01 HR 2 1904 CLC(41)
SUB(31) #0000
Second subtraction
HR 2 HR 2 1904 HR 300
HR 300
Turned ON to indicate negative result.
5–16–3 Set Carry – STC(40) Set carry is used to set (turn ON) the CY (SR bit 1904) to “1”. 0002 STC(40)
5–16–4 Clear Carry – CLC(41) Clear carry is used to reset (turn OFF) the CY (SR bit 1904) to “0”. 0002 CLC(41)
93