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

The text of a manual · part 36 of 60

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

Pages 329 to 338 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 329

Section 5-24

Increment/Decrement Instructions

5-23-5 EXCLUSIVE NOR – XNRW(37) Operand Data Areas I1: Input 1

Ladder Symbols

IR, SR, AR, DM, HR, TC, LR, # XNRW(37)

@XNRW(37)

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, XNRW(37) is not executed. When the execution condition is ON, XNRW(37) exclusively NOR’s the contents of I1 and I2 bit-by-bit and places the result in R. 15

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

0

1

1

00 0

1

1

0

0

1

1

0

0

1

1

0

0

1

1

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

ER: EQ:

5-24 Increment/Decrement Instructions 5-24-1 BCD INCREMENT – INC(38) Ladder Symbols

Operand Data Areas

INC(38)

@INC(38)

Wd

Wd

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

Limitations

DM 6144 to DM 6655 cannot be used for Wd.

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).

Precautions

The content of Wd will be incremented every cycle if the undifferentiated form of INC(38) is used. Use the differentiated form (@INC(38)) or combine INC(38) with DIFU(13) or DIFD(14) to increment Wd just once.

Flags

ER:

EQ:

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

311

Page 330

Section 5-24

Increment/Decrement Instructions

5-24-2 BCD DECREMENT – DEC(39) Ladder Symbols

Operand Data Areas

DEC(39)

@DEC(39)

Wd

Wd

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

Limitations

DM 6144 to DM 6655 cannot be used for Wd.

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.

Precautions

The content of Wd will be decremented every cycle if the undifferentiated form of DEC(39) is used. Use the differentiated form (@DEC(39)) or combine DEC(39) with DIFU(13) or DIFD(14) to decrement Wd just once.

Flags

ER:

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

EQ:

312

ON when the decremented result is 0.

Page 331

Section 5-25

Subroutine Instructions

5-25 Subroutine Instructions Subroutines break large control tasks into smaller ones and enable you to reuse a given set of instructions. When the main program calls a subroutine, control is transferred to the subroutine and the subroutine instructions are executed. The instructions within a subroutine are written in the same way as main program code. When all the subroutine instructions have been executed, control returns to the main program to the point just after the point from which the subroutine was entered (unless otherwise specified in the subroutine).

5-25-1 SUBROUTINE ENTER – SBS(91) Ladder Symbol

Definer Data Areas N: Subroutine number

SBS(91) N

000 to 255

Limitations

The CQM1-CPU11/21-E supports only subroutine numbers 000 through 127. The CPM1/CPM1A/SRM1 support only subroutine numbers 000 through 049.

Description

A subroutine can be executed by placing SBS(91) in the main program at the point where the subroutine is desired. The subroutine number used in SBS(91) indicates the desired subroutine. When SBS(91) is executed (i.e., when the execution condition for it is ON), the instructions between the SBN(92) with the same subroutine number and the first RET(93) after it are executed before execution returns to the instruction following the SBS(91) that made the call.

Main program SBS(91)

00

Main program

SBN(92)

00

Subroutine RET(93) END(01)

SBS(91) may be used as many times as desired in the program, i.e., the same subroutine may be called from different places in the program).

313

Page 332

Section 5-25

Subroutine Instructions

SBS(91) may also be placed into a subroutine to shift program execution from one subroutine to another, i.e., subroutines may be nested. When the second subroutine has been completed (i.e., RET(93) has been reached), program execution returns to the original subroutine which is then completed before returning to the main program. Nesting is possible to up to sixteen levels. A subroutine cannot call itself (e.g., SBS(91) 000 cannot be programmed within the subroutine defined with SBN(92) 000). The following diagram illustrates two levels of nesting.

SBS(91) 010

SBN(92) 010

SBN(92) 011

SBS(91) 011

SBS(91) 012

RET(93)

RET(93)

SBN(92) 012

RET(93)

The following diagram illustrates program execution flow for various execution conditions for two SBS(91).

A SBS(91)

000

A

B Main program

SBS(91)

OFF execution conditions for subroutines 000 and 001

B

