How to reference a DINT in RSLogix 5000?

Well, knowing the details of what you are doing and why you are doing it would be helpful. You may be using the wrong tool for the job.

Whatever is determining when/why you are indirectly switching between Bool[3] and Bool[4] needs to be limited to the values of 3 and 4.

What may make more sense is something like:

Code:
BST XIC Condition XIC Bool[3] NXB XIO Condition XIC Bool[4] BND OTE DoSomething

If you are unfamiliar with what I posted above, add a new rung and double click the rung number. This a text box that gives you the text version of the rung, you can paste what I have above there to construct the rung. The tags won't exist, but you will be able to see the psudo-code a san actual rung.
I'm trying to program a battleship game. If I press PB[0] (Spot A1), the square behind it, A[0] turns grey symbolizing a ship. I currently have this and I'm still getting a fault. BST XIC PB[0]-[127] MOV 1 A[0]-[127] NXB XIO PB[0]-[127] MOV 0 A[0]-[127] BND
 
Well, knowing the details of what you are doing and why you are doing it would be helpful. You may be using the wrong tool for the job.

Whatever is determining when/why you are indirectly switching between Bool[3] and Bool[4] needs to be limited to the values of 3 and 4.

What may make more sense is something like:

Code:
BST XIC Condition XIC Bool[3] NXB XIO Condition XIC Bool[4] BND OTE DoSomething

If you are unfamiliar with what I posted above, add a new rung and double click the rung number. This a text box that gives you the text version of the rung, you can paste what I have above there to construct the rung. The tags won't exist, but you will be able to see the psudo-code a san actual rung.
I'm trying to make it to where BST XIC PB[Index1] MOV 1 A[Index1] NXB XIO PB[Index1] MOV 0 A[Index1] BND, but I'm not sure how to change Index1 to the wanted DINT
 
If you want to use indirection to handle this logic, you probably need to set up a loop to increment the index and perform the needed rungs of logic on all of the possible elements of the array every PLC scan.

You can do this with a FOR loop or with your own implementation using JMP and LBL instructions or you could invoke an AOI with 128 instances.

The advantage to writing a program like this is that you can create a program that does a lot with very little effort.

The disadvantages are that it will be harder to make one of the elements of your array behavior unique if that becomes a requirement and that it will be harder to monitor the status of any one instance of the logic.
 

CLR A[Index1] XIC PB[Index1] OTE A[Index1].0
ADD Index1 1 Index1 AND Index1 127 Index1


Caveats

  • I am not sure how to address bits in array elements of DINTs in RSLogix5k; I know it's /0 in RSL5h, and that .0 suffix is my best guess.
  • That code, and the other code proposed by OP, will assign a 0 to the value of A[Index1] when PB[Index1] is released.
  • That code, as written, will handle one PB per program scan, so it will take 128 scans, probably a tenth of a second, to process all PBs, so some PB presses might be missed.
 
DrBitBoy's pseudocode would write ones to the correct bits when the button being examined is pressed, but would not write zeroes to the correct bits when the button is not pressed and would not affect any of the other bits within the array of bits. You could do it to the bit level of the DINTs by using OTL and OTU instructions which is just about as straightforward as this example which writes to all the bits in each of the DINTs (not sure if that is desirable or not):

EDIT: strike some of what I corrected in later post.

This example is not as concise as DrBitBoy's version.

indirect.png
 
Last edited:
Okay, I will be sure to get back to you as soon as I can. Also, for the A[Index1] moving to 0 after releasing the PB, I have all of the buttons set as maintained push buttons so they only change states when they’re pressed. And for the last caveat, this is not going to be applied in any real world situation and I’m only pressing one button at a time so that really shouldn’t be an issue.
 
Building on @OkiePC's example a bit:

CLR Index1 FLL 0 A 128
LBL loop LES Index1 128 XIC PB[Index1] A[Index1].0 ADD Index1 1 Index1 JMP loop



See also the FAL instruction cf. this link.

