CPM2A_PROGRAMMING MANUAL (W353-E1-2) (986750), страница 15
Текст из файла (страница 15)
This includes the status of the interruptinput bit that activated the interrupt.71SectionCPM1/CPM1A Interrupt Functions2-3For example, IR 00000 would not be ON in interrupt routine for input interrupt 0unless it was refreshed. In this case, use the Always ON Flag, SR 25313 in theinterrupt routine instead of IR 00000.Input Interrupt ModeWhen an input interrupt signal is received, the main program is interrupted andthe interrupt program is executed immediately, regardless of the point in thecycle in which the interrupt is received. The signal must be ON for 200 µs or moreto be detected.Main programMain programInterrupt programInput interruptUse the following instructions to program input interrupts using the Input Interrupt Mode.Masking/Unmasking of InterruptsWith the INT(89) instruction, set or clear input interrupt masks as required.(@)INT(89)000000Make the settings with word D bits 0 to 3, which correspondto input interrupts 0 to 3.0: Mask cleared.
(Input interrupt enabled.)1: Mask set. (Input interrupt disabled.)DAll of the input interrupts are masked when PC operation is started. If input interrupt mode is being used, be sure to enable the inputs by executing INT(89) asshown above.Clearing Masked InterruptsIf the bit corresponding to an input interrupt turns ON while masked, that inputinterrupt will be saved in memory and will be executed as soon as the mask iscleared. In order for that input interrupt not to be executed when the mask iscleared, 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.(@)INT(89)001000If D bits 0 to 3, which correspond to input interrupts 0 to 3, areset to “1,” then the input interrupts will be cleared from memory.0: Input interrupt retained.1: Input interrupt cleared.DReading Mask StatusWith the INT(89) instruction, read the input interrupt mask status.(@)INT(89)002000D72The status of the rightmost digit of the data stored in word D (bits0 to 3) show the mask status.0: Mask cleared.
(Input interrupt enabled.)1: Mask set. (Input interrupt disabled.)SectionCPM1/CPM1A Interrupt Functions2-3Program ExampleWhen input 00003 (interrupt no. 0) goes ON, operation moves immediately tothe interrupt program with subroutine number 000. Inputs for DM 6628 havebeen set to 0001.25315 First Cycle FlagON for 1 cycle@INT(89)000Mask/unmask input interrupts.000#000ESBN(92)Unmasks 00003 (interrupt input 0), masks others.000Interrupt programRET(93)Counter ModeExternal signal inputs are counted at high speed and an interrupt is generatedwhen the count reaches the set value.
When an interrupt is generated, the mainprogram is interrupted and the interrupt program is executed. Signals up to1 kHz can be counted.Main programMain programInterrupt programInput interruptSet valueUse the following steps to program input interrupts using the Counter Mode.1, 2, 3...1.
Write the set values for counter operation to the SR words shown in the following table. The set values are written between 0000 and FFFF (0 to65,535). A value of 0000 will disable the count operation until a new value isset and step 2, below, is repeated.InterruptWordInput interrupt 0SR 240Input interrupt 1SR 241Input interrupt 2SR 242Input interrupt 3SR 243The SR words used in the Counter Mode (SR 240 to SR 243) contain hexadecimal data, not BCD. If the Counter Mode is not used, these words can beused as work bits.Note These SR words are cleared at the beginning of operation, and mustbe written from the program.73SectionCPM1/CPM1A Interrupt Functions2-32. With the INT(89) instruction, refresh the Counter Mode set value and enableinterrupts.(@)INT(89)003000DIf 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: Not refreshed.Be sure to set the corresponding bit to 1 if an input interrupt isn’t being controlled.The input interrupt for which the set value is refreshed will be enabled in CounterMode.
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.Note1. If the INT(89) instruction is used during counting, the present value (PV) willreturn to the set value (SV). You must, therefore, use the differentiated formof the instruction or an interrupt may never occur.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 bychanging the content of SR 240 to SR 243, i.e., if the contents are changed,the set value must be refreshed by executing the INT(89) instruction again.Interrupts can be masked using the same process used with the Input InterruptMode, but if the masked interrupts are cleared using the same process, the interrupts will operate in Input Interrupt Mode, not Counter Mode.Interrupt signals received for masked interrupts can also be cleared using thesame process as for the Input Interrupt Mode.Counter PV in Counter ModeWhen input interrupts are used in Counter Mode, the counter PV will be stored inthe SR word corresponding to input interrupts 0 to 3.
Values are 0000 to FFFE (0to 65,534) and will equal the counter PV minus one.InterruptWordInput interrupt 0SR 244Input interrupt 1SR 245Input interrupt 2SR 246Input interrupt 3SR 247Example: 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 beused as work bits.74SectionCPM1/CPM1A Interrupt Functions2-3Program ExampleWhen input 00003 (interrupt no.
0) goes ON 10 times, operation moves immediately to the interrupt program with subroutine number 000. The following tableshows where the counters‘ set values and present values –1 are stored. Inputsfor DM 6628 have been set to 0001.InterruptInput 00003 (input interrupt 0)Word containingSVSR 240Word containingPV–1SR 244Input 00004 (input interrupt 1)SR 241SR 245Input 00005 (input interrupt 2)SR 242SR 246Input 00006 (input interrupt 3)SR 243SR 24725315 First Cycle FlagON for 1 cycleMOV(21)#000ASets the SV to 10.
(0000 to FFFF)240Word containing the SV (SR 240)003Refresh counter SVs.@INT(89)000#000ESBN(92)Refreshes the SV of 00003 (interrupt input 0) only.000Interrupt programRET(93)2-3-3 Masking All InterruptsAll interrupts, including input interrupts, interval timer interrupts, and high-speedcounter interrupts, can be masked and unmasked as a group by means of theINT(89) instruction.
The mask is in addition to any masks on the individual typesof interrupts. Furthermore, clearing the masks for all interrupts does not clear themasks on the individual types of interrupts, but restores them to the maskedconditions 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 maskall interrupts and always use INT(89) instructions in pairs to do so, using the firstINT(89) instruction to mask and the second one to unmask interrupts.INT(89) cannot be used to mask and unmask all interrupts from within interruptroutines.Masking InterruptsUse the INT(89) instruction to disable all interrupts.(@)INT(89)100000000If an interrupt is generated while interrupts are masked, interrupt processing willnot be executed but the interrupt will be recorded for the input, interval timer, andhigh-speed counter interrupts.
The interrupts will then be serviced as soon asinterrupts are unmasked.75SectionCPM1/CPM1A Interrupt FunctionsUnmasking Interrupts2-3Use the INT(89) instruction to unmask interrupts as follows:(@)INT(89)2000000002-3-4 Interval Timer InterruptsThe CPM1/CPM1A is equipped with one interval timer. When the interval timertimes out, the main program is interrupted and the interrupt program is executedimmediately, regardless of the point in the cycle.There are two modes for interval timer operation, the One-shot Mode, in whichonly one interrupt will be executed when time expires, and the Scheduled Interrupt Mode in which the interrupt is repeated at a fixed interval.The interval timer’s set value can be set anywhere from 0.5 to 319968 ms, inunits of 0.1 ms.OperationUse the following instruction to activate and control the interval timer.Starting Up in One-Shot ModeUse the STIM(69) instruction to start the interval timer in the one-shot mode.(@)STIM(69)C1C2C31, 2, 3...C1C2C376C2: Timer set value (first word address)C3: Subroutine no.
(4 digits BCD): 0000 to 00491. When C2 is entered as a word address:C2: Decrementing counter set value (4 digits BCD): 0000 to 9999C2 + 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 reaches0, 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 elapsesis calculated as follows:(Content of C2) × (Content of C2 + 1) × 0.1 ms = (0.5 to 319,968 ms)2.
When C2 is entered as a constant:The set value of the decrementing counter will equal the specified constant(in ms) and the decrementing time interval will be 10 (1 ms).Starting Up in Scheduled Interrupt ModeUse the STIM(69) instruction to start the interval timer in the scheduled interruptmode.(@)STIM(69)1, 2, 3...C1: Interval timer, one-shot mode (000)C1: Interval timer, scheduled interrupt mode (003)C2: Timer set value (leading word no.)C3: Subroutine no.