You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

---------->>>>>Get FREE PLC Programming Tips

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

PLC training tools sale

Reply
 
Thread Tools Display Modes
Old February 22nd, 2018, 07:34 AM   #1
gimli
Member
United States

gimli is offline
 
Join Date: Nov 2014
Location: nowhere
Posts: 16
Boolean to DINT

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!
  Reply With Quote
Old February 22nd, 2018, 07:53 AM   #2
daba
Lifetime Supporting Member + Moderator
United Kingdom

daba is offline
 
daba's Avatar
 
Join Date: Jul 2004
Location: uk
Posts: 4,375
Quote:
Originally Posted by gimli View Post
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 ?
__________________
___________________________
ControlLogix & SLC Training
a-b train ltd.
abtrain@tiscali.co.uk
www.abtrain.co.uk
tel: 07506 73 9999
nil illegitimi carborundem


  Reply With Quote
Old February 22nd, 2018, 09:28 AM   #3
gimli
Member
United States

gimli is offline
 
Join Date: Nov 2014
Location: nowhere
Posts: 16
Hi..yes...I want to count how many of the bits are on..thats correct
  Reply With Quote
Old February 22nd, 2018, 10:19 AM   #4
daba
Lifetime Supporting Member + Moderator
United Kingdom

daba is offline
 
daba's Avatar
 
Join Date: Jul 2004
Location: uk
Posts: 4,375
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).
Attached Images
File Type: jpg 2018-02-22_161505.jpg (14.2 KB, 27 views)
File Type: jpg 2018-02-22_161536.jpg (10.7 KB, 25 views)
__________________
___________________________
ControlLogix & SLC Training
a-b train ltd.
abtrain@tiscali.co.uk
www.abtrain.co.uk
tel: 07506 73 9999
nil illegitimi carborundem


  Reply With Quote
Old February 22nd, 2018, 10:48 AM   #5
gimli
Member
United States

gimli is offline
 
Join Date: Nov 2014
Location: nowhere
Posts: 16
Cool...thanks for the great info...ill give it a try..see If I can get it to work!
  Reply With Quote
Old February 22nd, 2018, 11:38 AM   #6
daba
Lifetime Supporting Member + Moderator
United Kingdom

daba is offline
 
daba's Avatar
 
Join Date: Jul 2004
Location: uk
Posts: 4,375
Quote:
Originally Posted by gimli View Post
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".
__________________
___________________________
ControlLogix & SLC Training
a-b train ltd.
abtrain@tiscali.co.uk
www.abtrain.co.uk
tel: 07506 73 9999
nil illegitimi carborundem


  Reply With Quote
Old February 22nd, 2018, 11:44 AM   #7
Aardwizz
Member
United Kingdom

Aardwizz is offline
 
Aardwizz's Avatar
 
Join Date: Dec 2017
Location: Swindon
Posts: 178
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
  Reply With Quote
Old February 22nd, 2018, 11:45 AM   #8
gimli
Member
United States

gimli is offline
 
Join Date: Nov 2014
Location: nowhere
Posts: 16
Thanks for the help!

Cant seem to figure out what the Bool_Array[bitindex] XIC is
supposed to be set up as...
  Reply With Quote
Old February 22nd, 2018, 11:56 AM   #9
gimli
Member
United States

gimli is offline
 
Join Date: Nov 2014
Location: nowhere
Posts: 16
Ahh ok got to work!!! Very sharp!

thanks for all the help!
  Reply With Quote
Old February 22nd, 2018, 12:01 PM   #10
daba
Lifetime Supporting Member + Moderator
United Kingdom

daba is offline
 
daba's Avatar
 
Join Date: Jul 2004
Location: uk
Posts: 4,375
Quote:
Originally Posted by gimli View Post
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.
__________________
___________________________
ControlLogix & SLC Training
a-b train ltd.
abtrain@tiscali.co.uk
www.abtrain.co.uk
tel: 07506 73 9999
nil illegitimi carborundem


  Reply With Quote
Old February 22nd, 2018, 12:23 PM   #11
daba
Lifetime Supporting Member + Moderator
United Kingdom

daba is offline
 
daba's Avatar
 
Join Date: Jul 2004
Location: uk
Posts: 4,375
Quote:
Originally Posted by gimli View Post
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
Attached Images
File Type: jpg 2018-02-22_182212.jpg (43.4 KB, 10 views)
File Type: jpg 2018-02-22_182503.jpg (17.5 KB, 9 views)
__________________
___________________________
ControlLogix & SLC Training
a-b train ltd.
abtrain@tiscali.co.uk
www.abtrain.co.uk
tel: 07506 73 9999
nil illegitimi carborundem



Last edited by daba; February 22nd, 2018 at 12:26 PM.
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
Problems with Boolean or DINT array and OPC hardaysknight LIVE PLC Questions And Answers 4 June 1st, 2016 06:02 AM
Siemens STL Counter TrainS7 LIVE PLC Questions And Answers 8 March 28th, 2016 01:21 PM
misunderstanding CMP MartyMaucher LIVE PLC Questions And Answers 5 November 16th, 2015 01:37 PM
Compare bits of dint to another dint value seth350 LIVE PLC Questions And Answers 7 April 3rd, 2015 02:46 AM
DINT word mapped to UDT word RSLogix5000 Tugboat LIVE PLC Questions And Answers 6 December 12th, 2011 05:57 PM


All times are GMT -5. The time now is 02:18 PM.


.