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

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

Pages 229 to 238 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 229

Section 5-15

Timer and Counter Instructions Example

In the following example, CNT is used to create extended timers by counting SR area clock pulse bits. CNT 001 counts the number of times the 1-second clock pulse bit (SR 25502) goes from OFF to ON. Here again, IR 00000 is used to control the times when CNT is operating. Because in this example the SV for CNT 001 is 700, the Completion Flag for CNT 002 turns ON when 1 second x 700 times, or 11 minutes and 40 seconds have expired. This would result in IR 01602 being turned ON.

00000 25502

CP CNT 001

00001

R

#0700

CNT 001

Address

Instruction

00000 00001 00002 00003

LD AND LD NOT CNT

00004 00005

LD OUT

01602

! Caution

Operands

# CNT

00000 25502 00001 001 0700 001 01602

The shorter clock pulses will not necessarily produce accurate timers because their short ON times might not be read accurately during longer cycles. In particular, the 0.02-second and 0.1-second clock pulses should not be used to create timers with CNT instructions.

5-15-3 REVERSIBLE COUNTER – CNTR(12) Definer Values N: TC number

Ladder Symbol

# II DI R

CNTR(12) N

Operand Data Areas

SV

SV: Set value (word, BCD) IR, SR, AR, DM, HR, LR, #

Limitations

Each TC number can be used as the definer in only one TIMER or COUNTER instruction. TC numbers run from 000 through 511 in the CQM1 PCs and from 000 through 127 in the CPM1/CPM1A/SRM1 PCs.

Description

The CNTR(12) is a reversible, up/down circular counter, i.e., it is used to count between zero and SV according to changes in two execution conditions, those in the increment input (II) and those in the decrement input (DI). The present value (PV) will be incremented by one whenever CNTR(12) is executed with an ON execution condition for II and the last execution condition for II was OFF. The present value (PV) will be decremented by one whenever CNTR(12) is executed with an ON execution condition for DI and the last execution condition for DI was OFF. If OFF to ON changes have occurred in both II and DI since the last execution, the PV will not be changed. If the execution conditions have not changed or have changed from ON to OFF for both II and DI, the PV of CNT will not be changed. When decremented from 0000, the present value is set to SV and the Completion Flag is turned ON until the PV is decremented again. When incremented past the SV, the PV is set to 0000 and the Completion Flag is turned ON until the PV is incremented again.

211

Page 230

Section 5-15

Timer and Counter Instructions

CNTR(12) is reset with a reset input, R. When R goes from OFF to ON, the PV is reset to zero. The PV will not be incremented or decremented while R is ON. Counting will begin again when R goes OFF. The PV for CNTR(12) will not be reset in interlocked program sections or by the effects of power interruptions. Changes in II and DI execution conditions, the Completion Flag, and the PV are illustrated below starting from part way through CNTR(12) operation (i.e., when reset, counting begins from zero). PV line height is meant to indicate changes in the PV only. Execution condition on increment (II)

ON

Execution condition on decrement (DI)

ON

OFF

OFF ON

Completion Flag

OFF

SV

PV

SV

SV – 1

SV – 1 0001

SV – 2 0000

SV – 2 0000

Precautions

Program execution will continue even if a non-BCD SV is used, but the SV will not be correct.

Flags

ER:

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

5-15-4 HIGH-SPEED TIMER – TIMH(15) Definer Values N: TC number

Ladder Symbol

# TIMH(15) N SV

Operand Data Areas SV: Set value (word, BCD) IR, SR, AR, DM, HR, LR, #

Limitations

SV is between 00.00 and 99.99. (Although 00.00 and 00.01 may be set, 00.00 will disable the timer, i.e., turn ON the Completion Flag immediately, and 00.01 is not reliably scanned.) The decimal point is not entered. Each TC number can be used as the definer in only one TIMER or COUNTER instruction. Use TC numbers from 000 through 015 in the CQM1 PCs and from 000 through 003 in the CPM1/CPM1A/SRM1 PCs. High-speed timers with timer numbers TC 016 through TC 511 (TC 004 through TC 127 in the CPM1/CPM1A/SRM1) should not be used if the cycle time exceeds 10 ms.