Finally, if this code is executed every scan, A must always be either 0 or 1, so A could just as easily be an array of BOOLs, no?
 
Okay, I will be sure to get back to you as soon as I can. Also, for the A[Index1] moving to 0 after releasing the PB, I have all of the buttons set as maintained push buttons so they only change states when they’re pressed.

Thinking this through:
PB[1] is pressed becoming = 1.

The PLC scans Index1 = 1, finds that PB[1] is true and so A[1] is now set to 1
PB[1] is pressed again becoming =0.

The PLC scans Index1 = 1, finds that PB[1] = 0 and successfully writes a 0 to A[Index1].0

So DrBitBoy's code would work properly even if those buttons are momentary since the OTE is always destructive even when the preceding conditions are false.
 
  • I am not sure how to address bits in array elements of DINTs in RSLogix5k; I know it's /0 in RSL5h, and that .0 suffix is my best guess.
Good guess, .0 will indeed address the first (least significant) bit of a DINT.

In 5k the . delimiter is used for essentially all parts of tags, regardless of the data type. About the only other delimiter I can think of is : used in system-generated module tags.

EDIT: Actually the : isn't a delimiter as the program considers it even then, it's actually part of the tag name.

Finally, if this code is executed every scan, A must always be either 0 or 1, so A could just as easily be an array of BOOLs, no?
Indeed. I am guessing A tracks the state of a tile, with individual bits indicating 'contains (part of) a ship' and 'has been fired on'. Would make colouring the tiles straightforward.
 
Last edited:
Specifying Bits with Arrays

There's a technique that's actually in the RSLogix Help files that may do what you want.

Back in the PLC5/SLC days, we could reference a B3 address either by Word/Bit (B3:2.5) or by straight bit (B3/37). Very handy when you had alarms number 37, and you wanted to reference bit 37.

But short of BOOL arrays (ugh!), you can't do that in RSLogix. Or can you?

If you create an array ("MyArray") of DInts, then bit 37 is MyArray[1].5

If you have a tag ("Pointer") with value of 37, then the following:

MyArray[(Pointer AND NOT 31) / 32].[Pointer AND 31]

will, believe it or not, reference MyArray[1].5 when you do all the bitwise math.

Change the value in Pointer to something else, and now you are referencing a different bit. And, yes, you can have an instruction XIC MyArray[(Pointer AND NOT 31) / 32].[Pointer AND 31] in a line of ladder. You can also use OTE, although I would advise against it: when Pointer changes, the OTE won't be pointing to the old register anymore. So the bit that was set when Pointer was a different value won't get reset if the OTE drops out. It's a powerful technique, but "with great power comes great irresponsibility" (which is what happens at first in all the movies).

And because you are using DInts, you can do all the bitwise logic on your array (like XOR to clear particular bits) using the FAL instruction. Or FBC which might find the first set bit in your array, to give you a value for "Pointer".

I don't know if this is the sort of thing you're looking for or not (you haven't been very clear). But it's a useful tool in the toolbelt regardless.

Cheers,
 
Last edited:

Similar Topics

Hello guys, I am new to this forum and have some problems with my PowerFlex755 EENET frequency inverter. I want to do a point to point...
Replies
9
Views
376
I have a FactoryTalk View Se project, Is it possible to export Direct Reference tags to edit in a CSV file or Excel? I know I can export HMI...
Replies
1
Views
280
Hey, I'm trying to do the following, I have some experience with Citect but can't seem to figure this out. I/O Tag: BoxPos1_ProdNum (Data Type...
Replies
0
Views
570
OK I'm ashamed that I'm here asking this as I think in 23 years I would have ran into this before. But here we are. Created an AOI to manipulate...
Replies
6
Views
1,991
Studio 5000 & PF 525, Ethernet Comms, Encoder FB, Using Motor RPM as speed reference I'm trying to figure out how to send a speed reference in...
Replies
6
Views
921
Back
Top Bottom