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

The text of a manual · part 35 of 60

SYSMAC CQM1/CPM1/CPM1A/SRM1 Programmable Controllers Programming Manual: SECTION 5 Instruction Set, pages 319 to 328

Pages 319 to 328 of 520, from SYSMAC CQM1/CPM1/CPM1A/SRM1 Programmable Controllers Programming Manual

The original document is the PDF (2.1 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 CQM1-CPU21

Page 319

Section 5-22

Special Math Instructions Flags

ER:

Indirectly addressed DM word is non-existent. (Content of DM word is not BCD, or the DM area boundary has been exceeded.) R1 and R1+N–1 are not in the same data area.

EQ:

ON when the maximum value is #0000.

5-22-2 FIND MINIMUM – MIN(––) Ladder Symbols

Operand Data Areas C: Control data

MIN(––)

@MIN(––)

C

C

R1

R1

D

D

IR, SR, AR, DM, HR, TC, LR, # R1: First word in range IR, SR, AR, DM, HR, TC, LR D: Destination word IR, SR, AR, DM, HR, LR

Limitations

This instruction is available in the CQM1 only. N must be BCD between 0001 to 9999. R1 and R1+N–1 must be in the same data area. DM 6144 to DM 6655 cannot be used for D.

Description

When the execution condition is OFF, MIN(––) is not executed. When the execution condition is ON, MIN(––) searches the range of memory from R1 to R1+N–1 for the address that contains the minimum value and outputs the minimum value to the destination word (D). If bit 15 of C is ON, MIN(––) identifies the address of the word containing the minimum value in D+1. The address is identified differently for the DM area: 1, 2, 3...

1. For an address in the DM area, the word address is written to C+1. For example, if the address containing the minimum value is DM 0114, then #0114 is written in D+1. 2. For an address in another data area, the number of addresses from the beginning of the search is written to D+1. For example, if the address containing the minimum value is IR 114 and the first word in the search range is IR 014, then #0100 is written in D+1. If bit 14 of C is ON and more than one address contains the same minimum value, the position of the lowest of the addresses will be output to D+1. The position will be output as the DM address for the DM area, but as an absolute position relative to the first word in the range for all other areas. The number of words within the range (N) is contained in the 3 rightmost digits of C, which must be BCD between 001 and 999. When bit 15 of C is OFF, data within the range is treated as unsigned binary and when it is ON the data is treated as signed binary. C:

15 14 13 12 11

00 Number of words in range (N) Not used – set to zero.

Data type 1 (ON): Signed binary 0 (OFF): Unsigned binary

Output address to D+1? 1 (ON): Yes. 0 (OFF): No.

301

Page 320

Special Math Instructions

Section 5-22

! Caution

If bit 14 of C is ON, values above #8000 are treated as negative numbers, so the results will differ depending on the specified data type. Be sure that the correct data type is specified.

Flags

ER:

Indirectly addressed DM word is non-existent. (Content of DM word is not BCD, or the DM area boundary has been exceeded.) R1 and R1+N–1 are not in the same data area.

EQ:

ON when the minimum value is #0000.

5-22-3 AVERAGE VALUE – AVG(––) Ladder Symbols AVG(––)

Operand Data Areas S: Source word IR, SR, AR, DM, HR, TC, LR

S N: Number of cycles N IR, SR, AR, DM, HR, TC, LR, # D

D: First destination word IR, SR, AR, DM, HR, LR

Limitations

This instruction is available in the CQM1 only. S must be hexadecimal. N must be BCD from #0001 to #0064. D and D+N+1 must be in the same data area. DM 6144 to DM 6655 cannot be used for S, N, or D to D+N+1.

Description

AVG(––) is used to calculate the average value of S over N cycles. When the execution condition is OFF, AVG(––) is not executed. Each time that AVG(––) is executed, the content of S is stored in words D+2 to D+N+1. On the first execution, AVG(––) writes the content of S to D+2; on the second execution it writes the content of S to D+3, etc. On the Nth execution, AVG(––) writes the content of S is stored in D+N+1, AVG(––) calculates the average value of the values stored in D+2 to D+N+1, and writes the average to D. The following diagram shows the function of words D to D+N+1.

Precautions

302

D D+1 D+2 D+3

Average value (after N or more executions) Used by the system. Content of S from the 1st execution of AVG(––) Content of S from the 2nd execution of AVG(––)

D+N+1

Content of S from the Nth execution of AVG(––)

The average value is calculated in binary. Be sure that the content of S is in binary. N must be BCD from #0001 to #0064. If the content of N ≥ #0065, AVG(––) will operate with N=64. The average value will be rounded off to the nearest integer value. (0.5 is rounded up to 1.) Leave the contents of D+1 set to #0000 after the first execution of AVG(––).

Page 321

Section 5-22

Special Math Instructions Flags

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

ER:

One or more operands have been set incorrectly. D and D+N+1 are not in the same data area. Example

In the following example, the content of IR 040 is set to #0000 and then incremented by 1 each cycle. For the first two cycles, AVG(––) moves the content of IR 040 to DM 1002 and DM 1003. On the third and later cycles AVG(––) calculates the average value of the contents of DM 1002 to DM 1004 and writes that average value to DM 1000. 00001 @MOV(21)

Address

Instruction

00000 00001

LD @MOV(21)

Operands

#0000 040

00001 #

AVG(––) 040

00002

AVG(––)

#0003

# DM

DM 1000

00003 00004

CLC(41)

0000 040 040 0003 1000

CLC(41) ADB(50)

ADB(50)

#

040

040 0001 040

#0001 040

IR 040

DM 1000 DM 1001 DM 1002 DM 1003 DM 1004

1st cycle 0000

2nd cycle 0001

3rd cycle 0002

4th cycle 0003

1st cycle 0000

2nd cycle 0001

3rd cycle 0001

4th cycle 0002

0000 -----

0000 0001 ---

0000 0001 0002

0003 0001 0002

Average Used by the system. Previous values of IR 40

5-22-4 SUM – SUM(––) Operand Data Areas

Ladder Symbols SUM(––)

@SUM(––)

C

C

R1

R1

D

D

C: Control data IR, SR, AR, DM, HR, LR, # R1: First word in range IR, SR, AR, DM, HR, TC, LR D: First destination word IR, SR, AR, DM, HR, LR

Limitations

This instruction is available in the CQM1 only. The 3 rightmost digits of C must be BCD between 001 and 999.

303

Page 322

Section 5-22

Special Math Instructions

DM 6143 to DM 6655 cannot be used for D. If bit 14 of C is OFF (setting for BCD data), all data within the range R1 to R1+N–1 must be BCD. Description

When the execution condition is OFF, SUM(––) is not executed. When the execution condition is ON, SUM(––) adds either the contents of words R1 to R1+N–1 or the bytes in words R1 to R1+N/2–1 and outputs that value to the destination words (D and D+1). The data can be summed as binary or BCD and will be output in the same form. Binary data can be either signed or unsigned. The function of bits in C are shown in the following diagram and explained in more detail below. C:

15 14 13 12 11

00 Number of items in range (N, BCD) Number of words or number of bytes 001 to 999 First byte (when bit 13 is ON) 1 (ON): Rightmost 0 (OFF): Leftmost

Data type 1 (ON): Binary 0 (OFF): BCD

Addition units 1 (ON): Bytes 0 (OFF): Words

Data type 1 (ON): Signed binary 0 (OFF): Unsigned binary

Number of Items in Range

The number of items within the range (N) is contained in the 3 rightmost digits of C, which must be BCD between 001 and 999. This number will indicate the number of words or the number of bytes depending the items being summed.

Addition Units

Words will be added if bit 13 is OFF and bytes will be added if bit 13 is ON. If bytes are specified, the range can begin with the leftmost or rightmost byte of R1. The leftmost byte of R1 will not be added if bit 12 is ON. R1 R1+1 R1+2 R1+3

MSB LSB 1 2 3 4 5 6 7 8

The bytes will be added in this order when bit 12 is OFF: 1+2+3+4.... The bytes will be added in this order when bit 12 is ON: 2+3+4.... Data Type

Data within the range is treated as unsigned binary when bit 14 of C is ON and bit 15 is OFF, and it is treated as signed binary when both bits 14 and 15 are ON. Data within the range is treated as BCD when bit 14 of C is OFF, regardless of the status of bit 15.

Flags

ER:

Indirectly addressed DM word is non-existent. (Content of DM word is not BCD, or the DM area boundary has been exceeded.) R1 and R1+N–1 are not in the same data area. The number of items in C is not BCD between 001 and 999. The data being summed in not BCD when BCD was designated.

EQ:

304

ON when the result is zero.

Page 323

Section 5-22

Special Math Instructions Example

In the following example, the BCD contents of the 8 words from DM 0000 to DM 0007 are added when IR 00001 is ON and the result is written to DM 0010 and DM 0011. 00001 @SUM(––)

Address

Instruction

00000 00001

LD @SUM(––)

#0008 DM 0000

Operands 00001 # DM DM

DM 0010

DM 0000 DM 0001 DM 0002 DM 0003 DM 0004 DM 0005 DM 0006 DM 0007

0001 0002 0003 0004 0005 0006 0007 0008

DM 0010 DM 0011

0008 0000 0010

0036 0000

5-22-5 ARITHMETIC PROCESS – APR(––) Operand Data Areas

Ladder Symbols

C: Control word APR(––)

@APR(––)

C

C

S

S

D

D

IR, SR, AR, DM, HR, TC, LR, # S: Input data source word IR, SR, AR, DM, HR, TC, LR D: Result destination word IR, SR, AR, DM, HR,TC, LR

Limitations

This instruction is available in the CQM1 only. For trigonometric functions S must be BCD from 0000 to 0900 (0°≤ ≤ 90°). DM 6144 to DM 6655 cannot be used for D.

Description

When the execution condition is OFF, APR(––) is not executed. When the execution condition is ON, the operation of APR(––) depends on the control word C. If C is #0000 or #0001, APR(––) computes or The BCD value of S specifies in tenths of degrees. If C is an address, APR(––) computes f(x) of the function entered in advance beginning at word C. The function is a series of line segments (which can approximate a curve) determined by the operator. The BCD or hexadecimal value of S specifies x.

Flags

ER:

Indirectly addressed DM word is non-existent. (Content of DM word is not BCD, or the DM area boundary has been exceeded.) For trigonometric functions, x > 0900. (x is the content of S.) A constant other than #0000 or #0001 was designated for C. The linear approximation data is not readable.

EQ:

The result is 0000.

305

Page 324

Section 5-22

Special Math Instructions Examples Sine Function

The following example demonstrates the use of the APR(––) sine function to calculate the sine of 30°. The sine function is specified when C is #0000.

00000 APR(––) #0000

Address

Instruction

00000 00001

LD APR(––)

00000

DM 0000

# DM DM

DM 0100

Input data, x 0 0

S: DM 0000 100 101 3 0

10–1 0

Cosine Function

10–1 5

D: DM 0100 10–2 10–3 0 0

10–4 0

Result data has four significant digits, fifth and higher digits are ignored. The result for sin(90) will be 0.9999, not 1.

The following example demonstrates the use of the APR(––) cosine function to calculate the cosine of 30°. The cosine function is specified when C is #0001.

00000 APR(––) #0001

Address

Instruction

00000 00001

LD APR(––)

DM 0010

Input data, x

00000 0001 0010 0110

Result data 10–1 0

Enter input data not exceeding #0900 in BCD.

Linear Approximation

Operands

# DM DM

DM 0110

0 0

0000 0000 0100

Result data

Enter input data not exceeding #0900 in BCD.

S: DM 0010 101 100 3 0

Operands

10–1 8

D: DM 0110 10–2 10–3 6 6

10–4 0

Result data has four significant digits, fifth and higher digits are ignored. The result for cos(0) will be 0.9999, not 1.

APR(––) linear approximation is specified when C is a memory address. Word C is the first word of the continuous block of memory containing the linear approximation data. The content of word C specifies the number of line segments in the approximation, and whether the input and output are in BCD or BIN form. Bits 00 to 07 contain the number of line segments less 1, m–1, as binary data. Bits 14 and 15 determine, respectively, the output and input forms: 0 specifies BCD and 1 specifies BIN. C: 15 14 13

Not used.

07 06 05 04 03 02 01 00

Source data form 1 (ON): f(x)=f(Xm–S) 0 (OFF): f(x)=f(S) Output form Input form

306

Number of coordinates minus one (m–1)

Page 325

Section 5-22

Special Math Instructions

Enter the coordinates of the m+1 end-points, which define the m line segments, as shown in the following table. Enter all coordinates in BIN form. Always enter the coordinates from the lowest X value (X1) to the highest (Xm). X0 is 0000, and does not have to be entered.

Y

Word

Ym Y4

Coordinate

C+1

Xm (max. X value)

C+2

Y0

C+3

X1

Y3

C+4

Y1

Y1

C+5

X2

C+6

Y2

Y2 Y0

X X0

X1

X2 X3

X4

↓

↓

C+(2m+1)

Xm

C+(2m+2)

Ym

Xm

If bit 13 of C is set to 1, the graph will be reflected from left to right, as shown in the following diagram. Y

Y

X0

Xm

X

Xm

X

X0

The following example demonstrates the construction of a linear approximation with 12 line segments. The block of data is continuous, as it must be, from DM 0000 to DM 0026 (C to C + (2 × 12 + 2)). The input data is taken from IR 010, and the result is output to IR 011.

00000 APR(––) DM 0000

Address

Instruction

00000 00001

LD APR(––)

Operands 00000

010

DM

011

Content Coordinate

Bit 15

DM 0000 DM 0001 DM 0002 DM 0003 DM 0004 DM 0005 DM 0006

$C00B $05F0 $0000 $0005 $0F00 $001A $0402

1 1 0 0 0 0 0 0 0 0 0 0 1 0 1 1

↓

↓

↓

DM 0025 DM 0026

$05F0 $1F20

X12 Y12

X12 Y0 X1 Y1 X2 Y2

(Output and input both BIN)

0000 010 011

Bit 00

(m–1 = 11: 12 line segments)

307

Page 326

Section 5-23

Logic Instructions

In this case, the input data word, IR 010, contains #0014, and f(0014) = #0726 is output to R, IR 011. Y $1F20

$0F00

(x,y)

$0726 $0402

(0,0)

$0005

$0014

$001A

$05F0

X

5-23 Logic Instructions 5-23-1 COMPLEMENT – COM(29) Ladder Symbols

Operand Data Areas

COM(29)

@COM(29)

Wd

Wd

Wd: Complement word IR, SR, AR, DM, HR, LR

Limitations

DM 6144 to DM 6655 cannot be used for Wd.

Description

When the execution condition is OFF, COM(29) is not executed. When the execution condition is ON, COM(29) clears all ON bits and sets all OFF bits in Wd.

Precautions

The complement of Wd will be calculated every cycle if the undifferentiated form of COM(29) is used. Use the differentiated form (@COM(29)) or combine COM(29) with DIFU(13) or DIFD(14) to calculate the complement just once. 15

Example Original

1

00 0

0

1

1

0

0

1

1

0

0

1

1

0

0

15 Complement 0

Flags

308

1

00 1

1

0

0

1

1

0

0

1

1

0

0

1

1

0

ER:

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

EQ:

ON when the result is 0.

Page 327

Section 5-23

Logic Instructions

5-23-2 LOGICAL AND – ANDW(34) Operand Data Areas Ladder Symbols

I1: Input 1 IR, SR, AR, DM, HR, TC, LR, #

ANDW(34)

@ANDW(34)

I1

I1

I2

I2

R

R

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

Limitations

DM 6144 to DM 6655 cannot be used for R.

Description

When the execution condition is OFF, ANDW(34) is not executed. When the execution condition is ON, ANDW(34) logically AND’s the contents of I1 and I2 bit-by-bit and places the result in R. 15

Example

1

I1

00 0

0

1

1

0

0

1

1

0

0

1

1

0

0

15 0

I2

00 1

0

1

0

1

0

1

0

1

0

1

0

1

0

15 0

R

Flags

1

1

00 0

0

1

0

0

0

1

0

0

0

1

0

0

0

1

ER:

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

EQ:

ON when the result is 0.

5-23-3 LOGICAL OR – ORW(35) Operand Data Areas I1: Input 1

Ladder Symbols

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

Limitations

ORW(35)

@ORW(35)

I1

I1

I2

I2

R

R

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

DM 6144 to DM 6655 cannot be used for R.

309

Page 328

Section 5-23

Logic Instructions Description

When the execution condition is OFF, ORW(35) is not executed. When the execution condition is ON, ORW(35) logically OR’s the contents of I1 and I2 bitby-bit and places the result in R. 15

Example I1

1

00 0

0

1

1

0

0

1

1

0

0

1

1

0

0

15

I2

0

00 1

0

1

0

1

0

1

0

1

0

1

0

1

0

15

R

Flags

1

1

1

00 1

0

1

1

1

0

1

1

1

0

1

1

1

0

1

ER:

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

EQ:

ON when the result is 0.

5-23-4 EXCLUSIVE OR – XORW(36) Operand Data Areas I1: Input 1

Ladder Symbols

IR, SR, AR, DM, HR, TC, LR, # XORW(36)

@XORW(36)

I1

I1

I2

I2

R

R

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

Limitations

DM 6144 to DM 6655 cannot be used for R.

Description

When the execution condition is OFF, XORW(36) is not executed. When the execution condition is ON, XORW(36) exclusively OR’s the contents of I1 and I2 bit-by-bit and places the result in R. 15

Example I1

1

00 0

0

1

1

0

0

1

1

0

0

1

1

0

0

15

I2

0

00 1

0

1

0

1

0

1

0

1

0

1

0

1

0

1

1

0

0

1

1

0

0

1

1

0

0

1

1

0

0

15

R

Flags

310

1

1

00

ER:

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

EQ:

ON when the result is 0.