# Recursive Function with PLC Software Pumping System

Joined Sep 5, 2014
57
Hello All,

I'm trying to design a general PLC function block that can assign lead and lag order to pumps based on runtime regardless of the number of pumps. Right now, I'm listing all combinations of runtime (max, min, middle, etc.) to determine the pump assignments (Ex. the pump the runs the least is assigned to lead while the pump that runs the least becomes the lowest lag pump). Is there a way to write the PLC function block in a way that prevents me from explicitly defining all combinations of runtimes for every pump? I was thinking recursive function, but what data type would allow this (bytes, integer, boolean array) and how would I even begin thinking about it in terms of PLC logic. The bit locations would represent lag order and the runtime values are converted to integers and compared using a comparison block.

I'm using Siemens TIA Portal S7 Version 13.0 with PLC Sim Version 13.0

Could anyone please lend me a hand?

Best,

Joined Jul 18, 2013
25,461
(Ex. the pump the runs the least is assigned to lead while the pump that runs the least becomes the lowest lag pump).
I assume the second 'Least' should be 'Most'?

I would assume there is a total or fixed time period over where the various times of each pump run time would be recorded, at the end of the period then the re-assignments would take place based on the different run times until the end of the next assessment period.
Is only one pump on at any given time or does each pump come on dependent on demand?
I am not sure if this fits your requirements, also I do not use Siemens so not sure of the commands it has.
Max.

#### Papabravo

Joined Feb 24, 2006
18,777
I'm unsure what the terms lead and lag refer to. It seems like an ordered list is the data structure you want with n elements. The list can be periodically sorted according to total accumulated runtime. The function does not need to be recursive since any recursive function with a termination condition that prevents infinite regress can be converted to a loop. So it is my belief that a periodic exchange sort can do what you want it to do.

Joined Sep 5, 2014
57
I assume the second 'Least' should be 'Most'?

I would assume there is a total or fixed time period over where the various times of each pump run time would be recorded, at the end of the period then the re-assignments would take place based on the different run times until the end of the next assessment period.
Is only one pump on at any given time or does each pump come on dependent on demand?
I am not sure if this fits your requirements, also I do not use Siemens so not sure of the commands it has.
Max.

I would be grateful if you could spare any insight that might help me come closer to solving this problem.

Best,

Joined Sep 5, 2014
57
I'm unsure what the terms lead and lag refer to. It seems like an ordered list is the data structure you want with n elements. The list can be periodically sorted according to total accumulated runtime. The function does not need to be recursive since any recursive function with a termination condition that prevents infinite regress can be converted to a loop. So it is my belief that a periodic exchange sort can do what you want it to do.
That sounds like an idea, but the pumps are only ordered by runtime when the operator presses a button and that may only happen once per month. I'll look into it though. Thank you!

#### BR-549

Joined Sep 22, 2013
4,928
I am no expert, but I did sleep at a Holiday Inn Express last nite.

Your descriptions make no sense to me.

Are you trying to control a process parameter?, such as pressure or flow?

Or are you trying to control pump run times?

Why are you adjusting turn on delay for next pump, based on pump position in pump turn on list(lag list)? What does this accomplish?

When the pressure is below the band, you will turn on 1 more pump, after a calculated delay, but when you get a bump in pressure that turns the lead off, why are you turning all the other pumps off and resetting?

A pump's accumulated runtime will always put it in order, relative to the other pumps.

Sometimes you can use an event to equalize runtimes. For instance, a tank that is pumped out at a predetermined level to another predetermined level. Alternating the pump with the event will insure equal runtimes.

Runtimes are usually used to schedule maintenance. Depending on your production schedule, you might not want to PM all the pumps at the same time.

Maybe I am missing something, but it seems a most unusual control strategy.

Are you getting relatively equal runtimes with your present setup?