Reader small image

You're reading from  Mastering PLC Programming

Product typeBook
Published inMar 2023
PublisherPackt
ISBN-139781804612880
Edition1st Edition
Right arrow
Author (1)
Mason White
Mason White
author image
Mason White

M.T. White has been programming since the age of 12. His fascination with robotics flourished when he was a child programming microcontrollers such as Arduinos. M.T. currently holds an undergraduate degree in mathematics, a master's degree in soft ware engineering, and is currently working on an MBA in IT project management. M.T. is currently working as a soft ware developer for a major US defense contractor and is an adjunct CIS instructor at ECPI University. His background mostly stems from the automation industry where he programmed PLCs and HMIs for many different types of applications. M.T. has programmed many different brands of PLCs over the years and has developed HMIs using many different tools.
Read more about Mason White

Right arrow

Putting It All Together — The Final Project

Congratulations on making it this far in the book. Hopefully, by this point, you have a good grasp of the more advanced concepts of PLC programming and software engineering in general. By this point, you should not only have become a better PLC programmer but also a better software developer in general. Thus far, we have explored OOP, advanced structured text, alarms, HMIs, the SDLC, and much, much more. In all, at this point, if you understand most of the material covered, you’re probably light years ahead of the average automation programmer.

As far as programming and HMI development are concerned, we have reached a point where we can combine all these concepts into a fully working project. This chapter will be unlike the other chapters in this book as we will not be exploring new concepts. Instead, we are going to explore putting the concepts we have learned throughout the book together to make a simulated industrial oven...

Technical requirements

This chapter will require a comprehensive knowledge of all the topics covered in the previous chapters. If you have been skipping around the book, it is best to go back and read the chapters that you did skip. If you feel comfortable with the material already covered, you are free to proceed.

The source code for this chapter can be found at the following URL:

https://github.com/PacktPublishing/Mastering-PLC-programming/tree/master/Chapter%2015

As with all previous chapters, you can pull the source code down for the aforementioned URL. It is recommended that you pull down the code and attempt to modify it once you have a thorough understanding of the material presented in this chapter.

Project overview

Before we dive into building the project, it is important to understand what we are developing and why. For our final project, we are going to build an industrial oven. Industrial ovens are often used in the manufacturing process for various applications such as curing paint, baking in chemicals, drying parts, or any number of other applications.

Our simulated customer is requesting an oven system for drying metal fixtures after they come from being washed. The way the manufacturing process works is that once a part is washed, it is placed in the oven for a variable amount of time depending on the fixture so that all excess moisture can be burned off. We have to be careful because there are rubber O-rings in the fixtures that will melt if the O-rings experience temperatures above their rated limit. The customer will want to be able to dry different parts that will require different dry times, and each fixture will have an O-ring with a different temperature limit...

Getting the requirements

Now, that we have a general overview of the goals of the project, we can work on figuring out the requirements. From the overview, we can get the following general project user stories:

  • As an operator, I want to be able to manually set the optimal temperature of the oven so that I can use the oven for different fixtures
  • As an operator, I want to know when the oven is too hot to enter so that I know not to enter the heated area
  • As an operator, I want the door to automatically lock and unlock
  • As an operator, I want to know when the oven’s temperature is at room temperature so that I can safely enter the oven to remove the dry fixtures
  • As an operator, I want to view an alarm when the temperature is over the O-rings’ rated temperature so that I know when the O-ring has been compromised
  • As an operator, I want the PLC to automatically shut down when the oven’s temperature reaches 10°F over the O-rings’...

HMI design

The first thing we should do is lay out our HMI. Based on the requirements, we are going to need the following at the minimum:

  • An alarm table
  • A series of inputs to allow the user to input the temperature of the oven
  • A gauge to show the current temperature of the oven
  • A power switch and LED for the oven
  • An LED for the following:
    • Oven ramping up to temperature
    • Oven at temperature
  • An alarm acknowledgment button

With the requirements, we can lay out our HMI to look like the following screenshot:

Figure 15.1 – Oven HMI

Figure 15.1 – Oven HMI

This is a simple HMI layout for our project. We have a simple Power button in the lower left-hand corner with a ramp-up and target temperature spinner above it. In the center of the screen, we have an alarm table for our alarm readout as well as three LEDs to indicate that the oven is on, another LED to indicate that the temperature of the oven is human-safe, and finally, an LED to indicate that...

HMI implementation

The first thing we need to do is start declaring variables. For this example, we are going to put all the variables that control the HMI in a global variable list (GVL) called vars for ease of use. For this project, we are going to declare the variables in groups such as LEDs and so on to make it easier for you, the reader, to follow along with the code. The first set of variables we are going to work on are the LED variables.

LED variables

