Siemens TIA Portal - PLC Programming Basics | Hans Schrynemakers | Skillshare

Playback Speed


  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Siemens TIA Portal - PLC Programming Basics

teacher avatar Hans Schrynemakers, Automation & Controls Engineer

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

39 Lessons (2h 48m)
    • 1. Getting Started - Introduction to this Course

      2:09
    • 2. Getting Started - Overview of the Sample Application used in this Class

      2:31
    • 3. Getting Started - Software Used in this Class

      1:17
    • 4. Getting Started - Activity: Retrieve the Sample Application

      0:58
    • 5. Getting Started - Let's Get Started!

      0:45
    • 6. Project Creation - First Steps

      1:01
    • 7. Project Creation - Creating a New TIA Project

      4:15
    • 8. Project Creation - Configuring the Hardware

      6:50
    • 9. Project Creation - Activity: Create a New TIA Project

      0:25
    • 10. Project Creation - Managing your Application

      3:28
    • 11. Project Creation - Additional Resources

      0:46
    • 12. Program Structure - Importance of Structure

      1:03
    • 13. Program Structure - Breaking Down the Application

      6:33
    • 14. Program Structure - Building Program Groups

      6:50
    • 15. Program Structure - Adding Global Data Blocks

      8:27
    • 16. Program Structure - Quiz

      2:41
    • 17. Program Structure - Adding Inputs and Outputs

      5:50
    • 18. Program Structure - Activity: Build your Application Structure

      0:25
    • 19. Program Structure - Groundwork is Done

      0:38
    • 20. Adding Logic - Let's get Functional

      1:27
    • 21. Adding Logic - Programming the StateHandler

      14:41
    • 22. Adding Logic - Programming the Supply Module

      7:31
    • 23. Adding Logic - Programming the Refill Module

      13:30
    • 24. Adding Logic - Quiz

      3:13
    • 25. Adding Logic - Adding Comments and Descriptions

      6:49
    • 26. Adding Logic - Compiling the Application

      3:33
    • 27. Adding Logic - Activity: Add Logic to the Application

      0:30
    • 28. Adding Logic - The Application is Done

      1:30
    • 29. Online - Going Online

      1:04
    • 30. Online - Downloading the Application

      7:09
    • 31. Online - Editing Logic

      5:06
    • 32. Online - Monitoring Code

      7:55
    • 33. Online - Modifying Tags

      8:27
    • 34. Online - Using Traces

      13:06
    • 35. Online - Activity: Download the Application

      0:30
    • 36. Epilogue - Congrats!

      1:35
    • 37. Epilogue - Bonus Activity

      1:23
    • 38. Epilogue - Bonus Solution

      10:25
    • 39. Epilogue - Thank You

      1:27
  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.

327

Students

--

Projects

About This Class

Are you excited to get into the world of TIA Portal but you don't know where to start? This course will allow you to add "TIA PLC Programmer" to your CV & start getting paid for your new skills.

Hi there! My name is Hans and I’m an automation and controls engineer.  I THRIVE on converting challenging and complicated automation projects in to fully functional PLC and HMI projects.

In this class, you'll learn the basic concepts, tools, and functions that you will need to create fully functional Step 7 PLC applications within the widely popular totally integrated automation solution, Siemens TIA Portal.

What you will get out of this course:

  • You’ll be able to create new projects in TIA Portal

  • You’ll be able to add a PLC to your TIA application and configure the hardware

  • You'll be able to structure your application in TIA portal using TIA specific structuring tools
  • You’ll be able to build data blocks using user-defined-types

  • You'll be able to create function blocks and add logic to them using TIA best practices
  • You’ll be able to simulate your application on your own laptop using S7-PLCSIM

  • You'll be able to monitor and troubleshoot your STEP 7 application online

Powerful TIA Tools and Best Practices at Your Fingertips 
Learning the fundamentals of TIA programming puts a powerful and very useful tool at your fingertips.  TIA Portal is one of the leading automation platforms used in industry, offering automation solutions for manufacturing companies all over the world.

Steve: "I feel this course has great information to offer, not only to beginning programmers but also to experienced programmers that perhaps use a different controller. Please continue to offer courses as you do an excellent job of explaining the proper steps and structure to coding."

Jobs in TIA development are plentiful.  Learning the foundations of TIA programming will give you a running start in the market and a strong background to more easily pick up other automation solutions such as Rockwell, Beckhoff or B&R.

Who did I design this course for:

  • This course is for anyone interested in starting with Siemens TIA Portal PLC programming

  • This course is especially beneficial to people who already have Step 7 and/or ladder knowledge

  • This course is for software developers who want to reduce their coding time by half and increase their TIA skillset

Abdelfattah: "This is an amazing course, Very well structured, The instructor is very knowledgeable! For me I am more familiar with Allen Bradley PLC environment, TIA was a dark area for me, This course has helped me a lot to find my way in this different environment. The fast Pace of the course really helped a lot to save my time and keep me motivated without distraction."

Content and Overview
Suitable for beginning programmers, through this class of 40 lectures and over 2.5 hours of content, you’ll learn all of TIA Portal´s fundamentals and establish a strong understanding of the concepts behind each step of creating a structured and well-written TIA PLC application.

Starting with an overview of the sample application used in the course, I will take you through the steps of creating a new TIA project, setting up the PLC and adding input/output modules to the hardware configuration.  Afterwards, we will look at how to structure the application into smaller, logical modules, and how to construct global data blocks using user-defined data types.

With these basic skills mastered, I will run you through the process of adding ladder logic to function blocks for the different modules used in the application.  We'll be putting a lot of importance on using TIA best practices while coding function blocks for the application.

Finally, with the application complete from a coding perspective, I will take you through the steps of downloading the application to a Siemens SIMATIC S7-1200/1500 PLC.  Furthermore, you'll get to learn how to edit code online, how to monitor/modify code and data online, and how to troubleshoot an application online using force tables, watch tables and data traces.

At the end of the course, YOU WILL BE ABLE to create, structure, program and download your first Step 7 PLC application from scratch using a wide array of TIA specific skills and TIA best practices.


What are the requirements for this course?

  • Some basic PLC knowledge is required - you should know what bits, bytes, timers and functions are

  • Basic Ladder knowledge is a plus - this course is based on (simple) ladder logic

Eric: "This course is highly recommended to starter who would love to learn solid foundation of programming, hobbyist and also professionals who has no proper technique. I enrolled many PLC lectures in my account none of them impress me but this one is superb. I love the concept and technique that no one talk about. I would say the Instructor is very well experienced in the field."

Complete with a link to a 21-day free TIA Portal trial version, downloadable TIA sample applications, checklists and other practical documents, you’ll be able to participate actively alongside me - your instructor - as we work together through each concept.

Now it´s time to upgrade yourself and get started with TIA Portal!

Meet Your Teacher

Teacher Profile Image

Hans Schrynemakers

Automation & Controls Engineer

Teacher

For over 20 years, I've been working professionally as a control engineer within the manufacturing industry.  During this time as a system integrator, I've had the pleasure to work on many diversified and challenging automation projects with many great machine builders and manufacturing companies all over the world.  A big part of my work consists of commissioning machines and production lines at customers on-site.

In 2013, I started my own automation company - Rock Solid Automation.  As a self-employed system integrator, I've build up a very successful customer base and I have been part of many fulfilling projects.  I have a real passion for programming, and I thrive on innovation and technology.

My professional expertise consists of software solutions... See full profile

Class Ratings

Expectations Met?
    Exceeded!
  • 0%
  • Yes
  • 0%
  • Somewhat
  • 0%
  • Not really
  • 0%
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.

Transcripts

