How to Create and Use FUNCTION BLOCKS in Mitsubishi GxWorks 2!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome back everybody I hope you're all safe and well today we're gonna be taking another look at Mitsubishi PLC programming with GX works to however today we're gonna be having a look at one of the best features inside of a PLC and that there is how to create a function block we've actually worked with function blocks on this channel before we've used them inside a seamless gie portal inside a seamless step seven as well as Mitsubishi GX works to last week function blocks are blocks of code that can be used as many times as we want inside of the program and we can address different forms of inputs and outputs to the PLC so if you think about a timer or a counter inside of GI a portal that there is a function block Siemens has created that block using code with inside of the PLC placed it inside of the function block and then they allow us to use it as many times as we want to create a timer operation we can then tweak things here and there with different forms with inputs different forms of outputs but the fundamentals of the program remain the same inside of the PLC function block so what we're gonna do is we're gonna have a good create our own function block so we're gonna do what the dear using GX works too so what we want to do is we want to flip you over the laptop and then get started okay so at the moment we've got our Mitsubishi GX works too PLC programmer open up at the moment what I'm gonna do here is I'm just gonna go at the project and I'm just going to good to new and it's gonna ask us again just like we did last week what sort of series of PLC do we want to use we want to use the FX CPU and we're gonna be using the FX 2nc that's the one that was connected to me behind me and then the type of project that we're going to use is a structured project we're not going to use a simpler project here because we want to create function blocks as a part of the IEC standard that they will be needing our structured project format our language is gonna remain our structure ladder and FBD function block diagrams just say okay of that and again our pu.1 will open up ready for us to write the program so today we're just gonna take a simple approach of creating a function block just to show you the very basics of how to understand how a function block works and what we're gonna do is we're going to create our start/stop latch that we've been creating in a lot of our videos before however this time instead of us creating the start/stop latch inside of our pou we're gonna create that start/stop latch inside of a function block and then what we can then do is use that as many times as we want if you aren't aware of how a start/stop latch is created we create one like so we select our normally open contact add that to our network select our normally closed contact add that to our network add in our output coil after that grab another normal and contact in place that below our first normally open contact and then connect that to our top rail here we then want to give this a dressing now I'm not gonna create a global labels just yet I'm just going to tie this straight to the X's and Y's so X 0 X 1 y 0 and y 0 so the way this works is when X 0 closes which is gonna be our start push button X 1 will remain closed because our stop push button hasn't been activated y 0 will then turn on and then turn on this contact here allowing us to latch on y 0 we can then let go of X 0 which let open this contact but Y Z will will remain on we can then reset y 0 by using the X 1 contact pressing the stop push button end but then open the contact disabling our latch allowing us to start again so that there is effectively our start/stop latch now if I needed to design another 10 start/stop latches but I would then have to do is I would have to create nine new networks and then create that start/stop latch another nine times now with the start/stop latch you only got two normally when contacts a normally closed contact in the core so it's not too much work to do that but imagine a program where we have sir all networks as part of one operation if I then have to design the operation several more times I would then have to take those networks duplicate them change all of the addressing to then represent the new hardware and then do it again and then again and then again and that there is where it can become very time-consuming you can also make mistakes very easily because you might then miss a contact that needed to be addressed and that then is a bug inside of your program what a function block allows us to do is allows us to take this code here and place it inside of a function block and that's what we're gonna do now so to create a function block on the left hand side underneath pou one is FB in fum and FB and fu n stand for function block and function we're not gonna have a look at functions just yet we're just gonna have a look at function blocks to create a function block right click the folder and then select add new data when we select this the first thing that pops up is a function block now we can drop this down and choose another type of block but we're gonna leave it as a function block and then it's gonna ask you for a name and I'm gonna call this start/stop latch next it's gonna ask you what sort of programming language I wanted to use well I'm gonna use structured ladder and FBD I'm not gonna look at structured text I'm not gonna look at an instruction list I'm just gonna be using structures ladder and then all we want to do is then select ok and this then creates our function block and if you look at the function block it looks very similar to our pou it has a network inside of it and I can in write my code inside of this network now we all notice alongside the actual program of the start of latch we also have our local labels this guy right here it's also here and these local labels are very similar to our local labels inside of our peel you like this and our global labels inside of global one the difference between our local labels here and our local labels of our pou is the type of class if we go to up here U and we drop down the class here you will see two options you've got a VAR and you got a VAR constant a var is like an internal bit to the block it can be used inside of that block and nowhere else in the program and of our constant is an address that will remain the same value if you look at our local labels for our function block however you are then given some extra classes we have a revoir which again is an internal address to the block cannot be used anywhere else we then have a VAR constant which again is just the value that remains the same and then we have our VAR input all of our output and our VAR in and out so what are these three guys right here well the VAR input is a signal that can be used inside of our function block that is coming from the main program into the block these can be used as contacts only with inside of that block nothing else contacts only these are read signals var outputs again to be used inside of our function block but they go out to the main program and making them be used inside of the main program to control whatever again these can only be used as coils these are right conditions and var in out if you haven't guessed these are a combination of them both these can go into the block and out of the block and they can also be read and written to from within side of the block and the main program as well so what I want to do first of all is I want to create little ladder to the start-stop latch just the ladder and mallanna is going to remain exactly the same I'm gonna have a normally open contact I'm then gonna have a normally closed contact I'm then gonna place in my output coil our normally open contact latch and then when I'd join the bottom rope to the top rung here and then it's gonna ask us for addresses now what I could do is I could tie this 2 X 0 X 1 y 0 X cetera the only problem with that is I could then only use that block once inside of the program because that block is now using physical addressing and if I use that block again there's output which would be Y zebra would be duplicated and that would cause problems inside of my program what I have to do is I have to create local labels for this so if I look at this guy right here this would be our X 0 or our start conditioner so what I want to do is I want to go to my local labels and I'm gonna create a label name I'm then gonna call this start P beer I'm then gonna tell it what type of class to be and it's automatically selected it as a bar the problem is this start push button is gonna be accessed from my main program it's gonna come in from the main program let's just say m 0 and when M 0 turns on I need the start push button to then turn on with inside of the function block to do this and it's hired this as a VAR input now what I can then do is I can then go to this normally open contact and then I can type in here start PB and there you go you can see it right there i double-click that there's my star PB the next address that I need create is my stop PB so again stop PB and that it's chosen as a bar again but similar to my start PB I want this to be of our input as again this is gonna be controlled from the main program so this is gonna be my stop PB finally what it's then asking me for is its then asking me for our output coil now our output coil and the contact is gonna be addressed to the same address this is gonna be our latching bit if I go back to my local labels let's just call this lamp again I can't just select it as a var but I can't just select it as an output even though it's gonna be used as an output coil because it's also gonna be used as a contact now because gonna be used as a compact and a coil and it's gonna be accessed from the main program I need to select this as far in out selected as a bar in out and then what I want to do here is I don't want to give it the data type a bit so each of these is gonna be a bit inside of the program it's just going to be on or off now I can go to my oppa Kyle tireless talent good and my contact here tireless to lamp and there we go that there is the program for my function block designed and what I can do now is I can now save my work I'll just call this Chris function blocks and then I can close down the start/stop program close down my local labels and then I can go back to my pou now what I'm going to do here is I'm going to leave this as it is I'm gonna create a new block so right click new block after and I'm just gonna expand this a little bit and what I'm gonna do now is I'm gonna drag and drop the start/stop latch function block into Network to so I'm gonna just drag it over drop it in and it's gonna ask me just like it did with our timers it's gonna ask me for a name label for this block this is very similar again a Siemens instance data blocks when I add this name start stop latch 1 to the program like so this block is then assigned that data block and when the PLC executes the code from this function block it's then gonna store it inside of that data block here the start/stop latched beta-blocker and what this will allow the plc to do is it will then allow the PLC and then go back to that data block pull out the data recently executed on the previous scan and then use it again on the next scan so it allows the PLC to have some sort of memory for this block right here now you can see here it's asking me to address our start push button our stock push born and our lamp now all we want to do here is we just want to address it to the addresses that we would use inside of the program so for my start push button I'm gonna tie this to m0 for my stop push but I'm gonna tie this to m1 for my lamp I'm gonna tie this to y1 because we're already using y0 and that there is my function block addressed next all i need to do is just save my work compile my work read all select yes to that and you'll see their zero errors zero warnings zero check warnings I can include that down everything on the left hand side which was read is now black which means it's being accepted and that there is my program ready to go but as I mentioned before the benefit to using a function block is I can use this multiple times in my program so what I'm going to do again is I want to drag and drop the start/stop match back into this network and now it's gonna ask me for another data block and this one is gonna be different to my first one so it's gonna be start/stop flash too and it's going to apply that which then allows the PLC to store information from this program here into the data block and then what I'm gonna do is then tie up my start push button stop push button my lambo from this one so let's just say this one is M 10 M 11 and y2 I can create another one like that give it another day a block apply that close that keep that in line and then address this start PB to M 20 M 21 y3 and you can see just from me doing this how easy it is for me just add a block to the program address D block and then just use it as many times as I want inside of the program to then complete the same task without me having to redesign the program over and over again so what I'm gonna do now is I'm going to save this once again and I'm gonna compile this rebuild all and then select yes there we go everything is fully checked out there okay I can then close that and then what I want to do is just set up the communications for this program go to the connection one it's already select this calm five so that's great I'll just do a connection test successful see okay that's so key of that and then right to plc select the main program and then select execute and then select yes to stop the PLC and now it's gonna begin downloading okay that's that downloaded next I'm just gonna say yes switch that back to remote run close this down close this down and then we're gonna go live on the PLC remember the goal live we didn't just start monitoring all windows yes to that and here we go alive so if I right-click M zero and I just like modify value and I'm just gonna turn M Jiro on what we should see is y1 turn on why to remain off and y3 remain off because these two blocks aren't being executed it's only this block here so if I just select on there we go I can in turn that off and the lump remains on which is y1 if I want to stop this block right here I'll just select the stop push button turn it on and then turns the lamp off switch it back off again and that's that block working if I then select M ten turn this one on this then turns on the second one turn it back off again I can then good to M 20 turn that one on y3 then turns on turn that one off I can then reset y3 by pressing M 21 and turning that off I can then reset y2 by selecting M 11 turning that on and then turning that off so what I've got is I've got a very simple program has just been designed once inside of a function block and then that's used multiple times inside of my main program each block is an assigned a different address and then each block works independently from each other because it's all storing its information in its own individual data block the start/stop lat one starts up not to starts not latched zebra you can just see here how easy it is to actually design the program using a function block multiple times saves us a hell of a lot of time when before in the past you were just have to rewrite the program multiple times as I mentioned it's not too difficult when you've got one network which is just three contacts in a coil but if you've got a program let's say it's controlling a conveyor and that program is ten networks long and on the shop floor you've got ten conveyors instead of you having to rewrite there was ten networks ten more times giving you a hunk networks in total all you do is you take there was ten networks to control that one can there place it inside of a function block address it all up inside of the function block using its local labels and then use that function block ten times in the program addressed to the individual addresses of each conveyor and that's it job's done now what's great about Mitsubishi is I can then just double-click any function block I want and it will show me the current state of that function block only using the data block alongside it so at the moment everything is off but if I go to my main program and I just turn on the start PB we can then go to the block for that and they'll actually see the start PB is on and the lamp is on if I open up start stopwatch one that block remains as it was previously because this block is only showing you the information for the very first start stop latch the only downside is it can't view multiple blocks at the same time so if you look here it's only showing you now the start stopwatch for the very first block and if I just hover over the actual tab you can see there starts up watch pou one dot start stopwatch underscore one if I go back to my main program and open up start stopwatch to that then replaces that previous block with this new block you can really monitor one at a time but if I hover over it I can then say start stopwatch - I go back and I don't start stop lunch brief I could then hover over it and there's my star stop last researchy monitor each individual block with inside of the program just by double-clicking the block which is a nice little thing that Mitsubishi is providing to GX works to makes monitoring programs a lot easiest especially if I develop a fault but let us say conveyor to I would just go to conveyor to double-click it's block and then I can monitor the program with inside of that block it makes fault-finding a lot easier when it comes to troubleshooting within a certain block so what I want to do now is just select the start/stop turn that on select my stop push button turn that off just like the stop push button turn that off close that down close that down and that there is my program with function blocks designed to that's it that there is a basic introduction to function blocks with inside the GS works too as I mentioned it is just a very basic program I didn't want to go too in depth with having a central network designed inside of there I just wanted to show you quickly how we can actually design function blocks inside of GX works too and then use them inside of the main program because if you're working on the shop floor now in today's industry and you open up a bladder program like this I would be very shocked to find out if there are no function blocks being used and that's all I want in this video it'd be just a brief introduction to function blocks with inside the GS works - how to create them how to assign local tags how to assign a date block to them in say in the main program and then how to monitor them inside of that program once again I hope you've enjoyed this short little free training video on Mitsubishi PLC's and I'll look forward to seeing you again next time thanks a lot
Info
Channel: Scantime Automation & Training
Views: 5,159
Rating: undefined out of 5
Keywords: scantime, mitsubishi, siemens, omron, allen bradley, function blocks, functions, data blocks, plc, scada, hmi, automation, programming, ladder logic
Id: Ger-CiFKnps
Channel Id: undefined
Length: 21min 44sec (1304 seconds)
Published: Fri Jul 03 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.