Dint bits to an array

Dariusincj

Member
Join Date
Jul 2011
Location
Missouri
Posts
43
Studio 5000 Ladder logic, i have a dint. We will call it Station. I want to see if there is a cleaner way of saying if bit .1 is true, then a dint array we will call SQOArray, SQOArray[1] = 1. If bit .2 is true the SQOArray[2] = 2. But then if bit .3 is true SQOArray[3] = 4, bit .4 is true SQOArray[4] = 8.... if you see what i'm trying to do is use my dint array in an SQO so i can sequence valves for each bit that is true. But if bit 2 is not true, then i leave it a 0. It's mostly used for a pump system. Not sure if this makes any sense. I have instructions now that if bit .1 is true then move a 1 into SQOArray[1], and so on and so forth. So that my SQOArray[0] thru [30] is equal to 0, 1, 2, 4, 8, 16...
Tell me if i'm crazy in trying to do this or if i just need to write out all the move statements.
 
You did not say what should be each SQOArray value, if the corresponding bit in Station is Off.
Zero? If yes:
XIC Station.1 OTE SQOArray[1].1
XIC Station.2 OTE SQOArray[2].2
...
XIC Station.30 OTE SQOArray[30].30

But be sure other bits in the destinations are always Off.
This may be achieved by executing FLL before the above code.
 
Last edited:
Update II: if we are only going to SQOArray[30] then use the upper construct and use 31 in the LES

Bitwise AND:

MOV 1 j MOV 0 i
LBL x MVM Station j SQOArray ADD i 1 i LES i 32 ADD j j j JMP x

That has an overflow, but the basic idea should work.

Update:

That would work with UDINTs, btw, no overflow, if the ADD j j j were moved to after the LES.

Or this

MOV 1 j MOV 0 i
LBL x MVM Station j SQOArray ADD i 1 i LES i 31 ADD j j j JMP x
MVM Station -2147483648 SQOArray[31]
 
Last edited:
drbitboy, it would be little more readable as:
MOV 1 j
MOV 0 i
LBL x
MVM -1 j SQOArray
ADD j j j
ADD i 1 i
LES i 32 JMP x

So where is the Station in this code?.
 
I intentionally did not suggest a loop, but if using it I would do:

MOV 1 i
LBL x
MOV 0 SQOArray
XIC Station. OTE SQOArray.
ADD i 1 i
LES i 31 JMP x
 
P.S. in the time it took to execute this thread you could have done the FLL/XIC brute force ten times over, and it it easier to grow the months hence. Leave the code golf to dilettantes like me.
 
Last edited:
What about FAL?
- built in loop
- ctl.POS replaces i
- maybe the "&" operator does the bitwise AND in the FAL expression?
 

Similar Topics

Logix Platform - I am looking thru some code and noticed the Original programmer had configured a Boolean array with 320 elements. Isn't this...
Replies
2
Views
3,679
Hi I am being given several fault words (as a DINT) from a Drive that I am receiving into a Compactlogix L33ER controller. I have a small...
Replies
12
Views
1,148
I am passing DINTs between a Micro800 and CompactLogix - each bit in the DINT has its own unique meaning. On the Studio5000 side I can just write...
Replies
3
Views
1,114
Hey everybody, I have a bunch of bits used for diagnostics all compiled into a couple of DINTS. I have an x-ref sheet in Excel that aligns...
Replies
8
Views
1,879
Hi I have a value stored within the first 25 bits of a DINT value and i'm wondering how to move/extract those 25 bits to another DINT? I'm...
Replies
9
Views
3,217
Back
Top Bottom