C

001 ON execution condition for subroutine 000 only

A

C

SBN(92)

000

D

B

C

ON execution condition for subroutine 001 only

A

B

E

C

D

Subroutines

RET(93) SBN(92)

001

ON execution conditions for subroutines 000 and 001

A

D

B

E

C

E

RET(93) END(01)

Flags

ER:

A subroutine does not exist for the specified subroutine number. A subroutine has called itself. An active subroutine has been called.

! Caution

314

SBS(91) will not be executed and the subroutine will not be called when ER is ON.

Page 333

Section 5-26

Special Instructions

5-25-2 SUBROUTINE DEFINE and RETURN – SBN(92)/RET(93) Ladder Symbols

Definer Data Areas N: Subroutine number

SBN(92) N

000 to 255 RET(93)

Limitations

The CQM1-CPU11/21-E support only subroutine numbers 000 through 127. The CPM1/CPM1A/SRM1 PCs support only subroutine numbers 000 through 049. Each subroutine number can be used in SBN(92) once only.

Description

SBN(92) is used to mark the beginning of a subroutine program; RET(93) is used to mark the end. Each subroutine is identified with a subroutine number, N, that is programmed as a definer for SBN(92). This same subroutine number is used in any SBS(91) that calls the subroutine (see 5-25-1 SUBROUTINE ENTER – SBS(91)). No subroutine number is required with RET(93). All subroutines must be programmed at the end of the main program. When one or more subroutines have been programmed, the main program will be executed up to the first SBN(92) before returning to address 00000 for the next cycle. Subroutines will not be executed unless called by SBS(91). END(01) must be placed at the end of the last subroutine program, i.e., after the last RET(93). It is not required at any other point in the program.

Precautions

If SBN(92) is mistakenly placed in the main program, it will inhibit program execution past that point, i.e., program execution will return to the beginning when SBN(92) is encountered. If either DIFU(13) or DIFU(14) is placed within a subroutine, the operand bit will not be turned OFF until the next time the subroutine is executed, i.e., the operand bit may stay ON longer than one cycle.

Flags

There are no flags directly affected by these instructions.

5-26 Special Instructions 5-26-1 TRACE MEMORY SAMPLING – TRSM(45) ! Caution

This instruction is not CPM1/CPM1A/SRM1 PCs.

supported by

CQM1-CPU11-E/21-E, the

Data tracing can be used to facilitate debugging programs. To set up and use data tracing it is necessary to have a host computer running SSS; no data tracing is possible from a Programming Console. Data tracing is described in detail in the SSS Operation Manual: C-series PCs. This section shows the ladder symbol for TRSM(45) and gives an example program. Ladder Symbol TRSM(45)

Description

TRSM(45) is used in the program to mark locations where specified data is to be stored in Trace Memory. Up to 12 bits and up to 3 words may be designated for tracing. (Refer to the SSS Operation Manual: C-series PCs for details.)

315

Page 334

Section 5-26

Special Instructions

TRSM(45) is not controlled by an execution condition, but rather by two bits in the AR area: AR 2515 and AR 2514. AR 2515 is the Sampling Start bit. This bit is turned ON to start the sampling processes for tracing. The Sampling Start bit must not be turned ON from the program, i.e., it must be turned ON only from the peripheral device. AR 2514 is the Trace Start bit. When it is set, the specified data is recorded in Trace Memory. The Trace Start bit can be set either from the program or from the Programming Device. A positive or negative delay can also be set to alter the actual point from which tracing will begin. Data can be recorded in any of three ways. TRSM(45) can be placed at one or more locations in the program to indicate where the specified data is to be traced. If TRSM(45) is not used, the specified data will be traced when END(01) is executed. The third method involves setting a timer interval from the peripheral devices so that the specified data will be tracing at a regular interval independent of the cycle time. (Refer to the SSS Operation Manual: C-series PCs.) TRSM(45) can be incorporated anywhere in a program, any number of times. The data in the trace memory can then be monitored via a Programming Console, host computer, etc. AR Control Bits and Flags

