Function Blocks // Absolute Beginners guide to Siemens PLC Programming

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
this is Mike whispers into training resolving today I want to talk about function blocks and for those of you that already watch my my own video that I've created before um this is basically what we did last time with the operating hours we just copy that on that whole function into a function block the difference between this is pretty much like when you create a function um this will be executed one time and only for one reason that you create the function for um and it's not really reusable other than you just copy and paste it and then um use it for something else to come something out with a function block though you can you can create a function and then reuse that function all over again all the time are for whatever you want in our case we're counting operating hours so let's say you want to you want not only count be all over time for the CPU or like with the function that we created in the last video let's say you want also to count operating hours for different other devices or other other other functions and you want to you don't want to write too much code or you don't want to program too much functions um that way you just create a function block and reuse it all over again with every every device you want to count the operating hours for example in our case we use that as a simple example um consider here um for all of you who didn't see this the last video I recommend to go to my channel and watch for arm the video called functions and then um you can you can go through that and then create what we created in the last video um and you're on the same page that we are right now so then stop right in let's create a function block you go on add new block this time function block is a name in our case it will be operating hours counter um and then it will create an automatic FB one you can put it on menu and give it whatever number you want we also again we use the letter date diagram um just to make it more graphic for everyone and then I'll go ahead and create it so the difference between a function and function block as you can see um even though the function has its own data here - um the data in there in the function block is little bit more than the data in our data blocks in general so you have the accessibility and visibility in the H and I put that up and you have set points and comments and stuff like that and yeah let's create our function block um we actually pretty much copy our function from the last time on just this time we have to create our inputs and outputs and static values in within the function block just to to make sure we're on the safe side so let's first create the input so what we want to do is we want for example when one device is active we want to have a trigger for that so we say okay um let's say device active and we want to be a pool arm then that's actually pretty much everything we need as an input and we need a arm and output and we need seconds minutes minutes we need hours pony's days all of them has to be an integer of course it's full numbers okay then we also need a couple of arm static values in our case for example we need a sugar counter that's a bull then we need um contra seconds that will be in integer and then we also need works WowWee here longer minutes counter hours one date okay what else do we need arm we need something Oh as you know out of our function oh we need a positive trigger in order to count the one hurts our clock and but this time you can use a global memory you have to use in internal memory for that so what we do is we create one just on + sugar and we can use that that will be able we can use that in within our function just to make sure we don't use global global data in within our function other than the inputs all that we create here so let's start and what we do actually is just on making sure um we can copy the function that we did last time we just use the internal data instead of a global data that we use in the function so um we start with a normally open say okay we want divide the active and you can see on the internal data is marked with a pound sign before it so um here you have global data that's marked with whatever it is memory or inputs or authors or whatever so we want to use the internal data divide active enter and then from here on we kind of copy our function so what we say is okay we want to have normally open and then we use that's the only global thing we use that's the clock one Hertz that's all not giving us a signal every second and then what we want to use is a positive trigger and this time we use G internal one plus Syria so that we don't use any global data and then we want to do something and that is um we want to trigger our on countdown did we create that yeah trigger counter so you go there trigger counter so enter and then in the next network we use that trigger Konza trigger counter and say okay every time that is triggered we want to do something like we did it in our function we say okay every time we we have this trigger we want to add two armed counter seconds we want to add one and put it back into counter seconds pretty much the same that we did in our function just now we using the internal data so next network we say compare counter seconds to 60 then do something in our case we want to say um we want to reset something that we praised that yet now we didn't so we have to create more um data that reset seconds reset minutes is that ours that's pretty much it so now we can use it um and then say okay when we have when counter seconds equals 60 then we want to reset the second so per column reset second then the next network every time reset seconds this trigger we want to do something we want to move zero to counter seconds and we want to add to counter minutes one and put into complements so and then again compare Oh minutes was 60 and then coil reset minutes we said minutes make sure we move 0 into counter minutes and add to counter hours one and put it into controllers again compare counter hours to 24 then we set hours instead hours does move 0 into counter hours and add to counter the base 1 and puts it into console days Oh all right and ex-con today's one to count today's okay so what we have now our link or function set up what we didn't do is um give it out out of the function block this is this will count but all the data will stay in within the function block well one good do is we want to give it out we created the outputs already where is it here we have an output for seconds minutes hours and days so what we're going to do is we move and that is unconditional we just want to move it all the time to the output so what we're going to do is move counter seconds into seconds and then again and at the same time we want to move counter minutes in two minutes at the same time all right and move counter hours in two hours and move on today's in two days so that's pretty much it so we are now already done with our function block so we can because we didn't use other than the input of device active we don't use and the clock of course we don't use any global data we only use the data and within our block and then give it out arm to our outputs whatever it is seconds minutes hours or days so we have to do now is like just with our function block we don't have nothing would happen here because we didn't we didn't put any any input in it and all we didn't ask for an output yet so what we're going to do is we create a arm a function don't forget to save we create a function for calling that function block and now we can implement a function we can call that function block as often as we want and for whatever you want so let's let's create a add another block this time a function um say we call it operating our devices so please all make or what give it whatever number you want to convert into letter diagram and then create so now we have our F c2 or whatever you called it so what we're going to do is first we want to make sure okay we have devices um because we only using the simulator on the PLC sim and don't have any input from outside we just use the global on this that we talked about before in the device configuration you have the system arm where is it properties system and clock memory and we enable that in the last term in the last video so we use always one always true that's M 1.2 arm to make sure we have a device we have an input for device active and we do that in our function and say ok armed with a normally open and then we say always to activate you live one well that's not right one okay enter and then it gives you the red hammered line that means um that tag is not defined yet so with the red right click on it and then say define tag and say okay so it will automatically give it a address um you don't have to do anything although you you want that but for now we just stick with the recommendations of the CIA portal we didn't find the tag so we have device one active this is always true so what we do now is we just copy that oops just copy that copy and then click on here paste click on here paste click on here paste so the only thing we have to do is now because it's all device one we go ahead click a couple of times in here say device to enter enter define tag define us three-time tag time device and do the same right click define tag fine so now we have our of our four devices kind of like create it it's not really a device but it's just our a where spot right now then what we want to do is we want to call our function block and within this function and we want to call it for each of these devices and the way we do that is go in a new network I'll mark that here and then put an empty box in click on it and say FB one and then just enter enter and it will create an instant a single instance data block because um every time you call a function block it will create its own data block an instant instance data block um so just to make sure that arm every cold function blog has its own data and not on interfering with one of the other arm function plot instances so let's go ahead create that it will create it here you don't have to touch it the data is already created by the function bar so what you do now is okay say okay our input is divided active we want to take device 1 to s 1 and then our output will go in whatever we want it to go I already created um device 1 through 4 and then all the different seconds minutes hours days for each of them just to shorten that video up a little bit so what we're going to do is we say okay we want to times device 1 seconds and then 4 minutes the same amount times device 1 minutes and then 4 hours times device 1 hours and of course times device 1 days and then go ahead if you want to arm so we created our first calling of this function block and then now you can go ahead and say ok I want more for you and say ok I'll empty box put it in again FB 1 enter enter then it creates a new single instant data block for you you don't have to do anything just put it on automatic that's okay it calls it um like USB is called and then calls it's just a number so here you see okay that's the DB DB the real DB number variant but it calls it DB 1 because it's the that's that's the second instance so it always stops with no number and then 1 2 3 um so that should be ok and then you can say ok now this one is device 2 and then also time device two seconds times Z was two minutes times cos two hours times us two days so it will now even though we use the same function blog arm it will only count in this one in this instance it will only count this device one one is active and will give the outputs to the bottom two times device one seconds minutes hours and days and this one will only be active if device 2 is active and gets it out to the arm seconds minutes hours and days off device to that I created in our data block times so that's some that's pretty much it if you now go ahead and say ok I want Dom I want more I want all my four devices just go ahead I will stop that video here and put it out for you so that that video is not that long um one second here we go so now we that we go on arm we don't have to call the FP you know OB one because um this it's not necessary for FP you call them wherever you want them to call and that's fine so we call them here all four of them we have all our data in place um see how they work down first of all um if you didn't start you your simulation yet do it now click on here and then load your new program into your PLC sim and then now we can see what happens so in my case I already did that the only thing I have to do is download everything we say ok we want to reinitialize okay something's wrong here see where it is safe project compiled software changes oh okay oh this one safe no don't know okay we initialize load finish okay it's in there now um what we can't do is be going on our operating horse devices and see what's going on here you see better Oh see we forgot something we didn't call our function we don't have to call it from the blackboard we do have to call our function so go to the main UV say call fc2 and download yes we want to overwrite it so now go you to your function only tor here we go so because this is always true we said our devices also true and if you go down here you can see true that means it counts also what's the next one it comes also what's the next one and the very next one so what we can do now is in order to check if everything is ok and it only counts when a device is active what we can do is we say ok we say this here should be always false and then this here also should be always false then download download it to your own simulator yeah all right then you can see now it's set to false so device 1 is not active that also means that also means that because this is inactive this doesn't count so when you have a device like a motor and you want to monitor the operating hours of a motor or something every time that is off it won't count so when you create a memory for for that device to be on or off you can you can stop counting or give it give it back to counting and even if you shut down your um your CPU if you set it in your if you set it on on retain the output arm here is on non retain set it on retain even then it will be filling your memory whenever you fire that CPU up again so what else do we need we need to have the counters meeting otherwise it will all start from zero and move your zeros or whatever in your output even if your output this routine um it will overwrite it so you put all that to retain you should be good so now we have differences here or we're going to do is like just download no action reinitialize load so while we put the relational we initializing we set our data all the time back to our default values in was an integer that if you don't define it otherwise it's always zero so we start new so every time you reinitialize something it sets it back to your default value so in our case our we want to monitor our function now okay still monitoring and now this one is false so it doesn't count it's all set to zero because we re initial initialize it this is true 45 seconds yet on since we restarted so and then just to test um if we did it right we can go ahead and say ok we go into our arm [Music] in our FB and say okay we want to monitor that actually we don't go into the FB we go into the instance data block of the UM authors device you want to many manipulate and then go to a monitor so you can see okay we had thirty right now one minute so we want to arm say okay we we are not like modifying the output we are modifying the static values so we go ahead and say okay we want to have arm modified operon 23 hours and we want to have modified operand we want to have 59 minutes and we want to have [Applause] fifty-five seconds so now as you can see it should move here see now we have one day everything else was we said it counts comes again so everything works and because we're using the DFB you only have to test that one because everything is the same so if the 1f beef arm is working then everything is working so now we accomplish pretty much the same that we accomplished with our function in the in the video before just was a function block and we can reuse it for different devices or whatever you want to count in okay okay so we just like stick to the easy easy task of counting operating hours or just to to show you a little bit on what it is like to to count something to move something to to create a function block to use data it's not the most advanced um task I know that but we're starting from scratch here and that's for all of you who are not so family I would feel cheap programming and everyone who is already a kewpie program and it's looking for something to learn I think that's not the right course here for you um this is really for absolute beginners and we're starting from scratch and we are processing more and within more videos but for now we're really starting from scratch so I'm sorry about that but you may be might not learn anything here so um this is it for today just come recent comments tell me what you think about that there was helpful also don't forget to subscribe for new videos and I would say um see you in the next video thank you
Info
Channel: Siemens PLC Training
Views: 52,872
Rating: undefined out of 5
Keywords: Siemens TIA Portal, Siemens Step 7, Siemens PLC Programming, PLC Programming, Peters Industry Training, PLC tutorial, Siemens Tutorial, PLC Programming tutorial, siemens tia portal v14 tutorial, siemens tia portal tutorial
Id: i1cQG0gD1BM
Channel Id: undefined
Length: 31min 58sec (1918 seconds)
Published: Thu Apr 13 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.