CompacLogix Array Sorting

R

Thread Starter

Rene Venter

Hi all.

I have an application where I have 10 mixers which can be operated manually or automatically. Every time a mix has been made (either in auto or manual mode) that mixer's counter will increment, so that you can see exactly how many mixes have been made in each mixer. As soon as you switch to auto mode, the mixer that has been used the least, should be flagged as the next one to be used. How do I do that with RS Logix 5000? I have an idea that you have to use dimensions in an array, but as far as I could gather, you can only sort one dimension at a time. So if you have an array with a)Mixer Number and b)Mixer Count, how do you sort the array so that the mixer with the least amount of mixes are at the top?
 
T

Trevor Ousey

Hi Rene,

As the saying goes "there are many ways to skin a cat". Is a two dimensional array a more complex method to use? The sort function is a good function but not what I would use. As you have 10 mixers this is even simpler, have a single dimension array, i.e. MixCount[0] is the mix count for mixer 1, then use a routine that loops for ten either in ST or LAD checking for the least counts. The loop could increment on each scan and just have an update on the lowest mix count. If you use a SRT this may give you a further complication as it will not sort the array as a complete table only the single dimension of the array.

Cheers,
Trevor.
 
I don't see any reason why you need an array or to do a sort to do what you said you want to do. You have 10 mixers. Call these 1 to 10. Each of these has a count for "number of mixes". You just need to do 10 compare operations to find the lowest count. That just needs two variables - "selected mixer number" and "lowest count".

For example, initialize the "selected mixer" to 0, and "lowest count" to some arbitrary large number (e.g. 32767). Next, start with mixer 1 and compare the "number of mixes" to "lowest count". If it is less than "lowest count" then store a "1" in "selected mixer number" and "number of mixes" in "lowest count".

Repeat this for the other 9 mixers. At the end of this you should have the number of the mixer with the lowest count in the "selected mixer number" address. That should take you 10 rungs of ladder and execute in 1 scan.

If any mixer is unavailable, you just have to add an interlock to that rung to disable the compare operation for that mixer. If you end up with an invalid mixer number (e.g. "0"), then none of the mixers are available.
 
R
I have tried this and it works like a dream. Thanks for the help. Sometimes you just need someone to set your thinking in another direction. But since we are on the subject now, is it possible to sort two-dimensional arrays in the way that I mentioned?
 
I don't know of a direct way to sort 2D arrays. If you wrote your own sort algorithm using compare and move instructions then you could do it that way of course, but that would take a fair bit of ladder code.
 
Top