Newbie programming question

kallileo

Lifetime Supporting Member
Join Date
Jun 2008
Location
Thessaloniki, Macedonia, Hellas
Posts
353
I have a water tank and I use two water pumps that to pump the water out of the tank. When the water in the tank reaches the float sensor Pump A starts working. Until now the program is pretty easy even for a beginner like myself.

The problem is that the next time the water reaches the waterlevel sensor the pump that will start working should be Pump B. So I have to find a way to start the pump that wasn't working on the previous cycle for the next cycle.

Any tip on how to program it will be appreciated....:confused:

BTW I use Twido PLC...
 
I almost made it work with 2 flip flops...Thank you.
But the real problem is a bit more complicated. There is also a second waterlevel sensor and when the water activates it both pump start working. Then when again the water level drops below the second sensor the pump which was working from the start stops and only the second pump is working until the water level drops below the first sensor and the second stops working too...

What options do I have hear?
 
One of the thing I tell new programmer is to learn to talk to the PLC, in english. You already know what you want, going directly to ladder logic is difficult for new programmer, so try to write out in pseude code as an intermediate step.

As for you problem, since both pumps needs to be running when the other sensor is triggered, it should be a simple OR branch.
 
If you know boolean logic, then you can convert your ideas into a boolean logic representation, and then transfer that to ladder logic (it makes things much easier once you have it in boolean logic, because it converts so easily to ladder logic.)
 
This sounds like a typical study type question - we don't give out homework answers here but we do help those who show effort and it looks like you have definitely tried.

First lets build a boolean truth table describing the problem. For this I will assume our tank has three level switches. One at the bottom to indicate the tank is low. We will tag this one LSL. One near the top to indicate the tank is high. We will tag this on LSH. And One at the very top to indicate the tank is over full, tagged LSHH. Last we have an alternator bit that selects which pump runs.


Here is our Table:
CONDITIONS | OUTPUTS
LSL LSH LSHH Alternator | PUMP1 PUMP2
0 0 0 - | 0 0
1 0 0 - | 0 0
1 1 0 0 | 1 0
1 1 0 1 | 0 1
1 1 1 - | 1 1
Places where we don't care about a bit state are marked with a -



From the table we can easily describe our pump logic.
Lets start with Pump 1.

CONDITIONS | OUTPUTS
LSL LSH LSHH Alternator | PUMP1 PUMP2
0 0 0 - | 0 0
1 0 0 - | 0 0
1 1 0 0 | 1 0
1 1 0 1 | 0 1
1 1 1 - | 1 1



Pump1 = (LSL AND LSH AND NOT ALTERNATOR) OR (LSL AND LSH AND LSHH)
This should be easy to convert to ladder logic. We could simplify it a little to
Pump1 - LSL AND ((LSH AND NOT ALTERNATOR) OR LSHH)

Now lets do Pump 2.

CONDITIONS | OUTPUTS
LSL LSH LSHH Alternator | PUMP1 PUMP2
0 0 0 - | 0 0
1 0 0 - | 0 0
1 1 0 0 | 1 0
1 1 0 1 | 0 1
1 1 1 - | 1 1


Pump2 = (LSL AND LSH AND ALTERNATOR) OR (LSL AND LSH AND LSHH)
Simplified:
Pump2 = LSL AND ((LSH AND ALTERNATOR) OR LSHH)

That takes care of out pump logic. Now all we need to do is program the alternator.

Lets describe it in plain words: If LSH then toggle the alternator bit. If LSHH then toggle the alternator bit again. The alternator logic has to happen first so it will be ahead of the pump logic in our program.

Since you seem to be understanding the basics of the flip flop you probably just need help combining two inputs into a single flip flop to make the alternator bit. Here is a hint: Program two different oneshots, one from each level switch. Lets tag them LSH_OS and LSHH_OS. Now combine LSH_OS and LSHH_OS to make a third bit.

Combo_OS = LSH_OS OR LSHH_OS

Now used Combined_OS to toggle the alternator bit.

I hope that helps.
 
First of all thank you for your help. Especially Alaric...
No it's not an educational problem...

Actually I only have two level switches LSL and LSH.

I believe I have two cases:

FIRST
When LSL is activated one of the pumps(lets say PUMP1) starts running. Then if it manages to do the job and the water level drops below LSL it stops and the next time the water reaches LSL the other pump(PUMP2) starts running. So we need the alternator in this case.

SECOND
Lets now assume that PUMP1 couldn't do the job and the water has reached LSH so now the second pump(PUMP2) needs to be running too. Then when the level drops below LSH on of the two should stop. Then one that will stop running is the pump that started first. Since I assumed that PUMP1 started running first it will stop and PUMP2 will continue to run until the water level drops below LSL when it will stop as well.
On the next cycle PUMP1 will start first since it rested more time than PUMP2 which stopped running last.

Now I need to build a truth table for the logic I have described above and this is my main problem.:unsure:

For the first case the table should be:

LSL LSH Alter | Pump1 Pump2
0 0 0 0
1 0 1 1 0

Second case:
LSL LSH Alter | Pump1 Pump2
0 0 0 0
1 0 1 1 0
1 1 1 1 1

Is the correct for the logic described above?:ROFLMAO:
 
Grafect sequences is the key here

this kind of application usually needs at least 2 floating cell.

1 to stop
2 to start 1 pompe

having starting and stopping on the same triger level will burn the pump very quickly if you didn't put a timer to prevent pump start from jogging too much....By using 2 float, you have a kind of bigger deadband in between

1 step waiting for flot to start pump1
2 step start pump 1 when needed
3 step waiting to start pump 2
4 start pump2

you can also add a condition to enter step 3 from step1 if pump1 fail and same to enter step 1 from 3 if pump 2 fail
 
When ALT = 0 lets define pump1 as main pump and when ALT = 1 then pump2 is the main pump. When the level rises and turns on LSL the pump alternator bit will toggle its state. Which ever pump is the main pump now starts. When the level falls so the level switch is off, and then rises again so that the level switch makes contact again then the alternator again toggles state and the other pump becomes the main pump and starts. If the level rises so that LSH makes then the state toggles again and the main pump that is running is switched to be the secondary pump and the pump that was off becomes the main pump. Note that with this definition that PUMP2 will run first when the system is started up, then they will alternate.

This isn't a truth table, its a state table that describes one possible scenario as you step down the table to show how the pumps will alternate.

LSL LSH ALT Pump1 Pump2
0 0 0 0 0 OFF
1 0 1 0 1 LSL on. Pump2 is on
0 0 1 0 0 Level drops. Pumps off
1 0 0 1 0 LSL On. Pump1 is on
1 1 1 1 1 Level is high. Both pumps on
1 0 1 0 1 LSH Off. Pump1 is off, Pump2 is on
0 0 1 0 0 Pumps are off
1 0 0 1 0 Pump1 is main and on.



I'm not a TWIDO ILL expert (disclaimer: the ILL syntax might be wrong) but I think that this will set up a pump alternator

First create a one shot that combines rising edge detection of the two float switch inputs. Substitute input number for {LSL} and {LSH}

LDR %I0.{LSL}
ORR %I0.{LSH}
ST %My

%My is internal bit number you choose to be the one shot bit that combines the rising edge of each float switch input into a single one shot pulse that toggles the flip flop that is our pump alternator.

