For the last day or so I have been reading on here about how to discover what bit is true in an integer. Most of the info is from Peter Nachtwey.
My application requires me to find the least significant bit in a 32 bit DINT on the ControlLogix platform. I don't usually need to do this type of operation so I looked on here and found that RSLogix 500 had the ENC instruction. Unfortunately CLX does not have this. I found much information on here about how to find the bit using log if you only had one bit on at a time. What I'm doing may have many bits on at a time so this didn't work. I also wanted to avoid using a loop.
To accomplish this I used the FSC instruction. I then made a map (using many rungs unfortunately) to map my DINT's bits to a DINT array using MOV instructions. I then made a second DINT with the value of 1 that the FSC will use to compare.
The FSC stops when it finds a match (the first 1 in the array) and the .POS is the bit place value. This is the least significant bit. If you want to keep searching the array you just unlatch .IN and it will find the position of the next true bit. To only search for the LSB just CLR the .POS and reset the control bits for the FSC.
By stepping through the search you should also be able to find the most significant bit by paying attention to the .DN bit of the FSC.
I have a few questions.
What other methods are there to find the LSB in ControlLogix?
Is there a better way to map a DINT's bits to an array?
My application requires me to find the least significant bit in a 32 bit DINT on the ControlLogix platform. I don't usually need to do this type of operation so I looked on here and found that RSLogix 500 had the ENC instruction. Unfortunately CLX does not have this. I found much information on here about how to find the bit using log if you only had one bit on at a time. What I'm doing may have many bits on at a time so this didn't work. I also wanted to avoid using a loop.
To accomplish this I used the FSC instruction. I then made a map (using many rungs unfortunately) to map my DINT's bits to a DINT array using MOV instructions. I then made a second DINT with the value of 1 that the FSC will use to compare.
The FSC stops when it finds a match (the first 1 in the array) and the .POS is the bit place value. This is the least significant bit. If you want to keep searching the array you just unlatch .IN and it will find the position of the next true bit. To only search for the LSB just CLR the .POS and reset the control bits for the FSC.
By stepping through the search you should also be able to find the most significant bit by paying attention to the .DN bit of the FSC.
I have a few questions.
What other methods are there to find the LSB in ControlLogix?
Is there a better way to map a DINT's bits to an array?
Last edited: