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

The text of a manual · part 27 of 60

C200HX/C200HG/C200HE Programmable Controllers Operation Manual, pages 254 to 263

Pages 254 to 263 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 254

Section 5-19

BCD Calculations

5-19-10 DOUBLE BCD MULTIPLY – MULL(56) Operand Data Areas Md: First multiplicand word (BCD)

Ladder Symbols

IR, SR, AR, DM, HR, TC, LR MULL(56)

@MULL(56)

Md

Md

Mr

Mr

R

R

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

Limitations

Md and Md+1 must be in the same data area, as must Mr and Mr+1. R through R+3 must be in the same data area.

Description

When the execution condition is OFF, MULL(56) is not executed. When the execution condition is ON, MULL(56) multiplies the eight-digit content of Md and Md+1 by the content of Mr and Mr+1, and places the result in R to R+3.

x R+3

Flags

ER:

EQ:

R+2

Md + 1

Md

Mr + 1

Mr

R+1

R

Md, Md+1,Mr, or Mr+1 is not BCD. Indirectly addressed DM word is non-existent. (Content of word is not BCD, or the DM area boundary has been exceeded.) ON when the result is 0.

5-19-11 BCD DIVIDE – DIV(33) Operand Data Areas Dd: Dividend word (BCD)

Ladder Symbol

IR, SR, AR, DM, HR, TC, LR, # DIV(33) Dr: Divisor word (BCD) Dd

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

Dr

R: First result word (BCD)

R

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, DIV(33) is not executed and the program moves to the next instruction. When the execution condition is ON, Dd is divided by Dr and the result is placed in R and R + 1: the quotient in R and the remainder in R + 1.

Dr

236

Remainder

Quotient

R+1

R

Dd

Page 255

Section 5-19

BCD Calculations Flags

ER:

Dd or Dr is not in BCD or when Dr is #0000. Indirectly addressed DM word is non-existent. (Content of word is not BCD, or the DM area boundary has been exceeded.)

EQ: Example

ON when the result is 0.

When IR 00000 is ON with the following program, the content of IR 020 is divided by the content of HR 09 and the result is placed in DM 0017 and DM 0018. Example data and calculations are shown below the program.

00000 DIV(33) 020

Address

Instruction

00000 00001

LD DIV(33)

Operands 00000

HR 09 DM 0017

1

0

Quotient

Remainder

R: DM 0017 1 5 0

R + 1: DM 0018 0 0 0 2

Dd: HR 09 0 0 3

3

HR DM

020 09 0017

Dd: IR 020 4 5 2

5-19-12 DOUBLE BCD DIVIDE – DIVL(57) Operand Data Areas Dd: First dividend word (BCD)

Ladder Symbols

IR, SR, AR, DM, HR, TC, LR DIVL(57)

@DIVL(57)

Dd

Dd

Dr

Dr

R

R

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

Limitations

Dd and Dd+1 must be in the same data area, as must Dr and Dr+1. R through R+3 must be in the same data area.

Description

When the execution condition is OFF, DIVL(57) is not executed. When the execution condition is ON, DIVL(57) the eight-digit content of Dd and D+1 is divided by the content of Dr and Dr+1 and the result is placed in R to R+3: the quotient in R and R+1, the remainder in R+2 and R+3. Remainder R+3

Dr+1

Flags

ER:

R+2

Dr

Quotient R+1

R

Dd+1

Dd

Dr and Dr+1 contain 0. Dd, Dd+1, Dr, or Dr+1 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.

237

Page 256

Section 5-19

BCD Calculations

5-19-13 FLOATING POINT DIVIDE – FDIV(79) Operand Data Areas Dd: First dividend word (BCD)

Ladder Symbols

IR, SR, AR, DM, HR, TC, LR FDIV(79)

@FDIV(79)

Dd

Dd

Dr

Dr

R

R

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

Limitations

Dr and Dr+1 cannot contain zero. Dr and Dr+1 must be in the same data area, as must Dd and Dd+1; R and R+1. The dividend and divisor must be between 0.0000001 x 10–7 and 0.9999999 x 107. The results must be between 0.1 x 10–7 and 0.9999999 x 107.

Description

When the execution condition is OFF, FDIV(79) is not executed. When the execution condition is ON, FDIV(79) divides the floating-point value in Dd and Dd+1 by that in Dr and Dr+1 and places the result in R and R+1. Quotient

Dr+1

Dr

R+1

R

Dd+1

Dd

To represent the floating point values, the rightmost seven digits are used for the mantissa and the leftmost digit is used for the exponent, as shown below. The mantissa is expressed as a value less than one, i.e., to seven decimal places. First word 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00 1

0

1

0

0

0

0

1

0 exponent (0 to 7) sign of exponent

0

0

1

0

0

0

1 mantissa (leftmost 3 digits) 0: + 1: –

Second word 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00 0

0

0

1

0

0

0

1

0

0

0

1

0

0

0

1 mantissa (leftmost 4 digits)

= 0.1111111 x 10–2 Flags

ER:

Dr and Dr+1 contain 0. Dd, Dd+1, Dr, or Dr+1 is not BCD. The result is not between 0.1 x 10–7 and 0.999999 x 107. Indirectly addressed DM word is non-existent. (Content of word is not BCD, or the DM area boundary has been exceeded.)

EQ:

238

ON when the result is 0.

Page 257

BCD Calculations Example

Section 5-19 The following example shows how to divide two whole four-digit numbers (i.e., numbers without fractions) so that a floating-point value can be obtained. First the original numbers must be placed in floating-point form. Because the numbers are originally without decimal points, the exponent will be 4 (e.g., 3452 would equal 0.3452 x 104). All of the moves are to place the proper data into consecutive words for the final division, including the exponent and zeros. Data movements for Dd and Dd+1 are shown at the right below. Movements for Dr and Dr+1 are basically the same. The original values to be divided are in DM 0000 and DM 0001. The final division is also shown.

239

Page 258

Section 5-19

BCD Calculations 00000 @MOV(21)

HR 01

#0000

HR 00 0 0

0

0

HR 00 @MOV(21)

0000

#0000 HR 02 @MOV(21)

HR 01 4 0 0 0

#4000

HR 00 0 0

0

0

HR 01 @MOV(21)

4000

#4000 HR 03

DM 0000 3 4 5 2

@MOVD(83) DM 0000 #0021

HR 01 4 3 4 5

HR 01 00000 @MOVD(83)

0

HR 00 0 0

0

DM 0000 3 4 5 2

DM 0000 #0300 HR 00

@MOVD(83)

HR 01 4 3 4 5

2

HR 00 0 0

0

HR 01 4 3 4 5

2

HR 00 0 0

0

HR 03 4 0 0 7

9

HR 02 0 0

0

DM 0003 2 4 3 6

9

DM 0002 6 2 0

DM 0001 #0021 HR 03

@MOVD(83) DM 0001 #0300 HR 02

@FDIV(79)

÷

HR 00 HR 02

0.4369620 x 102

DM 0002

Address

Instruction

00000 00001

LD @MOV(21)

00002

00003

00004

00005

240

Operands 00000 # HR

0000 00

# HR

0000 02

# HR

4000 01

# HR

4000 03

DM # HR

0000 0021 01

Address

Instruction

00006

@MOVD(83)

00007

@MOV(21)

00009

0000 0300 00

DM # HR

0001 0021 03

DM # HR

0001 0300 02

HR HR DM

00 02 0002

@MOVD(83)

@MOV(21)

@MOVD(83)

DM # HR @MOVD(83)

@MOV(21) 00008

Operands

@FDIV(79)

Page 259

Section 5-19

BCD Calculations

5-19-14 SQUARE ROOT – ROOT(72) Ladder Symbols

Operand Data Areas Sq: First source word (BCD)

