Logix 5000 instruction or method to clear / 0 out an array of bits

look at BTD instruction
the following is From 5000 Instruction Manual
Description:

When enabled, the BTD instruction copies a group of bits from the Source to the Destination. The group of bits is identified by the Source bit (lowest bit number of the group) and the Length (number of bits to copy). The Destination bit identifies the lowest bit number bit to start with in the Destination. The Source remains unchanged. If the length of the bit field extends beyond the Destination, the instruction does not save the extra bits. Any extra bits do not wrap to the next word. If you mix integer data types, the instruction fills the upper bits of the smaller integer data types with 0s so that they are the same size as the largest data type.
 
Last edited:
Thanks. I referenced that instruction, and it does not work with bool's. In fact it does not appear that any of the move, or clr, or .. . .instructions even work with word arrays.

Kind of dissapointing.

Unless someone knows of a way.
 
Second cwal61's suggestion. In logic you can do indirect, using '[]' to make it kind of like an array. If you don't alias the bit then you'll have to type int the bit number yourself from Factorytalk for a display reference.
 
If you have to use BOOL arrays, (you've already discovered they are pretty unfriendly!), there is a way out of your dilemma, but it will require some careful thought, re-coding, and re-testing !!!!

Make a UDT (User-Defined Data-Type) with one element of data-type BOOL[xxx], where xxx is the size of your BOOL array. Let's say you call the UDT "BOOLARRAY"

Re-create the tags you have as data-type BOOL[xxx], to make them of data-type BOOLARRAY.

Now your BOOL arrays are embedded in a "structure", and structures can be copied and filled using COP and FLL instructions.

To reset your BOOL array, (let's say the tag is called MyData), simply fill the structure with 0, with a length of 1 (1 element, your embedded BOOL array) .....

FLL 0 MyData 1


For future reference, avoid BOOL arrays, but if you have to use them make the BOOL array part of a structured tag by creating a UDT.
 
Don't need to use a bool array. I understand your technique here, thanks for that.

Perhaps you can comment on the lack of any instructions in this product that allow you to do anything with arrays, bool or word, other that shifting.

To me its a Logic 500 instruction set inside a Logic 5000 which allows arrays, and tag names . ... .

Does Rockwell add instructions ever for 5000?
 
All of the "old faithful" SLC/PLC file handling instructions are present in Logix5000, like FSC, FAL etc.

Plus there are others like SRT, AVG, etc.

But Logix5000 arrays are more than just SLC "data-tables".

For instance you can make arrays of any data-type, including UDTs, and you can have (up to) 3-dimensional arrays.
 
A Boolean is not the same thing as a B data type and you need to stop thinking of them as the same thing. The SLC B data is really just an integer and for all intensive purposes is the same as N data and in fact the two can be used interchangeably. N data can be used as bits and you can do math on B words. For the ControlLogix Boolean memory is allocated differently by the compiler and word instructions don't work on it. The compiler allocates a full 32 bit word for a stand alone boolean but it still may contain only boolean information and so word level instructions are not allowed. When you create an array the memory allocation is word optimized but the data type remains the same, meaning you may not use word level instruction on it.



If your array is small then a brute force unlatch is the simplest and fastest.

CLEAR A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7]
--] [-----(U)---(U)---(U)---(U)---(U)---(U)---(U)---(U)---



For larger arrays you may want to use a for/next loop to clear the array or define a UDT as Daba described.

If you want to name the bits so that you can access them by word or as a named bit you can create a bit overlay. A bit overlay is an advanced topic and once you create it you cannot redefine it or modify it, but if you are interested there are some forum threads you can search for on how to do it.
 
Last edited:
If you have to use BOOL arrays, (you've already discovered they are pretty unfriendly!), there is a way out of your dilemma, but it will require some careful thought, re-coding, and re-testing !!!!

Make a UDT (User-Defined Data-Type) with one element of data-type BOOL[xxx], where xxx is the size of your BOOL array. Let's say you call the UDT "BOOLARRAY"

Re-create the tags you have as data-type BOOL[xxx], to make them of data-type BOOLARRAY.

Now your BOOL arrays are embedded in a "structure", and structures can be copied and filled using COP and FLL instructions.

To reset your BOOL array, (let's say the tag is called MyData), simply fill the structure with 0, with a length of 1 (1 element, your embedded BOOL array)
.....

FLL 0 MyData 1


For future reference, avoid BOOL arrays, but if you have to use them make the BOOL array part of a structured tag by creating a UDT.

To be pedantic, and for clarity, i made a few typos in the post above. What i should have said was....

Now your BOOL arrays are embedded in a "structure", and elements of structures can be copied and filled using COP and FLL instructions.

To reset your BOOL array, (let's say the BOOL Array element is called MyData), simply fill the element with 0, with a length of 1 (1 element, your embedded BOOL array)
 
Might be a dumb question but, what is the difference between a BOOL[32] and a single DINT? For whatever reason I have always used the DINT addressed at a bit level and never thought about using a Bool[32]. I had a coworker that was using a Bool[32] for a one shot array. I have always used the DINT. Would they consume the same amount of memory?

Sorry, I hope I am not highjacking the thread...
 
Other logical and math operations on BOOL arrays are possible by COPying them into suitably sized DINT arrays, doing the operations on the DINT arrays, then COPying the modified data back. COP doesn't worry about data-type, it is simply a bit-copier, so each 32 bits of your BOOL array will lay into successive 32-bit words of the DINT array.

Just remember that the Length specified in the COP instruction is the number of elements of the destination tag.

Be careful with this. Instructions that address array tags will not go beyond the destination tag boundaries, but if the destination is a member of a structure, a bad Length parameter will cause following members of a structured tag to be stomped on. Ask if you want to see a practical example of this.

It all gets messy, but a lot can be done this way.
 
Might be a dumb question but, what is the difference between a BOOL[32] and a single DINT? For whatever reason I have always used the DINT addressed at a bit level and never thought about using a Bool[32]. I had a coworker that was using a Bool[32] for a one shot array. I have always used the DINT. Would they consume the same amount of memory?

Sorry, I hope I am not highjacking the thread...

Its a perfectly legitimate question.

I usually define a Boolean array called OneShots[64] in my projects. But I only use that for one shot storage bits. For most other Booleans I prefer to use stand alone tags. I've never had a memory limitation problem from doing that and a boolean tag named Process_Ready is a lot more clear than B[19].

Boolean arrays should be defined in 32 bit chunks (In fact I think if you try to make it smaller the compiler will change it for you). Bool[32] and a single Dint will occupy the same space in memory. However they are fundamentally different kinds of data as far as the compiler is concerned and that affects how you can use them. If you ever want to use any math instructions or bitwise manipulation instructions that work on words (eg, CLR, AND, NOT, XOR, ADD, SUB, etc) then use a DINT instead of Bool[32].
 
Last edited:

Similar Topics

In studio 5000, is there a way to write a force mask into a rung? Long story short, I would like to create a test routine for a FAT test. In...
Replies
7
Views
1,238
Hey guys, thanks for taking the time to look into my question. I'm building a system to monitor several other systems for faults and one of the...
Replies
17
Views
4,608
I"m trying to average an array of DINT's called FIFO_ARRAY. It has 1000 elements in it. Here is what I have entered into the AVE instruction...
Replies
11
Views
4,646
I have a RS Logix 5000 program that i feel was poorly structured and I'm trying to make the best of it. There is a series of approx 40 tags with...
Replies
8
Views
1,777
Good morning everyone. I am apparently confused on the COP instruction. What I am trying to do is copy a DINT to a DINT in a User Defined Data...
Replies
16
Views
6,785
Back
Top Bottom