1. Getting Started - Introduction to this Course: Hi, welcome to this course on TIA Portal - PLC Programming Basics. My name is Hans Schrynemakers and I am an automation engineer. For over ten years I've been working professionally with TIA software and hardware. The last six of those years, as a self-employed system integrator. My professional life consists of programming, implementation, commissioning and troubleshooting TIA software on production lines all over the globe. I once found myself in a similar position that you are in now. I was just starting my first TIA application. I was not really sure which steps I should take first. I had many question... In this course, I would like to help you jumpstart your first TIA experience by sharing my years of knowledge with you. So what will you get out of this course? In this course you will learn how to convert a real world application into a TIA Portal PLC application. You will learn how to download your software and how to monitor your code online. In this course, we will also put a lot of importance in using TIA specific tools and implementing code using TIA best practices. Because these two will speed up your code process, improve your code efficiency and optimize your project resources. I am confident that by the end of this course you will be able to create your own TIA applications. Throughout this course, you will be encouraged to participate in activities like creating a new TIA project, coding function blocks, etc.. I've added a couple of fun quizzes as well to test your progress throughout the course. We will use a real world sample application for this course. Step-by-step, we will translate this application into a fully functional TIA PLC application. In the following lecture, I will give you a short overview of our sample application. Thank you for now and see you on the next lecture. 2. Getting Started - Overview of the Sample Application used in this Class: In this lecture, we'll have a look at the sample application that we'll be using for our coding in this course. I've attached a PDF of the application overview in the resource section of this lecture. So feel free to download it and follow along. The basic idea of our sample application is this: we have two process tanks with a certain amount of water in them. The water in a process tank is being fed to a process in the plant. When the water level reaches a low level in either one of the process tanks, a refill sequence will start using water from the supply tank. So let's take a closer look at the individual parts of this application. Let's start with the supply tank. Our supply tank setup is pretty simple. We have a big tank filled with water. We have a low level digital sensor that indicates when the water level gets low in the tank. Now let's have a look at our process tanks. Both process tanks are identical in setup. So we're just gonna look at one of them. The process tanks are filled with water from the supply tank. They each have an analog level measurements to indicate the amount of water left in each tank. Two important levels for our application are indicated on the overview by low level, for example 10 percent, and high level, for example 60 percent. In order to transfer water from the supply tank to a process tank, each process tank is equipped with a membrane pump and a pneumatic valve. So that was a short overview of the individual parts of the application. Now let's have a look at how the refill sequence actually works. A refill sequence is triggered as follows: the water level in a process tank drops below the low level of 10 percent. The appropriate valve is opened and the appropriate pump starts pumping water from the supply tank to the process tank. When the water level in the process tank rises above the high level of 60 percent, the pump operation is stopped and the valve is closed. The refill sequence is now complete and will trigger again next time the water level drops below 10 percent. So this lecture was about giving you guys an overview of our sample application. Our next section in this course will focus on turning this application into a TIA Portal PLC application. I hope you've enjoyed this lecture, and I'll see you in the next lecture where we'll have a quick look at the software that we'll be using in this course. 3. Getting Started - Software Used in this Class: During this course, you and I will build an application together. Most of the activities will require you to have TIA Portal installed on your computer. The finished version of our sample application is written in TIA Portal version 14 service pack 1. In order for you to use this application, you should have TIA Portal version 14 service pack 1 or a higher version installed on your computer. But don't worry if you do not have TIA Portal installed yet. Our next lecture will include a link to a free 21-day trial version of TIA Portal version 15.1. Our sample application is called "Refill". In the next lecture you will be able to download this finished version of our application. Throughout this course we will build our application together, step-by-step. I would recommend you to use the finished version of the refill application as a comparison tool for your progress. In this lecture I've provided you with a quick overview of the software that we'll be using in this course. Now it's your turn. In the next activity you will receive steps on how to download our finished refill application and how to retrieve the application in TIA Portal. Good luck. 4. Getting Started - Activity: Retrieve the Sample Application: 5. Getting Started - Let's Get Started!: So did you get the sample application? I hope you did, because participation is a very important part of this course. Just listening to someone explaining how to do things will only get you this far. Actively participating in coding activities and other activities throughout this course, will make sure that the obtained knowledge will stick with you. Learning by doing. In this section, I've provided you with a short overview of this course. Furthermore, we had a look at our sample application. In the next section of this course, we will create a new TIA project for our application. We will configure the hardware and we will set up the PLC. See you there. 6. Project Creation - First Steps: Developing a new TIA application requires you to take a certain number of steps. The first step in this process is creating a new TIA project. In this section of the course, you'll learn how to create a new project. First, we're gonna go through the steps of creating a new project and we're going to add a PLC to our application. Then we're gonna have a look at the hardware, how to configure the hardware, how to set up the PLC, and we're gonna add some input and output modules to our configuration. Finally, we're gonna have a look at project management, how to save an application, load and application, how to backup your application and restore your application. By the end of the section, you will be able to create a new TIA project, configure your hardware of your application and manage your project. So let's get started. 7. Project Creation - Creating a New TIA Project: In this lecture, we're going to create a new project for our sample application. As mentioned in a previous lecture, I'm going to use TIA Portal version 14 service pack 1. You guys can of course use whichever TIA version you have, as long as it's version 14 service pack 1 or a later version. When you first start TIA Portal, this is the first screen that you'll see. TIA portal has two different environments. The Portal View, which is this one we're on right now, and the Project View, which we're going to see in a second. The Portal View provides a simple navigation in the tasks and data of the project. On the left we have the portals for the different tasks. In the middle you'll find actions for the selected portal. And finally on the right, you'll find a selection panel for the selected action. So now we're in the Start portal. The actions available here are: open an existing project, create a new project, migrate a project, etc. We are going to create a new project. Now we have to define a name for our project. Our application is called Refill. And because it's a work in progress version, we'll call it Refill Work. By pressing enter or clicking on Create, our new project will be created. As you can see, our project was opened successfully. We were going to skip these next steps in the Portal View. Instead, we're gonna go to the Project View where the rest of the application creation process takes place. So now we're in the Project View. The Project View provides a structured view of all components of a project. The Project View has the following main components: at the top you have the menu bar. Below the menu bar you've got the toolbar. Below this toolbar the screen is divided in two different sections. On the left side you'll find the project tree, and on the right side, you'll find the work area. Personally, I do all of my TIA work in the Project View. I don't really use the Portal View except for maybe loading a project. I would recommend you to do the same because the Portal View just doesn't have all the functionality that the Project View has. Stick with the Project View. So let's start by adding a PLC to our application. This is done by clicking on "Add new device" in the project tree on the left. There are four different categories: Controllers, HMI, PC systems, and Drives. We are adding a PLC. This is a controller. For this application, we're using a Step 7 1500 type PLC. Let's select the 1511-1 PN PLC. As you can see, there are different versions of this device. We'll just select the latest version. Now that our PLC is added to our application, the only thing left to do is assigning a name to the PLC. This name should be coherent with your application name. Our application is called Refill Work, so let's change the name of the PLC to PLC Refill Work. We'll close this configuration screen for now. We'll come back to it later. Don't forget to save your application once in a while. You do this by pressing "Save project" in the toolbar. Alternatively, you can use the shortcut command Ctrl+S. I would recommend to make it a habit to press Ctrl+S regularly during your coding process. This way you make sure that your work doesn't get lost. We now have successfully created a new project for our application and we've added a PLC. In the next lecture, we're going to set up the PLC and add input and output modules. Thank you, and see you on the next lecture. 8. Project Creation - Configuring the Hardware: Hi, welcome back. In the previous lecture we've created a new TIA project called Refill Work. In this lecture, we're going to have a look at the PLC settings and add and configure the necessary hardware for our application. Once TIA Portal is started, you'll see that our refill work application is under "Recently used". Just double-click on it and our application will open. As I mentioned before, we're not really gonna use this current view, the Portal View, for anything other than creating or opening a project. So let's go to the Project View. Let's start by taking a look at our PLC setup. We do this by clicking on "Device configuration" underneath our PLC in the project tree. First, we're going to set up the network configuration. Under "Profinet interface", we're going to click on "Ethernet addresses". Here you can see that we are not connected to any network yet. If we are not connected to a network, we will not be able to download our application later on. So let's add a new subnet. There we go. Now we are connected to the subnet PN/IE_1. This is fine and we'll just leave it like that. Here you have the possibility to change your controller's IP-address as well. We are just going to leave it like it is. So now we've set up the PLC's network configuration. You could just leave the PLC setup like this, but I would recommend to you to enable the PLC's system memory bits and clock memory bits. You do this by going to "System and clock memory" and enabling both use of system memory byte and use of clock memory byte. The system memory byte contains useful bits like the first cycle bit and an always-high and always-low bit. The clock memory byte contains different clock frequencies which can be used in your code. For example, marker M0.5 here is the 1 Hz clock. 1 Hz equals one per second so we'll have one pulse per second. Since the pulse-to-no-pulse ratio here in TIA Portal is one to one, this means that we'll have a pulse of 500 milliseconds high signal, 500 milliseconds low signal. Now that we are finished setting up our PLC, let's go and add some input and output modules to our application. In the resource section I've attached a PDF with all the inputs and outputs that we'll use in our application. So you can open this and follow along. I have opened the PDF here as well. As you can see, we're going to need a total of 12 digital inputs, 6 digital outputs and 2 analog inputs. Now back to our application. In order to add IO modules, we'll need to open the hardware catalog situated on the right side of the screen. So let's first add a module for our digital inputs. We'll select this module right here with 16 inputs and we'll just drag and drop the module to the next available slot next to our controller, which is slot 2 in this case. Now we're going to do the same for our digital output module. So we're going to drag this output module to slot number 3. There you go. Digital output module added. The last module that we need is an analog input module. We're taking this first analog input module right here. Our application has 2 analog inputs. This module has 4. So it's more than sufficient. We're dragging and dropping this into slot 4, and there you go. All of our IO modules have been added to our application. The final thing that we're going to do here, is configure our IO addresses. You could leave them the way they are because TIA will automatically assign valid IO addresses to new modules. But I always prefer to set them manually. This way you can assign IO address ranges which are intuitive for your application. So let's start by clicking on our digital input module and go to "I/O addresses". Here you can see the start address at 0. We'll leave this at 0. Next, our digital output module. Let's change the start address to 2. And finally, our analog input module. We'll change the start address to 4. So now we have our digital input addresses at 0 and 1, our digital output addresses at 2 and 3, and our analog input addresses from 4 to 11. So that concludes the configuration of our IO modules. One last thing I'd like to show you guys here, are the different views that you can choose in your hardware configuration. At the moment we're in the Device view. This is great for setting up your device, for example a PLC or an HMI. The Network view will give you an overview of how multiple devices in your application are connected together to different networks. In our application, we only have one device, a PLC, which is connected to a profinet network. This is what the Network view shows us at the moment. The final view here in the hardware configuration is the Topology view. This view comes in handy when you have more advanced applications where port configurations and interconnections are important. So that concludes this lecture on configuring the hardware for your application. In this lecture, we've set up our PLC and we've added and configured our IO modules. Now it's your turn. In our next activity, you get to create a new TIA project, set up the PLC and configure the hardware. Thank you for now, and good luck with the activity. 9. Project Creation - Activity: Create a New TIA Project: 10. Project Creation - Managing your Application: Hi, guys. Welcome back. So how did you do on the previous activity? If you have any questions regarding the activity or any questions regarding other topics, just use the Q&A section below this video. In this last lecture of this section, we're gonna have a quick look at project management. First, we'll have a look at how to save and open an application. Then we'll go through the steps of backing up and restoring an application. Saving your application can be executed in different ways. First, there is the quick save method, which we've seen before, by pressing Ctrl+S. You can also press on "Save project" in the toolbar. Another way of saving your application is to go to Project in the menu bar and press on Save. Here you have the option as well to save your application under a different name. This comes in handy when you have version numbers or dates in your application name. Let's say your application is called Refill_V1.0. Now you've made some changes to this application and you want to save your application. Here you can use the "Save as..." command and save your application under a new name. Like for example Refill_V1.1. Opening an application can be done by pressing the shortcut Ctrl+O. Alternatively, you can go to Project in the menu bar and press on "Open...". So now that we've looked at saving and opening and application, let's see how we can backup and restore an application in TIA Portal. Backing up an application in TIA Portal is called Archiving. By archiving your application, the application will be compressed and stored into a single file. This makes it easy to store a backup of your application on an external hard disk or any other storage medium. To archive your application, go to Project and press on Archive. In the archive settings, you can choose the name for your archive and a path where to save your archived project. Furthermore, you can add a date and time to your archive name, which I would recommend. Now we press enter or Archiving and the project will be archived. Now let's have a look at how to restore a project. Restoring a project is called Retrieve in TIA Portal For retrieving an archived project, just go to Project in the menu bar and press on "Retrieve...". Here you have to select the archive file, so let's select the archive that we've just made. Now you have to select the target directory. Where do you want the retrieved project to be saved? We'll just save it under the default folder that it suggests here. Now our application has been retrieved and it has been opened automatically after retrieval. So there you go. That's how you backup and restore your application in TIA Portal. Thank you and see you on the next lecture. 11. Project Creation - Additional Resources: So that's how you create a PLC project in TIA Portal. Now we've reached the end of this section. In this section you've learned how to create a PLC project in TIA Portal, how to set up the PLC and the hardware configuration, and how to manage a project. If you have a look at the resource section of this lecture, you'll see that I've attached a PDF with my personal recommendations regarding project creation and project management. Feel free to have a look and use what seems valuable to you or your work. Now in our next section, we're going to look at how to structure an application and how important it is to first define your application structure before starting any coding. Thank you once again for following me on this journey. Bye for now and I'll see you on the next section. 12. Program Structure - Importance of Structure: If I had to pick one skill that has contributed the most to my successes in my professional career, it has to be the ability to work organized and structured. An organized application is an application that is built using logical modules with code that is organized, well-documented and easy to read. 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. By the end of this section, you will be able to structure an application in TIA Portal. I'll see you on the next lecture where we're going to start by breaking down our sample application. 13. Program Structure - Breaking Down the Application: In this lecture, we're going to break down our sample application into smaller, logical modules. Afterwards, we'll have a look how this translates into a PLC program structure and program code. All the slides used in this lecture can be found as downloadable PDF's in the resource section of this lecture. So let's start again by having a look at the overview of our sample application. 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. Now, I'd like you to pause the video and just take a moment here. How would you break down this application into smaller, logical modules? So did you find a way of structuring the application into smaller, logical modules? I will share with you the solution that I came up with. Now, keep in mind, this is not an exact science. There is more than one way to structure an application. Important is that you give it some thought and that you can identify logical modules or modules where code can be reused. 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, and 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 our application. So now we have defined function blocks for our equipment modules, 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. So there you go. This lecture was all about breaking down our application into smaller, logical modules, and defining a structure in the PLC program for these modules. In the next lecture we will start implementing our structure in TIA Portal by creating program folders and our main function calls. Thank you and see you on the next lecture. 14. Program Structure - Building Program Groups: Welcome back. 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 00 to my machine group name and 01 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 call "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: an 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 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. OB1. First we double click on OB1 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 a 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 instance DB's in a later lecture. For now, let's assign a name to our instance DB. 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 instance DB 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 our instance DB. Finally, we move the instance DB to our equipment group. To further improve the readability of the application, I'm going to add network titles here in our OB1. There we go. Now it's clear what each network is used for. That brings us to the end of this lecture. In this lecture, we have added a group structure to our application and we have created our main function calls. In our next lecture, we are going to add global data to our application. I hope you enjoyed this lecture. Thank you, and see you on the next lecture. 15. Program Structure - Adding Global Data Blocks: 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 DB's. 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 our global DB's 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 4 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 4 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 Statehandler 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. 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 fault 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. In this lecture, we've built global data structures for our application, using user defined data structures for each module. In our next lecture, we're going to create input and output tags for our application. But before we do that, I have created a little quiz for you guys to test your progress so far on program structures. So have fun with it and I'll see you all on the next lecture. 16. Program Structure - Quiz: 17. Program Structure - Adding Inputs and Outputs: In our last lecture of this section on application structuring, 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 a reset button here. So I'm adding those here in the tag table. I have the habit of adding "i_" at the beginning of input tag names and "q_" at the beginning of output tag names. For example, by reading the tag name "i_xButton_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 IO's. 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 one and for process two. I have added "_P1" at the end of refill process one tag names and "_P2" at the end of refill process two 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 IO tags, is assigning your hardware addresses. They need to fit with the addresses that you've assigned to your IO modules in the hardware configuration. Our digital input module is configured with addresses zero and one, our digital output module with two and three. And our analog input module from four to eleven. 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. In this lecture we've created the inputs and outputs tags for our application. Now it's your turn again. In our next activity you'll get to use all the tools that we've learned in this section to structure your work-in-progress refill application. You'll be building program groups and main function calls, adding global data blocks, and creating input and output tags. Thank you and good luck with the activity. 18. Program Structure - Activity: Build your Application Structure: 19. Program Structure - Groundwork is Done: So the foundation of our application is finished. In this section we have broken down our application into smaller, more digestible, logical modules. We've added a folder structure to our program and we've defined our main function calls. Furthermore, we've built a global data structure, which we're gonna use afterwards, and we've added input and output tags to our application. In our next section we're going to fill up our structure with program code. So exciting times are ahead of us. See you in the next section. 20. Adding Logic - Let's get Functional: Welcome back. So what have we done in this course so far? First, we have created a new TIA project. Here we looked at the PLC setup and the hardware configuration. Then we added structure to our application by creating program groups and main function calls, building global data structures and adding input and output tags to our application. In this section, we're going to add functionality to the application. This means that we're going to build the function blocks that control the machine and equipment modules of our application. We're going to put a lot of importance on using TIA best practices when programming our function blocks. This way, our function blocks will be optimized for reusability and scalability, while at the same time using less PLC resources. It's gonna be a Win-Win. First, we're going to program our machine state handler. Then we're going to build up our supply and refill function blocks. Finally, we're going to improve the readability of our code by adding comments and descriptions. By the end of this section you will be able to create your own function blocks. In our next lecture we're going to start by adding functionality for our machine state handler to the application. See you there. 21. Adding Logic - Programming the StateHandler: In this lecture, we're going to program the functionality of our machine state handler. For this purpose we are going to build a function block. You should always look at blocks as encapsulated functions. Each block represents a complete partial task within the entire user program. In our case, our state handler function block will contain the complete machine state handler task within our user application. We are going to build our function block in four steps. First, we are going to create and name our new function block. Then we are going to add inputs, outputs and inouts to our block interface. Afterwards, we are going to add code to our function block. Finally, we are going to call our function block in the user program and assign interface parameters to the block call. We start with our first step. We are going to create and name our new function block. Let's have a quick look at our PLC program hierarchy. Here you can see that our state handler will be called by "FB - Machine Modules". As we've mentioned before, "FB - Machine Modules" will contain all the calls for our machine modules, in our case only one module - the state handler. In order to improve the overview of our application, I'm going to add a group under our machine group called Functions. This group will contain all the function blocks for our machine modules. So here we'll create our state handler function block. Right-click on the functions group and "Add new block". We are creating a function block, so we click on that. The name for our function block will be "FB - StateHandler". Our language is ladder and we let TIA assign a number automatically. Press enter or click on OK, And our function block has been created. Now for step two, we are going to add our interface parameters - inputs, outputs and inouts - to our block structure. First, we open our function block by double-clicking. TIA Portal has these handy little triangles here you can click on to enlarge or shrink the view of the interface parameters. By having a look here at our state handler inputs, we can see that we are going to need 3 inputs for start, stop and reset button. I start by adding these to our block interface. For our outputs, we're going to need a lamp for application running, and another one for application faulted. So I'm adding those as well. Furthermore, I would like to output some information about the active machine state. For this purpose I'm adding 4 boolean outputs, one for each state. As we've mentioned before, our modules will communicate, exchange data with each other using global data structures. When we have a look at our PLC program structure, we can see that the state handler will exchange data using data structures of "DB - Machine" and "DB - Equipment". We are going to add these data structures to our InOut area of our block interface. So why do we add them to the InOut area and not to the Input or the Output area? Well, TIA Portal recommends to use the InOut interface type for structured tags, like arrays, user defined structures, strings, etc... This way you avoid enlarging the required data memory unnecessarily. With inputs and outputs, the value of the parameter is copied onto the formal parameter of the function block. This requires additional memory in the called block. For InOuts only a reference of the actual parameter is used. And this does not require additional memory. So in short, using InOuts for larger structures will optimize the use of your PLC resources. So let's start by adding the state handler data structure to our InOut area. I'm adding "iq_" to the beginning of the name to indicate that it's an InOut, followed by the letters "st" to indicate that our tag type is a structure. The data type for our state handler structure is the UDT_Statehandler that we've created in a previous lecture. Our state handler will need the fault information from the equipment modules. So I'm adding the supply and refill data structures as well to our InOut area. There we go. Now, we've completed step two of our process. We have added the inputs, outputs and inouts to our block interface. Our static and temporary areas are still empty, but we will assign parameters to them when we start coding our function block. So why did we assign our PLC tags - inputs and outputs - and our global data structures as inputs, outputs and inouts? Why did we not just use them directly in the function block code? Well, the reason for this is that function blocks should be universal, modular and reusable. If possible, only use local tags inside a function block. All global data and PLC tags should be assigned to inputs, outputs or inouts. In our next step, we're going to add code to our function block. We'll start by adding the control of our state handler, followed by status information. Our ladder elements are situated just above the block title. We will use a state integer to control our state handler. Our first network will contain the code to go from our ready state, which we define as state zero to our running state, which we define as state one, by pressing a start button. So we start by checking for a zero state. We do this by selecting the ladder in network one and clicking on the empty box element. Now we need to use the comparison element "equal to" here, which in TIA Portal is defined by the signs equal to, equal to. First, we define a local tag for our state. Now, since it doesn't exist yet, it's underlined in red. To create this tag, we right-click on it and we select "Define tag...". This tag will be a local static tag and the data type is integer. There we go. Our tag has been created and as you see here, it has been added to our block interface under the Static area. For tags that require remembering the value in the next cycle, use static tags. For tags that are only used as intermediate memory in the current cycle, use temporary tags. Now we add our start button condition, which can be a start command by pressing a hardware push button or a start command from our state handler data structure. The start command from our state handler data structure can be connected, for example, to a software push button on an HMI. Finally, we move one into our state. To add the move element, first insert the empty box element and then type MOVE. You can see that TIA auto-suggests tags while you're typing. Use this to save time in your coding process. Now we just add a title to our network. And there you go, our official first line of coding. So in this network, we go from state zero, which is our ready state, to state one, which is our running state, by pressing a hardware or a software start button. Our other control networks will have a buildup using a similar structure. So I'm just going to copy this network one here a couple of times to save time. So left-click on the network, Ctrl+C - Ctrl+V - Ctrl+V a couple of times. And now we have our starting point for our other control networks. In our second control network we are going from a running state one to a ready state zero by pressing a stop button, hardware or software. In the following control network, we are going from a ready or a running state to a fault state. Our fault state we define as state two. The conditions for going into a fault state are defined by a fault on either one of the equipment modules. Here we are using the fault states of our supply and refill data structures. To go from a fault state back to a ready state, we first need to execute a reset command, in order to clear the active faults. In our next network, we go from our fault state two to our reset state, which we define as three, by pressing a hardware or software reset button. In our final control network, we hold the reset state for two seconds before going back to our ready state. We are using here an on-delay timer for this purpose. We start again by adding an empty box and pressing TON in the input field. In the call option for our timer, we can choose between a single instance, a multi instance or a parameter instance. A single instance will create a new separate instance DB for this timer call. A multi instance will create the instance data in the static area of the block interface of our current function block. A parameter instance will create the instance data in the InOut area of the block interface of our current function block. The parameter instance is only used for special cases like when processing different instances iteratively in program loops. In all other cases, TIA best practices will tell you to use multi instances. The advantage of using multi instances are a lower number of instance DBs, which improves your application structure and the re-usability of function blocks. So we click here on multi instance. The name for our timer will be "stOnDelay_Reset". I've added "st" to the start of the name to indicate that this is a structured tag type. Now we just add the time duration of two seconds to our timer block. And as you can see, our multi instance has been added to the static area of our block interface. Clean, structured, perfect. So now we have programmed our networks for the control of our state handler. What we're still missing here in our function block are the status of each state - ready, running, faulted and reset. We'll start with our ready state. We have defined state zero as our ready state. When our state is equal to zero, we activate both the ready state in our state handler data structure, and at the same time, we activate our information output. Let's add a title to our network as well. So that's it for the status of our ready state. I'm going to do the same here for our running, faulted and reset state. We start again by copying and pasting the ready status network three times. This saves us coding time. Now we adapt the three networks so they represent the status for the states running, faulted and reset. Now the only thing left to do is adding our output lamps to our state status for running and faulted. And done. We have completed our coding for our state handler function block. Let's minimize the networks to have a quick look at our structure. We have created and programmed five networks for control of the state handler states and four networks for status of the state handler states. Let's add a block title here as well for a short description of this function block. In our last step, we're going to call our state handler function block in our "FB - Machine Modules". So we start by opening the "FB - Machine Modules" block. Now we just drag and drop "FB - StateHandler" into network one. As mentioned before, we'll be using multi instances whenever possible to minimize the number of instance DBs in our project and to optimize our structure. We'll call this "Instant_StateHandler", and enter. You can see now that our multi instance has been added to the static area of our block interface. We are still missing our interface parameters. So we'll add those to the block call. For inputs we're adding the start, stop and reset button. Because we've started all of our input names with "i_" and because TIA auto-suggests tags when entering the tag name, it is now a very easy and quick process to add our input tags. We do the same for our output tags lamp running and lamp faulted. For our information outputs I'm first going to create a temporary info structure with our four states - ready, running, faulted and reset. Now I'll just add them to the outputs of the block call. A small side note here - starting from TIA version 15, you don't need to create these temporary tags anymore to see the result of a block output. The output status will automatically be displayed when online. Finally, we're adding our data structures to the InOuts of the block call. As we've mentioned before, data exchange between blocks should be done via the block interfaces - inputs, outputs, or inouts. This guarantees the re-usability of the block. Never use instance DB's for data exchange between blocks. Instance DB's should only be used as local memory for the respective function block. We add a title to our network as well, and we're done with our final step of adding our state handler function block to our main machine modules. So we've come to the end of this lecture. In this lecture, we've programmed our machine state handler. We've gone through the four steps of creating a function block, adding interface tags, coding the control and status of our states, and calling our function block in our "FB - Machine Modules". In our next lecture we're going to create and code our supply and refill function blocks. Thank you, and see you on the next lecture. 22. Adding Logic - Programming the Supply Module: In our previous lecture, we programmed the machine state handler. The state handler is a machine module. In this lecture, we're moving on to equipment modules by programming the supply module. In our next lecture we're going to program the refill modules. For programming our supply function block, we're going to use the same four steps from our last lecture. We are going to create a function block and assign a name to it. We'll add inputs, outputs and inouts to our block interface. We are going to write code for our function block. Finally, we're going to call our function block in the user program and assign our PLC tags and global data to the block call. So we start with step one - creating a new function block. In our PLC program hierarchy we can see that our supply module is being called by "FB - Equipment Modules". This means that in our application structure, we are going to create our function block under the group Equipment. First, we create a new group called Functions under our Equipment group. This Function group will contain all modules that we'll use in our Equipment group. For our application this means our supply function block and our refill function block. So for creating our supply function block, we right click on the Functions group, and select Add new block. We are creating a function block and the name for our block is "FB - Supply". Our languages is Ladder and we let TIA automatically assign a number to our function block. Press Enter, and our supply function block has been created. For our second step, we are going to add our inputs, outputs and inouts to our block interface. So double-click to open our function block and we'll maximize the block interface view by pressing on the little downward triangle right here. Taking a look at our inputs, we can see that we only defined one input for our supply module. A low level digital feedback. So I'm adding this input to my input area. We have not defined any outputs for our supply module, but just for information I'm adding one fault status output here. Now we just need to add our global data structures. In this function block we're going to need our supply data structure and our state handler data structure. So I'm adding those to our InOut area. As mentioned in our previous lecture, large data structures like user defined types, arrays and strings should be added to the InOut area of the block interface in order to optimize the use of your PLC's memory resources. So now that we've added all of our inputs, outputs and inouts, step two of our process is complete. In our third step we're going to add code to our function block. Our supply module does not contain much functionality. We'll start by adding a couple of fault networks, followed by a status network with a fault summary status. In our first network we're going to create a low level fault. Whenever our supply tank is low on water, we would like to indicate this via a fault on the supply module. We're only interested in the low level when the machine is running. So we start by adding a condition for our running state. This running state we take from our state handler data structure. Now we add our low level input condition. And finally, we set our fault. You can see that I'm using the trigger word here that we've defined in our supply fault-structure. By adding ".%X0" to the end of the trigger word, I'm only accessing bit zero of the word instead of the whole word, which is 16 bits in total. In TIA Portal, this is called Slicing. The reason I'm using a word here for fault triggering is as follows: a common method for visualizing alarms on a Siemens HMI is by using a word. Choosing a word now for my alarms in my PLC code will make it very easy afterwards to add those alarms to an HMI. In our second network, we add a fault reset. All the faults in our application will be reset when the state handler reset state is active. So we add the condition of our reset state, and when it occurs, we move zero into our trigger word. Here you can see another advantage of using this trigger word. By moving zero into the word we reset all fault bits of the word. In our case, we are only using bit zero for our low level fault, but in other applications, all bits could be used for false. Our last two networks here will be status networks with a low level status and a fault summary status. For our low level status we activate the low level status in our data structure if our low level input is high. Our last network here will be a status network with our fault summary. When our fault word is different from zero - this means we have a fault - we activate the fault status in the supply data structure. Furthermore, we output the fault status in our block interface. Let's minimize our networks and add a title to our block. So that's all the coding we're going to do for our supply module. The supply module in our sample application is more like a passive module. It only has fault information, it does not actively control anything. Our refill module on the other hand, that we're going to program in the next lecture, will have an active control part. In step four, our last step, we're going to add our "FB - Supply" to our "FB - Equipment Modules". First, we open the "FB - Equipment Modules". And now we drag and drop our "FB - Supply" into Network 1. We're using a Multi-instance, and our instance name will be "Instance_Supply". Now we'll add our PLC tags and data structures to the block call. So we have one input for low level, our state handler data structure, and our supply data structure. For our output on fault information, I'm going to create a new temporary tag. Now we just add a title to our network and to our block, and there we go, our final step is complete. We have added a call of our "FB - Supply" to our application. In this lecture, we've added code for our supply module to the application. The only module that we're missing now is our refill module. We're going to work on that in our next lecture. So thank you guys, and I'll see you on the next lecture. 23. Adding Logic - Programming the Refill Module: Hi, welcome back. In our last two lectures, we've programmed our state handler function block and our supply function block. In this lecture we're going to finish the programming of our function blocks by creating code for our second equipment module, our refill module. We're going to use the same four steps from our last two lectures to build up our refill function block. In step one, we're going to create and name our function block. In step two, we'll add our inputs, outputs and inouts to the block interface. In step three, we're going to add all the code to the function block. And finally, in step four, we'll call the function block and we'll assign PLC tags and global data to the block call. So let's start by creating a new function block. A refill function block is part of the functions of our equipment group. So to create our new refill block here, we right-click on the Functions group and we select "Add new block". We are creating a function block and the name for our new function block is called "FB - Refill". Press enter, and there we go. Our new refill block has been created under the Equipment Functions group. For step two, let's open our "FB - Refill" and start adding inputs, outputs and inouts to our block interface. We maximize our block interface view first. Now for our refill module, we have defined three pump inputs - circuit breaker, local isolator and running feedback - one valve input - valve position open feedback - and one tank analog input for the actual water level. Looking at our outputs, we'll need one output for starting our pump and one output for opening our valve. Furthermore, I would like to output some information about the module fault status. In the InOut area we're adding the data structures for the state handler, the supply module and the refill module. In our next step, it'll become more clear how we're going to use the data structures in our program code. So that's step two done. We've added our inputs, outputs and inouts to our block interface. Now, let's continue with our third step. We're going to add code to our function block. First, we're going to code our refill request followed by control of our pump and valve outputs. Then we're going to implement our fault handling. And finally, we're adding some code for status information. In network one we start with our refill request. Let's have a quick look at our application overview. Here you can see that we've defined our refill tank low level at 10 percent and high level at 60 percent. So we're going to code setting the refill request when we go below 10 percent. And when we go above 60 percent, we'll reset the refill request. We start by adding an empty box element in our network one, and we type SR for selecting the set-reset element. Here, we'll use our refill request command from our data structure. Our refill request command will be set when our tank level goes below 10 percent, and it will be reset when we go above 60 percent. So that's all the code we need for our refill request. In our second network we're going to control the operation of our pump. The conditions to start our pump are as follows: the application should be running and a refill tank has to be low on water. So we need a refill request. Furthermore, the refill module cannot be in a fault state, and the valve needs to be open. Else we'd be pumping against a closed valve. Probably not good for the lifespan of the pump... Finally, we add the condition that the supply tank level cannot be low. It doesn't make sense to refill our refill tank with water from a supply tank if the supply tank has no water. If all of these conditions are met, we start the pump operation. I'm adding a local temporary tag as well here, which we'll use later in our fault handling. In our next network, we'll add the control of our valve. Since the valve control is pretty similar to the pump control, I'm going to start with a copy of the pump control network and adapt it to my valve control. I'm taking out the valve open condition here and I'm changing the output to the output Open Valve. I'm adding a local tag here as well, for fault handling later on. So that's it for the control of our pump and valve. In our next networks we're going to program the faults for our pump and valve. Our pump will have faults for motor circuit breaker off, local isolator switched off and pump running feedback missing. Our valve will have a fault for not in open position. For our circuit breaker fault we check if our circuit breaker signal is missing when the application is running. We only check if our refill module is not faulted. Using TIA slicing, we set bit zero of our trigger word for this fault. Our other faults will have a similar structure. So I'm copying this network three times. If the application is running and our local isolator signal is missing, we set bit one of our trigger word. For our feedback pump running fault, we want to check that the pump is running when we enable our pump operation. So if our application is running and we activate the command to run our pump, we should get a feedback from the pump that it is running. This feedback will not come straight away after enabling the pump operation. So we need to implement a small delay here after the start of our pump operation. For this purpose we are going to use a two seconds on delay timer here. Finally, we set bit two of our trigger word, if the pump running feedback is not available after our pre-defined time limit. Our valve not in open position fault is very similar to our pump not running fault. If the application is running and we give a command to open our valve, we should get a position open feedback within a pre-defined time limit. For this fault, we use bit three of our trigger word. In our last fault network, we're going to reset our faults. If the state handler is in a reset state, we clear all of our fault bits by moving zero into the trigger word. Our last networks will contain code for status information about our tank water level, our pump running signal, our valve open signal and our fault summary. For our tank water level, we move the actual level input to the level status in our refill data structure. For our pump running status, we activate the pump running status in our data structure if the pump running input signal is high. The same goes for our valve open status. We activate the valve open status in our data structure if our valve open input is high. One way to use all these status informations of our components, is to visualize the state of a component on the HMI. If, for example, the pump running status is low, we display a grey pump symbol on the HMI. If, on the other hand, our pump running status is high, we display a green pump symbol on the HMI. Finally for our fault summary we check for a trigger word value different than zero. If this is the case, we have a fault and we activate our fault status in the refill data structure. At the same time, we activate our information output. So let's minimize our networks. We first programmed our refill request, followed by control of our pump and valve. Then we programmed the different faults for our refill module. And finally, we've added networks for status information. Let's just add a block title here, and we're done with coding our refill function block. In our last step we're going to call our refill function block in our "FB - Equipment Modules". So we start by opening the equipment modules function block. Now we drag and drop our "FB - Refill" into our second network. We'll use a multi instance, and since this is the block call for our refill process one, we'll call our instance "Instance_Refill_Process_1". Press enter, and we have added our refill block call for process one. Now we'll add our PLC tags - inputs and outputs - and our global data structures to the block call. For our inputs, we have three pump inputs: circuit breaker, local isolator and running feedback. As you can see, we're selecting the inputs for process one. Then we have our valve open input and our actual water level. For outputs, we add our pump and valve commands for process one. For our module faulted information output, I'm going to create and add a temporary local tag. Finally, we add our global data structures for state handler, supply and refill process one. So we're done with our block call for our refill process one. For our block call of refill process two, we'll start by copying and pasting the network of refill process one. Now we're going to adapt the tags for process two. So, first of all, we change the instance to process two. This instance does not exist yet, so we select multi instance here. Enter, and our new instance for process two has been created. Now we adapt the inputs and outputs for process two. We create and add a new temporary tag for our module faulted information, and we change our refill data structure to process two. Now, let's minimize our networks. Here in our equipment modules, you can see that we've created a call for our supply module in network one. This we've done in our previous lecture. In this lecture we've added a block call for our refill process one to network two and another block call for our refill process two to network three. So now all our equipment modules have been created, programmed, and added to our application program cycle. Now, if we maximize our block interface view, you can see that our multi instances for our supply and refill modules have been created in the static area of our block interface. By using multi instances here, We have minimized the number of instance DBs, which leads to a less cluttered, better overview of the application structure. We only have one instance DB for all of our equipment modules, independent of the number of block calls inside our "FB - Equipment Modules". So we've reached the end of this lecture. We have now created all of our machine modules and equipment modules. If we open up our program groups in our tree structure, you can see that we have created a well-structured application. Just take a moment here and look back at our PDFs for application overview, PLC program structure, and program hierarchy, and see how we've translated our original application on paper, our PDF in our case, to a fully functional, well-structured PLC application. In our application overview here, our application is structured into one supply module and two refill modules, one for process one, and another one for process two. This application structure than translates into a PLC program structure consisting of machine modules and equipment modules. Our machine modules contain our machine state handler, and our equipment modules contain a supply and two refill modules. Data exchange between modules is executed by use of global data structures in our global data blocks "DB - Machine" and "DB - Equipment". In our PLC program hierarchy, we have three layers, within the top layer, our main program cycle OB1. In our OB1, we call our main function calls "FB - Equipment Modules" and "FB - Machine Modules". Our "FB - Machine Modules" contains the call for our state handler function block and in our "FB - Equipment Modules" we call our supply and refill function blocks. From a pure programming perspective, our application is finished. All of our code is there for the application to run. In our next lecture, we're going to have a quick look at how to make your code more clear by adding descriptions and comments to your code. But before that, let's have some fun. Let's test your knowledge on function blocks. I've added a little quiz about function blocks here, and I'm confident that you guys are going to do just great. So have fun with the quiz and I'll see you on the next lecture. 24. Adding Logic - Quiz: 25. Adding Logic - Adding Comments and Descriptions: So how did you do on the quiz? Did you get all the answers straight? If you did, that's great. If you didn't, that's great as well! The best way for knowledge to stick is to make mistakes and learn from them. As we've mentioned in the previous lecture, our application is finished from a coding perspective. All of our code is there for the application to be functional. In this lecture we're going to have a look at how to improve our code's documentation by adding descriptions and comments to our code. In step one we're going to add comments to our PLC tags and global data structures. Then in step two we're going to add block descriptions and network descriptions to our function blocks. Finally, in step three, I'll show you how to use TIA Portal's free comments for blocks and coils to highlight certain aspects of your code. We're going to use our state handler module as an example for adding comments and descriptions. So we start with our PLC tags. Let's open our machine inputs tag table. You can see here that we've named our inputs, but we haven't added any description to them. So we'll add those now. Generally, I would recommend to keep the names of your tags as short as you can, using abbreviations if possible. You can then use the comment section to explain the tag in more detail. This way the short tag names will improve the readability of your code by not taking up too much space, and the comments provide more information on the tag if needed. So now I've added information about my machine input tags in the comment section. These tags here are inputs and they are hardware buttons for start, stop and reset. Now we do the same for our machine output tags. So we open the tag table and we add information to the comment section. These tags are outputs and they are indication lamps for application running and faulted. So that's it for our PLC tags. Now let's have a look at our global data. When we open our "DB - Machine" and expand our view, we can see that our structure has no comment yet. You can either add the comments to the state handler UDT structure right here in the DB, but I would recommend to add them in the UDT itself. This way, the comments are part of the user defined type and this will improve the re-usability of the UDT. So we open the PLC data type for our state handler and we maximize our view. Now we add comments for our state structure and command structure. As mentioned before, it's a good habit to keep your name short, but descriptive, and use the comment section to add information about the name. And done. So we have clarified our system states and operation commands under the comment section. So now let's open our DB machine again and maximize the view. You can see that our comments have been added. We just add a description for our state handler structure, and we're done here. In step two we're going to add block and network descriptions to our "FB -StateHandler". So we start by opening our function block. As you can see, we have a block title here that describes the content of this function block. Now we can use the comment section below to add more information about this block. I typically add a more detailed description of the purpose of the function block, followed by some information on who created the block and when was the block created. Now, in our first network, we can see that we have a network title here, but no further description yet. We can use the comment section below the network title here to further describe the code in this network. For example, here in network one, we'll add information on how we go from a ready state to a running state by pressing a start button. By doing the same for the other networks, we add clarity to each network. Just make sure that your information in the comment section is to the point. Try keeping it short in order not to clutter the program with too much text. It's all about striking the right balance between added information and a visually appealing piece of code. For our final step, we're going to have a look at free comments. TIA Portal will allow you to add these free comments to blocks or coils. These free comments are best explained in an example. I'll be using "FB - Machine Modules" for this example. Let's assume that our "FB - StateHandler" here in network one is not finished yet, and we would like to be reminded of this fact whenever we are here in our code. So by right-clicking on the function block, we can select "Insert comment". This creates a nice little text square next to our function block where we can add the comment "Block programming incomplete". So now each time we are here, we are reminded of the fact that this block is incomplete. Of course, after we've completed the block code, we can just delete the comment again. To turn on or off our free comments, there is a small button here in the top bar. So that's it for our final step. Before concluding this lecture, I would like to point out a couple of comment related buttons here in the top bar. Next to our free comment toggle button, we have a button to choose between absolute and symbolic representation of our tags. Default it shows both, and this is a tag representation that I normally use. But if you want, you can go for a pure symbolic tag representation or a pure absolute tag representation. This means only hardware addresses will be shown. I'll put this back on showing both. The next two buttons here are for displaying the tag information and the location of the displayed tag information. We can choose to show for example our tag information and we would like the information to be shown at the tag name itself. Now you can see that the informations that we've added earlier in this lecture to our PLC tags and data structures are now displayed above the names of our PLC tags and data structures. So that concludes this lecture on comments and descriptions. In our next lecture, and this will be the final lecture of this section, we're going to compile our project and see how we can use the compilation results for troubleshooting faults in our code. So thank you for now, and see you on the next lecture. 26. Adding Logic - Compiling the Application: In this last lecture of our section on application programming, we're going to compile our project. Furthermore, we're going to have a closer look at how to use the application results to troubleshoot any faults left in our program code. So I've opened our refill work application here. In order to compile a device, we first need to select the device, in our case our PLC_Refill_Work. Now that we have selected our device, there's two ways to compile your project. The first option is to use the compile button right here in the toolbar. This is the quickest way. Alternatively, you can right-click on the device and select Compile. Here you can see that you get more options for your compilation compared to the single button press on the toolbar. I would recommend you to just use the compile button on the toolbar. I only use this and it hasn't failed on me yet. So let's compile our application using the toolbar button. While compiling, the pop-up window shows us the different parts and blocks of the program that are being compiled. Now our compilation is finished and we can see in our compile view here that we have zero errors and two warnings. Let's open up the view a bit more. As you can see, TIA indicates the path where the warnings or faults are originating from. By double-clicking on a warning or a fault, TIA will take us to the place where the warning or the fault was generated. For example, our second warning tells us that the CPU display does not contain any password protection. So we double-click on it and TIA takes us to the PLC configuration and shows us here that we have not enabled any display protection. As this is just a warning and it won't interfere with the functionality of our application, we just leave it like it is. But what about faults? Let's introduce a small fault in our code and see what happens to our compilation results. For this purpose, I'm adding an empty box element here in network 1 of our OB1. Now we close the OB1 again and we compile our application. As you can see, the compilation result tells us we have a fault in network 1 of our OB1. By double-clicking on the fault, it takes us to the place where the fault is situated. One last thing I'd like to mention here in the compile view are these three buttons here at the top. The first button shows or hides errors. The second one shows or hides warnings. And the third one shows or hides information. These buttons come in real handy when you're working with larger applications. Most of the time, we're not really interested in warnings or information. Only in errors. These buttons will then allow you to only show the errors. So you don't need to go sifting through all messages to find your faults. We've reached the end of the lecture. In this lecture, we have compiled our project and we had a look at how to use the compilation results to find warnings and faults in your application. Time for you guys now to get your hands dirty. In our next activity you get to program our refill sample application by creating function blocks for our machine and equipment modules. So good luck with the activity and I'll see you in the next lecture. 27. Adding Logic - Activity: Add Logic to the Application: 28. Adding Logic - The Application is Done: Great! You've made it to the end of this section. So let's look back at what we have achieved so far. In previous sections, we have created a new project, added a PLC and configured the hardware. Then we have structured our application into smaller, logical modules. We have added our main function calls, created global data structures, and added inputs and output tags to our application. In this section, we have programmed the different modules of our application and we have added meaningful documentation to our application by using comments and descriptions. Finally, we have compiled the application. Our refill application is now complete from a coding perspective. So the next question is now: How do we know if our application is functional? How do we figure out if it really works? As you might have guessed, the answer to that question is: by testing the application. So how do we test our PLC application? By downloading the application to a PLC and running the application online. This will be the goal of our next section. In our next section, we're going to download our finished refill application to a software PLC using TIA's own PLC-simulator. It's going to be really exciting to finally see all of our hard work pay off in a fully functional online running application. So fasten your seatbelts, we're going online. 29. Online - Going Online: I'm glad you're still here guys. Most of the work is behind us and we're in the homestretch now. In the previous sections of this course, we've been building up our application, brick-by-brick. Now our application is finished and ready for testing. In this section of the course, you'll learn how to download a PLC application to a PLC. Furthermore, you'll learn how to edit your program online. Finally, we're going to have a look at how to manipulate and troubleshoot an application online using watch tables, force tables and data traces. By the end of this section, you will be able to download to your application to a PLC and troubleshoot any faults left in your program using TIA specific tools. In our next lecture, we're going to start by downloading our refill application to a PLC using TIA's PLC-simulator. So grab your favorite drink and let's go online. 30. Online - Downloading the Application: In this lecture, we're going to download our refill application to a PLC. Since not everyone has a spare PLC lying around at home, I'm going to use TIA Portal's built in PLC-simulator called S7-PLCSIM. The application that I will be using for the remainder of this course is the finished version of our refill application. If you haven't downloaded it yet in the first section of this course, I've added it once again to the resource section of this lecture. So just remember to delete the .zip at the end of the name. Afterwards you'll be able to retrieve the project in TIA Portal without a problem. So I have my finished refill application opened here. When we download to a PLC, a real one or a simulator, we connect to the PLC using an interface or a subnet. If we open up our PLC device configuration here and we go to Network view, you can see that we've assigned the profinet subnet PN/IE_1 to our PLC. This is important because this will be the interface that we'll use to connect and download to our PLC. So let's close this again. Before we download to our simulator, I'd like to show you how to download your application to a hardware PLC. First, you click on the device that you would like to download to. In our case we'd like to download to our PLC_Refill. There are three ways to initiate your download. The quickest way is the keyboard shortcut command Ctrl+L. The second option is to press the download button in the toolbar. Finally, you can download as well by going to the Online tab in the menu bar and selecting "Download to device". So we'll click on that. Now here in this extended download screen, there are four important areas: at the top the configured access nodes of our PLC are displayed, in our case we have configured a PN/IE type interface, this is a profinet interface, and we have assigned an IP address 192.168.0.1 to our PLC. So this is how we can reach our PLC. The second area of the screen lets you setup the connection that you want to make. In our case, we're using a profinet interface. So the type is PN/IE. The Intel PRO/1000MT desktop adapter is the network card in our PC that we're using to make the connection. And finally, we have to select a connection to the interface or the subnet. So here we're selecting ou PN/IE_1 subnet. This is the subnet that I've showed you just before in the hardware configuration of our PLC. The third area of our download screen will show you the possible targets that you can download to, after the start search is complete. Finally, at the bottom of the pop-up screen, there is an online status information display. So by pressing "Start search", TIA Portal will try to find a PLC on the PN/IE_1 profinet subnet with IP address 192.168.0.1. You can see here in the online status information section that TIA is searching for compatible devices in our subnet. As expected, no accessible devices were found because we don't have a hardware PLC connected to our PC network. But what we do have is a PLC-simulator. So let's download to our simulator. There are three ways to start our simulator and initiate a download. The first way is by pressing the start simulation button in the toolbar. The second way is via the Online tab in the menu bar by selecting "Simulation" - "Start". The third way to start a simulation is by pressing the shortcut command Ctrl+Shift+X. We'll use the button in the toolbar now. So starting the simulation will disable all other online interfaces. That's fine. So we press OK. Now, here on the left, you can see that our PLC-simulator has opened. It shows us that our simulation PLC is in Stop, indicated by the orange light here, and that no configuration has been loaded yet. In our pop-up window on the right here, we get the option to download our PLC application to our simulator. So we just press on Load here, and now we're downloading our refill application to our PLC. The download has been executed without any errors. By selecting "Start all" here, our PLC_Refill will go from Stop to Run after finishing here on the screen. So we select "Start all" and we press Finish. As you can see by the green color indication, our PLC is in Run. Furthermore, we can see that our PLC_Refill application has been downloaded to the PLC-simulator. With our PLC-simulator, you have the same functionality as you would have with a hardware PLC. You can stop your PLC by pressing to stop button here. You see the light switched to orange again, indicating we're in stop mode. In stop mode the PLC is not cyclically running through your application code anymore. The application is still there, just not actively running at the moment. In order to remove the application from the memory, you can press the memory reset button here. This will clear all the PLC memory. Finally, you can power down or power up the PLC by pressing the green power button. Let's put our PLC back in Run and move the simulator a bit lower to clear our view. So now we've downloaded our application and our PLC is in Run. The next step is to go online with our application. To go online with the device, we first click on the device. Now we have three options to go online. The first option is to press the "Go online" button in the toolbar. Our second option is via the shortcut command Ctrl+K. Our last option to go online with our PLC is by using the Online tab in the menu bar and selecting "Go online". So let's select this. Now, the first thing you'll notice when online are these green circles here in our tree structure. They indicate that our online blocks, tags, data, etc. are consistent with our offline project. When you're online in TIA Portal, you're online with the whole program. This is very different than, for example, the old Step 7 in Simatic Manager, where you were only online with a specific block. Being online with the whole program is a huge advantage because you can see straight away how your online project compares to your offline project. So that concludes this lecture. We have downloaded our application to a PLC and we went online with our application. In our next lecture, we're going to have a look at how to monitor our code and how to edit our code while being online. So I hope you've enjoyed this lecture. Thank you for now, and I'll see you on the next lecture. 31. Online - Editing Logic: Welcome back. In our last lecture, we downloaded our application and we went online with our project. In this lecture, we're going to edit some code online. I will show you how easy and straightforward this is. As you can see here, I'm already online with my application using TIA's PLC-simulator. If you can't remember how to use the PLC-simulator and go online, please have a look again at the previous lecture. First, we minimize the PLC-simulator so it doesn't block our view. To showcase the online editing possibilities in TIA Portal, I'm going to add a lamp indicator to our state handler. Let's start by having a look at our state handler here in "FB - Machine Modules". So far we have a lamp indication for application running and a second one for application faulted. I would like to add a third lamp indication output here for application ready. Let's open up our "FB - StateHandler". We can do this by double-clicking anywhere here inside the function block square. Our new ready lamp indicator will be an output, so we start by adding the output in our block interface. We maximize the view and we add our new output. I would like my lamp ready to be the first output in my output area here. We do this by right-clicking on the lamp running output row, and selecting "Insert row". "Insert row" will add an empty row before the selected row. "Add row" will add an empty row after the selected row. So you've noticed that as soon as we've added our output, our tree structure is indicating that we are not consistent anymore online-offline. The orange circle with an exclamation mark tells us there's a difference in a lower level component, while the half blue, half orange circle tells us there is a difference in the specific block between the online and the offline version of that block. The edits that you make in TIA Portal while you're online are always made in the offline version of the block. In order to carry over the changes to our online project, we need to execute a download. So we use the keyboard shortcut command Ctrl+L. After compilation, the load preview window here comes with a warning that all data values in our instance DB for machine modules will be initialized because of this download. This is fine. So we change the action here from "No action", which doesn't allow us to download, to "Re-initialize", which will allow us to download. Now we press on Load and our offline changes have been carried over to our online project. You can see in the tree structure that all of our consistency indicators are green again, meaning that our online project is consistent with our offline project. So now that we've added our output to the block interface, we need to add our output into the code. So we open up our network six where our ready state is programmed. Here we add an extra coil for our output lamp. We press Ctrl+L to download, and since we haven't changed anything to our block interface, we don't get a warning this time. We press on Load and our new code is now online. The only thing missing now is creating a new output tag in our PLC tags and adding this output tag to our "FB - StateHandler" function call. We start by opening our tag table for machine outputs. Now we create a new output here for our ready lamp indicator. As you can see, TIA has automatically assigned the next available output address. Furthermore, you can see in the tree structure that our PLC tags have become inconsistent because we haven't downloaded our change yet. Before downloading though, I'd like to add our new output to the state handler block call. So we open up "FB - Machine Modules" and now we add our output to the block call. Ctrl+L to download, and all of our changes are online. One final afterthought here before concluding this lecture... Of course, you could have made all the changes offline first, then go online with your PLC, and finally make the download. But sometimes you're at a customer, you're working on a line or a machine and you're monitoring some data or blocks. In this case, you'd prefer to stay online and make those edits while you're online. So it really depends on the situation and the amount of editing that needs to be done. For large amounts of editing, for example adding new function blocks to your application, it probably makes more sense to do this offline first and make the download afterwards. So we've reached the end of this lecture. In this lecture we've learned how to edit code while being online with the application. In our next lecture, we're going to monitor function blocks and data. So exciting times are ahead of us. I'll see you on the next lecture. 32. Online - Monitoring Code: In this lecture, we're going to have a look at how to monitor code in blocks. Furthermore, we'll look at how to monitor data in data blocks and in PLC tag tables. Finally, I'm going to show you how to use watch tables to create your own list of tags for a better monitoring overview. So we start by monitoring code in blocks. As you can see, I've already downloaded the application to the simulator and I'm online. As an example for monitoring code, I'm going to use our refill module for process one. So let's open up our "FB - Equipment Modules" and go to the network for our refill process one. We are offline in our code now. For monitoring our code online, we have three possibilities. First, we can turn monitoring on or off by pressing the keyboard shortcut command Ctrl+T. Alternatively, we can go to the Online tab in the menu bar and select Monitor. Finally, we can press the monitor button here in the top bar of our work area. So let's press on this one. The first thing you can see now is that our network, including the outline of our function block, has turned green. This indicates that our network and function block call are cyclically being processed in our application. When we look at the inputs of our block call, we can see that the actual states, which are false at the moment, are being displayed above the inputs. The same goes for our outputs. The actual false states are being displayed here as well. Now let's go inside "FB - Refill" and monitor code inside the function block. We'll use the keyboard shortcut command Ctrl+T this time and we're online with the code. Now, as you might remember, this "FB - Refill" has two instances. It is being called two times in our "FB - Equipment Modules" - once for process one and another call for process two. So now that we are monitoring our code, how do we know which instance we are monitoring? Are we monitoring code for process one or for process two? To select a call environment for this function block, process one or process two, we press on this icon right here in the top right corner. Now we can select our instance for process one or instance for process two. We select process one and we press OK. So now we're monitoring the code for our process one instance. Let's have a closer look at some code. Here in network one, you can see that our tank level has the actual value zero. This makes the comparison to set the refill request true, and is indicated by the green color of the comparison element and the set-reset element. The comparison to reset the request is false, and this is indicated by the striped blue line. Let's monitor one more network here. Let's take for example network 7 - fault valve not opening. Here you can see that our conditions for state handler running and command open valve are false, indicated by the striped blue line. Our refill module is not faulted at the moment, so the normally closed element is green. Next, we have our on delay timer. It is not active at the moment indicated by the striped blue line, and furthermore, the actual elapsed time is indicated above the timer and at the elapsed time output. Since the timer is inactive, the elapsed time is zero milliseconds. Our input valve open is false, so the normally closed contact is green. Finally, because not all conditions are true, bit three of our trigger word is not being set here at the end of our network. So now that we've had a look at how to monitor code, let's go and monitor data inside a data block. We're sticking with our example of refill process one. So we're opening our "DB - Equipment". Now for data bases and PLC tags, the keyboard shortcut Ctrl+T does not work. The only way to monitor here, is by using the button in the toolbar. It's in a different location here compared to the function blocks, but the icon you're looking for is the glasses with the green play button. So we press on it and we expand our structure. All the current values of our tags are indicated in orange here in the monitor tab. The states of our booleans, like pump running or valve open, are indicated by false or true. Our actual tank level is an integer and is indicated by a decimal number - zero in this case. Our trigger word is indicated here as a hexadecimal value, because bytes, words, and double words are typically indicated in hexadecimal format. Interesting to notice here, is that our refill request command is true. When we go back quickly to our "FB - Refill" and we look at our network one, we see the same result here. Our refill request command is active. This makes perfect sense of course, since the refill request commands inside our "FB - Refill" is part of the data structure of our refill process one. Next up is monitoring of PLC tags. As an example, we're using our equipment inputs tag table. The only option here for turning monitoring on or off is the button in the top bar here. So we press that and now we're actively monitoring our input tags. In our monitor tab right here, the actual values for our tags are shown. Boolean states like refill circuit breaker or refill pump running are displayed as false or true, and our actual tank levels are displayed as decimals. Great. So far we've looked at how to monitor code in function blocks and how to monitor data blocks and PLC tags. Finally, in this lecture about monitoring, I'm going to show you the advantages of using watch tables when monitoring data. Watch tables are created in the tree structure on the left, under the "Watch and force tables" group. With watch tables, you can create your own lists of tags and data to monitor. This way you can group PLC tags and data block tags together that make sense to monitor in a single view. I've already created a watch table for our state handler, so let's open up this one. First, I have added global data tags for our commands and states, followed by the instance DB tag "iState". Finally, I have added the state handler input and output tags. The comments here in green improve the readability of the watch table. So in one overview, you get useful monitoring information of the components that make up our state handler. Monitoring here is initialized by the button in the top bar, or by going to the Online tab of the toolbar and selecting "Monitor all". So we click on that. Our actual values or states are now being displayed in the monitor tab. As you can see, our state handler is in the ready state at the moment, waiting for a start command. To add or insert rows in a watch table, use the first two buttons here from the left in the top bar. To insert a comment line in a watch table, press the third button from the left in the top bar. To insert a new tag in the watch table, just start typing the name of the tag and TIA auto-complete will make the rest of the process very easy for you. And as you can see here, new tags and comments can be added and existing tags and comments can be removed while you're monitoring. So we've reached the end of this lecture. This lecture was all about monitoring code and data and the tools that TIA provides for this purpose. Now that we know how to monitor data and tags, our next step in our next lecture will be how to modify the states and values of tags. So great to still have you here, and I'll see you on the next lecture. 33. Online - Modifying Tags: In our previous lecture, we learned how to monitor block code and individual tags and data blocks, PLC tag tables and watch tables. This lecture builds upon the foundation from our last lecture. We're going to start by modifying tag values in a watch table and using the results to troubleshoot our application. Then we'll have a look at the advantages of using the force table. Finally, we're going to test the state handler functionality of our application by using a combination of modifying tags in our watch table and forcing tags in the force table. The first part of this lecture is about using watch tables to modify tag states or values. To showcase this, we open up our state handler watch table here, and we turn monitoring on by clicking on the monitor button in the top bar. Now we can see that our state handler is ready and waiting for a start command. I would like for the state handler to go into the running state. In order to achieve this, I will need to modify the start command here from false to true. There are four ways to modify a tag. The fastest way for modifying boolean tags is by using the keyboard shortcut command Ctrl+F2 to modify the tag to true, and the keyboard shortcut command Ctrl+F3 to modified the tag to false. Another fast way to modify the state of a boolean tag is by right-clicking somewhere in the row of the tag and selecting "Modify to 0" or "Modify to 1". Alternatively, the same commands can be reached in the Online tab of the menu bar. The last way to modify tags, and this way makes more sense for non-boolean tags like bytes, integers, etc., is by entering a new value in the Modify value tab and then clicking on the modify button in the top bar. Alternatively, you can right-click anywhere in the row and select "Modify" -> "Modify now". As you can see, Shift+F9 will do the trick as well. My personal recommendation is to use Ctrl+F2 or Ctrl+F3 for toggling the states of booleans, and using the modify value tab together with the modify button in the top bar for all non-boolean tags. So back to our state handler. We would like the state handler to go from its current ready state to a running state. In order to achieve this, we need to simulate pressing the start button. So we are going to do that by modifying the start command to one by pressing Ctrl+F2, followed by Ctrl+F3 to modify the state back to zero. So here we go. Ctrl+F2 and Ctrl+F3. Did you see how the actual state of the start command changed from false to true and back to false? Fantastic. Now, we were expecting our state handler to go from a ready state to a running state, but instead it is in a faulted state now. Let's use this result to do some troubleshooting here and figure out why we are in a faulted state. The state handler goes into a faulted state when an equipment module is faulted. This is how we've programmed it in our state handler code in the previous section of this course. Let's add the fault states from each equipment module to our watch table and see which modules are faulted. Ok, so now we can see that both of our refill modules are faulted and are preventing our application from running. The logical next step now is to go inside the refill function block and use monitoring to find our fault. So we open up our "FB - Refill", and we activate monitoring. Our call environment - instance process one or instance process two - is not so important at the moment since both our process one and two are faulted. Now, when we go to our fault networks starting here from network four, and open them up, we can see that we have a circuit breaker fault and a local isolator fault. Both of these inputs are false because we are not connected to real hardware, and their fault state is causing the faulted state of the refill modules. So how do we manipulate, how do we force hardware input states from false to true, in case we are not connected to real hardware? This is where the force table comes into play. The force table is situated in the tree structure under "Watch and force tables" and will allow you to force states and values upon tags. The advantage of a force table is that you can manipulate states and values of tags that are being written to in your application. With watch tables, your program code will always override whichever changes you make to your tags. If, let's say for example, you tried to modify a refill pump output that is false to true in your watch table, the you'll find out that it is not possible because our program code writes to this pump output. In a force table on the other hand, you override the code. So if you would force the same pump output to true in the force table, the state will be true, independent what your program code writes to the output. So in order to be able to run with our application, we're going to force all the refill boolean inputs to true. This way they won't interfere anymore by setting fault bits. Let's start by opening the force table here. You can see that I've added the inputs and outputs for our refill process one and two. Adding tags and comments to a force table is the same procedure as adding them to a watch table, as we've seen in the previous lecture. Now we press on the glasses with the play button icon, and we are monitoring the force table. You can see that peripheral inputs can only be monitored in expanded mode. So we press this button right here in the top bar to expand our columns. I'm not sure why, but TIA Portal has not made it possible to monitor peripheral outputs here in the force table. To force our boolean inputs to true, we have three possibilities. We can right-click on the row of an input and select "Force" -> "Force to 1". Alternatively, you have the same command in the Online tab of the menu bar. Finally, and this is the way that we will use because it will save us time, is by first entering the force value "1" in the force value tab of each input row, and then afterwards pressing the start forcing button here in the top bar. A small caution window pops up, informing us that we'll be forcing tags. This is fine. So we accept this. Now all of our boolean inputs from our refill process one and two are forced to true. If you want to stop all forcing, you can use the button next to the start forcing button here in the top bar. When we quickly open up our "FB - Equipment", we can see that the forcing on the inputs is indicated by the letter "F" above our forced input tags. Now that our refill inputs are forced to true in the force table, we can go back to our watch table and see if we can get the application to run. We are still in a faulted state here. So we need to toggle a reset command first to go back to a ready state. So we click on our reset command tag, and we press Ctrl+F2 to modify the state to true, followed by Ctrl+F3 to modify the state back to false. As you might have noticed, our state handler went first into the reset state before returning to its ready state. Now we are ready again to start our application. We press on the start command tag and we toggle the value from false to true and back to false to simulate a push on a start button. Our application is running now, we are in the running state. Furthermore, you can see that our indication lamp for running is active, as expected of course. Now, to stop our application, we're going to simulate a push button on the stop button by toggling the stop command tag. So we select the row and we modify the state to true - Ctrl+F2 - and back to false - Ctrl+F3. We are not running anymore and we are back to our ready state. We've reached the end of this lecture. In this lecture we have used a watch table to modify tags, and we have forced PLC input tags using the force table. In the last lecture of this section, we are going to monitor data over time using traces and we're going to perform a refill operation test-run. Thanks for now. I'll see you on the next lecture. 34. Online - Using Traces: In this last lecture of this section, we're going to look at how to setup and use traces to monitor data over time. Furthermore, we're going to do a test-run of a refill sequence while tracing refill relevant tags. This lecture builds upon the last 2-3 lectures of this section. So please revisit those if you're having any trouble following. As you can see, we're already online with our refill application using TIA Portal's PLC-simulator. Now, traces are typically used for monitoring a custom set of tags or data over time. Traces can be used for testing out functionality of new code or, and this is how they're used most of the time, to troubleshoot faults in the code. The Traces group is situated in the tree structure on the left and by clicking on "Add new trace", we can start setting up our new trace. So here we are in the configuration of our trace. Here we will add the tags that we would like to monitor over time. I'll start by adding our state handler start and stop buttons, followed by our states ready and running. Since we are going to simulate a refill sequence later on, I'm adding our tank level status for refill process one, our refill request command, and finally, our pump start command and valve open command of our refill process one. Now, when we quickly look at our recording conditions, we can see that our trace will record every cycle of our OB1, and that we'll be recording the maximum possible recording duration, which is 30838 samples in total. Recording every cycle is not really necessary here, because our tags that we are recording are not cycle time critical. So I'm changing this value here to record every five cycles. This way we'll have a longer recording time. Furthermore, we are not using a tag trigger to start the recording process. It will start recording immediately as soon as we press the record button. Now we are done with our trace configuration. Before we can start our trace, we first need to transfer our trace configuration to our refill PLC. We do this by clicking on the button right here in the top bar. So we've transferred the trace configuration to our device, our PLC, and we are ready to start recording. To activate recording, we press on the button right here in the top bar. Our trace status changed from inactive to recording, and our recording time is accumulating here on the x-axis. Since our application is not running and we are not modifying any tags at the moment, our measuring data here represented on the trend by different colors, are straight horizontal lines. This is of course because their states, their values, are constant at the moment. They are not changing. In order to stop our trace recording, we press on the deactivate recording button right here in the top bar. If we want, we can remove the trace configuration from our PLC device by pressing this button right here. So now we know how to set up a trace and how to run a trace. Let's make it more fun now by using our trace here in an example. What we're going to do now is we're going to simulate a refill sequence for process one and we're going to use our trace here to record the data while we execute this refill sequence. We start by forcing the boolean inputs of our refill process one and two to true in our force table. We've done the same in our previous lecture in order to run the state handler without going into a faulted state. Now we're going to simulate a refill sequence by modifying tag values in a watch table. So let's add a new watch table here and rename it, by pressing F2, to "Watch Refill Process 1". We start by adding refill process one tags. To test the refill sequence functionality, it will be useful to monitor the refill request command, so we add that. Furthermore, we would like to modify the actual tank level because the level in the tank will start or stop a refill sequence. Finally, we would like to monitor our pump start output and our valve open output, so we add those as well. Now, in order to run our application, we're adding the state handler start and stop commands and the ready and running states for feedback. Good. So now we've added the tags in our watch table that we're going to modify and monitor in order to test a refill sequence. Before we start our test, let's have a quick look at our application overview, and let's define how we are going to execute our test. So to quickly refresh our memory here, a refill sequence starts when the process tank level goes below 10 percent. During the refill sequence, our pump starts and our valve opens and water is being pumped from the supply tank to the process tank. Now, when our water level in the process tank rises above 60 percent, the pump stops and the valve closes. The refill sequence is finished now. We are going to test this refill sequence in the following steps. In step one, we're going to modify our process tank level to 70 percent. We do this to simulate a high water level in the process tank where no refill is needed. In step two, we're going to run the application by simulating a push on the start button. Now that we are running, we're going to use step three to monitor our refill request command together with our pump and valve outputs. These should all be false because we have a high water level in our process tank. In step four, we're going to lower our process tank level from 70 percent to just below 10 percent, by modifying the tank level input. Here we expect a refill request command to occur. So in step five, we'll monitor if our refill request command is true, together with our pump and valve outputs. In step six, we're going to simulate the water level in the process tank going up again. So we'll modify the level to a value above 60 percent. Now we expect the refill sequence to stop. So we monitor our refill request command and pump and valve outputs in step seven. They should all be false. Finally, in step eight, we stop our application by simulating a push on the stop button. So now that we have the steps defined for our test procedure, and we have our trace ready for recording data, let's go and start the trace and execute our test steps afterwards. So we open up our trace again and we activate recording. Now we go to our watch table. We start monitoring and we start executing our test steps. So in step one, we're modifying our process tank level to 70 percent. We type 70 in the modify value tab and we press Shift+F9 to modify the value. In step two, we're starting the application, so we select the row with the state handler start command, and we toggle the state with Ctrl+F2, and Ctrl+F3. Now our application is running. Furthermore, our refill request command together with our pump and valve outputs are all false, as expected. So that's step three done. Now in step four, we're going to lower the tank level from 70 percent to just below 10 percent, let's say 9 percent. I'll do a couple in-between levels here just to make it more realistic. Have you noticed how our refill request command went to true and consequently our pump and valve outputs change to true as well? Now we are pumping water from the supply tank to our process tank. That's step five done. In step six, we're going to raise our water level again to just above 60 percent. Our refill request command went to false, our pump stopped running and our valve closed. Our refill sequence has executed successfully. Step seven. You are done. Finally in step eight, we stop our application by simulating a push on the stop button. So we select the state handler stop command row, and we toggle the state. Now we are not running anymore, and we are back to our ready state. Fantastic! Our refill sequence seems to work as expected. Let's go and have a look at our trace and see what we've recorded. First, let's deactivate recording. Now, in order to help me interpret the results of the data here, I'm going to use a vertical measuring cursor. To use a vertical measuring cursor, we press on this button right here in the toolbar. So now we have two vertical measuring cursors displayed on the screen, T1 and T2. The T1 and T2 cursor will show us the actual value of the different tags at the point in time of T1 and T2. T2 shows us delta values as well. Delta values are the change in value between the T2 value and the T1 value. We are only using one measurement cursor here, so we move T2 out of the way for a cleaner view of the trace. The value range of our recorded tags are indicated here on the left side of our y-axis, and the x-axis displays the recorded time in minutes. Now, if we start at the beginning of our test, we can see that our tank level is at zero percent, indicated by the zero at the point where our T1 cursor crosses the tank level tag recording. Our state handler, indicated by the green color recording, is in the ready state. Our pump and valve outputs here at the bottom of our trace, are false. One thing to notice here is that our refill request command is high due to our water level at zero percent being lower than 10 percent. A refill sequence will not start though, because our application is not running. We are in the ready state. But I would argue that setting a refill request should only be possible when the application is running. Our code would look more correct this way. We are not going to change this now, I just wanted to point out that a trace is a great tool to find these kind of software inconsistencies or irregularities. Now, if we move forward on our recorded timeline, you can see that we've modified our tank level to 70 here. The next important point in time on our trace is here, where we've started the application by toggling the start command. You can see that the ready state went to false here and at the same time, the running state went to true. If we now drag our cursor forward in time, we can see that we've lowered the water level in the process tank by modifying the tank level input value. Let's stop right here where our tank level was modified to 9 percent, just below the refill start level of 10 percent. As expected, this level triggered a refill request command which went from false to true. Since our application is in a running state at this point in time T1, and we have a refill request command, our pump and valve outputs transitioned from false to true. So here at T1, we are pumping water from the supply tank to the refill process tank. Before we continue on our timeline, let's move our legend to the left side by pressing this button right here in the toolbar. Now we have a clean view of the right half side of our trace. Now when we continue our cursor in a forward direction of the trace, you can see that we've modified the water level value again, simulating a rising water level in the refill process tank. The moment we went above 60 percent again, right here at the time position where we stopped with our cursor T1, the refill request command went false again and our pump and valve outputs consequently went to false as well. Here our refill sequence was completed. The final step that we took in our test, was stopping the application by issuing a stop command. This you can see at our current T1 position. A stop command was toggled and the state handler went from a running state back to a ready state. So I hope this lecture gave you an idea of what is possible with traces in TIA Portal. Personally, I use traces a lot, much more than watch tables or force tables. When you are working with more complex programs that contain synchronized servo axes or intricate control sequences, traces are very useful for troubleshooting. Now, in our next activity, it's your turn again. You'll be downloading the refill application to the PLC-simulator, and you'll be performing a test-run of the application state handler while tracing data. So good luck and have fun with the activity. 35. Online - Activity: Download the Application: 36. Epilogue - Congrats!: You've made it! This is it. The final section of this course. I want to start by congratulating you for sticking with this course until the end. You are now able to create your own well-structured PLC applications in TIA Portal. Great work! Furthermore, you're able now to download your brand new PLC application to a PLC, and use proper TIA tools like watch tables and data traces to monitor and troubleshoot your application. So what's next for you now after completing this course? I would recommend to keep practicing the skills that you've learned in this course. Maybe take a couple more advanced PLC programming courses. Another great way to follow up this PLC course is by taking an HMI course. This way you'll complete your TIA PLC knowledge with TIA HMI knowledge. With both of these TIA disciplines under your belt, you'll be well on your way to become the ultimate TIA Portal application builder. Now, for those of you who are not tired and still hungry for more, I have added a bonus activity in the next lecture. In this bonus activity you will have to add a supply valve to the existing refill application, using all of the TIA skills that you've learned in this course. So for those of you who are up for it - let's enter the TIA Portal one last time in this course and show them how it's done. Good luck. 37. Epilogue - Bonus Activity: In this bonus activity, you get to add a supply valve to our refill application. As you can see on the screen, I have opened up the application overview. This is what our application looks like right now. We have a supply module with a tank and no valve yet. Furthermore, we have two refill modules, each with a process tank, a pump and a valve. Now, I would like you to add a valve to the supply module, as indicated in the next slide right here. As soon as a refill module, process 1 or process 2, requests a refill, the supply valve should open together with the refill pump and valve. When a refill sequence is finished, the supply valve should close again, together with the pump and valve of the respective refill module. Our new valve will have a new input for valve position open feedback, and a new output for valve command. You will need to add those to the application as well. In the resource section of this lecture I've added a PDF with instructions and a PDF of this new application overview. So go and have a look at the instructions, work your magic on the application, and I'll see you on the next lecture where I'll provide you with the solution for this activity. Thank you. 38. Epilogue - Bonus Solution: Welcome back. The previous bonus assignment was about adding a valve to the supply module. This valve should open if one of the refill modules requests a refill. Furthermore, a refill pump cannot start pumping water from the supply to a process tank before the supply valve is in an open position. We are going to implement this new supply valve using the following steps. In step one we're going to create the new input and output for our valve. In step two we're going to update our supply data structure. In step three we're adding the new supply valve to the supply function block. This will include the new fault for our valve. In step four we're going to update our refill function block with our new valve information. Finally, in step five, we're going to test the application online with this new valve software. So we start with step one - adding the new valve input and output. To add our valve position open input, we open up our tag table for equipment inputs and we add our new input right here at the bottom. The next available hardware address is input 1.4, so we just use that one. We complete the input entry by adding information in the comment tab. And we're done. To add our new valve command output, we open up the outputs tag table and we add the new output right here. So that's step one done. We've added the input and output for our new supply valve. Now in step two, we're going to update the supply data structure with the new valve information. So let's open up our UDT_Supply here in the equipment group of PLC data types. Now we expand the view for a better overview. Our new supply valve has an open position feedback. So we add that here in our status structure under the low level status. Apart from our valve open status, no other changes need to be made to the structure. Let's just quickly compile our application here so that our changes are consistent everywhere in the program. So that's it for step two - data structure updated, check. Now that we've done the groundwork for our new valve addition, let's go and add this valve to our supply function block. So we open up our supply function block. Let's start with our block interface. Here, we need to add an input for our valve open feedback and an output for our valve command. That's the input done, and now the output. Now, our new valve will only open if we get a refill request from refill process one or refill process two. In order to access the data from refill process one or two inside our supply function block here, we need to add these refill data structures to our block interface. Since they are complex data types, I'm adding those to the InOut of the block interface. As mentioned before, using the InOut for larger data structures, arrays or strings will improve the performance of your application. All right. Our block interface is updated. Now we go back to our networks. First, we'll need a network to control our valve output. We add the following conditions for opening the valve: The application should be running and we'll need a refill request from either one of the refill processes. Our supply module should not be in a faulted state and our water level should not be low. When all of these conditions are met, we open the supply valve. I'll add a local output here as well, which we'll use in our fault network. Now for our fault network, I'm going to start by copying the valve fault from our refill module. The fault conditions are very similar for both valves, so I'll save some time compared to creating the fault network from scratch. Now that we have copied the valve network from our refill module to our supply module, we adapt the tags to fit our supply module. We'll use trigger bit one here instead of three. Now we just adapt to comment information. And we're done. The last network that we need to add here is a status network for our valve open status. We start again by copying the network from the refill module. And we adapt the copied network to our supply module. Now that we've updated the block interface and added new code to our function block, the last thing to do here in step three is to add the new input and output, which we've created in step one, to our block call. So we open up our "FB - Equipment Modules". You can see that our block call is displayed in red color here. This is because we've made a change to the block interface. In our case, we've added an input and an output. But we haven't updated the block call yet. One way to update the block call here is by compiling the application once again. I will show you now another way of updating the block call, by right-clicking on the block and selecting "Update block call". Now, the pop-up shows us what the block call will look like after the update. We press OK here and we've updated our block call. As I said before, compiling the application would have updated the block call as well. And I would recommend to use this most of the time. The manual method of updating a block call make sense when you have a very large application, where a compilation of the whole application would take a lot of time. In this case, the manual method will save you some time. So now that our block call is up to date, we add the new valve input and output and the data structures for refill process one and two to the block call. And that is step three done. In step four we're going to open our "FB - Refill" and we're going to add the supply valve open condition to the conditions to start our pump. So we open up our "FB - Refill" and we open the network where we write to the pump output. Here we add the condition that our supply valve needs to be open in order to start our pump. Now for our final step, we're going to test our application online with this new supply valve. I'm going to fast forward here and skip the steps of downloading the application to our PLC-simulator and going online. If you're not sure anymore how to do this, please revisit the first lecture of the previous section. So I'm online now with the application and we start again by forcing some inputs to true in order to run the application without faults. So we open our force table and we enable forcing. As you see, I have added the new supply valve input here at the bottom of the force table, and it's forced to true as well. Now to test our application with the new supply valve, I've created a new watch table called "Watch Refill". So let's open it. And once open, we activate monitoring. We are going to start our test with a high water level in both process tanks. This way, no process tank is requesting a refill. So I add the value 80 for each tank level and I enable Modify by pressing Shift+F9. Good. Now we start the application by toggling the start command, Ctrl+F2 and Ctrl+F3. Now our application is running and we have no refill requests. Now let's lower the water level in the process two tank in steps until we go below our minimum level of 10 percent. When the water level goes below 10 percent, we expect a refill request to occur. Now we are at nine percent water level. And as you can see, a refill request for process two was triggered. Our new supply valve has opened and our pump and valve for process two are both activated. So far, so good. Now we'll simulate the water level in the tank for process two going up again by modifying the value in steps to just above 60 percent. This is the water level where our refill sequence stops again. Now we are above 60 percent. And you can see that our refill request is inactive again. Furthermore, our new supply valve is not open anymore - as expected - and our refill pump and refill valve stopped operating. We've successfully executed a test run with our new supply valve. Our added code seems to be working as expected. Our final step five is finished and we've reached the end of this bonus lecture. So did you solve the bonus assignment in the same manner that we've solved it here in this lecture? If you have a different solution that works, just let me know. If you have any more questions about this bonus assignment, you can write them down in the Q&A section below this video. Thank you for doing this bonus activity together with me. Take care for now. 39. Epilogue - Thank You: So this is it. We've reached the end of this course. I'd like to thank you once again for choosing this course and sticking with me through all of these lectures. If you really liked this course, I'd be very grateful if you would let others know by writing a small review about this course. Now, as I've mentioned before, I work as a self-employed system integrator in the field of Siemens automation. If you, or anyone that you know, is in need of professional assistance with a Siemens project, I'd be more than happy to hear from you or your contact. My contact details are on my website www.rsautomation.eu. If you guys have any more questions about this course, any recommendations or suggestions, feel free to write me. I wish all of you all the best with your future endeavors. And who knows, we might see each other on one of my other courses. Take care. ...application. So fasten your seatbelts, we're going online...