The text of a manual · part 18 of 39
Series 90-30/20/Micro PLC CPU Instruction Set Reference Manual: Chapter 8 - Bit Operation Functions, pages 144 to 149
Pages 144 to 149 of 337, from Series 90-30/20/Micro PLC CPU Instruction Set Reference Manual
The original document is the PDF (4.4 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 GE Fanuc IC692CPU211D / IC692MDR541C, Fanuc IC692CPU211D / IC692MDR541C, GE IC692CPU211D / IC692MDR541C and GE Fanuc IC693CPU311X
Page 144
8
Valid Memory Types Parameter flow
%I
%Q
%M
%T
%S
%G
%R enable
•
IN
•
•
•
•
•
•
•
•
•
POS
•
•
•
•
•
•
•
• ok •
%AI %AQ const
• none
•
Valid reference or place where power may flow through the function.
Example Note that the Bit Position function can only be a WORD type; therefore, any memory address used at IN will appear on a Logicmaster screen in hexadecimal format. However, the value at POS will appear in integer format. Logicmaster displays the first 16 bits at IN in hexadecimal format. In the following example, if %I0001 is on, the bit string starting at %M0001 is searched until a bit equal to 1 is found, or until the entire bit string has been searched. Coil %M0100 is turned on. If a bit equal to 1 is found, its location within the bit string is written to %R0002; otherwise a value of 0 is written to %R0002. In the example shown, bit 5 is the first logic 1 encountered by the search (which starts at bit 1), so the value written to %R0002 is 5. %M0100
%I0001
%M0001 6910
BIT_ POS_ WORD IN LEN 00001 POS
GFK-0467M
%R0002 +00005
%M Bits
16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
Bit Value
0 1 1 0 1 0 0 1 0 0 0 1 0 0 0 0
Chapter 8 Bit Operation Functions
8-17
Page 145
8
MSKCMP (WORD, DWORD) The Masked Compare (MSKCMP) function (available for Release 4.41 or later CPUs) is used to compare the contents of two separate bit strings with the ability to mask selected bits. The length of the bit strings to be compared is specified by the LEN parameter (where the value of LEN specifies the number of 16-bit words for the MSKCMP word-type function or 32-bit words for the MSKCMP double-word type function). When its enable input is on, the function compares the bits in the first string with the corresponding bits in the second string. Comparison continues until a miscompare is found, or until the end of the string is reached. The function executes each scan that the enable input is on, so, for many applications, a “one-shot” contact is used for the enable input. The BIT input is used to store the bit number where the next comparison should start (where a 0 indicates the first bit in the string). The BN output is used to store the bit number where the last comparison occurred (where a 1 indicates the first bit in the string). Using the same reference for BIT and BN causes the compare to start at the next bit position after a miscompare; or, if all bits compared successfully upon the next invocation of the function block, the compare starts at the beginning. If you want to start the next comparison at some other location in the string, you can enter different references for BIT and BN. If the value of BIT is a location that is beyond the end of the string, BIT is reset to 0 before starting the next comparison.
If All Bits in I1 and I2 are the Same If all corresponding bits in strings I1 and I2 match, the function sets the “miscompare” output MC to 0 and BN to the highest bit number in the input strings. The comparison then stops. On the next invocation of MSKCMP, BN will be reset to 0.
If a Miscompare is Found When the two bits currently being compared are not the same, the function checks the correspondingly numbered bit in string M (the mask). If the mask bit is a 1, the miscompare is ignored and the comparison continues until it reaches another miscompare or the end of the input strings. If a miscompare is detected and the corresponding mask bit is a 0, the function does the following:
8-18
1.
Sets the corresponding mask bit in M to 1.
2.
Sets the miscompare (MC) output to 1.
3.
Updates the output bit string Q to match the new content of mask string M.
4.
Sets the bit number output (BN) to the number of the miscompared bit.
5.
Stops the comparison.
Series 90™-30/20/Micro PLC CPU Instruction Set Reference Manual – May 2002
GFK-0467M
Page 146
8 _____ | | (enable), |MASK_|| | |COMP_| | | | WORD| | | (input parameter I1), |I1 MC| - (miscompare) | LEN | |00001| | | (input parameter I2), |I2 Q| - (output parameter Q) | | | | (bit string mask), |M BN| - (bit number for last miscompare) | | | | (bit number), |BIT | |_____|
Parameters Parameter enable
Description Permissive logic to enable the function.
I1
Reference for the first bit string to be compared.
I2
Reference for the second bit string to be compared.
M
Reference for the bit string mask.
BIT
Reference for the bit number where the next comparison should start.
MC
Goes to a logic 1 for one scan if a miscompare has occurred. A set coil can be used on this output if it is desired to “capture” the output beyond one scan.
Q
Output copy of the mask (M) bit string.
BN
Number of the bit where the last compare occurred.
LEN
LEN is the number of words in the bit string.
Valid Memory Types Parameter flow enable
•
I1 I2 M BIT LEN MC Q BN • o † ‡
GFK-0467M
%I
%Q
%M
%T
%S
%G
%R
%AI %AQ const o o o • o o o • o o o • o o o • o o o† • o o o •
• • • •
• • • •
• • • • o • o • o • o • o† • o •
• •
• •
• •
• none
• •‡ •
Valid reference or place where power may flow through the function. Valid reference for WORD data only; not valid for DWORD. %SA, %SB, %SC only; %S cannot be used. Max const value of 4095 for WORD and 2047 for DWORD.
Chapter 8 Bit Operation Functions
8-19
Page 147
8 Example 1 – MSKCMP Instruction When %M0200 closes, the contact from the %M0201 transition coil closes for one scan, which enables the MSKCMP function to execute once. %M0001 through %M0016 (I1) are compared with %M0017 through %M0032 (I2). %M0033 through %M0048 (M) contains the mask value. The value in %R0001 (BIT) determines at which bit position (0) the comparison starts within the two input strings at I1 and I2. %M0201
%M0200
%M0201
%M0001 6C6C %M0017 606F
MASK_ COMP WORD I1 MC LEN 00001 Q I2
%M0033 000F
M
%R0001 00000
BIT
BN
%M0202
%M0033 000F %R0001 00000
Condition Before the First MSKCMP Execution The contents of the input references before the MSKCMP executes are as follows: %M Bits Input 1(I1)
16 15 14 13 12 11 10 0 1 1 0 1 1 0
9 0
8 0
7 1
6 1
5 0
4 1
3 1
2 0
1 0
%M Bits Input 2(I2)
32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 0 1 1 0 1 1 0 1 0 1 1 0 1 1 1 1
%M Bits Mask (M/Q)
48 47 46 45 44 43 42 41 40 39 38 37 36 35 35 33 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1
BIT/BN (%R0001) = 0 MC (%M0202) = OFF
8-20
Series 90™-30/20/Micro PLC CPU Instruction Set Reference Manual – May 2002
GFK-0467M
Page 148
8 Condition After the First MSKCMP Execution The following table shows the contents of the Mask (M/Q) references after the MSKCMP executes one time. (I1 and I2 are still at the values shown above.) Since the ninth bit produced a miscompare, the ninth bit (%M0041) in the Mask string is set to logic 1, BIT/BN contains a value of 9, and the MC output turned on for one scan. Although the first and second bit positions are not equal, they do not produce a miscompare because the mask bits are 1 for these positions. %M Bits Mask (M/Q)
48 47 46 45 44 43 42 41 40 39 38 37 36 35 35 33 0 0 0 0 0 0 0 1 0 0 0 0 1 1 1 1
BIT/BN (%R0001) = 9 MC (%M0202) = ON (for one scan)
Example 2 - Fault Detection with a Masked Compare Function Intermittent problems can be difficult to troubleshoot. One example is when several switches are arranged in a series circuit that energizes a fault relay. Under normal conditions, all switches are closed and the fault relay is energized (a “fail-safe” arrangement). When a fault occurs, one of the contacts opens and the fault relay drops out. If the faulted contact remains open, a troubleshooter will be able to easily determine which switch caused the fault. However, sometimes a contact only opens for a brief time, perhaps for less than a second, then closes again. This causes the fault relay to drop out briefly and shut down the process. Since the contact closes again, everything appears normal. To help with such a problem, the following circuit acts as a “fault catcher” in that it detects which contact opened and stores its number in a register. In the first rung, contacts from the input switches, which are each wired to an input module point (%I1 – %I9), are programmed in series to energize %M0021, a negative transition coil. The second rung initializes the MSKCMP so it is ready to capture the fault. The first Move instruction writes all logic ones to the I2 input of the MSKCMP. The second Move writes values of 1 to bits 10 - 16 of the mask word (so that these bits are ignored), since only the first nine bits of the compared words (the MSKCMP uses full words) are needed for switches %I0001 - %I0009. The third Move zeroes the output register, %R0001, so it is ready to report the latest fault. During normal operation, the first nine bits on input I1 of the MSKCMP are at logic 1 since the switches are all closed. Input I2 is initialized with all logic 1s since that is the normal condition to which the input switches are compared. The mask has 1s in bits 10 - 16 because these bits are not used since there are nine input switches. When a switch opens, %M0201’s contacts close for one scan. This causes the initializing moves to occur in the second rung, and in the third rung, the MSKCMP is enabled. The MSKCMP compares the input switches against the logic 1s at its I2 input, identifies which switch is logic 0 (open), and writes the bit number of the open switch to the BN (%R0001) output. The bits are numbered from 1 - 9 beginning with %I1. For example, if %I4 were to open, %R0001 would contain the number 4. Note that, in this circuit, if a switch opens and closes again, coil %M0201 drops out and picks back up, but the number of the switch that opened will be stored in %R0001. However, if a switch opens again, for example, the machine operator pushes an emergency stop button or opens a safety gate, the masked compare activates again and writes the number of the latest switch opening in %R0001. This means that the equipment should be left untouched after the fault occurs until the value in %R0001 can be checked. If this is not practical, an additional Move instruction could be used.
GFK-0467M
Chapter 8 Bit Operation Functions
8-21
Page 149
8 %I0001 %I0002 %I0003 %I0004 %I0005 %I0006 %I0007 %I0008 %I0009
%M0201
%M0201 MOVE_ WORD CONST FFFF
IN
Q
MOVE_ WORD
MOVE_ WORD %M0017 CONST FFFF FE00
LEN 00001
IN
Q
LEN 00001
%M0033 FE00
CONST 0000
IN
Q
%R0001 0000
LEN 00001
%M0201
%I0001 01FF %M0017 FFFF
8-22
MASK_ COMP WORD I1 MC LEN 00001 Q I2
%M0033 FE00
M
CONST 00000
BIT
BN
%M0202
%M0033 FE00 %R0001 00000
Series 90™-30/20/Micro PLC CPU Instruction Set Reference Manual – May 2002
GFK-0467M