How to Structure Your PLC Application in TIA Portal Like a Pro (Complete Course Chapter)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Applause] as you might have guessed in this section of the course we're going to structure our application we're going to start by breaking down our sample application into logical smaller modules afterwards we're going to create a folder structure for our program in our application we'll build our main function calls and our global data structure finally we're going to add our input and output tags to the application [Music] as we've already mentioned in the first section of this course our sample application consists of one supply tank and two process tanks the water in a process tank is being refilled by the supply tank using a pump and a valve i have broken down the application into one supply module and two refill modules each refill module consists of the same components a tank with an analog level measurement a pump and a valve this will be encapsulated into one reusable package of software code the supply module consists of a tank and a low level sensor so how does this modular structure translate to a plc program structure in our plc application we will have a structure for machine modules and for equipment modules we will get to the machine modules in just a sec so let's just start with the equipment modules the supply module and the two refill modules that we have identified in the previous slide will be programmed as function blocks under equipment modules as you can see we will program one function block containing all code for controlling the supply module this is called fb supply we will build another reusable function block called fb refill containing all code to control a refill module since we have two refill modules this function block will be used twice in our program so now let's have a look at machine modules what are machine modules they are all the modules that are used for controlling the machine that are not part of the equipment in our sample application we are going to use a state handler a state handler is a piece of code that controls the overall states of a machine the most common states for a machine are ready running and faulted a machine or a line is ready when there are no faults an operation can start a machine is running when an operator has enabled the machine operation by pressing a start button a machine is faulted when a fault has been detected in one of the equipment or machine modules i have added a reset state as well in this reset state the machine will try and reset any faults in the system that have occurred other examples of machine modules are a function for alarm handling of the machine a function for network control a function for recipe handling in case your application works with recipes or a function light tower for controlling different machine state lights like for example a red light for a machine fault or a green light for a machine that is operational we are just going to use a simple state handler for application so now we have defined function blocks for our equipment module supply and refill and we have defined our machine module state handler in order for our application to be functional these function blocks need to communicate with each other for example the supply function block needs to know if one of the refill modules is requesting a refill or another example is the state handler the state handler needs to know the condition or fault state from each equipment module and machine module in order to know what machine state should be active this communication between modules is achieved using global data blocks for our sample application i have defined one global data block for equipment modules data and one global data block for machine modules data equipment relevant data is shared between machine modules and equipment modules using the equipment data block likewise machine relevant data can be accessed by machine and equipment modules using the machine data block in one of the following lectures i'll show you what data we'll be using inside these data blocks for now it's important to remember that functions communicate with each other using global data structures before we conclude this lecture i would like to say a few words about the hierarchy that we are going to implement for our plc application on this next slide you can see that we have three layers of hierarchy the top layer of our hierarchy contains our main program cycle which typically is called the ob1 which stands for organization block this ob1 is called cyclically by the plc the speed of one cycle depends on your plc type typically these cycle times can be as low as 1 to 2 milliseconds up to 20 30 milliseconds in the ob1 we have our main function calls this is our middle layer in the hierarchy our fb equipment modules will contain all our equipment modules and our fb machine modules will group all of our machine modules together that brings us to the bottom layer of our application in the bottom layer of our application we will have the actual function blocks that are controlling the different modules [Music] in this lecture we're going to start building up our program structure first we're going to improve the readability of our plc application by adding a group structure in our program then we'll create our main function calls within that group structure as you can see i've already opened our work in progress application all of our coding will be situated under program blocks here we will start by building a logical group structure which will function as an easy to navigate frame for our application so what should our group structure look like let's have a quick look again at the plc program structure that we've defined in the previous lecture our application will be built using machine modules equipment modules and global data these definitions fit just perfect for our group structure so let's add those to our program we add a new group by right clicking on program blocks and selecting add new group so we'll be adding three new groups a machine group an equipment group and a global data group i would like my machine and equipment groups to be at the top unfortunately tia won't just let you move them up or down they are displayed in alphabetical order a way around this is using numbers in front of your group names so i will add double zero to my machine group name and 0 1 to my equipment name there we go now we have created a frame for our application let's continue building our program structure by adding our main function calls as you can see in this slide from our previous lecture we have defined fb equipment modules as our main function call for grouping all equipment modules and fb machine modules as our main function call for grouping all our machine modules first we'll create those two new function blocks and afterwards we will call them in our main program cycle ob1 we start by creating a function block for our main function called fb machine modules we do this by right-clicking on the machine group and selecting add new block so tia gives you the option of creating four different types of blocks on organization block a function block a function or a data block we are adding a new function block the name of our function block will be fb machine modules our programming language will be ladder and we will let tia automatically assign a number to the function block after pressing enter or clicking on ok our new function block will be created there we go our fb machine modules has been added to our machine group now we'll need an fb equipment modules for our equipment group we can perform the same steps as before but i'll show you a much quicker way to do this first left click on fb machine modules then press ctrl c to copy that block left click on the equipment group and press ctrl v to paste the block now we just need to rename the block you can do this either by pressing the function key f2 or by slow double clicking on the block this function block is called fb equipment modules enter and there you go you might have noticed that both our blocks have the same hardware address fb1 tia will automatically assign different hardware addresses during compilation so you don't need to do anything here let's give this a try to compile the whole application first left click on the application name plc refill work now press on compile in the toolbar as you can see tia has automatically assigned hardware address fb2 to our function block equipment modules so now we have added our main function calls in order to activate them in our application we need to call them in our main program cycle obi-wan first we double-click on obi-wan to open it the easiest way to add our function blocks here is to simply drag and drop them into the network now whenever a function block is being called in tia this is called an instance every function block call comes with its own instance data block the instance data block contains the variable declaration of the function block and is read-only since it adjusts automatically to the variable declaration inside the function block we'll talk more about instancedbs in a later lecture for now let's assign a name to our instancedb since this is the instance data block for our machine modules fb i'm going to call it instance machine modules again we'll let tia automatically assign a number so now we've created our main function call for our machine modules to improve the readability of our application i'm going to move our instancedb to our machine group now we're going to perform the same steps for our equipment modules call so we drag and drop our function block into the network and we add a name for instance db finally we move the instancedb to our equipment group to further improve the readability of the application i'm going to add network titles here in our ob1 [Music] in our refill application different modules are going to communicate with each other this communication is achieved using global data structures in this lecture we're going to add these global data structures to our application in our previous lecture we've added a program group called global data this is still empty so let's create our global data blocks here when we quickly take a look at our plc program structure you can see that we need to add two data blocks one called db machine for data related to our machine modules and another one called db equipment for data related to our equipment modules we add a new data block to our group by right-clicking on the group and selecting add new block we are adding a data block so we click on that the name of our first global data block is db machine our type is a global db so we leave this like that press enter or click on ok and our new data block has been added to our group for our second db we're going to use our handy copy paste solution so ctrl c for copying the db and ctrl v for pasting now we'll just rename the block and there you go we've created our global data blocks now let's open one of these dbs as you can see they're still empty we have only created the container so to speak we still need to fill it with data in our case with data structures the first step in creating data structures for a global dbs is creating a user-defined type for each module standard tia parameter types are booleans integers reals etc we are going to use a combination of these standard types to create a more complex user data type for each module for creating a new data type we go to plc data types in the project tree and we press on add new type now we're going to our work area so let's start by creating a data structure for our state handler module the state handler that we'll be using in our application will have four states ready running faulted and reset so it makes sense that part of my state handler data structure contains information about what state is active in the machine so let's add a state structure we do this by selecting data type struct and adding our four states as booleans as you can see here i have the habit of starting my tag names with a small letter to indicate the tag type for example x for booleans like what we have right here i for integer r for real etc i would highly recommend this habit because it improves the readability of your code so now we have our four states in our data structure in order for our machine to go from a ready state to a running state our operator needs to start the machine using a start button going from a running state to a ready state requires a stop command and to clear a faulty state requires a reset command i would like to add these commands start stop and reset to our data structure as well so in the same fashion as before i'm creating a command structure with the booleans start stop and reset last thing to do here is to give our new data type a name let's call it udt statehandler now we can add the structure to our machine data block first we open our db machine the name of our data structure is called state handler and our data type is the user defined type that we've just created so there you go now we've added a state handler data structure to our global machine data block you can always open up the structure by clicking on the little triangles to the left of the name our db equipment is still empty we're going to add a data structure for our supply module and a data structure for each of the two refill modules so for the supply data structure we start again by creating a new data type i'm going to create four structures here in our data type a status a command a configuration and a fault structure these are commonly used attributes of a data structure most modules will have some status information some commands to other modules a fault structure for fault status and possibly a configuration structure for our supply module we are not going to use the command and the config structure so i'm just adding one spare boolean into each of them in our status structure i'm going to add our low level status and a general fault status our fault structure consists of a word which will contain information about the individual alarms of the supply module we'll go more into detail with these structures in our next section of this course now we just name our new data type and that's it for our supply module data structure now we're only missing our refill module let's use our good old copy paste trick here we rename it to udt refill and we open it here in our status structure we're going to replace our low-level digital feedback with an analog level status because we have an analog level sensor in our refill tank furthermore we're adding status information for our pump running and our valve open [Music] now when our refill tank is low on water it will send a refill request to the supply tank so i'm adding this to our command structure we leave the config and the fold structure the way they are now we can add our supply and refill data structures to our global equipment db so let's open our db equipment first we'll add our supply structure and then our two refill structures one for each process since both of our refill processes are identical in components and functionality we can use the same udt refill for both of them now we've built global data blocks for our machine modules and our equipment modules before concluding this lecture i would like you to show this possibility of structuring your plc data types in the same manner that we've created groups for our program you can create groups for your data types just right click on plc data types and select add new group we'll make one for equipment and one for machine now we just drag and drop our data structures into the relevant groups and there you go we've improved our application overview and readability once again [Music] we are going to create input and output tags for our application input signals in a plc application are used for status of signals such as push buttons switches or for status of devices such as a pump fault status or a valve open feedback output signals in a plc application are used for controlling devices such as relays motor starters lights etc for our refill application i have defined a number of inputs and outputs for our equipment modules and our machine modules i've attached a list of these inputs and outputs in the resource section of this lecture we have two equipment modules our refill module consists of a pump a valve and a tank for our pump i have defined three inputs a circuit breaker a local isolator and a feedback that the pump is running the pump operation is started with a digital output our valve will have one input for feedback of the valve open position and one output to open the valve our tank will have an analog input for indicating the actual water level in the tank our supply module consists of a tank with an input for indication of low water level our state handler is the only machine module that we'll be using for our sample application here i've defined some inputs and outputs for operator interface with the application we will have three inputs for starting stopping and resetting the application for indicating the state of our application to the operator we're going to use two lamps one for application running and another one for application faulted so now that we've had a quick overview of our inputs and outputs let's go and add them to our application all plc tags inputs outputs and markers are created in our project tree under the group plc tags in the same way that we've created group structures for our program and for our user defined types in previous lectures i'm going to start here by adding two groups one for machine and one for equipment in tia portal tags are grouped together in a tag table if we open for example this default tag table here you can see that it contains the system memory bits and clock memory bits that we've enabled in our plc configuration in an earlier lecture of this course let's start by creating an input and output tag table for our machine group we'll name them inputs machine and outputs machine so we start by adding our machine inputs first we double click on the inputs machine tag table by having a quick look at our attached pdf we can see that we're adding a start stop and reset button here so i'm adding those here in the tag table i have the habit of adding i underscore at the beginning of input tag names and q underscore at the beginning of output tag names for example by reading the tag name i underscore x button start i know that this is an input tag of the type boolean now let's add our machine output tags we need two digital outputs here for our lamps and done now we've added our inputs and outputs for our machine modules we're going to perform the same steps for adding our equipment ios first we create two new tag tables in the equipment group we name them inputs equipment and outputs equipment in our inputs equipment we add our refill inputs according to the attached pdf keep in mind that we have two refill modules so we'll have inputs for process 1 and for process 2. i have added underscore p1 at the end of refill process 1 tag names and underscore p2 at the end of refill process 2 tag names now we add our supply inputs so that's it for the equipment inputs let's add our equipment outputs here we have two outputs a pump and a valve for each refill module so four outputs in total one last thing to pay attention to here when creating your i o tags is assigning your hardware addresses they need to fit with the addresses that you've assigned to your i o modules in the hardware configuration our digital input module is configured with addresses 0 and 1. our digital output module with 2 and 3 and our analog input module from 4 to 11. so we're good here if you've assigned a hardware address that does not exist in the configured hardware tia will let you know after the compilation in the compilation results hi guys i hope you liked this lecture now if i was able to wet your appetite a little bit with this video then go and check out the description below the video on how to enroll in this course if you'd like to see more videos like this in the future then go and hit that subscribe button below the video thank you and bye for now [Music] you
Info
Channel: Hans Rock Solid
Views: 1,115
Rating: undefined out of 5
Keywords:
Id: 8aQgk-eOO9o
Channel Id: undefined
Length: 25min 41sec (1541 seconds)
Published: Sun Sep 26 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.