ROOT(72)

@ROOT(72)

Sq

Sq

R

R

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

Limitations

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

Description

When the execution condition is OFF, ROOT(72) is not executed. When the execution condition is ON, ROOT(72) computes the square root of the eight-digit content of Sq and Sq+1 and places the result in R. The fractional portion is truncated. R

Sq+1

Flags

ER:

Sq

Sq or Sq+1 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: Example

ON when the result is 0.

The following example shows how to take the square root of a four-digit number and then round the result. First the words to be used are cleared to all zeros and then the value whose square root is to be taken is moved to Sq+1. The result, which has twice the number of digits required for the answer (because the number of digits in the original value was doubled), is placed in DM 0102, and the digits are split into two different words, the leftmost two digits to IR 011 for the answer and the rightmost two digits to DM 0103 so that the answer in IR 011 can be rounded up if required. The last step is to compare the value in DM 0103 so that IR 011 can be incremented using the Greater Than flag.

241

Page 260

Section 5-19

BCD Calculations

In this example, √6017 = 77.56, and 77.56 is rounded off to 78. 00000 @BSET(71)

DM 0101 0 0 0

#0000

0

0

DM 0100 0 0 0

DM 0100 DM 0101

0000

@MOV(21)

010 6 0 1

010

0000 7

DM 0101

DM 0101 6 0 1 7

@ROOT(72)

0

DM 0100 0 0 0

DM 0100

60170000= 77.56932

DM 0102 @MOV(21) #0000

DM 0103 0 0 0

011

0

0

IR 011 0 0

0

@MOV(21)

0000

#0000

0000

DM 0103 @MOVD(83)

DM 0102 7 7 5 6

DM 0102 #0012 011

@MOVD(83)

0 0

DM 0102

IR 011 7 7

5

DM 0103 6 0 0

#0210 DM 0103

@CMP(20)

5600 > 4900

DM 0103 #4900 25505 @INC(38)

0 0

011

Address

Instruction

00000 00001

LD @BSET(71)

00002

00003

00004

00005

Operands 00000 # DM DM

0000 0100 0101

DM

010 0101

DM DM

0100 0102

#

0000 011

Instruction

00006

@MOVD(83)

00007

00008

@MOV(21)

@MOV(21) # DM

242

Address

0000 0103

00009 00010

Operands

DM #

0102 0012 011

DM # DM

0102 0210 0103

DM # 25505

0103 4900

@MOVD(83)

@MOV(21)

@ROOT(72)

IR 011 7 8

@CMP(20)

LD @INC(38)

011

Page 261

Section 5-20

Binary Calculations

5-20 Binary Calculations Binary calculation instructions, ADB(50), SBB(51), MLB(52), DVB(53), ADBL(––), SBBL(––), MBS(––), MBSL(––), DBS(––), and DBSL(––), perform arithmetic operations on hexadecimal data. Four of these instructions (ADB(50), SBB(51), ADBL(––), and SBBL(––)) can act on both normal and signed data, two (MLB(52) and DVB(53)) act only on normal data, and four (MBS(––), MBSL(––), DBS(––), and DBSL(––)) act only on signed binary data. 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 the execution of any other instruction. STC(40) and CLC(41) can be used to control CY. Refer to 5-19 BCD Calculations. Signed binary addition and subtraction instructions use the underflow and overflow flags (UF and OF) to indicate whether the result exceeds the acceptable range for 16-bit or 32-bit signed binary data. Refer to page 27 for details on signed binary data.

5-20-1 BINARY ADD – ADB(50) Operand Data Areas Au: Augend word (binary)

Ladder Symbols

IR, SR, AR, DM, HR, TC, LR, # ADB(50)

@ADB(50)

Au

Au

Ad

Ad

R

R

Ad: Addend word (binary)

Description

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

When the execution condition is OFF, ADB(50) is not executed. When the execution condition is ON, ADB(50) adds the contents of Au, Ad, and CY, and places the result in R. CY will be set if the result is greater than FFFF.

