Book Image

Instant PLC Programming with RSLogix 5000

Book Image

Instant PLC Programming with RSLogix 5000

Overview of this book

RSLogix5000 is a user friendly IEC61131-3-compliant interface for programming the current generation of Rockwell Automation PLCs, which includes Ladder Diagrams (LD), Graphical Function Block Diagrams (FBD), Graphical Structured Text (ST), and Sequential Function Charts (SFC). Instant PLC Programming with RSLogix 5000 captures the core elements of PLC programming with RSLogix 5000 with a minimal investment of time. We will avoid getting into control theory and focus on condensing the information specific to RSLogix 5000. We have selected the key areas of RSLogix and provide a step-by-step approach to teaching them. This book start by follows the steps involved in creating a new RSLogix 5000 project and configuring racks, slots, and channels. Next, we will create routines using the various languages available in RSLogix 5000, troubleshooting and resolving issues we encounter along the way. Finally, we will dive into the advanced features, such as online changes, code generation, task management, and user-defined structures. You will also learn object-oriented PLC programming techniques using advanced features like user-defined types (UDTs) that improve the maintainability, uniformity, and readability of our routines. We also highlight the strengths and limitations of online changes and demonstrate techniques to maximize flexibility. You will learn everything you need to get up and running with RSLogix 5000 as well as best practices used by industry experts.
Table of Contents (7 chapters)

Organizing your project code (Advanced)


In this recipe, we will explore the way RSLogix organizes its controller into Scope, Tasks, Programs, and Routines.

Getting ready

To complete this recipe, you should have completed the previous exercises.

How to do it...

  1. In Controller Organizer, right-click on the Tasks icon and click on New Task.

  2. In our project, there is no need to check for our non-critical alarms every 10 ms. We will create a new periodic task for processing alarms every 250 ms and give it low priority in order to reduce the load on our processor.

  3. In the New Task form that appears, enter the following values:

    • Name: AlarmTask

    • Description: Task for Calculating Alarm Conditions

    • Type: Periodic

    • Period: 250.000 ms

    • Priority: 11

    • Watch Dog: 500 ms

  4. Next, we will add our Program that will contain our Alarm function and handle the alarm processing for our project.

  5. Right-click on our newly created AlarmTask task and click on the New Program option.

  6. In the New Program form that appears, enter the following values:

    • Name: MainAlarmProgram

    • Description: Program for processing Alarms

  7. Now we can move the DIGITAL_ALARM routine, which we created earlier in the book, to our newly created Alarm program. Expand MainTask and MainProgram in the Controller Organizer Tasks and drag-and-drop the DIGITAL_ALARM routine from MainProgram to MainAlarmProgram as shown in the following screenshot:

  8. As we learned earlier, in order for a routine to be executed, it must be linked to a program. We will now set the DIGITAL_ALARM routine as the MainRoutine of MainAlarmProgram. Right-click on MainAlarmProgram and select Properties (or hit Alt + Enter). In the Program Properties form that appears, select the Configuration tab and, under the Assign Routines header, select DIGITAL_ALARM from the Main dropdown as shown in the following screenshot:

  9. You will notice that, after assigning the DIGITAL_ALARM routine as the MainRoutine for MainAlarmProgram as shown in the following screenshot, the DIGITAL_ALARM icon changes to display 1 that indicates that it is the MainRoutine for the program:

  10. Next, we will check to see whether or not we have introduced any errors in our controller with our latest changes. From the drop-down menu at the top of RSLogix 5000, navigate to Logic | Verify | Controller.

  11. You will notice that the Errors pane has appeared and the following errors are listed:

    • Error: Sheet 1, B1, ALMD, FC1001_FLT_ALM: Tag doesn't reference valid object or target.

    • Error: Rung 1, JSR, Operand 0: Invalid reference to unknown routine.

  12. Clicking on the first error message will directly take you to the DIGITAL_ALARMS FBD and highlight the FC1001_FLT_ALM ALMD element.

    Note

    The red cross mark on the FBD element indicates that there is a problem with the block's configuration.

  13. The error has occurred because the original FC1001_FLT_ALM was created with a scope of MainProgram and it cannot be accessed from the MainAlarmProgram.

    Note

    FBD tags are automatically created with the scope of the current program you are working under when they are added to a diagram routine. In order to declare an FBD at the Controller scope (Global scope) level you will need to create it manually using the New Tag form.

  14. In order to fix this problem, we will need to create the ALMD tag again at the Controller scope. Right-click on the FC1001_FLT_ALM tag and select the New "FC1001_FLT_ALM" menu option (or press Ctrl + W).

  15. The New Tag form will appear. Ensure that the Scope field is set to FirstController and click on OK.

  16. Next, we should remove the duplicate FC1001_FLT_ALM tag that exists in the MainProgram Scope. Under the MainTask and MainProgram folders of Controller Organizer, right-click on the Program Tags icon and select Edit Tags.

  17. The Edit Tags table will appear; select the FC1001_FLT_ALM tag, right-click on the box to the left of the name, and select the Delete menu option (or press the Delete key).

  18. We have now fixed the first error message; now, let's resolve the second. Clicking on the second error message in the error pane will take you directly to the Jump To Subroutine (JSR) reference within our MainProgram element's MainRoutine object to the DIGITAL_ALARM routine. The error is being displayed because the DIGITAL_ALARM routine is no longer in the MainProgram element's scope. Delete this Ladder Logic Rung by right-clicking on it and selecting Delete (or by pressing the Delete key while clicking on the rung selected).

  19. Finally, we will Verify the program once more to ensure that we no longer have any problems.

  20. From the drop-down menu at the top of RSLogix 5000, navigate to Logic | Verify | Controller.

How it works...

As you can see from the exercise, your routines can be linked to different Tasks, which allows you to control how and when they are executed, and that can reduce the processing load on your PLC.

There's more...

Tasks provide us with control over how frequently sections of code will execute or if they will execute at all. It is critical to understand that these tasks are executed asynchronously in the world of RSLogix 5000, so let's take a look at a few features of Tasks in more detail.

Inhibit programs and tasks

One advantage of dividing your project into Tasks and Programs is that you can inhibit them individually, if needed, and prevent them from executing. To inhibit a Task or Program, right-click on it and open its properties. The Inhibit option is on the Configuration tab of the Properties window.

Understanding task types

There are three types of tasks in RSLogix 5000: Periodic, Event, and Continuous. Periodic tasks will run at an interval that you can specify in milliseconds. Event tasks will run when a predefined condition triggers it. Continuous tasks will execute as quickly as they can. Only one continuous task is allowed to be declared per controller. The main task that is added by default when you create a new project is automatically set up as a continuous task. More information on task types can be found in the Rockwell publication Logix5000 Controllers Tasks, Programs, and Routines available at http://literature.rockwellautomation.com/idc/groups/literature/documents/pm/1756-pm001_-en-e.pdf.