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

The text of a manual · part 11 of 27

SYSMAC C20P/C28P/C40P/C60P P-type Programmable Controllers Operation Manual: SECTION 5, pages 73 to 82

Pages 73 to 82 of 211, from SYSMAC C20P/C28P/C40P/C60P P-type Programmable Controllers Operation Manual

The original document is the PDF (2.2 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 C28P

Page 73

Section 5–11

Timer and Counter Instructions tion for CP and the execution condition was OFF for the last execution. If the execution condition has not changed or has changed from ON to OFF, the PV of CNT will not be changed. Counter is turned ON when the PV reaches zero and will remain ON until the counter is reset. CNT is reset with a reset input, R. When R goes from OFF to ON, the PV is reset to SV. The PV will not be decremented while R is ON. Counting down from SV will begin again when R goes OFF. The PV for CNT will not be reset in interlocked program sections or for power interruptions. Changes in execution conditions, the Completion Flag, and the PV are illustrated below. PV line height is meant to indicate changes in the PV only. Execution condition on count pulse (CP)

ON

Execution condition on reset (R)

ON

OFF

OFF ON

Completion Flag

OFF SV

SV

PV

0002

SV – 1

0001

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:

Example 1: Basic Application

In the following example, the PV will be decremented whenever both 0000 and 0001 are ON provided that 0002 is OFF and either 0000 or 0001 was OFF the last time CNT 04 was executed. When 150 pulses have been counted down (i.e., when PV reaches zero), 0205 will be turned ON.

SV is not in BCD.

0000

0001

CP CNT 04

0002

R

#0150

CNT 04 0205

Here, 0000 can be used to control when CNT is operative and 0001 can be used as the bit whose OFF to ON changes are being counted. The above CNT can be modified to restart from SV each time power is turned ON to the PC. This is done by using the First Scan Flag in the SR area (1815) to reset CNT as shown below. 0000

0001

CP CNT 04

0002

R

#0150

1815

CNT 04 0205

65

Page 74

Section 5–11

Timer and Counter Instructions Example 2: Extended Counter

Counters that can count past 9,999 can be programmed by using one CNT to count the number of times another CNT has reached zero from SV. In the following example, 0000 is used to control when CNT 01 operates and CNT 01, when 0000 is ON, counts down the number of OFF to ON changes in 0001. CNT 01 is reset by its Completion Flag, i.e., it starts counting again as soon as its PV reaches zero. CNT 02 counts the number of times the Completion Flag for CNT 01 goes ON. Bit 0002 serves as a reset for the entire extended counter, resetting both CNT 01 and CNT 02 when it is OFF. The Completion Flag for CNT 02 is also used to reset CNT 01 to inhibit CNT 01 operation once PV for CNT 02 has been reached until the entire extended counter is reset via 0002. Because in this example the SV for CNT 01 is 100 and the SV for CNT 02 is 200, the Completion Flag for CNT 02 turns ON when 100 x 200 or 20,000 OFF to ON changes have been counted in 0001. This would result in 0203 being turned ON.

0000

0001

CP CNT 01

0002

R

#0100

CNT 01

CNT 02

CNT 01

CP CNT 02

0002

R

#0200

CNT 02 0203

CNT can be used in sequence as many times as required to produce counters capable of counting down even higher values. Example 3: Extended Timers

CNT can be used to create extended timers in two ways: by combining TIM with CNT and by counting SR area clock pulse bits. In the following example, CNT 02 counts the number of times TIM 01 reaches zero from its SV. The Completion Flag for TIM 01 is used to reset TIM 01 so that is runs continuously and CNT 02 counts the number of times the Completion Flag for TIM 01 goes ON (CNT 02 would be executed once each time between when the Completion Flag for TIM 01 goes ON and TIM 01 is reset by its Completion Flag). TIM 01 is also reset by the Completion Flag for CNT 02 so that the extended timer would not start again until CNT 02 was reset by 0001, which serves as the reset for the entire extended timer. As the SV for TIM 01 is 5.0 seconds and the SV for CNT 02 is 100, the Completion Flag for CNT 02 turns ON when 5 seconds x 100 times, or 8 minutes and 20 seconds have expired. This would result in 0201 being turned ON.

66

Page 75

Section 5–11

Timer and Counter Instructions 0000 TIM 01

CNT 02

TIM 0100

TIM 01

5.0 s

CP CNT 02

0001

#0100 R

CNT 00 0200

In the following example, CNT 01 counts the number of times the 1-second clock pulse bit (1902) goes from OFF to ON. Here again, 0000 is used to control when CNT is operating. As the SV for CNT 01 is 700, the Completion Flag for CNT 02 turns ON when 1 second x 700 times, or 10 minutes and 40 seconds have expired. This would result in 0202 being turned ON. 0000

1902

CP CNT 01

0001

R

#0700

CNT 01 0202

Note The shorter clock pulses may not produce accurate timers because their short ON times may not be read accurately for longer scan times. In particular the 0.02-second and 0.1-second clock pulses should not be used to create timers with CNT.

5–11–5 Reversible Counter – CNTR(12) Definer Values N: TC number

Ladder Symbol

# (00 through 47) II DI R

CNTR(12) N

Operand Data Areas

SV

SV: Set value (word, BCD) IR, HR, #

Limitations

Each TC number can be used as the definer in only one timer or counter instruction.

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 execution condition

67

Page 76

Section 5–11

Timer and Counter Instructions was OFF for II for the last execution. The present value (PV) will be decremented by one whenever CNTR(12) is executed with an ON execution condition for DI and the execution condition was OFF for DI for the last execution. 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 has 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. 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 for 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.

5–11–6 High-speed Counter – HDM(98) Definer Values N: TC number

Ladder Symbol

Must be 47 HDM(98) N R

Operand Data Areas R: Result word IR, HR, DM

Limitations

68

If any of the lower limits for the DM ranges are set to “0000”, the corresponding output bits are turned ON when the high-speed counter is reset.

Page 77

Section 5–11

Timer and Counter Instructions

If the time it takes to count through some range is less than the scan time of the CPU, the high-speed counter may count past between scans and thus the output bit for this range may not be turned ON.

Counting Time Lower Limit

Upper Limit

The count signal must be at least 250 µs (2 kHz) wide and have a duty factor of 1:1, as shown below.

Input 0000 250 µs 250 µs

In the hard reset mode, the reset signal must have an ON time of at least 250 µs. Input 0001 250 µs max.

Description General

The high-speed counter counts the signals input from an external device connected to input 0000 and, when the high-speed counter instruction is executed, compares the current value with a set of ranges which have been preset in DM words 32 through 63. If the current value is within any of the preset ranges, the corresponding bit of a specified result word is turned ON. The bit in the result word remains ON until the current value is no longer within the specified range. An internal buffer is incremented whenever bit 0000 goes from OFF to ON. When the high-speed counter instruction is executed, the value in the counter buffer is transferred to counter 47 which serves as the count value storage area. When using the high-speed counter, the following bits are reserved and cannot be used for any other purpose: •

Input 0000 (count input)

•

Input 0001 (hard reset)

•

IR bit 1807 (soft reset)

•

TC 47 (present count value)

•

DM 32 to 63 (upper and lower limits)

Note If a power failure occurs, the count value of the high speed counter immediately before the power failure is retained. The high-speed counter is programmed differently depending on how it is to be reset. Two resetting modes are possible: hard-reset and soft-reset. The hard reset is made effective or ineffective with the DIP switch in the CPU.

69

Page 78

Section 5–11

Timer and Counter Instructions Hard Reset

To use the hard reset, turn pins 7 and 8 ON. In this mode, input 0001 is the reset input. When it is turned ON, the present value in the high-speed counter buffer is reset to “0000”. When the reset is ON, the count signal from input 0000 is not accepted. When programmed with the hard reset, the high-speed counter would appear as below. 0002 HDM(98) 10

Soft Reset

IR 1807 is the soft reset. When it is turned ON, the present value in the high-speed counter buffer is reset to “0000”. As for the hard reset, when the soft reset is ON, the count signal from input 0000 is not accepted. When programmed with the soft reset, the high-speed counter would appear as below. Note that when the soft reset is used, the timing at which the counter buffer is reset may be delayed due to the scan time of the CPU.

0003 1807

0002 HDM(98) 10

If required, both the hard reset and the soft reset can be used together.

70

Page 79

Section 5–11

Timer and Counter Instructions Upper and Lower Limit Setting

The following table shows the upper and lower limits that need to be set in DM 32 through DM 63. In this table, “S” denotes the present value of counter 47 and R is the results word.

Lower limit

Upper limit

Present value of the counter

Bit of R that turns ON

DM 32

DM 33

Value of DM 32 ≤ S ≤ value of DM 33

00

DM 34

DM 35

Value of DM 34 ≤ S ≤ value of DM 35

01

DM 36

DM 37

Value of DM 36 ≤ S ≤ value of DM 37

02

DM 38

DM 39

Value of DM 38 ≤ S ≤ value of DM 39

03

DM 40

DM 41

Value of DM 40 ≤ S ≤ value of DM 41

04

DM 42

DM 43

Value of DM 42 ≤ S ≤ value of DM 43

05

DM 44

DM 45

Value of DM 44 ≤ S ≤ value of DM 45

06

DM 46

DM 47

Value of DM 46 ≤ S ≤ value of DM 47

07

DM 48

DM 49

Value of DM 48 ≤ S ≤ value of DM 49

08

DM 50

DM 51

Value of DM 50 ≤ S ≤ value of DM 51

09

DM 52

DM 53

Value of DM 52 ≤ S ≤ value of DM 53

10

DM 54

DM 55

Value of DM 54 ≤ S ≤ value of DM 55

11

DM 56

DM 57

Value of DM 56 ≤ S ≤ value of DM 57

12

DM 58

DM 59

Value of DM 58 ≤ S ≤ value of DM 59

13

DM 60

DM 61

Value of DM 60 ≤ S ≤ value of DM 61

14

DM 62

DM 63

Value of DM 62 ≤ S ≤ value of DM 63

15

The values must be four-digit BCD in the range 0000 to 9999. Note that failure to enter BCD values will not activate the ERR Flag. Always set a lower limit which is less than the corresponding upper limit. MOV is useful in setting limits. The following ladder diagram shows the use of MOV for setting limits and the associated timing diagram shows the state of the relevant bits of the result word (IR 05) as the counter is incremented.

71

Page 80

Section 5–11

Timer and Counter Instructions 1813 (normally ON)

MOV(21) #0200 DM 32

MOV(21) #1500 DM 33

MOV(21)

Transfers preset value to DM 32 to 35

#0600 DM 34

MOV(21) #2000 DM 35

0002 (start input) HDM(98) 05

Corresponding result word is 05

Start input 0002

Count input 0000 200

1500

Output 0500 600

2000

Output 0501

Response Speed

The maximum response speed of the high-speed counter hardware is 2 kHz. Note however that the start signal, reset signal (in the case of soft reset), and corresponding outputs are all processed by software. Because of this, response may be delayed by the scan time.

Precautions

When programming the high-speed counter with the GPC, “00” is displayed on each of the three lines below the instruction code (HDM(60)). Do not alter the second and third lines; if they are not “00”, an error occurs when an attempt is made to transfer the program from the GPC to the PC. Do not program the high-speed counter between JMP and JME. The high-speed counter can be programmed between IL and ILC. However, the hard reset signal remains active, causing the corresponding output(s) to turn ON or OFF, even when the IL condition is OFF.

Examples Extending the Counter

72

The high-speed counter normally provides 16 output bits. If more than 16 are required, the high-speed counter may be programmed more than once. In the following program example, the high-speed counter is used twice to provide 32 output bits.

Page 81

Section 5–11

Timer and Counter Instructions 1813 (normally ON)

MOV(21) “S1” DM 32

Transfers limit values S1 to S32 to DM. Output thru HR 0

MOV(21) “S2” DM 33

MOV(21) “S32” DM 35

0002 HDM(98) HR 0

A

1813 (normally ON) MOV(21) “S33” DM 32

Transfers limit values S33 to S64 to DM. Output thru HR 1

MOV(21) “S34” DM 33

MOV(21) “S64” DM 35

0002 HDM(98) HR 1

B

In this program, each bit in the specified words, HR 0 and HR 1 are turned ON under the following conditions (where S is the present count value of the high-speed counter stored as the data of CNT 47): Where S1 ≤ S ≤ S2, HR 000 is ON. Where S3 ≤ S ≤ S4, HR 001 is ON. Where S31 ≤ S ≤ S32, HR 015 is ON. Where S33 ≤ S ≤ S34, HR 100 is ON. Where S63 ≤ S ≤ S64, HR 115 is ON. Note that in the program just mentioned, the present value in the counter buffer is transferred to counter number 47 at points A and B. In this case, if S31 (=1,000) < S < S32 (=2,000) and S33 (=2,000) < S < S34 (=3,000), and if the present count value of the first high-speed counter (at point A) is 1,999 and that of the second counter (at point B) is 2,003, HR 015 and HR100 may be simultaneously turned ON. If it is necessary to avoid this, set the values of

73

Page 82

Section 5–11

Timer and Counter Instructions

S32 and S33 so that there is a value difference equivalent to the time lag from points A to B. For example, set the value of S32 to 2,000 and that of S33 to 2,010. More than 16 output bits may be obtained using CMP. 1813 (normally ON) CMP(20) CNT 47 #6850

1905 (GR) 0600

In the above program, output 0600 is turned ON when the following condition is satisfied, where S is the present count value of the high-speed counter: 6,850 < S ≤ 9,999. 1813 (normally ON) CMP(20) CNT 47 #0300

1905 (GR) 1000

1813 (normally ON) CMP(20) CNT 47 #2300

1907 (LE) 1001

1000

1001 0601

In the above program, output 0601 is turned ON when the following condition is satisfied, where S is the present count value of the high-speed counter: 300 < S < 2,300. Cascade Connection (Counting Past 9,999)

The number of digits of the upper and lower limits of the high-speed counter can be increased from four to eight by using the high-speed counter together with CNTR and CMP. The high-speed counter is a ring counter and thus when its present count value is incremented from 9999 to 0000, the Completion Flag of CNT 47 is turned ON for one scan. By using this flag as an input to the UP input of the reversible counter (i.e., cascade connection) you can increase the number of digits to eight. Although an ordinary counter can be cascade-connected to

74