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

The text of a manual · part 26 of 60

C200HX/C200HG/C200HE Programmable Controllers Operation Manual, pages 244 to 253

Pages 244 to 253 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 244

Section 5-18

Data Conversion

5-18-15 2’S COMPLEMENT – NEG(––)

Ladder Symbols

Operand Data Areas

NEG(––)

S: Source word

S

IR, SR, AR, DM, HR, TC, LR, #

R

R: Result word IR, SR, AR, DM, HR, LR

Description

Converts the four-digit hexadecimal content of the source word (S) to its 2’s complement and outputs the result to the result word (R). This operation is effectively the same as subtracting S from 0000 and outputting the result to R. If the content of S is 0000, the content of R will also be 0000 after execution, and EQ (SR 25506) will be turned on. If the content of S is 8000, the content of R will also be 8000 after execution, and UF (SR 25405) will be turned on. Note Refer to page 27 for details on 16-bit signed binary data.

Flags

Example

ER:

Indirectly addressed DM word is non-existent. (Content of word is not BCD, or the DM area boundary has been exceeded.)

EQ:

ON when the content of S is 0000; otherwise OFF.

UF:

ON when the content of S is 8000; otherwise OFF.

N:

ON when bit 15 of R is set to 1; otherwise OFF.

The following example shows how to use NEG(––) to find the 2’s complement of the hexadecimal value 001F and output the result to DM 0020. 00000 NEG(––) #001F DM 0020

Address

Instruction

00000 00001

LD NEG(––)

#0000 #001F

#FFE1

226

00000 # DM

---

–

Operands

Output to DM 0020.

001F 0020

Page 245

Section 5-18

Data Conversion

5-18-16 DOUBLE 2’S COMPLEMENT – NEGL(––) Ladder Symbols

Operand Data Areas

NEGL(––)

S: First source word

S

IR, SR, AR, DM, HR, TC, LR

R

R: First result word

---

IR, SR, AR, DM, HR, LR

Limitations

S and S+1 must be in the same data area, as must R and R+1.

Description

Converts the eight-digit hexadecimal content of the source words (S and S+1) to its 2’s complement and outputs the result to the result words (R and R+1). This operation is effectively the same as subtracting the eight-digit content S and S+1 from $0000 0000 and outputting the result to R and R+1. If the content of S is 0000 0000, the content of R will also be 0000 0000 after execution and EQ (SR 25506) will be turned on. If the content of S is 8000 0000, the content of R will also be 8000 0000 after execution and UF (SR 25405) will be turned on. Note Refer to page 27 for details on 32-bit signed binary data.

Flags

Example

ER:

Indirectly addressed DM word is non-existent. (Content of word is not BCD, or the DM area boundary has been exceeded.)

EQ:

ON when the content of S+1, S is 0000 0000; otherwise OFF.

UF:

ON when the content of S+1, S is 8000 0000; otherwise OFF.

N:

ON when bit 15 of R+1 is set to 1; otherwise OFF.

The following example shows how to use NEGL(––) to find the 2’s complement of the hexadecimal value in LR 21, LR 20 (001F FFFF) and output the result to DM 0021, DM 0020. 00000 NEG(––) LR20 DM 0020

Address

Instruction

00000 00001

LD NEGL(––)

00000 LR DM

---

0000 S+1: LR 21

–

Operands

001F R+1: DM 0021 FFE0

20 0020

0000 S: LR 20 FFFF R: DM 0020 0001

227

Page 246

Section 5-19

BCD Calculations

5-19 BCD Calculations The BCD calculation instructions – INC(38), DEC(39), ADD(30), ADDL(54), SUB(31), SUBL(55), MUL(32), MULL(56), DIV(33), DIVL(57), FDIV(79), and ROOT(72) – all perform arithmetic operations on BCD data. For INC(38) and DEC(39) the source and result words are the same. That is, the content of the source word is overwritten with the instruction result. All other 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 other 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 calculations and shift operations also use CY. The addition and subtraction instructions include 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-19-1 INCREMENT – INC(38) Ladder Symbols

Operand Data Areas

INC(38)

@INC(38)

Wd

Wd

Wd: Increment word (BCD) IR, SR, AR, DM, HR, LR

Description