The following control bits and flags are used during data tracing. The Tracing Flag will be ON during tracing operations. The Trace Completed Flag will turn ON when enough data has been traced to fill Trace Memory. Flag

Function

AR 2515

Sampling Start Bit*

AR 2514

Trace Start Bit

AR 2513

Tracing Flag

AR 2512

Trace Completed Flag

Note *Do not change the status of AR 2515 from the program. Precautions

If TRSM(45) occurs TRSM(45) will not be executed within a JMP(08) – JME(09) block when the jump condition is OFF.

Example

The following example shows the basic program and operation for data tracing. Force set the Sampling Start Bit (AR 2515) to begin sampling. The Sampling Start Bit must not be turned ON from the program. The data is read and stored into trace memory. When IR 00000 is ON, the Trace Start Bit (AR 2514) is also turned ON, and the CPU Unit looks at the delay and marks the trace memory accordingly. This can mean that some of the samples already made will be recorded as the trace memory (negative delay), or that more samples will be made before they are recorded (positive delay).

316

Page 335

Section 5-26

Special Instructions

The sampled data is written to trace memory, jumping to the beginning of the memory area once the end has been reached and continuing up to the start marker. This might mean that previously recorded data (i.e., data from this sample that falls before the start marker) is overwritten (this is especially true if the delay is positive). The negative delay cannot be such that the required data was executed before sampling was started.

00000

AR 2514

TRSM(45)

AR 2513 ON when tracing

Instruction

00000 00001 00002 00003

LD OUT TRSM(45) LD

Operands

AR

0000 2514

AR

2513

Address 00004 00005 00006

Designates point for tracing.

00200

Indicates that tracing is in progress.

00201

Indicates that tracing has been completed.

AR 2512 ON when trace is complete

Address

Starts data tracing.

Instruction OUT LD OUT

Operands

AR

00200 2512 00201

5-26-2 MESSAGE DISPLAY – MSG(46) Ladder Symbols

Operand Data Areas

MSG(46)

@MSG(46)

FM

FM

FM: First message word IR, SR, AR, DM, HR, LR

Limitations

DM 6649 to DM 6655 cannot be used for FM.

Description

When executed with an ON execution condition, MSG(46) reads eight words of extended ASCII code from FM to FM+7 and displays the message on the Programming Console. The displayed message can be up to 16 characters long, i.e., each ASCII character code requires eight bits (two digits). Refer to Appendix H for the ASCII codes. Japanese katakana characters are included in this code. If not all eight words are required for the message, it can be stopped at any point by inputting “OD.” When OD is encountered in a message, no more words will be read and the words that normally would be used for the message can be used for other purposes.

Message Buffering and Priority

Up to three messages can be buffered in memory. Once stored in the buffer, they are displayed on a first in, first out basis. Since it is possible that more than three MSG(46)s may be executed within a single cycle, there is a priority scheme, based on the area where the messages are stored, for the selection of those messages to be buffered.

317

Page 336

Section 5-26

Special Instructions

The priority of the data areas is as follows for message display: LR > IR > HR > AR > TC > DM In handling messages from the same area, those with the lowest address values have higher priority. In handling indirectly addressed messages (i.e. DM), those with the lowest final DM addresses have higher priority. Clearing Messages

To clear a message, execute FAL(06) 00 or clear it via a Programming Console or the SSS. If the message data changes while the message is being displayed, the display will also change. Indirectly addressed DM word is non-existent. (Content of DM word is not BCD, or the DM area boundary has been exceeded.)

Flags

ER:

Example

The following example shows the display that would be produced for the instruction and data given when 00000 was ON. If 00001 goes ON, a message will be cleared.

00000

Address

Instruction

00000 00001

LD MSG(46)

00002 00003

LD FAL(06)

Operands

MSG(46) DM 0010 00001

DM

FAL(06) 00

DM contents DM 0010

4

1

4

2

ASCII equivalent A B

DM 0011

4

3

4

4

C

D

DM 0012

4

5

4

6

E

F

DM 0013

4

7

4

8

G

H

DM 0014

4

9

4

A

I

J

DM 0015

4

B

4

C

