Functions //Absolute Beginners guide to Siemens PLC Programming

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
as Mike Peters Peters industry training and consulting in this video I want to talk about functions with you so if you have seen my my first videos we already said um a little bit something up here and I want to go for the inky detail with that um first of all what I did was um I edit a power supply and on a digital input card in a digital output card to the CPU just to make it a little bit more complete even though we don't use that in the function but um well let's let's start right into the functions and let's create our first function so what we would do here is just add a new block so in this case we want to add a function and then we also have to decide what kind of programming language we use um well you have all different languages like the letter diagram or on the function block diagram you have STL and SCL when I go more into detail in erm in another video um but for now we just stick with the ladder diagram because that's some it's a really graphic program in that language and um it's easy to understand and want to give it a name um and because we just started with with the timer oh let's just call it on operating hours and then we also again can choose if we want to do it menu or automatic in our in our case we do it in arm in automatic I mean it's basically the same because we don't have any FC yet we just um we just go ahead and well just create number one so FC one well then here we go oh we have our first function created oh it's empty of course um and then now let's go ahead and let's try a little bit something out we want to create a an operating our timer counter um that counts the operating hours of the CPU the all over operating hours of the CPU so we already created um a couple of data here in our x DB one and all we want to go ahead and create a little bit more on all the data that we need so let's go ahead and um we need we already have the counter on time counter for seconds and reset for seconds now we want to go ahead and create arm a time counter for minutes and reset minutes time counter for hours reset hours and a time counter for base so keep in mind you have to give them a data type um it always it always takes the data type that was in the arm in the data bit before um in our case we don't want every everything to be a pool or we want this here to be an integer and we want this being in ginger and also this the reason why I didn't do a reset for days is because all we count we count days are we don't count month now because that would like make that video too long to do it like we we program here today arm because then we have different different numbers of day days in every month and arm would take a little bit too long to program all that by third like we do this song dis operating hours here in that video so let's see we have all this in gingers that we want to be routine so we click we chain on office so that means whenever we shut down the CPU that values in that um data doesn't go away it just will be saved to the memory card of the CPU and next time we fire up the CPU again this data will still be like it was when we shut it down so just to keep that in mind so let's go into programming so we have our function here and the first thing we want to do is we want to have an normally open and then put in okay arm like we talked about that before we use the clock function and in our case the one hurts what means like it will blink every second that means like every time that lights up we can within count seconds so next one is um every time that counts we want to trigger our counter so we put in a coil and go ahead and just lick it like you saw with the with the clock you don't have to like type everything in whatever data is already created or whatever PHP tags already created is giving you options so I just type in T and then okay I want to go into the global vbe b1 x and then it gives you more recommendations for whatever boobs are in there so how whenever you use a coil or a normally open normally close stuff like that um it only looks for bulls because that's the only thing they can process um they can't do anything with integers or something so they looking for bulls in this case we want to have it count to 1 enter and then that's our first network so in the second network we want to now use this here or counter one to do something with it so we say okay network to normally open then go for x counter one enter and then what we want to do every time this will be triggered is we want to count up that means we want to add something and as you can see here time terms of seconds that's an integer and the stop value is zero we want to add a 1 to it so every time this operator triggers we want to add a 1/2 hour time counter seconds so what we're going to do is we put an ad function in here and I already put that into my arm favorites here what you can do is just like um go on the right side here instructions if you don't see it yet um it's probably hidden here just click on that arrow and it will pull up and then you go to arm math functions and you have this operator here and you can just like drag and drop it over here and it will stay in there um but for now that's good enough for us um you can just go ahead you have this ad block now here what you do is like what we want to do is like we have this does integer um in x times counter second and then we want to add one to it and the output will be x counter seconds again so what happens is like whatever it is in time count a second will be edit by one and then gives it out back into time counter seconds so that's basically what happens every time the clock takes Serkis this here forget this here and then this triggers the add function and adds one second to time counter second so next step we want to do is like we want to arm count up to 60 and then convert that number into one minute and we set our time counter seconds back to zero we never want to count on more than 60 because that would mess everything up so what we do is say okay um go over here go to comprehend alterations take this here over that's equal put it in so and then say okay um we want to look into times now the second equal 60 and then do something come over one good what we want to do is put in a coil we already created something Alma what's called times reset seconds so we want to do that enter so now that's it for this network in the next Network we use this here put in a normally open again say okay times reset seconds and then we won't do something and what we want to do is two things first we want to move a zero in time counter seconds so that we back on zero and what we want to do we want to add one to our time counter minutes so we do that like that so we take the move put it in here say okay we want to move 0 into x counter second enter so but then we also want to do something at the same time and that is add one to the time counter minutes and that's how we do it we put it we click on here and then click on a branch if you don't have that yet in your favorites you can just go on general and then have a closed branch open branch and stuff like that so we did that now click on that arrow and then we want to say ok we want to have an ADD function again take that add function and then we say ok now we want to have time counter minutes at by one and put it out into time counter minutes so in that we make sure okay we count up in armed times now so then what we do is just like repeat what we did before so now we have our where we have the minutes um let's count up every time 60 seconds are awful we now want to have the hours count one up every time 60 minutes are full so what we do again is like um we take this stone here we compare it and say okay time counter minutes equals 60 then do something and we want to do the following we take a coil say x counter minutes this time reset come two minutes so and then again we go ahead and say okay normally open whenever that is triggers here it's times recent minute we want to do something in our case we want to like we did it here we want to move something we want to add something so first we say move and we say okay move 0 to x counter minutes that's pretty much it and then again we also want to oh I'm sorry of course not there we want it here move all right okay here move wait for that green thing and then we want to say okay move 0 into x counter minutes click on here open branch and then we want to add something at and this time we want to UM use x counter hours and add 1 to it and put it into x counter hours so same thing whenever that is triggered we'll move the 0 back into comp times counter minute that we start again we never want to go over 60 and then we also add 1 to time counter hours that means like after 60 minutes we have an hour put it into hours and so on the next one will be now we want to put it into date days and this is this is pretty much the same just all just a number will be a little bit different so we we take x counter hours and then compared to 24 so and then we want to do something and we want to do something like arm like we did here we just reset the hours so we say coil and then times reset hours here and then in the next network we go for a normally open again times reset hours should do something and again we do two operations first we do move something we move a 0 into x counter hours and also open a new branch and then say we add two times counter days one and put it out in time counter days so that they skid so now we are counting all the operating hours of our um our CPU that's pretty much it so then what we have to do is start a simulation um for that we go on this main block here PLC one that's all mean in block and then we go on this button here stop simulation go on it and we'll start up take the one so so if you don't get that window right away it's probably showing you a bigger window where you can choose um where you won't want to download um you project on or normally it also shows you um they exist existing hardware that the actual hardware that we don't have here but you can just like click on um PLC sim and then use the PLC sim 1200 1500 because we working with the 1500 it's a little bit different from the 300 400 so that's why they separated it in our action on in our in our case we stick to the 1500 so just use that then it will ask you to if you want to have that path for the future arm as a default just say yes or no whatever you want said yes that's the reason why it goes into the simulation right away and I don't have to go through there anymore so ah we want to re initialize all the data blocks that we created um so we say in reinitialize and then we say hello and then it opens it takes a while but then it opens up down the simulation and you can go ahead and use this Oh and then finish sorry okay so now what we have our simulator can play hunter it's not an run but it's kind of running so um what we're going to do is go ahead and try to arm monitor all that so what happens we click on that nothing happens why is that because we create our function but we never told the system to actually call the function and tell them tell it that we want to use it so that song why it doesn't doesn't go like you see that it's like right here and all that means like it's not active um my so ever in our cases because we never call that function that is what we're going to do now so we go offline go in our main ob1 this is some the operating block that comes with the program every time you are creating a program the main you'll be one will already be there for you because that's a mandatory operating block arm where you have to call all the functions and everything so what we're going to do is we go on let me know V and then arm I delete that for you to show it how it works so you just right click on network one and then go down here in set network so and then you have another network note this small what we want we want to insert FTL network because it's easy as a coal so what we do here in that deadline one will just type call and then FC one and then just hit enter enter enter and then you see it called the FC one with the name in it so what we prayed here operating those FC one was automatically put in here the only thing you have to do is call fc-1 and then hit enter three times and and you good and it will call it out for you so with it now it's okay um we we modified something so that means like the program that we modified here is not on our CPU or PLC sim yeah so what we're going to do is we go ahead and we take download to device what it will do is like yeah we want to overwrite it um it will compile the program for you into codices this is actually what arm the cpus are run on the actual code that the cpu run runs on is codices and our program that we programmed in on the letter diagram will be compiled into that language for us we don't have to do it now also download it um and we are ready to go now when we go on our function again and now it um monitoring you will see that something happens here see that so everything where the screen is like imagine it as electricity flowing through so let's see what it does oh so here you can see this is not counting second this is like going crazy so what we what we didn't do is um like prepare for that because even though that clock takes every second but it stays longer up stays on longer then only like it a bit its sting thing on or like I don't know how many milliseconds but it's just too long and like as long as that stays on it will put one it will add one to time count a second what we don't want we want to arm at one single one to time count of seconds every time this goes on so what we're going to do is we go back to instructions here and then you go on ARM based logic operations and then you search for something called P trick that's positive trigger I already have that here so what I want what I just do is like going on here click that and then I have a positive sugar here what I do is just like give it a name I already did that before I'll put that in hit enter so this is no this is a memory right now so create a memory and then now what you want to do is because now as you can see here you have like arm a difference between the online and offline program if I'm stay closer and you can see that online offline different um because we only change that in our Tia portal we don't change it on simulator so what we're going to do is like we hit that button we hit that block here and then we just download them compile it consistent download yep load it will be in it and then as you can see we're still on monitoring now it arm triggers it and then what you can see down here is it now count three of seconds the reason why you don't see that green here is because that is so short that the graphics can't handle them that's the problem but as you can see here it counted arm in a timely manner of a second so let's see what's going on on with our further um operations here we we compare let's not 60 yet um here what do we have here um we have already 14 minutes that comes from our messed up stuff before so let's go ahead and go into our times and money for that then we can see what's going on here so we have all we already have 20 days that's not right so what we're going to do is we modify the upper-end back to zero just that we can start from scratch zero you have to execute in mind so you can only modify operands if you click on the start value it's not going to happen here on the monitor value I mean it shows it shows it to you for like a second but then it's gone so we go here and then now we start from scratch so let's see if our arm time counter minute goes up by one after we have the 60 seconds for well I just you can see that it's like two one zero so um it turn it up and UK's probably you won't see anything everyone is scratching his hat right now or her head and the reason why you can see that is because um you didn't enable the the clock yet so I forgot to tell you that so um go ahead on your devices click on the CPU go on properties and then search for something called system and clock memory and then you have to enable the arm enable use of the system memory by we have our first scan our first cycle so whenever you fire up the CPU the first time when it was shut off it will set that bit to one and then delete it in the second circle um also we don't have to talk about Diagnostics that has changed yet um I go more into detail in a later video you also have a memory that is forced to one all the time so it's always true and you also have one bit that is always false um that you can use in your programs so go ahead and click that if that is not possible right now while you have this orange clock here this is because you can't change anything in your hardware before you are offline so go offline say go offline go offline so whenever that orange block is gone you can actually modify it so enable that and then scroll a little bit on you see the clock memory bit and then you enable that too um many of you maybe have these problems that in the beginning of programming the function you couldn't find that without typing it in all the way so because it wasn't enabled yet sorry about that arm the g1 and you want to fix that now and then everything will work like I say um also when we go back online here just go on like monitoring again we'll see it works so let's see if everything else works - so money tour we see okay we already have like three minutes in um and now we want to see um what is going on with the rest of it so because I don't want to wait an hour or a arm - to see if that works we just modify the operands so we put that here - 59 see it powder an hour up here so set that back on zero hundred an hour up here now let's see I wanna know I don't want to wait a day for that so we go ahead and modify the upper end here to 23 and after a minute though it should what I want it to be reset it here to zero and then count the day up let's put that IR - didn't do that why Stan what didn't count it out once again oh I know why okay so now 45 if you know okay please set and everything counted the days out arm we're done without function well guys let me let me know if you find that helpful let me know what do you think about the videos and I will add new ones tomorrow I will probably add on a video about function blocks tomorrow which kind of like the same functions just to tell you how what the difference between these two functions and function blocks are and um well let me know what you think about it don't forget to subscribe and see you in the next video thank you
Info
Channel: Siemens PLC Training
Views: 22,474
Rating: undefined out of 5
Keywords: Siemens TIA Portal, Siemens Step 7, Siemens PLC Programming, PLC Programming, Peters Industry Training, Peters Industry Training and Consulting
Id: ZU0a2tyUjLg
Channel Id: undefined
Length: 31min 50sec (1910 seconds)
Published: Tue Apr 11 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.