When the execution condition is OFF, INC(38) is not executed. When the execution condition is ON, INC(38) increments Wd, without affecting Carry (CY).

Flags

ER:

Wd is not BCD Indirectly addressed DM word is non-existent. (Content of word is not BCD, or the DM area boundary has been exceeded.)

EQ:

ON when the incremented result is 0.

5-19-2 DECREMENT – DEC(39) Ladder Symbols

Operand Data Areas

DEC(39)

@DEC(39)

Wd

Wd

Wd: Decrement word (BCD) IR, SR, AR, DM, HR, LR

Description

When the execution condition is OFF, DEC(39) is not executed. When the execution condition is ON, DEC(39) decrements Wd, without affecting CY. DEC(39) works the same way as INC(38) except that it decrements the value instead of incrementing it.

Flags

ER:

Wd is not BCD Indirectly addressed DM word is non-existent. (Content of word is not BCD, or the DM area boundary has been exceeded.)

EQ:

228

ON when the decremented result is 0.

Page 247

Section 5-19

BCD Calculations

5-19-3 SET CARRY – STC(40) Ladder Symbols STC(40)

@STC(40)

When the execution condition is OFF, STC(40) is not executed. When the execution condition is ON, STC(40) turns ON CY (SR 25504). Note Refer to Appendix C Error and Arithmetic Flag Operation for a table listing the instructions that affect CY.

5-19-4 CLEAR CARRY – CLC(41) Ladder Symbols CLC(41)

@CLC(41)

When the execution condition is OFF, CLC(41) is not executed. When the execution condition is ON, CLC(41) turns OFF CY (SR 25504). CLEAR CARRY is used to reset (turn OFF) CY (SR 25504) to “0.” CY is automatically reset to “0” when END(01) is executed at the end of each cycle. Note Refer to Appendix C Error and Arithmetic Flag Operation for a table listing the instructions that affect CY.

5-19-5 BCD ADD – ADD(30) Operand Data Areas Au: Augend word (BCD)

Ladder Symbols

IR, SR, AR, DM, HR, TC, LR, # ADD(30)

@ADD(30)

Au

Au

Ad

Ad

R

R

Ad: Addend word (BCD)

Description

R: Result word IR, SR, AR, DM, HR, LR

When the execution condition is OFF, ADD(30) is not executed. 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 + Ad + CY Flags

IR, SR, AR, DM, HR, TC, LR, #

ER:

CY

R

Au and/or Ad is not BCD. Indirectly addressed DM word is non-existent. (Content of word is not BCD, or the DM area boundary has been exceeded.)

CY:

ON when there is a carry in the result.

EQ:

ON when the result is 0.

229

Page 248

Section 5-19

BCD Calculations Example

If 00002 is ON, the program represented by the following diagram clears CY with CLC(41), adds the content of LR 25 to a constant (6103), places the result in DM 0100, and then moves either all zeros or 0001 into DM 0101 depending on the status of CY (25504). 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.

TR 0 00002 CLC(41)

ADD(30)

Address

Instruction

00000 00001 00002 00003

LR OUT CLC(41) ADD(30)

LR 25 #6103 DM 0100 25504 MOV(21)

00004 00005

25504 MOV(21)

00006 00007 00008

TR

LD AND NOT MOV(21)

#0000 DM 0101

00002 0

LR # DM

25 6103 0100 25504

# DM TR

0001 0101 0 25504

# DM

0000 0101

AND MOV(21)

#0001 DM 0101

Operands

Although two ADD(30) can be used together to perform eight-digit BCD addition, ADDL(54) is designed specifically for this purpose.

5-19-6 DOUBLE BCD ADD – ADDL(54) Operand Data Areas Au: First augend word (BCD)

Ladder Symbols

IR, SR, AR, DM, HR, TC, LR ADDL(54)

@ADDL(54)

Au

Au

Ad

Ad

R

R

Ad: First addend word (BCD) IR, SR, AR, DM, HR, TC, LR R: First result word IR, SR, AR, DM, HR, LR

Limitations

Each of the following pairs must be in the same data area: Au and Au+1, Ad and Ad+1, and R and R+1.

Description

When the execution condition is OFF, ADDL(54) is not executed. When the execution condition is ON, ADDL(54) adds the contents of CY to the 8-digit value in Au and Au+1 to the 8-digit value in Ad and Ad+1, and places the result in R and R+1. CY will be set if the result is greater than 99999999. Au + 1

