The text of a manual · part 16 of 39
Series 90-30/20/Micro PLC CPU Instruction Set Reference Manual: Chapter 8 - Bit Operation Functions, pages 128 to 135
Pages 128 to 135 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 128
Chapter
Bit Operation Functions
8 Bit operation functions perform comparison, logical, and move operations on bit strings. The AND, OR, XOR, and NOT functions are limited to operating on a single word. The remaining bit operation functions may operate on multiple words, with a maximum string length of 256 words. All bit operation functions require the WORD data type. Although data must be specified in 16-bit increments, these functions operate on data as a continuous string of bits, with bit 1 of the first word being the Least Significant Bit (LSB). The last bit of the last word is the Most Significant Bit (MSB). For example, if you specified three words of data beginning at reference %R0100, it would be operated on as 48 contiguous bits. %R0100 16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
%R0101 32
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
%R0102 48
47
46
45
44
43
42
41
40
39
38
37
36
35
34
33
← bit 1 (LSB)
↑ (MSB)
Note Overlapping input and output reference address ranges in multi-word functions may produce unexpected results.
GFK-0467M
8-1
Page 129
8 The following bit operation functions are described in this chapter:
8-2
Abbreviation
Function
Description
AND
Logical AND
If a bit in bit string I1 and the corresponding bit in bit string I2 are both 1, place a 1 in the corresponding location in output string Q.
8-3
OR
Logical OR
If a bit in bit string I1 and/or the corresponding bit in bit string I2 are both 1, place a 1 in the corresponding location in output string Q.
8-3
XOR
Logical exclusive OR
If a bit in bit string I1 and the corresponding bit in string I2 are different, place a 1 in the corresponding location in the output bit string.
8-5
NOT
Logical invert
Set the state of each bit in output bit string Q to the opposite state of the corresponding bit in bit string I1.
8-7
SHL
Shift Left
Shift all the bits in a word or string of words to the left by a specified number of places.
8-8
SHR
Shift Right
Shift all the bits in a word or string of words to the right by a specified number of places.
8-8
ROL
Rotate Left
8-10
ROR
Rotate Right
BTST
Bit Test
BSET
Bit Set
Rotate all the bits in a string a specified number of places to the left. Rotate all the bits in a string a specified number of places to the right. Test a bit within a bit string to determine whether that bit is currently 1 or 0. Set a bit in a bit string to 1.
BCLR
Bit Clear
Clear a bit within a string by setting that bit to 0.
8-14
BPOS
Bit Position
Locate a bit set to 1 in a bit string.
8-16
MSKCMP
Masked Compare
Compare the contents of two separate bit strings with the ability to mask selected bits (available for Release 4.5 or higher CPUs).
8-18
Series 90™-30/20/Micro PLC CPU Instruction Set Reference Manual – May 2002
Page
8-57 8-12 8-14
GFK-0467M
Page 130
8
AND and OR (WORD) For each scan that it is enabled, an AND or OR function compares the state of each bit in bit string I1 with the corresponding bit in bit string I2, beginning at the least significant bit in each. For each two bits compared for the AND function, if both are 1, then a 1 is placed in the corresponding location in output string Q. If either or both bits are 0, then a 0 is placed in string Q in that location. The AND function is useful for building masks or screens, where only certain bits are passed through (those that are opposite a 1 in the mask), and all other bits are set to 0. The function can also be used to clear the selected area of word memory by ANDing the bits with another bit string known to contain all 0s. The I1 and I2 bit strings specified may overlap. For each two bits examined for the OR function, if either or both bits are 1, then a 1 is placed in the corresponding location in output string Q. If both bits are 0, then a 0 is placed in string Q in that location. The OR function is useful for combining strings, and to control many outputs through the use of one simple function block. The function is the equivalent of two relay contacts in parallel for each bit position in the string. It can be used to drive indicator lamps directly from input states, or superimpose blinking conditions on status lights. The function passes power flow to the right whenever power is received. _____ | | (enable), | AND_| - (ok) | | | WORD| | | (input parameter I1), |I1 Q| - (output parameter Q) | | | | | | (input parameter I2), |I2 | |_____|
Parameters Parameter enable
GFK-0467M
Description When the function is enabled, the operation is performed.
I1
I1 contains a constant or reference for the first word of the first string.
I2
I2 contains a constant or reference for the first word of the second string.
ok
The ok output is energized whenever enable is energized.
Q
Output Q contains the result of the operation.
Chapter 8 Bit Operation Functions
8-3
Page 131
8
Valid Memory Types Parameter flow
%I
%Q
%M
%T
%S
%G
%R enable
•
I1
•
•
•
•
•
•
•
•
•
•
I2
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•†
•
•
•
• ok Q • †
%AI %AQ const
• none
•
Valid reference or place where power may flow through the function. %SA, %SB, or %SC only; %S cannot be used.
Example In the following example, whenever input %I0001 is set, the 16-bit strings represented by nicknames WORD1 and WORD2 are examined. The results of the Logical AND are placed in output string RESULT.
| _____ |%I0001 | | | - - | | - - - | AND_| - | | WORD| | | | | WORD1, |I1 Q| - RESULT | | | | | | | | | | | | | WORD2, |I2 | | |_____| |
8-4
WORD1 (I1) 0
0
0
1
1
1
1
1
1
1
0
0
1
0
0
0
WORD2 (I2) 1
1
0
1
1
1
0
0
0
0
0
0
1
1
1
1
RESULT (Q) 0
0
0
1
1
1
0
0
0
0
0
0
1
0
0
0
Series 90™-30/20/Micro PLC CPU Instruction Set Reference Manual – May 2002
GFK-0467M
Page 132
8
XOR (WORD) The Exclusive OR (XOR) function is used to compare each bit in the bit string at input I1 with the corresponding bit in the bit string at input I2. If the corresponding bits are different, a 1 is placed in the corresponding position in the output bit string. The XOR function is useful for comparing two bit strings, or to flash a group of bits on and off at the rate of one ON state per two scans. For each scan that the XOR is enabled, it compares each bit in string I1 with the corresponding bit in string I2, beginning at the least significant bit in each string. In a comparison, if only one is a logic 1, then a 1 is placed in the corresponding location in bit string Q. The XOR function passes power flow to the right whenever power is received. If string I2 and output string Q begin at the same reference, a 1 placed in string I1 will cause the corresponding bit in string I2 to alternate between 0 and 1, changing state with each scan as long as power is received. Longer cycles can be programmed by switching the enable input to the function at twice the desired rate of flashing; for this application, the enable input should go high for one scan long (use a contact from a one-shot type coil or self-resetting timer circuit). _____ | | (enable), | XOR_| - (ok) | | | WORD| | | (input parameter I1), |I1 Q| - (output parameter Q) | | | | | | | | (input parameter I2), |I2 | |_____|
Parameters Parameter enable
GFK-0467M
Description When the function is enabled, the operation is performed.
I1
I1 contains a constant or reference for the first word to be XORed.
I2
I2 contains a constant or reference for the second word to be XORed.
ok
The ok output is energized whenever enable is energized.
Q
Output Q contains the result of I1 XORed with I2.
Chapter 8 Bit Operation Functions
8-5
Page 133
8 Valid Memory Types Parameter flow
%I
%Q
%M
%T
%S
%G
%R enable
•
I1
•
•
•
•
•
•
•
•
•
•
I2
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•†
•
•
•
• ok
•
Q • †
%AI %AQ const none
•
Valid reference or place where power may flow through the function. %SA, %SB, or %SC only; %S cannot be used.
Example of an Alarm Circuit Using an XOR In the following example, whenever enable contact %M0001 is on, the 16-bit string nicknamed SWITCH is compared to a reference bit string, nicknamed REFER. The SWITCH bit string is a group of bits that represent the on/off status of alarm switch contacts. The REFER bit string represents the normal or non-alarm status of these bits. If the state of any SWITCH bit is different from its corresponding REFER bit, their corresponding output at Q goes to logic 1. Under normal (no alarm) conditions, the value of the word nicknamed STATUS will be zero. |%M0001 | | | - - | | - - - | XOR_| | | WORD| | | | | SWITCH - |I1 Q| - STATUS | | | | | | | | | | | | | REFER, |I2 | | |_____| |
Bit Position
16 15 14 13 12 11 10
9
8
7
6
5
4
3
2
1
I1 (SWITCH)
0
1
0
1
1
1
1
0
1
1
0
0
0
0
0
0
I2 (REFER)
0
0
0
1
1
1
1
1
1
1
0
0
1
0
0
0
Q (STATUS)
0
1
0
0
0
0
0
1
0
0
0
0
1
0
0
0
The data in STATUS could be used as an input to a Not Equal (NE) function, which would compare the word nicknamed STATUS to a constant of zero. If STATUS does not equal zero, the NE turns on its output, indicating the presence of an alarm. The bits in STATUS that are equal to logic 1 can be identified with the BPOS (Bit Position) function, which would search the bits in STATUS and report the position (a number between 1 and 16) of the first bit (starting at bit 1) it encounters that is at logic 1. In the example above, the BPOS would output the number 4, indicating the fourth bit is a logic 1. To test for more than one bit, you could store a record of bit 4, use a BCLR (Bit Clear) function to clear bit 4, then repeat the BPOS test to find the next bit that is equal to logic 1 (bit 9 in the example above). This process can be repeated until no more non-zero bits are found. Note that the BCLR and BPOS functions are discussed in detail elsewhere in this chapter.
8-6
Series 90™-30/20/Micro PLC CPU Instruction Set Reference Manual – May 2002
GFK-0467M
Page 134
8
NOT (WORD) The NOT function is used to set the state of each bit in the output bit string Q to the opposite of the state of the corresponding bit in bit string I1. The NOT function executes and passes power flow for each scan that it’s enable input is on. _____ | | (enable), | NOT_| - (ok) | | | WORD| | | (input parameter I1), |I1 Q| - (output parameter Q) | | | | | | |_____|
Parameters Parameter
Description enable
When the function is enabled, the operation is performed.
I1
I1 contains the constant or reference for the word to be negated.
ok
The ok output is energized whenever enable is energized.
Q
Output Q contains the NOT (negation) of I1.
Valid Memory Types Parameter flow enable
•
%I
%Q
%M
%T
%S
%G
%R
•
•
•
•
•
•
•
I1 ok
•
• none
•
•
•
Q •
%AI %AQ const
•
•
•
•
•†
•
Valid reference or place where power may flow through the function. †
•
•
•
%SA, %SB, or %SC only; %S cannot be used.
Example In the following example, whenever input %I0001 is set, the bit string represented by the nickname NOTCAT is set to the inverse of bit string CAT, as seen in the truth table below. | _____ |%I0001 | | | - - | | - - - | NOT_| - | | WORD| | | | | CAT, |I1 Q| - NOTCAT | | | | | | | | | | |_____| |
CAT NOTCAT
GFK-0467M
1 0
1 0
0 1
1 0
Chapter 8 Bit Operation Functions
0 1
1 0
0 1
0 1
1 0
1 0
0 1
1 0
0 1
0 1
0 1
1 0
8-7
Page 135
8
SHL and SHR (WORD) The Shift Left (SHL) function is used to shift all the bits in a word or group of words to the left by a specified number of places. When the shift occurs, the specified number of bits is shifted out of the output string to the left. As bits are shifted out of the high end of the string, the same number of bits is shifted in at the low end. MSB B2 ← 1
1
LSB 0
1
1
1
1
1
1
1
0
0
1
0
0
0 ←B1
The Shift Right (SHR) function is used to shift all the bits in a word or group of words a specified number of places to the right. When the shift occurs, the specified number of bits is shifted out of the output string to the right. As bits are shifted out of the low end of the string, the same number of bits is shifted in at the high end. MSB B1 → 1
1
LSB 0
1
1
1
1
1
1
1
0
0
1
0
0
0 →B2
A string length of 1 to 256 words can be selected for either function. If the number of bits to be shifted (N) is greater than the number of bits in the array (LEN) * 16, or if the number of bits to be shifted is zero, then the array (Q) is filled with copies of the input bit (B1), and the input bit is copied to the B2 output. If the number of bits to be shifted is zero, then no shifting is performed; the input array is copied into the output array; and input bit B1 is copied to the B2 output. The bits being shifted into the beginning of the string are specified via input parameter B1, which requires a contact to the power rail. If a length greater than 1 has been specified as the number of bits to be shifted, each of the bits is filled with the same value (0 or 1) of B1. The B1 input can be controlled by •
An ALW_ON (%S07) contact, which holds B1 permanently at logic 1.
•
An ALW_OFF (%S06) contact, which holds B1 permanently at logic 0.
•
A contact from an internal coil such as %M or %Q that lets you change the value.
• A %I contact that lets you change the value from an input contact. The SHL or SHR function passes power flow to the right, unless the number of bits specified to be shifted is zero. Output Q is the shifted copy of the input string. If you want the input string to be shifted, the output parameter Q must use the same memory location as the input parameter IN. The SHL/SHR instructions execute each scan that their enable input is on. Output B2 holds the value of the last bit shifted out; for example, if four bits were shifted, B2 would contain be the value (either 1 or 0) of the fourth bit shifted out. _____ | | (enable), | SHL_| | | | WORD| | | (words to be shifted) |IN B2| - (last bit shifted out) | LEN | |00001| | | | | (number of bits), |N Q| - (output parameter Q) | | (bit shifted in), |B1 | |_____|
8-8
Series 90™-30/20/Micro PLC CPU Instruction Set Reference Manual – May 2002
GFK-0467M