Next set up the flip flop to give you a bit %Mz that alternates when ever the rising edge of a float occurs.
LD %My
ANDN %Mz
OR(N %My
AND %Mz
ST %Mz


In RLL it should look something like this

%I.0.{LSL} %My
---]P[------+--------( )
|
%I.0.{LSH} |
---]P[------+

%My %Mz %Mz
---] [----]/[---+----( )
|
|
%My %Mz |
---]/[----] [---+




The truth table for just two level switches is

LSL LSH ALT | Pump1 Pump2
0 0 - | 0 0
1 0 0 | 1 0
1 0 1 | 0 1
1 1 0 | 1 1
1 1 1 | 1 1



PUMP 1 IS
LSL LSH ALT | Pump1 Pump2
0 0 - | 0 0
1 0 0 | 1 0
1 0 1 | 0 1
1 1 0 | 1 1
1 1 1 | 1 1

Pump1 = (LSL AND NOT ALT) OR (LSL AND LSH AND NOT ALT) OR (LSL AND LSH AND ALT)


We can obviously simplify this.

PUMP 1 = LSL AND (NOT ALT OR LSH)

Without changing the logic function I'm going to delete the parenthesis so that its easier to program

PUMP1 = LSL AND NOT ALT OR LSH
or
LD %I.0.{LSL}
ANDN %Mz
OR %I.0.{LSH}
ST O.0.{Pump1}



LSL LSH ALT | Pump1 Pump2
0 0 - | 0 0
1 0 0 | 1 0
1 0 1 | 0 1
1 1 0 | 1 1
1 1 1 | 1 1



PUMP2 = LSL AND ALT OR LSH

I hope that helps.
 
Last edited:
Jeff makes a really good point about rapid on/off operation of the pump.

One reason I originally assumed that there would be three switches is that a three switch set up is often used to get around that. Unless the level switch has a large hysteresis band and the tank volume/pump displacement ration is very high you might find that your pumps start/stop very rapidly.
 
First of all thank you for your help. Especially Alaric...
No it's not an educational problem...

Actually I only have two level switches LSL and LSH.

I believe I have two cases:

FIRST
When LSL is activated one of the pumps(lets say PUMP1) starts running. Then if it manages to do the job and the water level drops below LSL it stops and the next time the water reaches LSL the other pump(PUMP2) starts running. So we need the alternator in this case.

SECOND
Lets now assume that PUMP1 couldn't do the job and the water has reached LSH so now the second pump(PUMP2) needs to be running too. Then when the level drops below LSH on of the two should stop. Then one that will stop running is the pump that started first. Since I assumed that PUMP1 started running first it will stop and PUMP2 will continue to run until the water level drops below LSL when it will stop as well.
On the next cycle PUMP1 will start first since it rested more time than PUMP2 which stopped running last.

Now I need to build a truth table for the logic I have described above and this is my main problem.:unsure:

For the first case the table should be:

LSL LSH Alter | Pump1 Pump2
0 0 0 0
1 0 1 1 0

Second case:
LSL LSH Alter | Pump1 Pump2
0 0 0 0
1 0 1 1 0
1 1 1 1 1

Is the correct for the logic described above?:ROFLMAO:

Yeah, but you can rework it into something like the previous one. Just because you only have 2 actual floats doesn't mean you can't have another bit to describe the state of having both on. But I feel it's unnecessary here.

If you had a series of Case 2, do you want the same pump always initiating the sequence (Pump1 starts, Pump2 comes in, Pump2 finishes) or do you want to alternate that sequence?

If you want it to stay the same, and only alternate when Case 1 happens, you only need to alternate Alter when LSL triggers. If you want it to also alternate when Case 2 happens, you need to also trigger it when LSH returns to the off state (so a one shot falling, rather than rising).

The downside of the previous one is that if you have Case 1, Case 2, Case 1, the second Case 1 will have the same pump run. If you want to avoid that, you need something like a counter or a flip flop set up to alternate it even if you have a Case 2 happen between Case 1 events.

If you had Case 1, Case 2, Case 1, Case 2, over and over, that would burn out whatever pump was continuously doing Case 1.

There are plenty of more complex ways of balancing a load like this, because even these have weaknesses depending on the order of events happening.
 
Kallileo

You might want to take a look at this thread for a super simple alterantor.
http://www.plctalk.net/qanda/showthread.php?t=54494

Using the method in that thread the two float program is
LDR I0.{LSH}
ORR I0.{LSHH}
XOR %Mz
ST %Mz
LD %I0.{LSH}
ANDN %Mz
OR %I0.{LSHH}
ST %Q0.{Pump1}
LD %I0.{LSH}
AND %Mz
OR %I0.{LSHH}
ST %Q0.{Pump2}


If you add a third float so that there is more hysteresis in the level switching so that the pump doesn't switch rapidly due to waves in the tank, etc. the program is still pretty simple:
LDR I0.{LSH}
ORR I0.{LSHH}
XOR %Mz
ST %Mz
LD %I0.{LSH}
OR %Q0.{PUMP1}
ANDN %Mz
OR %I0.{LSHH}
AND %I0.{LSL}
ST %Q0.{Pump1}
LD %I0.{LSH}
OR %Q0.{PUMP2}
AND %Mz
OR %I0.{LSHH}
AND %I0.{LSL}
ST %Q0.{Pump2}
 
Last edited:
Hello guys,

Unfortunately I wasn't able to examine your posts. I will check them tomorrow.
In my project I need an alternator not only for the pumps but for two fans as well. I have created a flip flop for the fans and it seems to be working.
I have never programmed PLC professionally and the last time I had some practice was in 2005 when I was studying in university. I need your opinion on the program I have created so far. I have left out the pumps alternator part which I intend to finish tomorrow. Please have a look at the rest of the program.:unsure:

In this program I had to put two timers for the waves as you said. In the second part I have a circuit with a mixer and a fan. The mixer is working for some time, it stops and fan starts working immediately for some particular time. While the main fan is running if the input of the oxygen sensor is true Fan 1 or Fan 2 also start. This is where the alternator is needed again but it's much simpler than the pump alternator.
alloc.png
 

Similar Topics

  • Poll
Micrologix1100 PLC with rslogix software. Does anyone know how to use a single turn absolute rotary encoder as if it were a multiturn encoder...
Replies
2
Views
1,412
Hi everyone, I am new here in this Siemens world.Any Ebook, Tutorial or guide to learn siemens step7 programming TIA portal, WinCC?
Replies
6
Views
1,567
I have been using PLC's very many years, I understand what they can do, but new to programming PLC's. I am working on programming an OMRON ZEN PLC...
Replies
14
Views
3,638
hi ppl, appreciate if anyone can give a help here. I have a panasonic afpx c60-r which its output is connected to the switchgear module that...
Replies
0
Views
1,603
Hello all, I'm a new member here. I've joined as I want to learn about PLC programming. I've got a few questions to begin with. To get me...
Replies
37
Views
4,623
Back
Top Bottom