Au

Ad + 1

Ad

+ CY

230

CY R+1

R

Page 249

Section 5-19

BCD Calculations Flags

ER:

Au and/or Ad is not BCD. Indirectly addressed DM word is non-existent. (Content of word is not BCD, or the DM area boundary has been exceeded.)

Example

CY:

ON when there is a carry in the result.

EQ:

ON when the result is 0.

When 00000 is ON, the following program adds two 12-digit numbers, the first contained in LR 20 through LR 22 and the second in DM 0012. The result is placed in LR 10 through HR 13. In the second addition (using ADD(30)), any carry from the first addition is included. The carry from the second addition is placed in HR 13 by using @ADB(50) (see 5-20-1 BINARY ADD – ADB(50)) with two all-zero constants to indirectly place the content of CY into HR 13.

00000

Address

Instruction

00000 00001 00002

LD CLC(41) @ADDL(54)

Operands

CLC(41) @ADDL(54) LR 20 DM 0010 HR 10 @ADD(30)

00003

DM 0012 HR 12

00004

LR DM HR

20 0010 10

LR DM HR

22 0012 12

# # HR

0000 0000 13

@ADD(30)

LR 22

@ADB(50)

00000

@ADB(50)

#0000 #0000 HR 13

5-19-7 BCD SUBTRACT – SUB(31) Operand Data Areas Mi: Minuend word (BCD)

Ladder Symbols

IR, SR, AR, DM, HR, TC, LR, # SUB(31)

@SUB(31)

Mi

Mi

Su

Su

R

R

Su: Subtrahend word (BCD)

Description

IR, SR, AR, DM, HR, TC, LR, # R: Result word IR, SR, AR, DM, HR, LR

When the execution condition is OFF, SUB(31) is not executed. 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).

Mi – Su – CY

CY

R

Note The 2’s COMPLEMENT – NEG(––) instruction can be used to convert binary data only, it cannot be used with BCD data.

231

Page 250

Section 5-19

BCD Calculations Flags

ER:

Mi and/or Su is not BCD. Indirectly addressed DM word is non-existent. (Content of word is not BCD, or the DM area boundary has been exceeded.)

! Caution

Example

CY:

ON when the result is negative, i.e., when Mi is less than Su plus CY.

EQ:

ON when the result is 0.

Be sure to clear the carry flag 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.

When 00002 is ON, the following ladder program clears CY, subtracts the contents of DM 0100 and CY from the content of 010 and places the result in HR 20. If CY is set by executing SUB(31), the result in HR 20 is subtracted from zero (note that CLC(41) is again required to obtain an accurate result), the result is placed back in HR 20, and HR 2100 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 2100 is not turned ON. HR 2100 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 recycled. In this example, differentiated forms of SUB(31) are used so that the subtraction operation is performed only once each time 00002 is turned ON. When another subtraction operation is to be performed, 00002 will need to be turned OFF for at least one cycle (resetting HR 2100) and then turned back ON.

TR 0 00002 CLC(41)

@SUB(31) 010

First subtraction

Address

Instruction

00000 00001 00002 00003

LD OUT CLC(41) @SUB(31)

Operands TR

DM 0100

DM HR

HR 20 25504 CLC(41)

@SUB(31) #0000

Second subtraction

00004 00005 00006

AND CLC(41) @SUB(31)

HR 20 HR 20 25504 HR 2100

HR 2100

Turned ON to indicate negative result.

00007 00008 00009 00010

LD AND OR OUT

# HR HR TR HR HR

00002 0

010 0100 20 25504

0000 20 20 0 25504 2100 2100

The first and second subtractions for this diagram are shown below using example data for 010 and DM 0100.

232

Page 251

Section 5-19

BCD Calculations

Note The actual SUB(31) operation involves subtracting Su and CY from 10,000 plus Mi. For positive results the leftmost digit is truncated. For negative results the 10s complement is obtained. The procedure for establishing the correct answer is given below. First Subtraction IR 010 1029 DM 0100 – 3452 CY –0 HR 20 7577 (1029 + (10000 – 3452)) CY 1 (negative result) Second Subtraction 0000 HR 20 –7577 CY –0 HR 20 2423 (0000 + (10000 – 7577)) CY 1 (negative result) In the above case, the program would turn ON HR 2100 to indicate that the value held in HR 20 is negative.