We have three LEDs that are used as temperature indicators and one LED that is used as a power indicator. We are going to create four Boolean variables, as follows:

 PROGRAM PLC_PRG
VAR
     //LEDs
     power       : BOOL;
     safe_temp   : BOOL;
     target_temp : BOOL;
END_VAR

The following will show you which variables to map to which LEDs:

  • The power variable...

PLC code design

Since we are now moving into the PLC code development, we need to start looking at a design. Normally, the design of the PLC code is done in conjunction with the HMI design; however, we designed and implemented the HMI first because we are completing all the steps ourselves and this is an education project. Therefore, as stated before, it is common and best practice to perform the whole design phase for both the HMI and the PLC code at the same time if possible. Again, we only implemented the project the way we did so that we can have an HMI ready to start testing our PLC code.

To keep the design simple, let’s break the project down into the following function blocks:

  1. Oven: This function block will handle turning the oven on and off, as well as ramping the oven up to temperature.
  2. Alarms: This function block will trigger error, warning, and info alarms.
  3. Door: This function block will be responsible for locking and unlocking the oven door.
  4. ...

Implementing the PLC code

Now that we have a design, we can implement the code. The code implementation should be relatively minimal. The first thing we are going to do is declare our function blocks. For this, we are going to create a folder named FunctionBlocks and use it to house the Oven, Alarms, and Door function blocks. When all the function blocks and methods are implemented, your tree should look like this:

Figure 15.14 – Function blocks

Figure 15.14 – Function blocks

Once you create the tree, you can start to implement the methods. The first set of methods you will want to implement are the methods of the PLC_PRG file.

PLC_PRG file

The first place we’re going to start implementing code is in the PLC_PRG file. Since it is our entry point, we’re going to put our starting logic here. In short, you should have your variables all implemented in the vars GVL at this point, except a reference variable for the Oven, Alarms, and Door classes, which will look...

Testing the application

Now that we have the code implemented, we can run a few test cases to see if the code works as expected. If you look at the code, we have an oven_temp variable that in real life would be tied to some type of thermal sensor. For our purposes, we are going to control it manually to simulate the conditions inside the oven. In real-world automation programming, this is a common technique. We don’t always want to heat the oven to the target temperature until we know for sure the software is working; simply writing values to that variable will suffice. With all that being said, we can now start testing the application by testing out the door.

Testing the door lock

We are going to start with the most basic and safety-critical part: testing the door. Essentially, we want to ensure the door is locking and unlocking properly. For this, we are going to use the following test case:

Figure 15.15 – Test case

Figure 15.15 – Test case

The test case...

Summary

Congratulations—you have now completed all the technical sections of this book! In this chapter, we have explored creating a sample oven. We have built this project using a Waterfall-like methodology, and we have gone through most of the SDLC sections. In this section, we have built the code and HMI for a simulated real-world project. Now, we did find bugs in the code, and you will be responsible for finding bugs and retesting them. There are no right or wrong ways to solve these bugs and test cases; you are free to use your intuition and what we have covered to fix them. If you are completely stuck, I would recommend looking at the questions for a punch list of things to fix and a few more test cases to create. Once you are done with all that, you can move on to the next chapter and explore distributed systems.

Questions

Answer the following questions based on what you've learned in this chapter. The questions in this chapter are open-ended with no wrong or right answer. They are meant to be exploratory so readers can come to their own conclusions.

  1. Write a test case to test the LEDs.
    1. Does the LEDs’ behavior make sense for what they are meant for?
    2. If there is a bug, can you debug it?
  2. Test the Ack button.
    1. Write a few test cases for the Ack button.
    2. Does the button work as intended?
  3. Can you refactor the Alarms function block and condense everything into one method?
  4. Can you add extra functionality to the program or HMI? This is an open-ended question, so use your imagination.
  5. What should you do if there is no set value in the spinner? Should you set a default value, throw an alarm, or do something else? Use your imagination!
  6. Can the variables be renamed to better reflect what they do?
  7. Do the info, warning, and error alarm messages make sense? Can you improve...
lock icon
The rest of the chapter is locked
You have been reading a chapter from
Mastering PLC Programming
Published in: Mar 2023Publisher: PacktISBN-13: 9781804612880
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Mason White

M.T. White has been programming since the age of 12. His fascination with robotics flourished when he was a child programming microcontrollers such as Arduinos. M.T. currently holds an undergraduate degree in mathematics, a master's degree in soft ware engineering, and is currently working on an MBA in IT project management. M.T. is currently working as a soft ware developer for a major US defense contractor and is an adjunct CIS instructor at ECPI University. His background mostly stems from the automation industry where he programmed PLCs and HMIs for many different types of applications. M.T. has programmed many different brands of PLCs over the years and has developed HMIs using many different tools.
Read more about Mason White