Description

TIMH(15) operates in the same way as TIM except that TIMH measures in units of 0.01 second. Refer to 5-15-1 TIMER – TIM for operational details.

Precautions

Timers in interlocked program sections are reset when the execution condition for IL(02) is OFF. Power interruptions also reset timers. If a timer that is not reset

212

Page 231

Section 5-15

Timer and Counter Instructions under these conditions is desired, SR area clock pulse bits can be counted to produce timers using CNT. Refer to 5-15-2 COUNTER – CNT for details. Timers in jumped program sections will not be reset when the execution condition for JMP(04) is OFF, but the timer will stop timing if jump number 00 is used. The timers will continue timing if jump numbers 01 through 99 (01 through 49 in CPM1/CPM1A/SRM1 PCs) are used. CQM1 Precautions High-speed timers with timer numbers TC 000 through TC 015 will not be inaccurate when the PC Setup (DM 6629) is set to perform interrupt processing on these timers. High-speed timers with timer numbers TC 016 through TC 511 will be inaccurate when the cycle time exceeds 10 ms. If the cycle time is greater than 10 ms, use TC 000 through TC 015 and set DM 6629 for interrupt processing of the timer numbers used.

Flags

ER:

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

Example

The following example shows a timer set with a constant. 01600 will be turned ON after 00000 goes ON and stays ON for at least 1.5 seconds. When 00000 goes OFF, the timer will be reset and 01600 will be turned OFF.

00000 TIMH(15) 000 #0150

01.50 s

Address

Instruction

00000 00001

LD TIMH(15)

00002 00003

LD OUT

TIM 000 01600

Operands

# TIM

00000 000 0150 000 01600

5-15-5 INTERVAL TIMER – STIM(69) Ladder Symbols

Operand Data Areas C1: Control data #1

STIM(69)

@STIM(69)

C1

C1

C2

C2

C3

C3

000 to 008, 010 to 012 C2: Control data #2 IR, SR, AR, DM, HR, TC, LR, # C3: Control data #3 IR, SR, AR, DM, HR, TC, LR, #

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

C1 must be 000 to 008 or 010 to 012. If C1 is 000 to 005, a constant greater than 0255 cannot be used for C3. If C1 is 006 to 008, constants and DM 6143 to DM 6655 cannot be used for C2 or C3. If C1 is 010 to 012, both C2 and C3 must be set to 000.

Limitations (CPM1/CPM1A/SRM1)

C1 must be 000, 003, 006. or 010. If C1 is 000 or 003, a constant greater than 0049 cannot be used for C3. If C1 is 006, constants and DM 6143 to DM 6655 cannot be used for C2 or C3. If C1 is 010, both C2 and C3 must be set to 000.

213

Page 232

Section 5-15

Timer and Counter Instructions Description

STIM(69) is used to control the interval timers by performing four basic functions: starting the timer for a non-shot interrupt, starting the timer for scheduled interrupts, stopping the timer, and reading the timer’s PV. Set the value of C1 to specify which of these functions will be performed and which of the three interval timers it will be performed on, as shown in the following table. Refer to 1-5-4, 1-6-4, and 1-7-2 for more detailed descriptions of using interval timer interrupts. STIM(69) is also described in more detail after the table.

Note

Starting Interrupts

Function Starting timers

Timer

C1 value

0

000

Starting scheduled interrupts

1 2 0

001 002 003

Reading timer PV

1 2 0

004 005 006

Stopping timers

1 2 0

007 008 010

1 2

011 012

Applicable PCs CQM1/CPM1/ CPM1A/SRM1 CQM1 only CQM1/CPM1/ CPM1A/SRM1 CQM1 only CQM1/CPM1/ CPM1A/SRM1 CQM1 only CQM1/CPM1/ CPM1A/SRM1 CQM1 only

