Convert BOOL[32] to DINT in ladder, Allen-Bradley

CapinWinky

Member
Join Date
Aug 2011
Location
Virginia
Posts
566
I'm not a ladder or AB guy and the people asking me are using both, so this has me stumped.

Long story short, they have several arrays of BOOL[32] and in most case want to simply see if all of them are false, but in at least one case, they want to see if the first 12 are true and don't care about the rest.

Unless I want to create lots of 32 high rungs I need to find a clean way to do this. COP doesn't allow BOOL or BOOL[] input or I'd just use that; NEQ requires the the datatypes to match and might not accept arrays. I've also found that AOIs and subroutines don't allow arrays as inputs.

Maybe there is a way to change from

Code:
MyBOOL[MyIndex]
to
Code:
MyDINT.MyIndex

?
 
I convinced them to let me make an ST subroutine and just did this:

Code:
        CheckBOOL:=	0;
	FOR i:=0 TO 32 DO
		IF(MyBOOLs[i]) THEN
			CheckBOOL:=	1;
		END_IF;
	END_FOR;

But I'd be very interested to know of a ladder based solution that does not involve a 32 line high rung.
 
Check out the BTD (Bit distribute) tool. I've used this to move an array of BOOLs into a DINT before.
 
Example:

Source: BOOL[0]
Source Bit: 0
Dest: INT[0]
Dest Bit: 0
Length: 16

Will copy bits 0-15 from BOOL[0] and place them into INT[0] starting at bit 0
 
BTD doesn't accept BOOL or BOOL[] as a source.

Error: Rung #, BTD, Operand 0: Invalid data type. Argument must match parameter data type.

EDIT: This is what I've run into with everything. There seems to be no way to move data from an array of BOOL to an integer besides one bit at a time. Also, a side effect of AB not allowing the use of pointers is that there is no way just move the memory area or recast it.
 
Last edited:
Could you try a COP instruction? COP BOOL[0] DINT 1

*** Nevermind. COP instruction doesn't play nice with BOOL arrays either.
 
Last edited:
I would just make an AOI.

Input the bool array, brute force 32 rungs, output the DINT. Then you can use that instruction where you need it, write it in ladder one time.
 
BTD doesn't accept BOOL or BOOL[] as a source.

Error: Rung #, BTD, Operand 0: Invalid data type. Argument must match parameter data type.

Completely spaced when I was testing this and used an array of INTs with the name "B3[1]" from a converted project and just assumed they were BOOLs haha. Sorry!
 
I really think long and hard about using a Bool array. And I usually decide to do something else. It's an odd construct with limited uses. I'm not saying it isn't useful at all, but that it's rarely the best choice.
 
It's an odd construct with limited uses.

Hear, hear.

I use it sometimes as a place to store one-shot flags for a limited scope routine, or if there's a reason for me to index through a for/next look that works better with boolean instructions.

But I've seen it used for curious purposes too; an array of BOOL[x,32] sounds like somebody was reflexively trying to be memory-efficient.

I sometimes have to coax my junior engineers to do brute-force routines in logic. I pull the grumpy old man card fairly often, but try hard to include a pizza-and-beer meeting at the end of those workweeks.

Speaking of which, the bierstube opens in twenty minutes....
 
At the end of the day, brute force works.
It doesn't have to be elegant, it doesn't have to be pretty.
It does have to work and it really helps if it's easy to understand too.

Something that seems to bother people is using a lot of rungs.
It's OK, they don't cost extra and they will usually run faster than a for-next loop.
They will certainly be easier to troubleshoot than a for-next loop.

Of course there are limits and for-next loops are *good* things after all.
 

Similar Topics

I need to iterate though the bits in a DINT, but it seems you can't indirectly address a DINT at the bit level..... So my next thought was...
Replies
9
Views
3,418
Hello all, I'm currently working on a servo motor linear positioning system (ball screw). I'm all set up regarding communication between my HMI...
Replies
1
Views
80
I have an application using an incremental encoder and then I convert it to degree (0-360) using calculation program. For a while, the calculation...
Replies
7
Views
232
Hi all. Me again still learning Rockwell. So I'll be polling an INT data array from a Modbus SE power meter with a L82 (with a Modbus ProSoft in...
Replies
56
Views
1,341
Hello, could someone kindly convert the attached RSP files that are currently used for SLC 5 PLC into PDF please
Replies
6
Views
517
Back
Top Bottom