K

L

DM 0016

4

D

4

E

M

N

DM 0017

4

F

5

0

O

P

00000 0010 00001 00

MSG ABCDEFGHIJKLMNOP

5-26-3 I/O REFRESH – IORF(97) Ladder Symbol

Operand Data Areas St: Starting word

IORF(97) IR 000 to IR 115 St E: End word E

IR 000 to IR 115

Note This instruction is not supported by SRM1 PCs. Limitations

St must be less than or equal to E.

Description

To refresh I/O words, specify the first (St) and last (E) I/O words to be refreshed. When the execution condition for IORF(97) is ON, all words between St and E

318

Page 337

Section 5-26

Special Instructions will be refreshed. This will be in addition to the normal I/O refresh performed during the CPU Unit’s cycle. Note This instruction will have no effect on words that are not being used for I/O. Flags

There are no flags affected by this instruction.

5-26-4 MACRO – MCRO(99) Operand Data Areas N: Subroutine number

Ladder Symbols

000 to 127 MCRO(99)

@MCRO(99)

N

N

I1

I1

O1

O1

I1: First input word IR, SR, AR, DM, HR, TC, LR O1: First output word IR, SR, AR, DM, HR, LR

Limitations

DM 6144 to DM 6655 cannot be used for O1. The CPM1/CPM1A/SRM1 PCs support only subroutine numbers 000 through 049.

Description

The MACRO instruction allows a single subroutine to replace several subroutines that have identical structure but different operands. There are 4 input words, IR 096 to IR 099 (IR 232 to IR 235 in the CPM1/CPM1A/SRM1), and 4 output words, IR 196 to IR 199 (IR 236 to IR 239 in CPM1/CPM1A/SRM1 PCs), allocated to MCRO(99). These 8 words are used in the subroutine and take their contents from I1 to I1+3 and O1 to O1+3 when the subroutine is executed. When the execution condition is OFF, MCRO(99) is not executed. When the execution condition is ON, MCRO(99) copies the contents of I1 to I1+3 to IR 096 to IR 099, copies the contents of O1 to O1+3 to IR 196 to IR 199, and then calls and executes the subroutine specified in N. When the subroutine is completed, the contents of IR 196 through IR 199 is then transferred back to O1 to O1+3 before MCRO(99) is completed. Note Refer to page 128 for more details on MCRO(99).

Example

In this example, the contents of DM 0010 through DM 0013 are copied to IR 096 through IR 099, the contents of DM 0020 through DM 0023 are copied to IR 196 through IR 199, and subroutine 10 is called and executed. When the subroutine

319

Page 338

Section 5-26

Special Instructions is completed, the contents of IR 196 to IR 199 are copied back to DM 0020 to DM 0023. Main program MCRO(99)

10 DM 0010 DM 0020

Main program

SBN(92)

10

Subroutine RET(93) END(01)

Flags

ER:

A subroutine does not exist for the specified subroutine number. An operand has exceeded a data area boundary. Indirectly addressed DM word is non-existent. (Content of DM word is not BCD, or the DM area boundary has been exceeded.) A subroutine has called itself. An active subroutine has been called.

5-26-5 BIT COUNTER – BCNT(67) Operand Data Areas

Ladder Symbols

N: Number of words (BCD) BCNT(67)

@BCNT(67)

N

N

SB

SB

R

R

IR, SR, AR, DM, HR, TC, LR, # SB: Source beginning word IR, SR, AR, DM, HR, TC, LR R: Destination word IR, SR, AR, DM, HR, TC, LR

Note BCNT(67) is an expansion instruction for the SRM1. The function code 67 is the factory setting and can be changed for the SRM1 if desired. Limitations

N cannot be 0. DM 6144 to DM 6655 cannot be used for R.

Description

When the execution condition is OFF, BCNT(67) is not executed. When the execution condition is ON, BCNT(67) counts the total number of bits that are ON in all words between SB and SB+(N–1) and places the result in R.

Flags

ER:

N is not BCD, or N is 0; SB and SB+(N–1) are not in the same area. The resulting count value exceeds 9999.

320