Attached to the following technote is a DCD Add On Instruction...
42004 - How to implement RSLogix 500 DCD and ENC instructions in RSLogix 5000
Access Level: Everyone
It uses several Mask Equal To (MEQ) instructions...
Each instruction takes the same user-defined Source value and a pre-defined Compare value and passes both of them through the same mask value and then evaluates the two results for a match. A pre-defined hex mask of 16#F ((2#1111) is used in each instruction so only the first 4 bits, or first nibble, of the Source and Compare values are passed through the mask for evaluation.
There are 16 instructions on separate rungs. This is because there are 16 possible permutations for the 4 bit nibble (0000 - 1111). The MEQ instructions have uniquely pre-defined binary Compare values from 2#0 - 2#1111.
Each rung also has a Move (MOV) instruction after each MEQ instruction. A user-defined Destination is selected and is used for all the MOV instructions. The MOV instructions have pre-defined Source values from 2#1 - 2#1000000000000000 to represent the 16 x bit positions in the destination integer.
The MEQ instruction that matches its Source and Compare nibbles, via the mask, will be evaluated TRUE and so will execute its MOV instruction. This will place a 1 in the equivalent bit position in the destination integer.
Example:
MEQ on rung 12...
Source = 12 =2#0000 0000 0000 1100 ("TagSource" - tag for AOI)
_Mask = 15 = 2#0000 0000 0000 1111 (Entered as hex 16#F)
Compare=12= 2#0000 0000 0000 1100 (Displays as 2#1100)
Source = Compare, instruction evaluates TRUE.
MOV on rung 12 is executed...
Source = 2#0001 0000 0000 0000 (Displays as 2#1000000000000)
Destination = 0001 0000 0000 0000 (Bit 12 in "TagDest" is set; displays as 4096)
This AOI is just an example using a 16-bit INT as the destination data type. You can of course roll your own and use a SINT or DINT as the destination. You could, for instance, compare all 32 bits of a Source DINT (mask 16#FFFFFFFF) and set any one of 32 bits in a destination DINT.
Regards,
George