Boolean to DINT

gimli

Member
Join Date
Nov 2014
Location
nowhere
Posts
34
Hello all,

Pretty new at this...using logix 5000.

What i would like to do is move an boolean array to an integer array and add the values in that integer array.

So setting up for example Array1 bool[32] and array2 dint[32]
I want to move the values from bool to dint so I can do an addition.

Not sure if this is possible or the best way.

Any advise would be great!

thanks!
 
Hello all,

Pretty new at this...using logix 5000.

What i would like to do is move an boolean array to an integer array and add the values in that integer array.

So setting up for example Array1 bool[32] and array2 dint[32]
I want to move the values from bool to dint so I can do an addition.

Not sure if this is possible or the best way.

Any advise would be great!

thanks!

A little more information would be needed.

What "addition" are you needing ?

Do you want to know how many of your BOOL array bits are on ?
 
There are several methods, some involving "bit-hacks", but the biggest problem is that BOOL arrays in Logix5000 are just so unfriendly to w work with, and you can't easily copy them into DINTs for processing, without re-working of the BOOL array to be part of a UDT.

However, you can easily use a FOR instruction, and a separate routine called by the FOR, to "add-up" the number of bits that are "on".

Here's a working example :- the first rung goes in your normally scanned logic.....

The second rung is the routine called by the FOR. Do not put a JSR to this routine, the FOR does the calling n times, as programmed.

All the tags are DINTs (obviously with the exception of the BOOL Array and the Counter).

2018-02-22_161505.jpg 2018-02-22_161536.jpg
 
Cool...thanks for the great info...ill give it a try..see If I can get it to work!

Just make sure your FOR Initial and Terminal values are correct for the BOOL Array size, eg 0-31 for a 32-bit array, 0-127 for a 128-bit array and so on.

The other thing to know is that when you create a BOOL array, it "snaps" to the next highest 32-bit size, so if you try to create an array tag as BOOL[50], it will be entered as BOOL[64] : BOOL[16] will be created as BOOL[32] etc. Just use whatever size you want, and ignore the "extras".
 
If you're more familiar with PLC5 / SLC addressing, you might be thinking of a BOOL array as something equivalent to B3/x, where x is the bit number in B3. An indirect address of B3/[N7:0] makes for a pointer to a specific bit.

But 'B' files are actual integer arrays, addressable at the bit level, and can also be manipulated at the word level.

In ControlLogix, BOOL arrays don't work the same way as 'B' files. But you can reference bits in a DINT array by bit number higher than 31.

From the Studio/Logix help file:

MyArray defined as DINT[100]
MyIndex defined as DINT
MyArray[(MyIndex AND NOT 31) / 32].[MyIndex AND 31]
This example references a bit within a DINT array.

To do what your post asks, you can do something like:

XIC(MyBoolArray[MyIndex], OTE(MyDINTArray[(MyIndex AND NOT 31) / 32].[MyIndex AND 31])

so that MyBoolArray[55] drives bit 55 in MyDINTArray, e.g., MyDINTArray[1].23
 
Thanks for the help!

Cant seem to figure out what the Bool_Array[bitindex] XIC is
supposed to be set up as...
 
Thanks for the help!

Cant seem to figure out what the Bool_Array[bitindex] XIC is
supposed to be set up as...

I had assumed you already had your BOOL array - i.e. a tag of data-type BOOL[nn], where nn is the size of the BOOL array.

BOOL_Array[BitIndex] is an indirect address to element BitIndex of the BOOL Array.

BitIndex is the looping variable in the FOR instruction, which executes the counting routine (in my example) 32 times, after each execution of the counting routine, BitIndex is incremented so it goes from 0 to 31, then the FOR instruction stops executing. Each successive execution of the counting routine looks at successive bits in BOOL_Array.

You will notice if you run this code that BitIndex is 32 for most of the time, and can often appear static at that value on your screen due to the cyclic access time of the programming software. Do not be concerned about this, it has just incremented past the termination value of the FOR loop, so BOOL_Array[32] never gets addresssed, which is a good thing, as it would fault the controller with an "Array Subscript out of Bounds" major error.
 
Ahh ok got to work!!! Very sharp!

thanks for all the help!

Glad you got it working....

In the future steer clear of BOOL arrays - as I said they are not much use because you can't do a fat lot with them.

If you REALLY MUST use a BOOL array for any reason, make it a member of a User-Defined Data-Type (UDT).

Then it is possible to COPy it to a DINT tag or array for processing. It gets messy with length specifications etc., but it is do-able

2018-02-22_182212.jpg 2018-02-22_182503.jpg
 
Last edited:

Similar Topics

I was just curious if there is a way to search for a description of a boolean contained within a DINT/INT. For instance, I have a DINT[1] named...
Replies
6
Views
2,244
Hi All, I cannot seem to find a way to move a Boolean from an Arrays UDT into a DINT. I have an Array of 32 elements with a UDT data type of 4...
Replies
3
Views
1,720
The software: RSLogix5000 + Graphworx32 by Iconics + Iconics Unified Data Browser + Applicom OPC Server I need to have my HMI software...
Replies
4
Views
3,110
Hi. I haven't touched an Allen Bradley PLC for more than 10 years and I'm kind of rusty. I want to do something really simple in a FBD section...
Replies
5
Views
803
All, i nto fully get it. I read trough some froums but not finaly make it running. so I try to ask. Hopefully anybody has the kindness to answers...
Replies
7
Views
1,168
Back
Top Bottom