There's no single function to do what you want (well.... maybe), in part because what you want may not be what you really want.
First off, how are the "run-meter"s stored in the PLC? Are they a group of integers (ddddd:hh:mm) or a single float ddddd.dddddddd ? If the latter, then loading all the values in a UDT (CompNo,RunTime) array, using the sort (SRT) function on the RunTime dimension, and the Compressor numbers will be in the desired order. (So maybe there is actually a single instruction that can do it for you
).
EXCEPT.
What if a compressor has tripped on start? That should disqualify it from even being considered for Lead/Lagx.
Can a compressor be "Removed from Service", perhaps by a local HOA switch that the PLC can read, or maybe an HMI equivalent? That also disqualifies it.
What I usually do instead of figuring out which is "Lead" and which is "Lag1", etc., I really just want to know, "Which is the next one I should start?"
That's a fairly easy thing to determine. "Next" means:
- not currently running..
- not "out of service"
- not faulted
- Lower run-time than the next pump.
- (any other requirement that the customer has)
Each scan I initiate the "Next Pump" registers, setting PumpNo = 0, RunTimeDD = 9999999; RunTimeHH = 99 (etc.).
Then with one "identical" line of code for each pump, I check it against the above rules, and if it passes, move its pump number and RunTime(s) into the "Next Pump".
At the end of X rungs, I now have the number of who is "Next", which can be used with indirect addressing to start the thing
when the next is needed.
While it is trying to start, it is not "running", so it stays "Next". If it fails, that disqualifies it from being "next" and the next "next" jumps to the front of the line. If it goes to running, that also removes itself from the list, but also resets the "NeedToStartNextPump" bit as well, so the new "Next" doesn't start.
For some systems, I only ever want one and only one pump On at a time. For others, there may be a "demand curve" that requires running one, two, or more pumps. The "NeedToStartNextPump" logic is the only difference.
HTH
õ¿õ¬