Au + Ad + CY

CY

R

ADB(50) can also be used to add signed binary data. The overflow and underflow flags (SR 25404 and SR 25405) indicate whether the result has exceeded the lower or upper limits of the 16-bit signed binary data range. Refer to page 27 for details on signed binary data. Flags

ER:

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 greater than FFFF.

EQ:

ON when the result is 0.

OF:

ON when the result exceeds +32,767 (7FFF).

UF:

ON when the result is below –32,768 (8000).

N:

ON when bit 15 of the result is set to 1.

243

Page 262

Binary Calculations

Section 5-20

Example 1: Adding Normal Data

The following example shows a four-digit addition with CY used to place either #0000 or #0001 into R+1 to ensure that any carry is preserved.

TR 0 00000 CLC(41)

ADB(50)

Address

Instruction

00000 00001 00002 00003

LD OUT CLC(41) ADB(50)

Operands TR

010 DM 0100 HR 10

DM HR

=R

25504

00004 00005

MOV(21) #0000 HR 11

AND NOT MOV(21)

= R+1

25504 MOV(21) #0001 HR 11

= R+1

00006 00007 00008

LD AND MOV(21)

00000 0

010 0100 10 25504

# HR TR

0000 11 0 25504

# HR

00001 11

In the case below, A6E2 + 80C5 = 127A7. The result is a 5-digit number, so CY (SR 25504) = 1, and the content of R + 1 becomes #0001.

0

A

Au: IR 010 6 E 2

+

8

Ad: DM 0100 0 C 5

R+1: HR 11 0 0 1

2

R: HR 10 7 A

7

Note The UF and OF flags would also be turned ON during this addition, but they can be ignored since they are relevant only in the addition of signed binary data. Example 2: Adding Signed Binary Data

In the following example, ADB(50) is used to add two 16-bit signed binary values. (The 2’s complement is used to express negative values.) The effective range for 16-bit signed binary values is –32,768 (8000) to +32,768 (7FFF). The overflow flag (OF: SR 25404) is turned ON if the result exceeds +32,767 (7FFF) and the underflow flag (UF: SR 25405) is turned ON if the result falls below –32,768 (8000).

00000 CLC(41)

ADB(50) LR 20 DM 0010 DM 0020

244

Address

Instruction

00000 00001 00002

LD CLC(41) ADB(50)

Operands 00000

LR DM DM

20 0010 0020

Page 263

Section 5-20

Binary Calculations

In the case below, 25,321 +(–13,253) = 12,068 (62E9 + CC3B = 2F24). Neither OF nor UF are turned ON.

6

+

Au: LR 20 2 E 9

Ad: DM 0010 C C 3 B

2

Ad: DM 0010 F 2 4

Note The status of the CY flag can be ignored when adding signed binary data since it is relevant only in the addition of normal hexadecimal values.

5-20-2 BINARY SUBTRACT – SBB(51) Operand Data Areas Mi: Minuend word (binary)

Ladder Symbols

IR, SR, AR, DM, HR, TC, LR, # SBB(51)

@SBB(51)

Mi

Mi

Su

Su

R

R

Su: Subtrahend word (binary)

Description

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

When the execution condition is OFF, SBB(51) is not executed. When the execution condition is ON, SBB(51) 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 2’s complement of the actual result is placed in R.

Mi – Su – CY

CY

R

SBB(51) can also be used to subtract signed binary data. The overflow and underflow flags (SR 25404 and SR 25405) indicate whether the result has exceeded the lower or upper limits of the 16-bit signed binary data range. Refer to page 27 for details on signed binary data. Flags

ER:

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 plus CY.

EQ:

ON when the result is 0.

OF:

ON when the result exceeds +32,767 (7FFF).

UF:

ON when the result is below –32,768 (8000).

N:

ON when bit 15 of the result is set to 1.

245