Hello everybody this is Section 6 of P.L. C programming from scratch.
And we are about to start lobbing code.
We're about to write the first parts of logic and then the program.
So hopefully you are up to speed on everything we've discussed up to this point.
And if you are you should have no problem keeping up and comprehending what's going on around you.
If you maybe missed a little bit of one section now is probably a great time to go back and take a refresher
course.
Otherwise let's jump right in.
We're looking at a new program.
This is our main ladder and we don't even have a single run of logic in there.
So I've gone ahead and configured my IO modules.
I gave us an 8 input digital module on slot 1 and 8 digital output module on slot 2 and neither of those
require any type of configuration.
Once they're installed on the actual people say and then configured right here in the configuration
window we are ready to go ahead and start programming them.
So we're going to be putting the I O logic into Ladder 4 which we've designated as our IO ladder.
But first we know that this ladder is not going to run unless we call it.
So while we're in Maine Let's go ahead and click on new run and let's put in I J S R
and refer it to Ladder 4.
So we'll just type of 4 here and then we'll give it a description I know.
So now the only rung of code that we have in our main program file is a jump to subroutine for that
is going to call on this ladder which is where we're going to put our IO logic.
So let's get started.
We're going to go ahead and start putting in some digital inputs.
So I'm going to create a few new rungs.
And when we try to compile a program if you have any spare rungs like this that don't have anything
on them you will get an error from verification.
So we do have to use all of these rungs or clean them up when we're done.
Otherwise we get these rung has no instructions and an exclamation mark at the end which basically means
the software is yelling at us and rightly so.
Now going back to our IO configuration window you remember when we installed our IO modules that there
are slots over here on the left of this window slot 0 is our PLCC slot 1 is our 8 channel input module
and slot 2 is our output module.
Well we're going to start with inputs.
So we're going to be looking to slot one channel 0 for our first digital input.
So coming up two rungs zero that's the first rung in our IO ladder.
We're going to put in and examine if closed instruction and we're going to address that is I for input
Colan one because it's Module 1 slash 0 because it's Channel 0.
And as soon as we hit Enter we get a pop up looking for a description and a symbol.
Now a description is used within the program.
That is something that we use when we're looking at the ladders to know what that bit is what that address
location holds or does so that we're not just looking at alphabet soup trying to figure out what in
7:02 is and what EF 8:38 are.
So we're going to go ahead and say we have a power switch coming in to input module 1 channels 0.
So let's go ahead and describe this as power switch input.
Now down here on symbol this is something that we may or may not want to use when we are setting up
an HDMI later on we're going to be able to see some of these addresses within the program and we won't
be able to see the descriptions we'll be able to see addresses or depending on the protocol we're using
we'll be able to see symbols if there are symbols.
So if this is anything we're going to be possibly referring to in an HDMI later on or looking at from
a different scale a system or something along those lines.
We want to go ahead and give it a symbol.
But for reasons which I'll explain later on in this lecture we are not going to give it a simple because
we do not plan on referring to this input directly down the road.
So right now we have this instruction which is looking directly at Channel zero of our input module
imagining that we have a switch connected to that channel and it's wired correctly.
When our program is running and that switches closed her in the on position.
This element of this run is going to be evaluated as true.
And when that switches in the open or off position.
This I call and 1 slash 0 bit is in our data table is going to be equal to zero which means this instruction
which is in examen if closed is going to be evaluated as false.
So what are we going to do if this input is closed if the switch is on.
And if this evaluates is true we are going to energize one bit and we're going to address that from
our data table we already have one data file by default given to us which is full of binary switch or
bits and that's B-3.
So on our output energize output instruction that we just added to run 0 we're going to address it as
B-3 and by default it's offering me the first unused bit in that data file.
And that is B-3 colon zero slash zero.
Now I can use that one or I can decide to use any other bit that I want.
I could use B-3 3 5 2 or B-3 10 11 or I could go back to my data files on the project navigation pain
and I could define a completely new data file being 9 and fill it full of binary as well.
But in this case let's not make it too complicated.
I'll go ahead and take the default of B-3 00 again any time we introduce a new bit or float or integer
into our program we're prompted for a description.
And in this case I'm going to describe it as power switch bit or simply power switch.
Now if you remember when we set up our examen if closed which is reading directly from our input module
and channel 0 where the power switch is connected we opted not to enter a symbol.
And I said I would explain why we don't want to refer back to that input directly.
The reason is we're going to set up this bid on a one to one direct correlation with our input which
means any time the power switch is closed.
This bit B-3 0 0 is going to be energized.
And any time that power switch is open or in the off position this bit is going to be de-energized and
we're going to use this bit throughout our program in our HDMI and a host skater's system anywhere else
we want to know about the power switch.
We're only going to look at this bit and we're going to go ahead and call it power underscore switch
because no spaces are allowed in the symbol.
And now you see our description appears in yellow and our symbol appears in green.
Now that symbol will be visible in other systems depending on what type of protocol they're using to
communicate with this processor but power switch description does not get loaded into PLC it disappears
.
So the only thing that anything else will be able to see is a symbol and only if we apply one so the
million dollar question at this point why are we setting our input up to talk to one bit.
Why are we using a bit instead of just looking directly at the power switch everywhere throughout our
logic.
And the answer to that is it's a best practice to do it this way and with very good logical cause what
happens all too often in our programs lifecycle is it has to be changed.
It has to be revised and it's a favorite pastime of electrical engineers to remap.
I go on a whim or just to make it look better or to make the wires fit better in the control panel.
For whatever reason if we need to move our power switch from Channel 0 to channel 5 we want to make
that change in exactly one place.
What we don't want to have to do is to hunt the power switch down in 30 different locations from throughout
our program and make that change in every single one of them.
That three minute change that the electrical engineer made is going to take you an hour to straighten
out in the program and then you'll probably miss a spot or two and end up with all kinds of crazy bugs
.
So for that reason we segregate our I know you'll see other programmers that do not segregate their
IO and you'll see them put I Colan one slash zero throughout their program and all different ladder's
.
They'll tie it to alarms and whenever they have to change something they're the ones pulling their hair
out.
The wise the smart programmer will pull all of their IO out of the logic and set it aside somewhere
in a ladder or for ladders dedicated to Io and I 1 0 is going to appear one place and one place only
within this whole program and that is right where it is right now.
In the latter four rungs zero.
Anywhere else will be this B-3 colon zero slash zero.
And it might be a hundred different places that's fine.
I will never need to change this bit.
If there's ever a change to the electrical diagram or another thing that happens from time to time the
input channel on the module breaks and stops working.
And for that reason we usually design PLC to have maybe 25 percent additional spare input and output
channels.
So we will simply move that power switch to one of our spare channels and that's going to require a
program change if your IO is segregated and isolated from the rest of the program.
You'll have to make that change in one place.
It'll be a five second change you won't even have to test afterwards.
It'll be ready to go.
If you didn't set your IO up this way you're going to have a busy day just like we said our inputs up
to energize a single bit in our data table.
When we put an output into our logic we're going to write it the same way only in reverse.
We will start with an excise see another examinee if closed instruction we will give that a binary address
.
This time I'm using the next available bit B-3 0 1 and let's say we're working with a lightbulb which
is a famous example of mine.
So I will have
a bit described as light bulb.
And since this will be the bit that I refer to if I want to see the state of the light bulb anywhere
else in my program and more importantly this is the bit that I'm using to control the light bulb I'm
going to go ahead and call this light bulb with an underscore because you cannot use spaces and symbols
and I will tie that beard to my output.
Now if we remember back in our IO configuration we put our output module on slot 2.
So just like we referred to our input our power switch on input.
I Colan one for slot 1 slash zero for Channel 0.
Now we are going to address 0 for output colon to 4 slot to slash 0 for Channel 0 of that module which
is currently undefined.
And we're going to give that a name.
Light bulb output
and we won't need to give it a symbol because we are never going to look at this bit.
We are never going to show this bit to another system.
The only thing that bit is going to ever be concerned with is the actual output.
Otherwise if we ever want to know what the light bulb is doing or if we want to control the light we
we're going to look at this bit B-3 colon zero slash 1.
And that just like our power switch bit is going to be propagated throughout the whole program referred
to on the age of my and anywhere else we need to.
And if we ever need to change channel of our light bulb output we're going to have to do it in exactly
one place.
This practice which I am repeating so redundantly is called segregation segregating I know it is a best
practice and it's one of those things that if you don't do it you will learn the lesson the hard way
and you will go back to it.