The text of a manual · part 8 of 60
SYSMAC CQM1/CPM1/CPM1A/SRM1 Programmable Controllers Programming Manual: SECTION 1 PC Setup and Other Features, pages 61 to 70
Pages 61 to 70 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 61
Section
CQM1 Interrupt Functions
1-5
At the beginning of operation, all of the input interrupts are masked. Clearing Masked Interrupts If the bit corresponding to an input interrupt turns ON while masked, that input interrupt will be saved in memory and will be executed as soon as the mask is cleared. In order for that input interrupt not to be executed when the mask is cleared, the interrupt must be cleared from memory. Only one interrupt signal will be saved in memory for each interrupt number. With the INT(89) instruction, clear the input interrupt from memory. If D bits 0 to 3, which correspond to input interrupts 0 to 3, are set to “1,” then the input interrupts will be cleared from memory. 0: Input interrupt retained. 1: Input interrupt cleared.
(@)INT(89) 001 000 D
Reading Mask Status With the INT(89) instruction, read the input interrupt mask status. The status of the rightmost digit of the data stored in word D (bits 0 to 3) show the mask status. 0: Mask cleared. (Input interrupt permitted.) 1: Mask set. (Input interrupt not permitted.)
(@)INT(89) 002 000 D
Counter Mode
Use the following steps to program input interrupts using the Input Interrupt Mode. Note The SR words used in the Counter Mode (SR 244 to SR 251) all contain binary (hexadecimal) data (not BCD). 1, 2, 3...
1. Write the set values for counter operation to SR words correspond to interrupts 0 to 3. The set values are written between 0000 and FFFF (0 to 65,535). A value of 0000 will disable the count operation until a new value is set and step 2, below, is repeated. Note These SR bits are cleared at the beginning of operation, and must be written from the program. That maximum input signal that can be counted is 1 kHz. Interrupt
Word
Input interrupt 0
SR 244
Input interrupt 1
SR 245
Input interrupt 2
SR 246
Input interrupt 3
SR 247
If the Counter Mode is not used, these SR bits can be used as work bits. 2. With the INT(89) instruction, refresh the Counter Mode set value and enable interrupts. (@)INT(89) 003 000 D
If D bits 0 to 3, which correspond to input interrupts 0 to 3, are set to “0,” then the set value will be refreshed and interrupts will be permitted. 0: Counter mode set value refreshed and mask cleared. 1: Nothing happens. (Set to 1 the bits for all interrupts that are not being changed.)
The input interrupt for which the set value is refreshed will be enabled in Counter Mode. When the counter reaches the set value, an interrupt will occur, the counter will be reset, and counting/interrupts will continue until the counter is stopped. Note
1. If the INT(89) instruction is used during counting, the present value (PV) will return to the set value (SV). You must, therefore, use the differentiated form of the instruction or an interrupt may never occur.
41
Page 62
Section
CQM1 Interrupt Functions
1-5
2. The set value will be set when the INT(89) instruction is executed. If interrupts are already in operation, then the set value will not be changed just by changing the content of SR 244 to SR 247, i.e., if the contents is changed, the set value must be refreshed by executing the INT(89) instruction again. Interrupts can be masked using the same process as for the Input Interrupt Mode, but is masked are cleared using the same process, the Counter Mode will not be maintained and the Input Interrupt Mode will be used instead. Interrupt signals received for masked interrupts can also be cleared using the same process as for the Input Interrupt Mode. Counter PV in Counter Mode When input interrupts are used in Counter Mode, the counter PV will be stored in the SR word corresponding to input interrupts 0 to 3. Values are 0000 to FFFE (0 to 65,534) and will equal the counter PV minus one. Interrupt
Word
Input interrupt 0
SR 248
Input interrupt 1
SR 249
Input interrupt 2
SR 250
Input interrupt 3
SR 251
Example: The present value for an interrupt whose set value is 000A will be recorded as 0009 immediately after INT(89) is executed. Note Even if input interrupts are not used in Counter Mode, these SR bits cannot be used as work bits.
42
Page 63
Section
CQM1 Interrupt Functions Application Example
1-5
In this example, input interrupt 0 is used in Input Interrupt Mode and input interrupt 1 is used in Counter Mode. Before executing the program, check to be sure the PC Setup. PC Setup: DM 6628: 0011 (IR 00000 and IR 00001 used for input interrupts) The default settings are used for all other PC Setup parameters. (Inputs are not refreshed at the time of interrupt processing.)
25315 (ON for 1 scan)
Sets 10 as the counter mode SV for input interrupt 1.
MOV(21) #000A 245 00100 (@)INT(89) 001
When IR 00100 turns ON: Masked interrupts for input interrupts 0 and 1 are cleared.
000 #0003 (@)INT(89)
Interrupts are enabled in input interrupt mode for interrupt 0. 000 000 #000E
(@)INT(89) 003
Interrupts are enabled in counter mode for interrupt 1. (SV: 10 )
000 #000D BCD (24) 249 D0000
INC(38)
The contents of SR 249 (PV – 1) are converted to BCD and stored in DM 0000.
The content to DM 0000 is incremented to the PC. D0000
00100 (@)INT(89) 000 000
When IR 00100 turns OFF, input interrupts 0 and 1 are masked and interrupts are prohibited.
#000F SBN(92)
000
25313 (Always ON) ADB(50) 245 #000A 245
INT(89)
When the Input interrupt is executed for interrupt 0, subroutine 000 is called and the counter mode is refreshed with the SV for input interrupt 1 with 10 added (SV = 20)
003 000 #000D RET(93) SBN(92)
001
When the count is reached for the input interrupt 1 counter, subroutine 001 is called and the interrupt processing routine is executed.
RET(93)
43
Page 64
Section
CQM1 Interrupt Functions
1-5
When the program is executed, operation will be as shown in the following diagram. 00000 Subroutine 000 10 counts
10 counts
20 counts
00001 Subroutine 001
(see note 1)
(see note 1)
00100 (see note 2)
Note
1. The counter will continue operating even while the interrupt routine is being executed. 2. The input interrupt will remained masked.
1-5-3 Masking All Interrupts All interrupts, including input interrupts, interval timer interrupts, and high-speed counter interrupts, can be masked and unmasked as a group by means of the INT(89) instruction. The mask is in addition to any masks on the individual types of interrupts. Furthermore, clearing the masks for all interrupts does not clear the masks on the individual types of interrupts, but restores them to the masked conditions that existed before INT(89) was executed to mask them as a group. Do not use INT(89) to mask interrupts unless it is necessary to temporarily mask all interrupts and always use INT(89) instructions in pairs to do so, using the first INT(89) instruction to mask and the second one to unmask interrupts. INT(89) cannot be used to mask and unmask all interrupts from within interrupt routines. Masking Interrupts
Use the INT(89) instruction to disable all interrupts. (@)INT(89) 100 000 000
If an interrupt is generated while interrupts are masked, interrupt processing will not be executed but the interrupt will be recorded for the input, interval timer, and high-speed counter interrupts. The interrupts will then be serviced as soon as interrupts are unmasked. Unmasking Interrupts
Use the INT(89) instruction to unmask interrupts as follows: (@)INT(89) 200 000 000
1-5-4 Interval Timer Interrupts High-speed, high-precision timer interrupt processing can be executed using interval timers. The CQM1 provides three interval timers, numbered from 0 to 2. Note
44
1. Interval timer 0 cannot be used when pulses are being output to Output Units by means of the SPED(64) instruction. 2. Interval timer 2 cannot be used at the same time as the high-speed counter.
Page 65
Section
CQM1 Interrupt Functions
1-5
Processing
There are two modes for interval timer operation, the One-shot Mode, in which only one interrupt will be executed when time expires, and the Scheduled Interrupt Mode in which the interrupt is repeated at a fixed interval.
PC Setup
When using interval timer interrupts, make the following settings in the PC Setup in PROGRAM mode before executing the program. Input Refresh Word Settings (DM 6636 to DM 6638) Make these settings when it is necessary to refresh inputs. Bit 15 DM 6636: Timer 0 DM 6637: Timer 1 DM 6638: Timer 2
0
DM6636 to DM 6638
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 Settings (DM 6642) When using interval timer 2, check before beginning operation to be sure that the high-speed counter (PC Setup: DM 6642) is set to the default setting (0000: High-speed counter not used). Operation
Use the following instruction to activate and control the interval timer. Starting Up in One-Shot Mode Use the STIM(69) instruction to start the interval timer in the one-shot mode. (@)STIM(69) C1 C2 C3
C1: Interval timer no. Interval timer 0: Interval timer 1: Interval timer 2:
000 001 002
C2: Timer set value (first word address) C3: Subroutine no. (4 digits BCD): 0000 to 0255
C2: Decrementing counter set value (4 digits BCD): 0000 to 9999 C2 + 1: Decrementing time interval (4 digits BCD; unit: 0.1 ms): 0005 to 0320 (0.5 ms to 32 ms) Each time that the interval specified in word C2 + 1 elapses, the decrementing counter will decrement the present value by one. When the PV reaches 0, the designated subroutine will be called just once and the timer will stop. The time from when the STIM(69) instruction is executed until time elapses is calculated as follows: (Contents of word C2) x (Contents of word C2 + 1) x 0.1 ms = (0.5 to 319,968 ms) If a constant is set for C2, then the set value of the decrementing counter will take that value and the decrementing time interval will be 10 (1 ms). (The set value is expressed in ms.) Starting Up in Scheduled Interrupt Mode Use the STIM(69) instruction to start the interval timer in the scheduled interrupt mode. (@)STIM(69) C1 C2 C3
C1: Interval timer no. + 3 Interval timer 0: Interval timer 1: Interval timer 2:
003 004 005
C2: Timer set value (leading word no.) C3: Subroutine no. (4 digits BCD): 0000 to 0255
C2: Decrementing counter set value (4 digits BCD): 0000 to 9999 C2 + 1: Decrementing time interval (4 digits BCD; unit: 0.1 ms): 0005 to 0320 (0.5 ms to 32 ms)
45
Page 66
Section
CQM1 Interrupt Functions
1-5
The meanings of the settings are the same as for the one-shot mode, but in the scheduled interrupt mode the timer PV will be reset to the set value and decrementing will begin again after the subroutine has been called. In the scheduled interrupt mode, interrupts will continue to be repeated at fixed intervals until the operation is stopped. Note CQM1-CPU11-E/CPU21-E support subroutine numbers 0000 to 0127 only. Reading the Timer’s Elapsed Time Use the STIM(69) instruction to read the timer’s elapsed time. (@)STIM(69) C1 C2 C3
C1: Interval timer no. + 6 Interval timer 0: Interval timer 1: Interval timer 2:
006 007 008
C2: Leading word of parameter 1 C3: Parameter 2
C2: Number of times the decrementing counter has ben decremented (4 digits BCD) C2 + 1: Decrementing counter time interval (4 digits BCD; unit: 0.1 ms) C3: Elapsed time from previous decrement (4 digits BCD; unit: 0.1 ms) The time from when the interval timer is started until the execution of this instruction is calculated as follows: {(Contents of word C2) x (Contents of word C2 + 1) + (Contents of word C3)} x 0.1 ms
If the specified interval timer is stopped, then “0000” will be stored. Stopping Timers Use the STIM(69) instruction to stop the interval timer. (@)STIM(69) C1 000 000
C1: Interval timer no. + 10 Interval timer 0: Interval timer 1: Interval timer 2:
The specified interval timer will stop.
46
010 011 012
Page 67
Section
CQM1 Interrupt Functions Application Example
1-5
In this example, an interrupt is executed every 2.4 ms (0.6 ms x 4) by means of interval timer 1. Assume the default settings for all of the PC Setup. (Inputs are not refreshed for interrupt processing.)
25315 First Cycle Flag ON for 1 cycle
Interval timer set values: MOV(21) #0004
Sets 4 for the decrementing counter set value.
DM 0010
MOV(21) #0006
Sets 0.6 ms for the decrementing time interval.
DM 0011 00100 @STIM(69)
Interval timer 1 starts when IR 00100 turns ON. 004
DM 0010 #0023 00100 @STIM(69) 011
Interval timer 1 stops when IR 00100 turns OFF.
000 000 SBN(92)
023
Every 2.4 ms the count is reached for interval timer 1, and subroutine 023 is called.
RET(93)
When the program is executed, subroutine 023 will be executed every 2.4 ms while IR 00100 is ON.
IR 00100
2.4 ms
2.4 ms
2.4 ms
Subroutine 023
1-5-5 High-speed Counter 0 Interrupts Pulse signals from a pulse encoder to CPU bits 00004 through 00006 can be counted at high speed, and interrupt processing can be executed according to the count.
Processing Input Signal Types and Count Modes
Two types of signals can be input from a pulse encoder. The count mode used for high-speed counter 0 will depend on the signal type. Up/Down Mode:
A phase-difference 4X two-phase signal (A-phase and Bphase) and a Z-phase signal are used for inputs. The count is incremented or decremented according to differences in the 2-phase signals.
47
Page 68
Section
CQM1 Interrupt Functions
1-5
Incrementing mode: One single-phase pulse signal and a count reset signal are used for inputs. The count is incremented according to the single-phase signal. Incrementing Mode Up/Down Mode Pulse input
A-phase
B-phase
Count
1 2 3 4 5 6 7 8 7 6 5 4 3 2 1 0 –1 –2
Incremented
Count
1
2
3
4
Incremented only
Decremented
Note 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. 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 Bphase trailing edge. The following signal transitions are handled as reverse (decrementing) pulses: B-phase leading edge to A-phase leading edge to Bphase trailing edge to A-phase trailing edge. The count range is from –32,767 to 32,767 for Up/Down Mode, and from 0 to 65,535 for Incrementing Mode. Pulse signals can be counted at up to 2.5 kHz in Up/Down Mode, and up to 5.0 kHz in Incrementing Mode. The Up/Down Mode always uses a 4X phase-difference input. The number of counts for each encoder revolution would be 4 times the resolution of the counter. Select the encoder based on the countable ranges. Reset Methods Either of the two methods described below may be selected for resetting the PV of the count (i.e., setting it to 0). Z-phase signal + software reset: The PV is reset when the Z-phase signal (reset input) turns ON after the High-speed Counter 0 Reset Bit (SR 25200) is turned ON. Software reset: The PV is reset when the High-speed Counter 0 Reset Bit (SR 25200) is turned ON. Z-phase signal + software reset
Software reset
1 or more cycles
Z-phase (reset input)
1 or more cycles
SR25200 1 or more cycles
SR25200 Within 1 cycle
Within 1 cycle
Reset by interrupt.
Reset by cycle.
Not reset.
Reset by cycle.
Note The High-speed Counter 0 Reset Bit (SR 25200) is refreshed once every cycle, so in order for it to be read reliably it must be ON for at least one cycle. The “Z” in “Z-phase” is an abbreviation for “Zero.” It is a signal that shows that the encoder has completed one cycle.
48
Page 69
Section
CQM1 Interrupt Functions
1-5
High-speed Counter Interrupt Count For high-speed counter 0 interrupts, a comparison table is used instead of a “count up.” The count check can be carried out by either of the two methods described below. In the comparison table, comparison conditions (for comparing to the PV) and interrupt routine combinations are saved. Target value:
A maximum of 16 comparison conditions (target values and count directions) and interrupt routine combinations are saved in the comparison table. When the counter PV and the count direction match the comparison conditions, then the specified interrupt routine is executed.
Range comparison:
Eight comparison conditions (upper and lower limits) and interrupt routine combinations are saved in the comparison table. When the PV is greater than or equal to the lower limit and less than or equal to the upper limit, then the specified interrupt routine is executed.
The current count is compared to the target values in the order that target values are set in the comparison table and interrupts are generated as the count equals each target value. Once the count has equaled all of the target values in the table, the target value is set to the first target value in the table, which is again compared to the current counted until the two values are equal.
Target Value Comparisons
Count
Interrupts
Comparison Table Target value 1 Target value 2 Target value 3 Target value 4 Target value 5
Initial value Target value
1
2
3
4
5
The current count is compared in cyclic fashion to all of the ranges at the same time and interrupts are generated based on the results of the comparisons.
Range Comparisons
Comparison Table 0 Count 1
3 2
Rage setting 1 Rage setting 2 Rage setting 3 Rage setting 4
4
Note When performing target value comparisons, do not repeatedly use the INI instruction to change the current value of the count and start the comparison operation. The interrupt operation may not work correctly if the comparison operation is started immediately after changing the current value from the program. (The comparison operation will automatically return to the first target value once an interrupt has been generated for the last target value. Repetitious operation is thus possible merely by changing the current value.) Wiring
Depending on the count mode, the input signals from the pulse encoder to the CPU Unit’s input terminal are as shown below.
49
Page 70
Section
CQM1 Interrupt Functions Terminal no.
Up/Down Mode
1-5
Incrementing Mode
4
Encoder A-phase
Pulse count input
5
Encoder B-phase
---
6
Encoder Z-phase
Reset input
If only the software reset is to be used, terminal 6 can be used as an ordinary input. When in Incrementing Mode, terminal 5 can be used as an ordinary input. PC Setup
When using high-speed counter 0 interrupts, make the settings in PROGRAM mode shown below before executing the program. Input Refresh Word Settings (DM 6638) Make these settings when it is necessary to refresh inputs. The setting is the same as that for interval timer 2. Bit 15
0
DM6638
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 0 Settings (DM 6642) If these settings are not made, high-speed counter 0 cannot be used in the program. Bit 15 DM6642
0
0
1
High-speed counter 0 used. Reset method 0: Z-phase and software reset 1: Software reset Count mode 0: Up/Down Mode 4: Incrementing Mode Default: High-speed counter 0 not used.
Changes in the setting in DM 6642 are effective only when power is turned on or PC program execution is started. Programming
Use the following steps to program high-speed counter 0. High-speed counter 0 begins the counting operation 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 counter 0 is reset to “0” when power is turned ON and when operation begins. The present value of high-speed counter 0 is maintained in SR 230 and SR 231. Controlling High-speed Counter 0 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
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
50