1. In CQM1 PCs, interval timer 0 cannot be used when a pulse output is being output by the SPED(64) instruction. 2. In CQM1 PCs, interval timer 2 cannot be used when high-speed counter 0 operation has been enabled in DM 6642 of the PC Setup. Set C1=000 to 002 to start timers 0 to 2 to activate a one-shot interrupt. Set C1=003 to 005 to start scheduled interrupts using timers 0 to 2. C2, which specifies the timer’s SV, can be a constant or the first of two words containing the SV. The settings are slightly different depending on the method used. If C2 is a constant, it specifies the initial value of the decrementing counter (BCD, 0000 to 9999). The decrementing time interval is 1 ms. If C2 is a word address, C2 specifies the initial value of the decrementing counter (BCD, 0000 to 9999), and C2+1 specifies the decrementing time interval (BCD, 0005 to 0320) in units of 0.1 ms. The decrementing time interval can thus be 0.5 to 32 ms. C3 specifies subroutine number 0000 to 0255 (0000 to 0127 in the CQM1-CPU11/21-E, 0000 to 0049 in the CPM1/CPM1A/SRM1 PCs).

Note The time required from interval timer start-up to time-up is: (the content of C2) × (the content of C2+1) × 0.1 ms Reading Timer PVs

Set C1=006 to 008 to read the PVs of timers 0 to 2. C2 specifies the first of two destination words that will receive the timer’s PV. C2 will receive the number of times the decrementing counter has been decremented (BCD, 0000 to 9999) and C2+1 will receive the decrementing time interval (BCD in 0.1 ms units). C3 specifies the destination word that will receive the time which has elapsed since the last time the timer was decremented (BCD in 0.1 ms units). (Must be equal to or less than the decrementing time interval set in C2+1.) Note The time that has elapsed since the timer was started is computed as follows: (Content of C2 × (Content of C2 + 1) + Content of C3) × 0.1 ms

214

Page 233

Section 5-15

Timer and Counter Instructions Stopping Timers

Set C1=010 to 012 to stop timers 0 to 2. C2 and C3 have no function and should both be set to 000.

Flags

ER:

Interval timer 0 is started while a pulse output is operating. (C1=000 only) Interval timer 2 is started while the high-speed counter 0 is enabled (C1=002 only) Indirectly addressed DM word is non-existent. (Content of *DM word is not BCD, or the DM area boundary has been exceeded.) A data area boundary has been exceeded.

5-15-6 REGISTER COMPARISON TABLE – CTBL(63) Ladder Symbols

Operand Data Areas P: Port specifier

CTBL(63)

@CTBL(63)

P

P

C

C

TB

TB

000, 001, or 002 C: Control data 000 to 003 TB: First comparison table word IR, SR, AR, DM, HR, LR

This instruction is not available for SRM1 PCs. Limitations

The first and last comparison table words must be in the same data area. (The length of the comparison table varies according to the settings.) In the CQM1-CPU43-EV1, CTBL(63) cannot be used if the PC Setup (DM 6611) is set to pulse output mode. In the CPM1/CPM1A PCs, P must be 000.

Description

When the execution condition is OFF, CTBL(63) is not executed. When the execution condition is ON, CTBL(63) registers a comparison table for use with the high-speed counter PV. Depending on the value of C, comparison with the high-speed counter PV can begin immediately or it can be started separately with INI(61). The port specifier (P) specifies the high-speed counter that will be used in the comparison. P

Function

Applicable PCs

000

Specifies high-speed counter 0.

001 002

Specifies high-speed counter 1. Specifies high-speed counter 2.

CQM1/CPM1/CPM1A CQM1 only

The function of CTBL(63) is determined by the control data, C, as shown in the following table. These functions are described after the table. C

CTBL(63) function

000

Registers a target value comparison table and starts comparison.

001

Registers a range comparison table and starts comparison.

002

Registers a target value comparison table. Start comparison with INI(61).

003

Registers a range comparison table. Start comparison with INI(61).

When the PV agrees with a target value or falls within a specified range, the specified subroutine is called and executed. Refer to 1-5-5 High-speed Counter 0 Interrupts (CQM1 PCs) or 1-6-5 High-speed Counter Interrupts (CPM1/CPM1A PCs) for more details on table comparison.

215

Page 234

Section 5-15

Timer and Counter Instructions

