Back to tutorials
Beginner

Introduction to Structured Text Programming in RSLogix and Studio 5000 Allen Bradley

By
Vladimir Romanov
|
March 17, 2020
Table of Contents

Introduction

As you develop your skillset in PLC programming, you'll realize that there are many ways to accomplish the same task. However, certain approaches would be much more applicable in certain cases and less so in others. Through ladder logic, you can create programs that are easy to maintain, understand and augment over-time. That being said, most PLCs, including Allen Bradley ones, offer others ways of implementing logic. These different ways of programming are as follows: Structured Text [ST], Function Block Diagrams [FBD] and Sequential Function Charts [SFC].

The advantage of using structured text over ladder logic isn't always apparent. It's typically hard to transition into structured text after investing time in learning ladder logic. In contrast, those who are coming into PLC programming with a background in software engineering may found it easier to understand than ladder logic. In fact, the structure in ST is much closer to a traditional programming language such as C, C++, Java or Python than it is to ladder logic.

An implementation in structured text allows the programmer to create complex routines and flows that may not always be as easily implemented in ladder logic. For example, a FOR loop would take a single line of code to implement in ST while it requires a separate routine in ladder logic. Furthermore, it's also possible to leverage string manipulation through Excel in order to create easy to copy and paste code for your simple assignments.

In this introductory tutorial, we're going to explore the basics of structured text, go over the fundamentals of the interface that are different from ladder logic and lastly build a few simple examples to illustrate an assignment of a variable.

Structured Text Programming Interface in RSLogix Studio 5000

The process of creating a Structured Text routine is the same as before. Simply "right-click" the program, select "Create New Routine" and change the type to "Structured Text". Note that you will have to create a JSR instruction from the main routine in order for the code in the new routine to execute. Exactly the same way as we always did in Ladder Logic.

Structured Text programming interface in RSLogix Studio 5000 Allen Bradley Compact Logix PLC
Structured Text programming interface in RSLogix Studio 5000 Allen Bradley Compact Logix PLC
  1. Structured Text Routine "_05_Practice" was added to the "ST_Practice" program. A JSR instruction is added for the new routine to execute.
  2. Routine Edit Views - in Structured Text, we will be editing the entire routine as opposed to a single rung in ladder logic. By pressing on the left-most button, the user will be presented with the original view of the routine. In other words, the way the routine was before the edits. By pressing the middle button, the user is presented with a window in which he or she can add or edit existing logic. Lastly, the left-most button is used to see the "Test Edits" while certain changes are begin made.
  3. Pending Routine Edits - just like in Ladder Logic, it's possible to start edits, accept edits and cancel edits. These actions are performed with the three buttons in that specific order.
  4. Pending Program Edits - just like in Ladder Logic, it's possible to accept or cancel the edits made to the entire program.
  5. Finalize All Edits in Program - it's not always recommended to use this button, but it will commit all the changes made by the user within the program.

The interface for Structured Text differs slightly from Ladder Logic. That being said, most of what you've learned is re-applicable.

The first question that comes to mind as users transition from ladder logic to Structured Text is with regards to troubleshooting. In ladder logic, the user was shown which tag was energized, which value was set in an integer, which string was sent to a variable, etc. How is this displayed in Structured Text? In fact, Structured Text will display a window with all the tags utilized within the routine below the editor under the "Watch" tab. Within this window, the user will be able to see different tags and their values as they change. This window is very similar to what you would expect to see in the Tag Editor in "Monitor Tags". Note that this methodology of tracing tag values may take time to adapt to.

Structured Text Tag Watch window in RSLogix Studio 5000
Structured Text Tag Watch window in RSLogix Studio 5000

Structured Text Tag Assignment Structures

In Structured Text, values are assigned to tags. Think of this action as your OTE and MOV instructions combined into a single step. Just as we saw in ladder logic, there are certain rules you need to keep in mind. For example, a tag type will only take certain values; a boolean tag will only allow the program to compile if it's assigned to a 0, 1 or another boolean tag.

Starting with a boolean, we may issue the following assignments:

NewTagBOOL := 0;

NewTagBOOL := 1;

The assignments written as such are equivalent to an OTL and an OTU instruction we've seen in ladder logic programming. Note that the program will throw an error if the user attempts to assign the boolean to a static value different than 0 or 1.

NewTagBOOL := NewTagBOOL2;

As mentioned previously, it's possible to assign a boolean value to a tag that's of the same type (boolean). This operation would be equivalent to evaluating an XIC of a boolean and assigning a latch to 1 to a secondary boolean. In case of the XIC to be false, a 0 would be assigned.

Next, we have the integers: INT, DINT, SINT:

NewTagINT := 45;

NewTagINT := 567;

NewTagINT := NewTagINT2;

Integers can be assigned to values within their limits or other integers of the same type. Note that the compiler will throw an error if you attempt to write a DINT into an INT.

Working with Strings is slightly different in Structured Text than what you may be used to:

NewTagSTRING.DATA[0] := 65;

NewTagSTRING.DATA[1] := 66;

Strings are created through individual ASCII character assignments. By setting the first character to 65, the actual string value is set to the letter "A". Here's a table from which you can take values for use in Strings:

ASCII Table for String assignments in RSLogix 5000
ASCII Table for String assignments in RSLogix 5000

Non-Retentive Tag Assignments

The non-retentive tag assignment in Structured Text is equivalent to the action we see with the OTE Instruction in ladder logic. In other words, when the conditions are true, the tag will evaluate to 1; while they aren't the tag will be reset to 0. The assignments above won't have the same effect. They will set the tag to the value of choice and remain as is regardless of what occurs with the tag.

We haven't seen an example that would demonstrate the use of a non-retentive assignment at this time. However, it's important to understand the underlying principle for the tutorials to come and know that there's a difference in assignments.

Conclusion

We've looked at the basic features of Structured Text and implemented simple tag assignments. We also reviewed the minor differences in the editor features and how they reflect onto ladder logic. Lastly, we discussed tag assignments and how they differ in Structured Text.

At this point, it would be important to start looking through the editor, becoming familiar with the differences and how logic changes are implemented. You should also begin creating new tags and assigning them to variables and themselves to fully understand how tag assignment works. Lastly, make sure to review and become familiar with the "Watch" window; it's an essential tool for troubleshooting the status of your application in Structured Text.

Video Tutorial

Back to tutorials

Got a question or comment?

Related Tutorials

Beginner

How to Create a PLC Backup for a ControlLogix Controller

In this tutorial your will learn how to create software backups in an RSLogix 5000/Studio 5000 environment.

July 2, 2020
|
By
Jacques Venter
Beginner

An Introduction to Safety in Automation Systems

Automated machinery and systems can help improve productivity and quality, but safety must always be held to the most scrupulous of standards. In this tutorial, you will learn about safety best practices in automated systems.

June 25, 2020
|
By
Kyle Sanders
Beginner

How to Program PID Loops in RSLogix 5000

In this tutorial, you will learn about PID loops and how to create them in RSLogix 5000.

June 22, 2020
|
By
Jacques Venter