PLC Basics: Ladder Logic

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome to this is automation live I'm your host Corey Dallas and we were very happy to have you with us today to learn about ladder logic so a lot of people ask me why are you hating on ladder logic so much well I don't really hate ladder logic and we're actually gonna talk a little bit today about why it's actually a really great language to use in a PLC program we'll talk a little bit more about that but another language that I like is structured text which is what we're gonna be talking about next week so if you're not familiar with structured text or you want to learn a little bit more about it what some of the good use cases are for it some of the basic concepts make sure you tune in to that livestream which is going to be next week the best way to make sure you don't forget that is to subscribe to the channel and you can do that simply by hitting the subscribe button below and hitting the bell icon to make sure you get notifications you can actually go into the this's automation YouTube channel and look through all of the live streams that we have scheduled and click on the ones that you want to watch and from there you'll get notified every time I go live on one of those so I would highly recommend that so you don't miss any episodes in the future but now let's move on to ladder logic so we're gonna give a quick introduction to some of the concepts behind ladder logic where it comes from and then won't actually take a jump into some software and take a look at what it looks like live and hopefully my programming skills are as good as they used to be and we'll actually be able to make some sense out of all of this so to start let's just look at what we have here on the screen which is called a network or a rung so when we talk about ladder ladder diagram or ladder logic it's made up of these networks or rungs so the reason is called ladder is because when you have a program that is made up of multiple networks or rungs it looks like a ladder that's why they're called rungs so you know basically what we're trying to do with PLC programming just to take a step back for a second is ultimately take inputs whether those are from our i/o modules from sensors for example where they're internal variables apply some logic to them and then have outputs whether those outputs are simple you know digital outputs on Io modules they're internal variables or something more complicated like motion for for a servo axis that's ultimately we're doing we're taking inputs applying logic and getting outputs so that's the purpose of ladder diagram where ladder logic is to help enable us to do that so where this comes from actually is back in in the in the old days there was actually relays that were controlling machines not PLC's and you have to actually use relay logic - you know enable these logic statements that we're so comfortable now with in our PLC environments so ladder was kind of used as a bridge from the older method of doing things to the newer method of using PLC's and taking advantage of some of the advanced functionality in computation that we have now in PLC's so it's bridging the gap a little bit between two kind of paradigms for controlling equipment so the great thing about that is that it makes it very logical it's really easy to understand ladder once you've seen it once it gets explain to you so hopefully by the end of this you'll be feeling very comfortable with it the other thing that's really great about ladder is it's actually really easy to troubleshoot and I think you'll you'll start to see why when compared to text-based languages having a graphical language like ladder diagram can be super super helpful when you're trying to troubleshoot something it's as easy as looking finding the rung that has the output that you're trying to figure out why it's not turn it turned on and then you know kind of backtracking through there to understand what's going on so really simple to look back through and it serves as a nice you know bridge between two different ways of doing things looking at the old-school relay in modern PLC's so it's again a very shallow learning curve so to speak so let's start diving into exactly what is inside of these rungs and then we'll jump into the actual software to take a look at it so when we're looking at a rung on the left-hand side we're going to have our inputs in logic so again those inputs could be coming directly from an i/o module for example or it could be an internal variable and then on the right-hand side we have outputs so our outputs again could be tied to directly a IO module and output module or it could be an internal variable that we're using for something else but ultimately again we're just taking inputs applying logic and getting outputs it's it's really really quite simple in the way that ladder is designed makes it really easy to do this so the easiest way to think about a rung is again taking advantage of the relay logic that it's based on so when you're building out relay logic it's all about the flow of electricity so here if we think about electricity flowing across the rungs it's gonna help you understand exactly what's happening to turn on or off it give an output so on the left-hand and right-hand side we have rails so you know you can think about the left-hand side is your your know positive rail and then the right-hand side is your reference voltage or zero voltage rail and so power is gonna flow from left to right now the contacts that we have which is what we're seeing here on the left hand side this would be called a normally open contact we'll talk more about the types in just a second but that contact is either going to enable the flow to continue or it's going to stop it okay so with a normally open contact it's normally open so in the state that it's in right now the flow of electricity is going to stop at that contact so it's not reaching the output which means that the output is false okay so if we were to for example to close that contact by turning that value true then we would actually be able to enable the power to continue to flow through so it's gonna flow all the way to that output coil and what happens when we energize a coil well it's gonna turn that value true okay so you can see how this is you know very much a parallel to how electricity would work with actual contacts in coils okay so then it's gonna flow through to the rail on the other side which would be our reference voltage so this is how the power flow or electricity flow works in ladder logic and how you should approach reading a ladder logic program okay and if you have multiple wrongs it works exactly the same way there could be some nuance in the order in which rungs are executed we won't talk too much about that today but just know that you do need to be a little bit careful about the order of things depending on how it's going to execute okay but in general if you have multiple rungs it's still going to be flowing left to right and the contacts will either enable or disable the flow which will then either enable or disable that coil okay so pretty simple concept ultimately now I mentioned the word contact a couple times there are actually many types of contacts that you can use when building out a ladder logic program the basic types are shown here on the screen will quickly walk through them here but I think it makes the most sense to actually look at these directly in the software so you can see how they work when we apply values to them so the first one is a normally open contact this is kind of the standard one if you will so basically let's say we have input one is the tag or variable that we have tied to this contact if input one is true then that contact will close and if input one is false then that contact would be open okay so very much like a switch again so think about input one as whether that switch is opening or closing with a normally open contact it's normally open so when we turn on input one it's going to close then when we turn off input one it's gonna open now a normally closed contact is a little bit different it has a similar symbol but it's got slash through the middle of it with a normally closed contact it's very much the same concept but it's normally closed so when we turn on input one it's a little counterintuitive it's actually going to open the contact and we turn off input 1 it's going to close it ok so another way to think about this would be not so it's kind of the opposite of a normally open contact and so the kind of a logical way to think about it would be in a statement not input one okay so we'll talk more about how that works when we're actually looking at a full rung positive edge and negative edge these are very similar to the normally open normally closed but instead of being on or off all the time the positive edge is only going to react when the input one changes from false to true for a single scan it will remain on and then it will reset itself off okay same thing with negative edge that would only turn on when we're going from positive to negative so from one to zero and it would be true for one scan and then it would turn off okay so let's look at the basic types of coils again the most basic type of coil is just a coil this is a standard coil when it receives that power flow from the left hand side it's going to turn on so in this case we have output six tied to this coil so if we received power flow from the left output six would come on and if we lose power flow up at six goes off okay the negated coil is very similar to the normally closed contact that we were just looking at before so again it's kind of the opposite of the standard coil if we're receiving power flow from the left it's going to turn off and if we're not receiving power flow from the left it'll actually turn on output six so the exact opposite of this standard coil now is set and reset there's some interesting use cases here there are a couple other types of coils that we won't talk about today but with set and reset what's happening is when we're receiving power flow from the left hand side we will set a value but when we lose power flow we're not resetting it so that that would be the behavior of a normal coil when it sees power it sets it and when we lose power it resets it the set coil is really only the first half of that okay so again when it sees power it's going to set something high but when it loses it it's not going to change anything okay reset works the same way but resetting a value so it would take a value once it receives power flow from the left it would take a value from one to zero and then when it loses power flow nothing happens okay all right well I think the best thing to do at this point is actually jump into some software and take a look at what this stuff looks like so I'll go ahead and do that now all right so what we're looking at here is BN ARS automation studio this is the IDE for any VN our plc okay so what I've done here is dropped in a few rungs of ladder logic so you can see the first one here we're looking at pretty much our example from from the very beginning so we'll kind of walk through these examples one by one to explain the concepts now we mentioned earlier about how to read logically a ladder rung the easiest way to do it is really using kind of the logical statements that we already know if then or and so on and so forth so with a really simple rung like this we could read this as if normally-open is true then output one is true and similarly if normally open one is false then output one is false okay so this is an if-then okay so with the normally open contact again it's gonna work very much like a switch when we set it true it'll close and when we turn it false it'll open so right now it's false so if we set it true you'll see the power flow now can go through and it turns on output one so now output 1 is set to true and if we were to set it back to false again our power flow would then hit a brick wall here and not be able to continue through so our output 1 is false let's look at the opposite case of normally closed so right now normally closed is set to false but since this is a normally closed contact that's actually letting the power flow through it so by default it's switch is closed now when we set it to 1 it'll actually open up and then that would cause output to to turn off so let's do that real quick and see what that looks like so we'll set normally closed to 1 and then you can see here that now this is true and so I'm again hitting a brick wall and now output 2 is false okay so that's the basic concept of normally open normally closed and now we can start to combine these together to make logical statements so again let's look at this in the context of how we would read this out logically we said already we start with if right so if and now here we have two contactors before we had one so here we would treat this as an ant so really the way to read this would be if input 1 and input 2 then turn up with 3 on ok so this is what we would call an and statement and you're not just limited to 2 here you can actually include multiple in series and you would kind of just expand your and statement ok so let's take a look at this so what happens if we turn input 1 to true but input 2 is false in this case well we're gonna let the power flow through input 1 but then we're gonna hit that brick wall it input 2 because this contact is still open so our output 3 is still false and let's look at the case where okay maybe input 1 is true but or sorry input 1 is false but input 2 is true again we're hitting that brick wall up front so we're not even getting the power flow to input 2 now let's look at what happens when they're both true well of course because it's an and statement they're going to pass the power flow through both of them and now output 3 is true ok so again if input 1 and input 2 then output 3 okay so when they're both true output 3 is true all right now let's move on to the next logical statement which is what we call an or statement so in this or statement we're introducing something a little bit new which is this branch ok so most of our wrongs have been straight through you can actually create branches lots of different branches if you want and this would be kind of how we generate our or statement so again here what you want to think about is you have two different paths to turn on output for you can either do if input 1 then output 4 or if input 2 then output 4 okay so any time we have parallel branches like this that's going to indicate an or or multiple paths to turn on or coil alright so let's take a look at that so we turn in put one on and very easily you can see here our power flow is going through and turning on output 4 will turn input 1 off turn input 2 on and again you can see here we're coming through from this lower branch and then coming up to turn on for now the interesting thing here is if they're both true you can see it doesn't really make a difference so we're getting power flow through input 1 and through input 2 and of course output 4 is still true there now what happens if we want to be exclusive so we call this exclusive or where we want if and only if one of them is true right so exactly one to be true well that's where we can use this XOR statement this exclusive for ok so the way to do that in in ladder is pretty simple actually so we would use a normally open contact for input 1 followed by a normally closed contact for input 2 that would be our first path to up with 5 and then we would branch off in or and have a normally open for input 2 and a normally closed for input 1 now how this works is you can only ever have one of these true right because if input 1 is true then this one will inherently be false and the same thing if input 2 is true then this one will inherently be false so if they're both true at the same time we won't get any power flow all right so let's look at the case where only one of them is true so input 1 is true but input 2 is false so we have an easy path through here and vice versa if we were to turn input 1 false in input 2 true again you can see now we have a nice clear path to upload 5 to turn it on now what happens if they're both true you can see that we hit a roadblock because our normally closed contacts are false for both of them so they're open ok and so we hit our brick walls there and output 5 is false so an exclusive or statement only works when exactly one of the the paths is valid ok very good now something that we haven't talked about yet is the use of function blocks so function blocks are a really powerful part of ladder logic and of programming in general these can wrap up more complicated logic or functionality that you can then use inside of your ladder program so one example of that would be a timer so obviously we can't created timer with just our contacts and coils so we need some additional function block to handle that so in the beam our eco system this is called the T on more timer on function block and you can see here that it's got a couple inputs on the left-hand side so again we're still working left to right is our power flow a couple of inputs on the left-hand side one is in so this is going to actually turn on the timer so here we're actually using output 5 from above as our input and then this other one is actually the time delay until this output turns on so when output 5 is true we're gonna wait 3 seconds and then our timer out will turn trip ok so let's take a look at how that works by getting output 5 to turn true first so we'll have our exclusive or statement so you can see here we're starting to count up in our elapsed time and after our time lapses we will see this Q value turn to true so there we go so now our timer has worked and we are all good now if we were to turn output 5 false then the timer's going to reset so we'll show that real quick as well so there you go now output 5 is false so our timer output is false as well so that's an example of how you can use a function block inside of logic ladder logic now what I want to do is actually jump into a kind of example of how you might tie these all together in something like your first program so the example that I want us to work through is I want to turn on an indicator light if my line is stopped for more than two seconds and it's in the run state because I obviously don't want to be turning on indicator lights if my line is stopped and it's supposed to be stopped but I also want to be able to turn on that light when I put the machine in manual mode and I turn on the manual light switch ok so this is an example of a real-life use case that you could do and there's of course multiple solutions to this but let's look at the one that's on the screen here so we're gonna break this down kind of step by step and then walk through the example so again the first thing that we want to do is kind of out you know how this works logically so there's gonna be two paths to turn on the light one is that the line is stopped run mode is on and the other is if manual mode is on in the manual light switches on so we already know that we need two branches right and from there we can just build out this two independent branches so let's start at the top so first we want to say we want a timer right because we want to count the line stop only if it's been stopped for two seconds or more so here we'll use that T on block that we already use and in this case instead of having an output directly tied in we're actually going to use a contact to control the input so only when line stop becomes true will we start our timer here we've got our target time delay time set to two seconds which is again in accordance with specification and then we only want this to actually go through to turn on the light if we're in run mode and I've also added this normally close contact to make sure that we're not in manual mode okay because we don't want any conflicts between the two possibilities now looking at our other possibility our or what we want is manual mode to be on and the manual light switch to be on okay and then we would want our indicator light to turn on so we can see that indicated here all right so let's walk through these these possibly use cases so let's say our line stops okay we have some sort of fault or something we should probably be in run mode first of course because our line is running and it stops so now we're gonna see our timer count up until it hits two seconds and then it's actually going to turn on the indicator light so now you can see that our indicator light is on because our lines been stopped for more than two seconds and we're in run mode in not in manual mode now let's say our lines back running we get we're still in run mode but we want to be in manual mode so I turn manual mode true okay so now you can see that our normally closed contact appear is going to prevent a line stop event from causing the indicator light to come on now I can actually control this indicator light with my manual light switch so if I turn it to one you'll see that my light turns on and if I turn it to zero you'll see that my light turns off okay so this is just one example of you know how you can use ladder logic to solve a logical problem so we're again here taking inputs some of these would be internal some of them would be external and driving an output which in this case is an indicator light there you know is of course a lot that you can build out with ladder logic building multiple rungs to actually make a machine or piece of equipment run so there's a lot to it a lot of function blocks that you're going to be using but here you have kind of the basic building blocks of what you would actually need to write a program so you've got your contacts you've got your coils your function blocks you understand how the power flows in between and you can easily create something like this which you see here on the screen a pretty simple system okay so that's the basic introduction to ladder logic I hope that was helpful I hope it makes sense again know that our power flow is gonna go from left to right our contacts are going to be a combination of inputs and logics and then our coils are gonna be our outputs whether they're internal or directly tied to IO cards and from there we can build out a really powerful program to control an entire machine using just these rungs so it's a really really powerful tool and I think hopefully you can see how it can also be a really powerful Diagnostics tool for example in our example we were just looking at if our indicator light wasn't coming on but we thought it should be we could easily kind of walk back through those different contacts and see which one was not turning on so it's a really easy way to kind of trace back and understand what's going on so this is the basic programming language of industrial automation and now that you know the basics of it you can start to build on that knowledge and continue to grow as an automation engineer or is someone interested in automation hopefully this was helpful if you have questions or want a deeper dive into any of these topics please leave a comment below do read and respond to all of those so it be happy to engage with you on this or learn more about what you want to know do make sure you subscribe to the channel give it a like and share it with your friends we do appreciate all of the likes shares subscriptions the a lot thank you again for joining us on this episode of this is automation live and we will see you next time Thanks you
Info
Channel: This is Automation
Views: 16,900
Rating: 4.9060054 out of 5
Keywords: industrial, industrial automation, automation, manufacturing, machinery, hmi, human machine interface, hmi design, human machine interface design, human machine interface programming, hmi programming, hmi tutorial, visualization, visualization design, design, modern design, modern hmi, modern visualization, technology, tips for hmi design, design basics, hmi design basics, hmi basics, visualization basics
Id: 1WQ70KJu6EY
Channel Id: undefined
Length: 26min 20sec (1580 seconds)
Published: Fri Jul 10 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.