If the high-speed counter is enabled in the PC Setup (DM 6642), it will begin counting from zero when the CQM1 begins operation. The PV will not be compared to the comparison table until the table is registered and comparison is initiated with INI(61) or CTBL(63). Comparison can be stopped and started, or the PV can be reset with INI(61). Once a comparison table has been registered, it is valid until the CQM1 is halted or until a error occurs in attempting to register a new table. The differentiated form of CTBL(63) is recommended when possible to reduce cycle time. Target Value Comparison

A target value comparison table contains up to sixteen target values. For the CPU Units, up to 48 target values can be registered. A subroutine number is also registered for each target value. The corresponding subroutine is called and executed when the PV matches a target value. (When interrupt processing is not required, an undefined subroutine number may be entered.) Target value comparisons are performed one item at a time in order of the comparison table. When the PV reaches the first target value in the table, the interrupt subroutine is executed and comparison continues to the next value in the table. When processing has been completed for the last target value in the table, comparison returns to the first value in the table and the process is repeated. The following diagram shows the structure of a target value comparison table for use with high-speed counter 0, or high-speed counters 1 or 2 in linear mode. TB TB+1 TB+2 TB+3

Number of target values (BCD) Target value #1, lower 4 digits (BCD) Target value #1, upper 4 digits (BCD) Subroutine number (See note.)

One target value setting

The following diagram shows the structure of a target value comparison table for use with high-speed counters 1 or 2 in ring mode. Input the target values in ascending or descending order. The ring value specifies the number of points in the ring and the maximum count value (ring value = max. count value+1). Do not change the ring value while a comparison is in progress. TB TB+1 TB+2 TB+3 TB+4 TB+5

Ring value, lower 4 digits (BCD) Ring value, upper 4 digits (BCD) Number of target values (BCD) Target value #1, lower 4 digits (BCD) Target value #1, upper 4 digits (BCD) Subroutine number (See note.)

Ring value setting

One target value setting

The following diagram shows the structure of a target value comparison table for use with absolute high-speed counters 1 and 2 (CQM1-CPU44-E/-EV1 only). Input the target values in ascending or descending order. TB TB+1 TB+2

Note

216

Number of target values (BCD) Target value #1 (BCD) Subroutine number (See note.)

One target value setting

1. The subroutine number can be 0000 to 0049 for CPM1/CPM1A PCs. In CQM1 PCs, the subroutine number can be F000 to F255 (F000 to F127

Page 235

Section 5-15

Timer and Counter Instructions for the CQM1-CPU11/21-E) to activate the subroutine when decrementing and can be 0000 to 0255 (0000 to 0127 for the CQM1-CPU11/21-E) to activate the subroutine when incrementing. 2. Allow an interval of at least 0.2 ms for interrupt processing when setting the target value for high-speed counters 1 and 2. Target Value Comparison Operation The following diagram illustrates the operation of target value comparisons for target values 1 through 5 set consecutively in the comparison table.

Count

Interrupts

Initial value Target 1

Target 2

Target 3

Target 4

Target 5

As illustrated above, the current count is compared with each target value in the order that they are registered in the target value comparison table. When the count is the same as the current target value, an interrupt is generated, and comparison starts with the next target value. When all target values in the comparison table have been matched and interrupts for them generated, the target value is reset to the first target value in the table and the operation is repeated. Range Comparison

A range comparison table contains 8 ranges which are defined by an 8-digit lower limit and an 8-digit upper limit, as well as their corresponding subroutine numbers. The corresponding subroutine is called and executed when the PV falls within a given range. (When interrupt processing is not required, an undefined subroutine number may be entered.) Always set 8 ranges. If fewer than 8 ranges are needed, set the remaining subroutine numbers to FFFF. If more than 8 ranges are needed, another comparison instruction such as BCMP(68) can be used to compare ranges with the highspeed counter PVs in IR 230 through IR 235 (SR 248 and SR 249 in CPM1/CPM1A PCs). Bear in mind that these words are refreshed just once each cycle. There are flags in the AR area which indicate when a high-speed counter’s PV falls within one or more of the 8 ranges. The flags turn ON when a PV is within the corresponding range. Counter

