OK for our next example we're going to write a C program to control the machine in front of us.
We have a pump that fills the tank within that tank.
We have four floats which is at various levels.
You'll recognize here we have our high high level our high level our low level and our low low level
.
And we also have a discharge valve naturally located at the bottom of the tank so it'll be gravity fed
and we are going to write the program that will fill and drain this tank.
So once again I've set up largely clean Bill C program.
I've got our main ladder calling our digital gyro and our controls which are the only ladders we'll
will be using on our IO configuration.
I still have 8 inputs on slot 1 and I have 8 outputs on slot 2.
All are digital and we are going to jump right into bringing our IO in.
So going back to our graphic we have 1 2 3 4 inputs and we have 1 2 outputs those are pump in our valve
.
Let's go ahead and start laying these out and I'm going to work through this a little bit more quickly
than I have in past examples because I know you've been keeping up I know you understand this by now
and I don't want to kill you with redundancy but I certainly do want you to understand and retain these
things.
So let's go ahead and address our first input that's on slot 1 channel zero and we're going to go ahead
and call that our low low switch
then we're going to associate that with a bit in our data table.
We'll take our first one be 3 0 0 and we'll define that as our L-L switch.
Now just to program a little faster.
I'm going to go ahead and copy rungs 0 and paste it three more times and I'm going to copy and paste
my way through some of this so I just copied the description out of I call and 1 slice zero and I'm
going to change the second rung to 1 which is our next channel and that's just going to be Elle's switch
input because that's the low not the low low.
The next one I said is two and this one's actually going to be H for high.
And the last one on one is set for three and we're going to call that H.H. which is high high
and just like we did that on the left.
And when I come over here and cheat the same way on the right.
So we have an el switch.
Then we have an eight switch.
Again that's our high switch
and last but certainly not least is going to be our high high switch.
And you'll remember that L-L and H.H. are four alarm conditions.
So I'm programming the alarm level switches in here and the L-L and the a change but I'm not actually
going to program the alarms just yet.
We're going to hold off until the next section on alarms and notifications and we're going to come back
to this program and we're going to put those in at that time.
But we've gone ahead and set up the IPO now.
And now we've got two more that's are going to be our digital outputs.
So the first thing we need to do is establish control bits for them.
We have one that's going to be our pump
and we have one that's going to be our valve
and we need to tie those to the output.
So we'll say that our valve is on output 2 channels 0
and we'll put our pump on channel 1.
So that is it for our show.
We've got that all mapped out.
Now we're ready to jump into the exciting part that's the controls and figure out how we want to make
all of this stuff work.
The first thing we know we want to look at is our low and high switches.
Remember those are process control.
Low low and high high.
Those are four alarms.
Right now we're just programming process controls so we can for go worrying about the L-L and H.H. until
we get to the next section.
So we're going to be pulling B-3 0 1 and B-3 0 2 into our controls.
So let's create a few rungs here.
We're going to go ahead and use excise sees examine if closed blocks
and we're going to go ahead and look at our low and high switches.
Then we also know we're going to want a couple of rungs that are going to energize our pump and our
valve.
So let's go back and look those are on B-3 0 4 and B-3 0 5.
So we're going to go ahead and put output energises and be 3 0 4 and 1 4 be 3 0 5.
So we've got our inputs we've got our outputs now we have to do is put some logic in that makes these
things work.
So when we think about our tank we are going to really be running two modes.
We're going to be running a fill and we're going to be running a drain now the way I'm envisioning this
working right now is when the pump is running the valve is closed and that's going to fill our tank
up to the high level and then the pump is going to shut off and the valve is going to open that's going
to drain our tank down to the low level when we get to the low level.
We're going to close our discharge valve again and start our fill pump.
So this maybe isn't a very practical operation but we want this tank just to fill and drain and fill
and drain and cycle back and forth and that's what we're going to reprogram it to do right now.
We're going to look at the low switch and when that's going to tell us when the level is low that means
it's going to trigger the fill mode.
So when we're setting modes we can use an integer if there are more than two modes or we can use a bit
.
If there's only two modes.
So in this case we only have two modes and we've already seen an example of using an integer to control
status with our blower example.
So this time I'm going to use a bid to control the mode.
So our low switch is going to energize a bit and that is going to set our film mode.
And when that bit is de-energize we're going to call that our dream mode.
The thing is if you understand anything about levels of fluids or liquids inside of a tank especially
when you're pumping into that tank or draining with a valve you know it's not always a smooth level
on the top the pump especially tends to create some waves.
And when you're working with the level switches again you have to consider reality when you're writing
PLC program when the level is right next to that switch.
That switch is going to be rocking back and forth opening and closed open and closed.
If we are triggering our pump based directly on that switch then our pump is going to be starting and
stopping back and forth and it's not going to take too long before our pump burns up the valve will
be doing the same thing clicking and chattering back and forth and it's actuators going to burn up.
So we need to put some smart code into this program.
That's not going to allow the pump to rock back and forth is not going to allow the valve to open and
close repeatedly.
And the way we're going to do that is we're going to use delay timers to establish these modes.
So I'm going to go to timer counter and I'm going to use our timer on delay and I'm going to set a timer
for zero and that's going to be our fill mode delay timer
and we'll go ahead and leave that as a second time or we don't need milliseconds or hundreds of a second
for this kind of operation and let's call it a 10 second delay on that timer.
What that means is when this level switches close and that's going to happen when the water level drops
down below the low level switch then this timer is going to energize and start timing.
And we're going to get a down get out of that timer.
So let's go ahead and add a couple of rungs in here because we still haven't set a mode for anything
.
All we've really done so far is energized the timer.
So we want to analyze that down bit for T for zero.
And that's our Phil mode delay timer if you remember back from programming fundamentals the way that
a timer works is when it times all the way down this down bit Energizers and it'll stay energized until
this rung is deactivated by rendering the conditions to the left as false or until the reset command
is activated against this timer rocking the accumulator back to zero.
So right now we're not going to worry about resetting that circuit.
We're going to worry about when this film mode delay timer times out then we want to go ahead and set
a bet and this bet is going to be film mode equals one drain mode equals zero.
So this is our control bet and we'll go ahead and give it a simple symbol as well fill mode.
OK so now let's think through this when the level in our tank gets down to the low switch it's going
to rock back and forth a little bit.
And this timer is going to start and then stop and reset itself and start again.
But that water levels going to keep going down and pretty soon it's going to get far enough below the
switch that it's going to close and stay closed.
And when that happens then this time is really going to be able to make some progress and start counting
up.
And once it times all the way up to 10 seconds without the water level creeping back up then this down
it's going to energize and we're going to start film mode.
Now we already know once we start film mode this system's going to start filling back up and the level's
going to come up above the low switch pretty quickly.
Once it does the way this program is written right now the timer will de-energize the down bit will
be lost and this mode is going to change right back to drain mode.
And that means our water levels are going to start going down again.
And that's not good process control.
If you remember we wanted to go down to the low level then we wanted to start filling and stay filling
all the way up to the high level.
So what we need is a latch something that once this film mode bit is triggered it's going to lock it
in.
And even when this bit for T4 0 is lost we want something to hold this until we get up to the higher
level.
So we're going to put a branch around this condition here and we're going to use this bit as its own
hold in.
So we're going to put in excise C and we're going to address it to be 3 0 6.
So we're referring to the bit that's energized on the same run.
And let's step by step through just this run so far.
What's happening is when this timer times out and then this down is going to energize and it's going
to energize this a bit right here.
The next time this scans.
Now this is going to be energized.
So we can't.
We have a path through here on the top branch of this run we also have a path on the bottom branch so
fill mode is going to stay energized though level in our tank is going to start coming up and eventually
it's going to go above the level switch which means this timer will reset and it's down.
It will open but since this was already energized this will still be true and we'll still be able to
come in around this down bit and we'll still have a path to keep this film mode energized and it'll
stay energized and keep filling the tank.
Now we need a way to terminate Phil mode.
So let's look to our high switch once again and the same problem we had when our level was at our low
switch.
We're going to have our high switch.
That means the water levels are going to rock back and forth and this switch is going to open close
open close.
And we solved that above with a timer and I don't see any reason why a timer won't work here as well
.
So this is going to be our drain mode delay timer.
Are going to go ahead and set that as a one second timer.
And we're going to give it 10 seconds as well.
And now we're going to use the down bit of this timer as an interrupt for the hold in the circuit on
this run.
So we're going to use the x y o command and we're going to address that to the timer for one's down
bit for coal and one slash Dnt.
So that's step by step through this again.
We already know that this timer is going to trigger this bit which is going to energize this that we're
just going to make this true.
And that gave us a path through this branch to sustain this even once we lose that.
Now as of yet our drain mode delay timer that's not going to start timing until our high switch is met
.
So this down bit is going to be open.
It's going to be de-energized and that's good because we're looking at that bit and saying we want it
to be de-energized.
And as long as it is de-energized this instruction is going to be true and our film mode is going to
be locked in and it's going to keep going up up up until our high switches met for 10 straight seconds
then we're going to energize our down bit making this condition false.
We already know this is still going to be false.
This will be false.
That means our film mode is going to be lost.
De-energized intend drain mode and it's going to stay in drain mode until we re-energise with our low
switch and the former delay timer.
So right now we've got the code necessary to control this fill mode bit.
Now we have to do is connect the fill mode bet to our pump into our valve.
So when do we want our pump to come on.
We want our pump to come on during film mode which means when B-3 0 6 is true.
So let's use an exercise see instruction and tie it to be 3 0 6.
So now our pump will come on any time we're in film mode.
As for our valve we want that to work in drain mode which means this fill mode bit needs to be false
.
That's as easy as an X.
O command which is the exact opposite of what we used unrung 3.
We're going to address it to the very same bit and we're done.
So now when our film mode bit equals one which means it's closed.
That's why we're using an excise c command our pump comes on and when our Filmore bit equals zero that
means it's in drain mode then our valve comes on and by on we mean that's going to actuate into the
open position and we want the pump and the valve to work opposite each other and that's perfect because
we're using the same bit to control them both in opposite polarity which means they'll never be actuated
or energized at the same time and you'll never have both of them off at the same time.
One will always be going the other one will always be at rest.
So that program should make sense to you at this point if it doesn't.
Please watch this lecture again.
Look at the logic.
Work through it in your head without my voice.
Just pause the video work through the logic.
Once all of this makes sense to you start up the next lecture and we're going to transition this program
from digital controls to analog controls.
So this was a bit of a more complicated lecture.
I understand that the next one is going to be somewhat of a break because we're not really going to
be originating a whole program from scratch.
We're going to be modifying an existing program and in the life of a programmer.
That's something you have to do from time to time.
It will be determined in the field.
There are means of control isn't satisfactory for the process and they want to retrofit an existing
design which means you're digging into a year old program or a three year old program that you maybe
didn't even write and you're changing digital controls for analogs you're adding redundant controls
you're changing the way things work.
And I pay a lot of my bills.
Retrofitting old programs that I didn't write