Array in ControlLogix PLC


Thread Starter


How can I find how many elements in an array in ControlLogix PLC are greater than zero?

I have a one dimensional array of 500 elements.

James Ingraham

Unfortunately, there is no easy way to do this. You have to do it the old fashioned way; loop through each element and check it. You could loop once per scan with a counter, but that could take awhile for 500 elements. Or you use a FOR instruction, which is like a JSR but is executed repeatedly and uses a loop counter variable.

William Sturm

I have not done this, but a For Loop in a separate task would seem to be a good approach. The separate task will keep the For Loop from messing up your main tasks update rate.

David Ferguson

What are you trying to find out? Do you want to find out after some test or are you actually using that number and calc for something in logic?

If gathering data, I usually pull the live array data into excel offhand I think the OPC formula is is RSLinx help or I if you go in Linx there is a place to copy and paste it (I could help you if this is what you are after).

I then put a formula to count greater than zero or use conditional formatting to color the zero can do all kinds of thing once it's in excel.

Dave Ferguson
Control Systems Engineer

Sent from my iPhone
Thanks guys for all the helpful suggestions.

It is always so easy when you have figured out the solution and it works :).

I used a decrementing pointer to the array location and a compare instruction which increments a count every time it is true.
Works great.

Thanks again.

Burhan Qadri.

James Ingraham

"...FSC instruction..."

Good point. I had forgotten that FSC could be used to find multiple values. Normally, it will find the FIRST value for you, but it then sets the .IN bit high. If you clear the .IN, it will find the next value, and so on. So it's not QUITE as easy as the example on page 360; you'll have to add some logic to handle the .IN bit coming on. This is only one rung:

XIC testFSC.IN CTU testCount 0 0 OTU testFSC.IN

You can paste that straight in to RSLogix, but basically it says examine If Closed on the .IN bit, count up and unlatch .IN. (An ADD instruction would work just as well in this case.)

After looking at it, I feel pretty strongly that the FSC is the best solution. Probably the best argument is that it's a documented command. (Albeit somewhat poorly documented.) Second, it can split the difference between all-at-once and and one-index-per-scan. The "Mode" parameter can be "all" or "inc" for those two options, or you can type in a number not to exceed in one scan. For length 500, you probably don't need this. For big arrays, you have the option. Third, I've never liked FOR loops because they require you to create a JSR, which in this case would be one rung.

-James Ingraham
Sage Automation, Inc.