AR area flags

High-speed counter 0

AR 1100 to AR 1107 correspond to ranges 1 to 8.

High-speed counter 1

AR 0500 to AR 0507 correspond to ranges 1 to 8.

High-speed counter 2

AR 0600 to AR 0607 correspond to ranges 1 to 8.

Note CPM1/CPM1A PCs are equipped with high-speed counter 0 only.

217

Page 236

Section 5-15

Timer and Counter Instructions

The following diagram shows the structure of a range comparison table for use with high-speed counter 0, or high-speed counters 1 or 2 in linear mode. TB TB+1 TB+2 TB+3 TB+4

Lower limit #1, lower 4 digits (BCD) Lower limit #1, upper 4 digits (BCD) Upper limit #1, lower 4 digits (BCD) Upper limit #1, upper 4 digits (BCD) Subroutine number (See note 1.)

First range setting

TB+35 TB+36 TB+37 TB+38 TB+39

Lower limit #8, lower 4 digits (BCD) Lower limit #8, upper 4 digits (BCD) Upper limit #8, lower 4 digits (BCD) Upper limit #8, upper 4 digits (BCD) Subroutine number (See note 1.)

Eighth range setting

The following diagram shows the structure of a range comparison table for use with high-speed counters 1 or 2 in ring mode (CQM1 only). The ring value specifies the number of points in the ring and the maximum count value (ring value = max. count value+1). Do not change the ring value while a comparison is in progress. TB TB+1 TB+3 TB+4 TB+5 TB+6 TB+7

Ring value, lower 4 digits (BCD) Ring value, upper 4 digits (BCD) Lower limit #1, lower 4 digits (BCD) Lower limit #1, upper 4 digits (BCD) Upper limit #1, lower 4 digits (BCD) Upper limit #1, upper 4 digits (BCD) Subroutine number (See note 1.)

TB+37 TB+38 TB+39 TB+40 TB+41

Lower limit #8, lower 4 digits (BCD) Lower limit #8, upper 4 digits (BCD) Upper limit #8, lower 4 digits (BCD) Upper limit #8, upper 4 digits (BCD) Subroutine number (See note 1.)

Ring value setting

First range setting

Eighth range setting

The following diagram shows the structure of a range comparison table for use with absolute high-speed counters 1 and 2 (CQM1-CPU44-E/-EV1 only).

Note

218

TB TB+2 TB+4

Lower limit #1(BCD) Upper limit #1 (BCD) Subroutine number (See note 2.)

First range setting

TB+21 TB+22 TB+23

Lower limit #8 (BCD) Upper limit #8 (BCD) Subroutine number (See note 2.)

Eighth range setting

1. The subroutine number can be 0000 to 0255 (0000 to 0127 for the CQM1-CPU11/21-E, 0000 to 0049 for the CPM1/CPM1A) and the subroutine will be executed as long as the counter’s PV is within the specified range. A value of FFFF indicates that no subroutine is to be executed. 2. The subroutine number can be 0000 to 0255 (0000 to 0127 for the CQM1-CPU11/21-E, 0000 to 0049 for the CPM1/CPM1A) to activate the subroutine when incrementing. 3. Allow a time interval of at least 2 ms between the lower and upper limits (upper limit – lower limit > 0.002 × input pulse frequency) in range comparisons with high-speed counters 1 and 2.

Page 237

Section 5-15

Timer and Counter Instructions

The following table shows the possible values for target values, lower limit values, and upper limit values. The hexadecimal value F in the most significant digit of indicates that the value is negative. Counter

Possible values

High-speed counter 0 High-speed counters 1 and 2 Absolute high-speed counters 1 and 2

Up/Down mode: F003 2767 to 0003 2767 Incrementing mode: 0000 0000 to 0006 5535 Linear mode: F838 8607 to 0838 8607 Ring mode: 0000 0000 to 0006 4999 BCD mode: 0000 to 4095 360° mode: 0000 to 0355 (5° units)

In 360° mode the absolute high-speed counter’s angular values are internally converted to binary values. The binary value after conversion depends on the resolution selected in the PC Setup (DM 6643 and/or DM 6644). The following table shows the converted values for 5° to 45°. Resolution

