The text of a manual · part 9 of 60
SYSMAC CQM1/CPM1/CPM1A/SRM1 Programmable Controllers Programming Manual: SECTION 1 PC Setup and Other Features, pages 71 to 80
Pages 71 to 80 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 71
Section
CQM1 Interrupt Functions
1-5
If C is set to 000, then comparisons will be made by the target matching method; if 001, then they will be made by the range comparison method. The comparison table will be saved, and, when the save operation is complete, then comparisons will begin. While comparisons are being executed, high-speed interrupts will be executed according to the comparison table. For details on the contents of the comparison tables that are saved, refer to the explanation of the CTBL(63) instruction in Section 5 Instruction Set. Note The comparison results are normally stored in AR 1100 through AR 1107 while the range comparison is being executed. If C is set to 002, then comparisons will be made by the target matching method; if 003, then they will be made by the range comparison method. For either of these settings, the comparison table will be saved, but comparisons will not begin, and the INI(61) instruction must be used to begin comparisons. 2. To stop comparisons, execute the INI(61) instruction as shown below. (@)INI(61) 000 001 000
To start comparisons again, set the second operand to “000” (execute comparison), and execute the INI(61) instruction. Once a table has been saved, it will be retained in the CQM1 during operation (i.e., during program execution) as long as no other table is saved. Reading the PV There are two ways to read the PV. The first is to read it from SR 230 and SR 231, and the second to use the PRV(62) instruction. Reading SR 230 and SR 231 The PV of high-speed counter 0 is stored in SR 230 and SR 231 as shown below. The leftmost bit will be F for negative values. Leftmost 4 digits SR 231
Rightmost 4 digits
Up/Down Mode
Incrementing Mode
SR 230
F0032767 to 00032767 (–32767)
00000000 to 00065535
Note These words are refreshed only once every cycle, so there may be a difference from the actual PV. When high-speed counter 0 is not being used, the bits in these words can be used as work bits. Using the PRV(62) Instruction Read the PV of high-speed counter 0 by using the PRV(62) instruction. (@)PRV(62) 000
P1: Leading word of PV
000 P1
The PV of high-speed counter 0 is stored as shown below. The leftmost bit will be F for negative values. Leftmost 4 digits P1+1
Rightmost 4 digits
Up/Down Mode
Incrementing Mode
P1
F0032767 to 00032767 (–32767)
00000000 to 00065535
The PV is read when the PRV(62) instruction is actually executed.
51
Page 72
Section
CQM1 Interrupt Functions
1-5
Changing the PV There are two ways to change the PV of high-speed counter 0. The first way is to reset it by using the reset methods. (In this case the PV is reset to 0.) The second way is to use the INI(61) instruction. The method using the INI(61) instruction is explained here. For an explanation of the reset method, refer to the beginning of this description of high-speed counter 0. Change the timer PV by using the INI(61) instruction as shown below. (@)INI(61)
D: Leading word for storing PV change data 000 002 D
Leftmost 4 digits D+1
Rightmost 4 digits
Up/Down Mode
Incrementing Mode
D
F0032767 to 00032767
00000000 to 00065535
To specify a negative number, set F in the leftmost digit. Operation Example
52
This example shows a program for using high-speed counter 0 in the Incrementing Mode, making comparisons by means of the target matching method, and changing the frequency of pulse outputs according to the counter’s PV. Before executing the program, set the PC Setup as follows: DM 6642: 0114 (High-speed counter 0 used with software reset and Incrementing Mode). For all other PC Setup, use the default settings. (Inputs are not refreshed at the time of interrupt processing, and pulse outputs are executed for IR 100.)
Page 73
Section
CQM1 Interrupt Functions
1-5
In addition, the following data is stored for the comparison table: DM 0000 DM 0001 DM 0002 DM 0003 DM 0004 DM 0005 DM 0006
0002 1000 0000 0101 2000 0000 0102
Number of comparison conditions: 2 Target value 1: 1000 Comparison 1 interrupt processing routine no.: 101 Target value 1: 2000 Comparison 2 interrupt processing routine no.: 102
25315 (ON for 1 scan) CTBL(63)
Saves the comparison table in target matching format, and begins comparing.
000 000 DM 0000 SPED(64) 020
Begins continuous pulse output to IR10002 at 500 Hz.
001 #0050 SBN(92)
101
25313 (Always ON) SPED(64)
When the high-speed counter value reaches 1000, subroutine 101 is called and the frequency of the pulse output is changed to 200 Hz.
020 001 #0020 RET(93) SBN(92)
102
25313 (Always ON) SPED(64)
When the high-speed counter value reaches 2000, subroutine 102 is called and the pulse output is stopped by setting the frequency to 0.
020 001 #0000 RET(93)
When the program is executed, operation will be as follows: Pulse frequency (Hz)
500
200
Time elapsed (s) 0
2
7
1-5-6 High-speed Counter 0 Overflows/Underflows If the allowable counting range for high-speed counter 0 is exceeded, and underflow or overflow status will occur and the counter’s PV will remain at 0FFF FFFF for overflows and FFFF FFFF for underflows until the overflow/underflow status is cleared by resetting the counter. The allowable counting ranges are as follows: Up/Down Mode: F003 2767 to 0003 2767 Incrementing Mode: 0000 0000 to 0006 5535
53
Page 74
Section
CQM1 Interrupt Functions Note
1-5
1. The values given above are theoretical and assume a reasonably short cycle time. The values will actually be those that existed one cycle before the overflow/underflow existed. 2. The 6th and 7th digits of high-speed counter 0’s PV are normally 00, but can be used as “Overflow/Underflow Flags” by detecting values beyond the allowable counting ranges. High-speed counter 0 can be reset as described in the previous section or it can be reset automatically by restarting program execution. High-speed counter 0 and related operations will not function normally until the overflow/underflow status is cleared. Operations during overflow/underflow status will be as follows. • Comparison table operation will stop. • The comparison table will not be cleared. • Interrupt routines for the high-speed counter will not be executed. • CTBL(63) can be used only to register the comparison table. If an attempt is made to start comparison table operation, operation will not start and the comparison table will not be registered. • INI(61) cannot be used to start or stop comparison table operation or to change the present value. • PRV(62) will read out only 0FFF FFFF or FFFF FFFF as the present value.
Recovery
Use the following procedure to recover from overflow/underflow status. With Comparison Table Registered 1, 2, 3...
1. Reset the counter. 2. Set the PV with PRV(62) if necessary. 3. Set the comparison table with CTBL(63) if necessary 4. Start comparison table operation with INI(61). Without Comparison Table Registered
1, 2, 3...
1. Reset the counter. 2. Set the PV with PRV(62) if necessary. 3. Set the comparison table and start operation with CTBL(63) and INI(61).
Note The range comparison results in AR 11 will remain after recovery. The interrupt routine for a interrupt condition meet immediately after recovery will not be executed if the interrupt condition was already met before the overflow/underflow status occurred. If interrupt routine execution is necessary, clear AR 11 before proceeding. Reset Operation
When high-speed counter 0 is reset, the PV will be set to 0, counting will begin from 0, and the comparison table, execution status, and execution results will be maintained.
Startup Counter Status
When high-speed counter 0 is started, the counter mode in the PC Setup will be read and used, the PV will be set to 0, overflow/underflow status will be cleared, the comparison table registration and execution status will be cleared, and range execution results will be cleared. (Range execution results are always cleared when operation is begun or when the comparison table is registered.)
Stopped Counter Status
When high-speed counter 0 is stopped, the PV will be maintained, the comparison table registration and execution status will be cleared, and range execution results will be maintained.
54
Page 75
Section
CQM1 Interrupt Functions
1-5
1-5-7 High-speed Counter 1 and 2 Interrupts (CQM1-CPU43-EV1) Pulse signals from a pulse encoder to ports 1 and 2 of the CQM1-CPU43-EV1 can be counted at high speed, and interrupt processing can be executed according to the count. The 2 ports can be operated separately. The counter for port 1 is called highspeed counter 1 and the counter for port 2 is called high-speed counter 2. This section describes how to use high-speed counters 1 and 2. Refer to the CQM1 Operation Manual for hardware information such as equipment and wiring specifications. Note
Processing
1. High-speed counters 1 and 2 can be used with the CQM1-CPU43-E/-EV1 only. 2. Some instructions cannot be used when the PC Setup (DM 6611) is set to high-speed counter mode. DM 6611 setting
Affected instructions
High-speed counter mode (0000) Pulse output mode (0001)
PLS2(––) and mode 0 of ACC(––) cannot be used. CTBL(63) cannot be used with ports 1 and 2.
Input Signals and Count Modes Three types of signals can be input to ports 1 and 2. The count modes used for high-speed counters 1 and 2 are set in DM 6643 and DM 6644 respectively. 1, 2, 3...
1. Differential Phase Mode (Counting Rate = 25 kHz): A phase-difference 4X two-phase signal (A-phase and B-phase) and a Zphase signal are used for inputs. The count is incremented or decremented according to differences in the 2-phase signals. This mode is identical to high-speed counter 0’s up/down mode. 2. Pulse/Direction Mode (Counting Rate = 50 kHz): The A-phase is the direction signal and the B-phase is the count pulse. The counter increments when the A-phase signal is OFF and decrements when it is ON. 3. Up/Down Mode (Counting Rate = 50 kHz): The A-phase is the decrementing signal and the B-phase is the incrementing signal. The counter decrements when an A-phase pulse is detected and increments when a B-phase pulse is detected.
Differential Phase Mode
Pulse/Direction Mode
Up/Down Mode
A-phase
A-phase (Direction)
A-phase (Down)
B-phase
B-phase (Pulse)
B-phase (Up)
Count
1 2 3 4 5 6 7 8 7 6 5 4 3 2
Incremented
Decremented
Count
1
2
3
Incremented
2
1
Decremented
Count
1
2
3
Incremented
2
1
Decremented
Counting Modes The counting modes (ring mode or linear mode) for high-speed counters 1 and 2 are specified in DM 6643 and DM 6644 respectively. 1, 2, 3...
1. Ring Mode: In ring mode, the maximum count value +1 is set in CTBL(63). The counter will go from the maximum count value to 0 when incrementing, and from 0 to the maximum count value when decrementing. There are no negative values.
55
Page 76
Section
CQM1 Interrupt Functions
1-5
The number of points on the ring (maximum count value +1) can be set from 1 to 65,000. 2. Linear Mode: The counting range in linear mode is –8,388,607 to 8,388,607. If the allowable counting range for high-speed counter 1 or 2 is exceeded, an underflow or overflow status will occur and the counter’s PV will remain at 0838 8607 for overflows and F838 8607 for underflows, counting or comparison will be stopped, and AR 0509 (port 1) or AR 0609 (port 2) will be turned ON. Ring Mode Max. count value
Linear Mode 0
–8.388,607 Decrement
0
Underflow
PC Setup
Overflow
Note
1. One of the methods in the following section should always be used to reset the counter when restarting it. The counter will be automatically reset when program execution is started or stopped. 2. The following signal transitions are handled as forward (incrementing) pulses: A-phase leading edge to B-phase leading edge to A-phase trailing edge to B-phase trailing edge. The following signal transitions are handled as reverse (decrementing) pulses: B-phase leading edge to A-phase leading edge to B-phase trailing edge to A-phase trailing edge. Reset Methods Either the Z-phase signal + software reset or software reset may be selected for resetting the PV of the count (i.e., setting it to 0). These resets operate the same as they do for high-speed counter 0. Refer to page 48 for details.
Note
1. The reset bits for high-speed counters 1 and 2 (SR 25201 and SR 25202) are refreshed once every cycle. Make sure that a reset bit is ON for at least one full cycle so it can be read reliably. 2. The comparison table, execution status, and range comparison results will be retained through a reset. (A comparison will be continued after a reset is performed.) High-speed Counter Interrupt Count The comparison tables used for high-speed counters 1 and 2 are just like the one used for high-speed counter 0. Refer to page 49 for details. When using high-speed counter 1 and/or 2 interrupts, make the settings in PROGRAM mode shown below before executing the program. Port 1 and 2 Mode Setting (DM 6611) Specify high-speed counter mode for ports 1 and 2. If high-speed counter mode is not specified, CTBL(63) cannot be used to make count comparisons. This setting is read when the PC is turned ON. If it is changed, the PC must be turned off and then on again before executing the program. Bit 15 DM 6611 0
0
0
0
0
Port 1 and 2 Mode Setting 0000: High-speed counter mode Default: The default mode setting is high-speed counter mode.
56
8.388,607
Increment
Page 77
Section
CQM1 Interrupt Functions
1-5
Note If DM 6611 is set to pulse output mode, another comparison instruction such as BCMP(68) can be used to compare the PV of high-speed counters 1 and 2. Input Refresh Word Settings (DM 6634 and DM 6635) DM 6634 contains the input refresh word settings for high-speed counter 1, and DM 6635 contains the settings for high-speed counter 2. Make these settings when it is necessary to refresh inputs. Bit 15
0
DM 6634/DM 6635
Number of words (2 digits BCD)
00 to 12
Beginning word no. (2 digits BCD)
00 to 11
Default: No input refresh
High-speed Counter 1 and 2 Settings (DM 6643 and DM 6644) DM 6643 contains the settings for high-speed counter 1, and DM 6644 contains the settings for high-speed counter 2. These settings determine the operating parameters for these high-speed counters. Bit 15 DM6643/DM 6644
0
–
Counting mode 0: Linear mode 1: Ring mode Reset method 0: Z-phase and software reset 1: Software reset Count mode 0: Differential Phase Mode 1: Pulse/Direction Mode 2: Up/Down Mode Defaults: Linear Mode, Z-phase and software reset, Differential Phase Mode
Programming
Use the following steps to program high-speed counters 1 and 2. High-speed counters 1 and 2 begin counting when the proper PC Setup settings are made, but comparisons will not be made with the comparison table and interrupts will not be generated unless the CTBL(63) instruction is executed. High-speed counters 1 and 2 are reset to “0” when power is turned ON, when operation begins, and when operation stops. The present value of high-speed counter 1 is maintained in SR 232 and SR 233 and the present value of high-speed counter 2 is maintained in SR 234 and SR 235. Controlling High-speed Counter 1 and 2 Interrupts 1, 2, 3...
1. Use the CTBL(63) instruction to save the comparison table in the CQM1 and begin comparisons. (@)CTBL(63) P C TB
P: Port 001: 002:
Port 1 Port 2
C: (3 digits BCD) 000: Target table set and comparison begun 001: Range table set and comparison begun 002: Target table set only 003: Range table set only TB: Beginning word of comparison table
57
Page 78
Section
CQM1 Interrupt Functions
1-5
If C is set to 000, then comparisons will be made by the target matching method; if 001, then they will be made by the range comparison method. The comparison table will be saved, and, when the save operation is complete, then comparisons will begin. While comparisons are being executed, high-speed interrupts will be executed according to the comparison table. For details on the contents of the comparison tables that are saved, refer to the explanation of the CTBL(63) instruction in Section 5 Instruction Set. Note The comparison results are normally stored in AR 1100 through AR 1107 while the range comparison is being executed. If C is set to 002, then comparisons will be made by the target matching method; if 003, then they will be made by the range comparison method. For either of these settings, the comparison table will be saved, but comparisons will not begin, and the INI(61) instruction must be used to begin comparisons. 2. To stop comparisons, execute the INI(61) instruction as shown below. Specify port 1 or 2 in P (P=001 or 002). (@)INI(61) P 001 000
To start comparisons again, set the second operand to “000” (execute comparison), and execute the INI(61) instruction. Once a table has been saved, it will be retained in the CQM1 during operation (i.e., during program execution) as long as no other table is saved. Reading the PV There are two ways to read the PV. The first is to read it from SR 232 and SR 233 (port 1) or SR 234 and SR 235 (port 2), and the second is to use PRV(62). Reading SR 232 and SR 233 or SR 234 and SR 235 The PV of high-speed counter 1 is stored in SR 232 and SR 233, and the PV of high-speed counter 2 is stored in SR 234 and SR 235 as shown below. In linear mode, the leftmost digit will be F for negative values. Leftmost 4 digits
Rightmost 4 digits
Linear Mode
Ring Mode
F8388607 to 08388607 (–8,388,607 to 8,388,607)
00000000 to 0006499
Port 1:
SR 233
SR 232
Port 2:
SR 235
SR 234
Note These words are refreshed only once every cycle, so there may be a difference from the actual PV. Using the PRV(62) Instruction Read the PV of high-speed counter 0 by using the PRV(62) instruction. Specify high-speed counter 1 or 2 in P (P=001 or 002). (@)PRV(62) P 000
P: Port (001: port 1; 002: port 2) P1: Leading word of PV
P1
The PV of the specified high-speed counter is stored as shown below. In linear mode, the leftmost bit will be F for negative values. Leftmost 4 digits D+1
58
Rightmost 4 digits D
Linear Mode
Ring Mode
F8388607 to 08388607 (–8,388,607 to 8,388,607)
00000000 to 0006499
Page 79
Section
CQM1 Interrupt Functions
1-5
The PV is read when the PRV(62) instruction is actually executed. Changing the PV There are two ways to change the PV of high-speed counters 1 and 2. The first way is to reset it by using the reset methods. (In this case the PV is reset to 0.) The second way is to use the INI(61) instruction. The method using the INI(61) instruction is explained here. For an explanation of the reset method, refer to the beginning of this description of high-speed counters 1 and 2. Change the timer PV by using the INI(61) instruction as shown below. (@)INI(61)
P: Port (001: port 1; 002: port 2) P
D: Leading word for storing PV change data
002 D
Leftmost 4 digits D+1
Rightmost 4 digits D
Linear Mode
Ring Mode
F8388607 to 08388607 (–8,388,607 to 8,388,607)
00000000 to 0006499
To specify a negative number in linear mode, set F in the leftmost digit. Note Do not use INI(61) to repeatedly change the PV and start comparison for target value comparison while pulses are being input. If the comparison operation is started immediately after forcing the PV to change, the interrupts may not work properly. The target value will return to the first target value following completion of the interrupt for it, enabling repeating operation by only changing the PV. High-speed Counter Status
The status of high-speed counters 1 and 2 can be determined either by reading the status of the relevant flags in the AR area or executing PRV(62). The following table shows the relevant AR area flags and their functions. Word
Bit(s)
Function
AR 04
08 to 15
Indicates high-speed counter status.
AR 05
00 to 07 08 09
AR 06
00 to 07 08 09
00: Normal 01 or 02: Hardware error 03: PC Setup error High-speed Counter 1 Comparison Result flag for ranges 1 to 8. (0: Not in range; 1: In range) High-speed Counter 1 Comparison flag (0: Stopped; 1: Comparing) High-speed Counter 1 Overflow/Underflow flag (0: Normal; 1: Underflow or overflow occurred) High-speed Counter 2 Comparison Result flag for ranges 1 to 8. (0: Not in range; 1: In range) High-speed Counter 2 Comparison flag (0: Stopped; 1: Comparing) High-speed Counter 2 Overflow/Underflow flag (0: Normal; 1: Underflow or overflow occurred)
The status of high-speed counters 1 and 2 can also be determined by executing PRV(62). Specify high-speed counter 1 or 2 (P=001 to 002) and the destination word D. The status information will be written to bits 00 and 01 of D. Bits 02 to 15 will be set to 0. Execution condition @PRV(62) P 001 D
59
Page 80
Section
CQM1 Interrupt Functions
1-5
Bits 00 and 01 of D contain the specified high-speed counter’s status. Bit
Operation Example
60
Function
00
Comparison flag (0: Stopped; 1: Comparing)
01
Overflow/Underflow flag (0: Normal; 1: Underflow or overflow occurred)
This example shows a program that outputs standard pulses from port 1 while counting those pulses with high-speed counter 1. The high-speed counter operates in Up/Down Mode, with the pulse output’s CW pulses incrementing the counter (B-phase input) and the CCW pulses decrementing the counter (Aphase input). Before executing the program, set the PC Setup as follows and restart the PC. DM 6611: 0000 (High-speed counter mode). DM 6643: 0002 (Port 1: Standard pulse output, linear counting mode, Z-phase signal with software reset, and Up/Down Mode). Other PC Setup settings use the default settings. (Inputs are not refreshed at the time of interrupt processing.)