5-19-8 DOUBLE BCD SUBTRACT – SUBL(55) Operand Data Areas Mi: First minuend word (BCD)

Ladder Symbols

IR, SR, AR, DM, HR, TC, LR SUBL(55)

@SUBL(55)

Mi

Mi

Su

Su

R

R

Su: First subtrahend word (BCD) IR, SR, AR, DM, HR, TC, LR R: First result word IR, SR, AR, DM, HR, LR

Limitations

Each of the following pairs must be in the same data area: Mi and Mi+1, Su and Su+1, and R and R+1.

Description

When the execution condition is OFF, SUBL(55) is not executed. When the execution condition is ON, SUBL(55) subtracts CY and the 8-digit contents of Su and Su+1 from the 8-digit value in Mi and Mi+1, and places the result in R and R+1. 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. Since an 8-digit constant cannot be directly entered, use the BSET(71) instruction (see 5-16-3 BLOCK SET – BSET(71)) to create an 8-digit constant. Mi + 1

Mi

Su + 1

Su

– CY

CY

R+1

R

Note The DOUBLE 2’s COMPLEMENT – NEGL(––) instruction can be used to convert binary data only, it cannot be used with BCD data.

233

Page 252

Section 5-19

BCD Calculations Flags

ER:

Mi, M+1,Su, and Su+1 are not BCD. Indirectly addressed DM word is non-existent. (Content of word is not BCD, or the DM area boundary has been exceeded.)

CY:

ON when the result is negative, i.e., when Mi is less than Su.

EQ:

ON when the result is 0.

The following example works much like that for single-word subtraction. In this example, however, BSET(71) is required to clear the content of DM 0000 and DM 0001 so that a negative result can be subtracted from 0 (inputting an 8-digit constant is not possible). Example

TR 0 00003 CLC(41)

First subtraction

@SUBL(55) HR 20 120 DM 0100 25504 @BSET(71) #0000 DM 0000 DM 0001 CLC(41)

Second subtraction

@SUBL(55) DM 0000 DM 0100 DM 0100 25504 HR 2100

HR 2100

Address

Instruction

00000 00001 00002 00003

LD OUT CLC(41) @SUBL(55)

Turned ON to indicate negative result.

Operands

TR

HR DM 00004 00005

AND @BSET(71) # DM DM

234

00003 0

20 120 0100 25504 0000 0000 0001

Address 00006 00007

00008 00009 00010 00011

Instruction

Operands

CLC(41) @SUBL(55)

LD AND OR OUT

DM DM DM TR HR HR

0000 0100 0100 0 25504 2100 2100

Page 253

Section 5-19

BCD Calculations

5-19-9 BCD MULTIPLY – MUL(32) Operand Data Areas Md: Multiplicand (BCD)

Ladder Symbols

IR, SR, AR, DM, HR, TC, LR, # MUL(32)

@MUL(32)

Md

Md

Mr

Mr

R

R

Mr: Multiplier (BCD) IR, SR, AR, DM, HR, TC, LR, # R: First result word IR, SR, AR, DM, HR LR

Limitations

R and R+1 must be in the same data area.

Description

When the execution condition is OFF, MUL(32) is not executed. When the execution condition is ON, MUL(32) multiplies Md by the content of Mr, and places the result In R and R+1. Md

X R +1

Example

Mr

R

When IR 00000 is ON with the following program, the contents of IR 013 and DM 0005 are multiplied and the result is placed in HR 07 and HR 08. Example data and calculations are shown below the program.

00000 MUL(32) 013 DM 0005 HR 07

0

Flags

Instruction

00000 00001

LD MUL(32)

Operands 00000

DM HR

3

Md: IR 013 3 5 6

X

0

Mr: DM 0005 0 2 5

R+1: HR 08 0 0 8

3

R: HR 07 9 0

ER:

Address

013 00005 07

0

Md and/or Mr is not BCD. Indirectly addressed DM word is non-existent. (Content of word is not BCD, or the DM area boundary has been exceeded.)

EQ:

ON when the result is 0.

235