Converted value

8-bit (0 to 255)

5° 4

10° 7

15° 11

20° 14

25° 18

30° 21

35° 25

40° 28

45° 32

10-bit (0 to 1023)

14

28

43

57

71

85

100

114

128

12-bit (0 to 4095)

57

114

171

228

284

341

398

455

512

For higher values, find the converted value to the nearest 45° and add the remainder from the table. For example, to convert 145° into 8-bit resolution: 32×3 (for 135°) + 7 (for 10°) = 103. ! Caution

With 10-bit and 12-bit resolution, interrupt processing might not be triggered when the angular value matches the comparison value because the converted values do not match exactly. Range Comparison Operation The following diagram illustrates the operation of range comparisons for range settings 1 through 4 set consecutively in the comparison table. 0 Count Range 3

Range 1 Range 2

Range 4

As illustrated above, the current count is compared against all the comparison ranges at the same time and the result for each range is output. Flags

ER:

There is an error in the high-speed counter’s settings. The specified port and function are not compatible. There is a CTBL(63) instruction in the subroutine called by another CTBL(63) instruction. A CTBL(63) instruction using a different comparison format is executed during comparison. Indirectly addressed DM word is non-existent. (Content of *DM word is not BCD, or the DM area boundary has been exceeded.) The comparison table exceeds the data area boundary, or there is an error in the comparison table settings. CTBL(63) is executed in an interrupt subroutine while a pulse I/O or high-speed counter instruction is being executed in the main program.

219

Page 238

Section 5-15

Timer and Counter Instructions

AR 05: Flags AR 0500 to AR 0507 are turned ON to indicate when the PV of high-speed counter 1 is in ranges 1 to 8. AR 06: Flags AR 0600 to AR 0607 are turned ON to indicate when the PV of high-speed counter 2 is in ranges 1 to 8. AR 11: Flags AR 1100 to AR 1107 are turned ON to indicate when the PV of high-speed counter 0 is in ranges 1 to 8. Subroutines are executed only once when the execution conditions are first met. AR status is refreshed only once per cycle. If conditions are met for more than one item in the table at the same time, the first item in the table takes priority.

5-15-7 MODE CONTROL – INI(61) Ladder Symbols

Operand Data Areas P: Port specifier

INI(61)

@INI(61)

P

P

C

C

P1

P1

000, 001, or 002 C: Control data 000 to 003 P1: First PV word IR, SR, AR, DM, HR, LR

This instruction is not available for SRM1 PCs. Limitations

In the CPM1/CPM1A PCs, P must be 000 and C must be 000 to 003. In CQM1 PCs, P must be 000, 001, or 002 and C must be 000 to 003. P1 must be 000 unless C is 002. P1 and P1+1 must be in the same data area. DM 6143 to DM 6655 cannot be used for P1.

Description

When the execution condition is OFF, INI(61) is not executed. When the execution condition is ON, INI(61) is used to control high-speed counter operation and stop pulse output. The port specifier (P) specifies the high-speed counter or pulse output that will be controlled. P

Function

000

Specifies high-speed counter 0 or a pulse output from a bit.

001

Specifies high-speed counter 1 or a pulse output from port 1.

002

Specifies high-speed counter 2 or a pulse output from port 2.

Note CPM1/CPM1A PCs are equipped with high-speed counter 0 only. The function of INI(61) is determined by the control data, C. (P1 and P1+1 contain the new high-speed counter PV when changing the PV.) C

CTBL(63) Table Comparison

220

P1

INI(61) function

000

000

Starts CTBL(63) table comparison.

001

000

Stops CTBL(63) table comparison.

002

New high-speed counter PV

Changes high-speed counter PV.

003

000

Stops pulse output.

If C is 000 or 001, INI(61) starts or stops comparison of the high-speed counter’s PV to the comparison table registered with CTBL(63). Refer to 1-5-5 High-speed Counter 0 Interrupts (CQM1 PCs) or 1-6-5 High-speed Counter Interrupts (CPM1/CPM1A PCs) for details on table comparison.