# 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,778
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.
Thank you for the reply! The pump with the highest runtime becomes lag n-1 (n=number of pumps), and the pump with the lowest runtime becomes lead. When the lead pump is switched to automatic mode, it stays on at all times, unless the pressure exceeds the control band by a significant amount. If the lead is placed in automatic mode and it happens to be stopped while other pumps are running, the pumps that are running are turned off, the lead is turned on, and the automatic sequence resets itself. If the pressure is below the control band for a specific delay time, the next pump turns on. The operator can choose which pump is lead, lag1, and lag2....etc and the PLC checks if the selection is valid or not. The way I have it set up now involves explicitly defining the the delay time for each pump based on whether its lead, lag1, or lag2. I also have make sure that pump 1 receives feedback to start or stop from pump 2 and pump 3 in case pump 1 is lead. If pump 2 is lead, then pump 2 receives feedback form pump 1 and pump 3. The pumps I'm working with right now have only 1 speed, so this configuration works in this case. However, I will soon be working with many more pumps and if I don't figure out a more efficient way to design the program, I won't be able to reuse the function blocks to add additional pumps.

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?