Back to tutorials
PLC Instructions

Introduction to Add-On Instructions or AOIs

By
Vladimir Romanov
Table of Contents

Introduction

In other programming languages (Java, C, C++, Python), programmers are taught functions early on. They are constructs that allow programmers to create custom pieces of code. By doing so, programmers have the advantage of re-utilizing their function and simplifying the code they build.

In PLC programming, AOIs are exactly the same. They are custom functions defined by the programmer. They can be used within a PLC program to standardize the implementation of specific code, shorten development time and reduce possible human mistakes when duplicating code.

It is important to note that although AOIs are a powerful construct, they’ve gained a bad reputation in the eyes of many. Here are these reasons and our arguments against them,

  1. AOIs are difficult to work with | Just like with any other programming language, a “function” construct needs to be understood by those who work with it. Once you explain how AOIs are implemented to those who will be working with them, they become quite easy to troubleshoot and work with.
  2. AOIs are unnecessary | We see a wide range of AOI implementations in the field. It is true that in most cases, code can be copied and pasted. However, it becomes extremely inefficient to duplicate large chunks of code; AOIs will save a lot of time.
  3. Troubleshooting AOIs is difficult | From our experience, the time it takes to learn how to navigate AOIs is well worth the investment in time saved by engineering and maintenance.

Advantages of an AOI

To further expand on the points above, let’s discuss practical advantages of building AOI through various examples.

Example 1 - VFD Motor Faceplates

In a system that uses Variable Frequency Drives, it’s not uncommon to see hundreds of such field devices. By creating a single AOI that encapsulates the control of a single drive, the programmer can save hours of programming by reapplying the same AOI to every single drive. Furthermore, the AOI will be identical and thus reduce the chance of making a typo while copying and pasting the blocks of code.

Example 2 - Proprietary Equipment

In a system that was developed for a non-common purpose, it’s useful to “hide” certain pieces of code from the customer. While adding a password to the entire program may create a sour relationship with the client, password protecting a small chunk of code that is responsible for a specific calculation or execution is acceptable. An AOI can be easily password protected to achieve this result.

Example 3 - Versioning

In a system that requires certain update roll-outs, an AOI can be used to standardize across versions. For example, a manufacturer of a 3rd party servo drive may release v1.0 AOI for their servo motor. As engineers around the world used this servo drive, the manufacturer released an upgraded version of this drive that now requires v1.1 AOI. It’s easy for the manufacturer to manage this roll-out as the programmers now know which version is compatible with each drive and can manage their code accordingly. Furthermore, they can easily get support from the manufacturer by identifying which drive and AOI version they’re dealing with during a support call.

Basic Implementation of an AOI

We believe that the best way to learn the concept is by following a simple example we can all relate to. Let’s build our first AOI.

Task description: Implement an AOI that will convert from Meters to Inches.

Implementation Breakdown:

  • The conversion formula from meters to inches is as follows: 1meter = 39.3701inches.
  • The AOI will require 1 input that will contain the number of meters to convert.
  • The AOI will require 1 output that will contain the number of inches computed.

Building the AOI

Let’s walk through the steps required to build the defined AOI. We’re using a CompactLogic PLC running v30 of Studio 5000.

Step 1 - Go Offline

Note: one of the drawbacks of AOIs is that they must be created and modified Offline.

RSLogix Studio 5000 Add-On Instruction [AOI] PLC Programming - PLC Offline
RSLogix Studio 5000 Add-On Instruction [AOI] PLC Programming - PLC Offline

Step 2 - Right Click “Add-On Instructions” in the I/O tree and Select “New Add-On Instruction…”

RSLogix Studio 5000 Add-On Instruction [AOI] PLC Programming - New Instruction
RSLogix Studio 5000 Add-On Instruction [AOI] PLC Programming - New Instruction

Step 3 - Define the AOI Parameters

  • Step 3.1 - Give the Instruction a Name
  • Step 3.2 - [Optional] Write a Description that outlines what the AOI does
  • Step 3.3 - Specify the Programming Language you’ll use within the AOI

Note: An AOI will need to use the same programming language for the entire implementation; there’s no way to refer to external routines.

  • Step 3.4 - Specify the Major and Minor Revisions
  • Step 3.5 - [Optional] Specify the Vendor Name
RSLogix Studio 5000 Add-On Instruction [AOI] PLC Programming - Instruction Parameters
RSLogix Studio 5000 Add-On Instruction [AOI] PLC Programming - Instruction Parameters

If you have selected “Open Definition” in the menu above, you’ll notice that a new prompt will open as soon as you press on “OK”. Within this menu, we will define additional parameters of the AOI we just created.

Step 4 - [Optional] “Open Definition” of the AOI from the IO Tree

RSLogix Studio 5000 Add-On Instruction [AOI] PLC Programming - Instruction Definition
RSLogix Studio 5000 Add-On Instruction [AOI] PLC Programming - Instruction Definition

Step 5 - Specify the I/O registers

  • Step 5.1 - Open the “Parameters” Tab
  • Step 5.2 - Add a “REAL” Input Register used for the meters to convert
  • Step 5.3 - Add a “REAL” Output Register used for the inches computed

You must select that both of these parameters are “Req” or Required. This makes it so that every implementation of the AOI will force the user to specify a variable to use for these parameters. If the input or output are not required, the user may choose not to include them. Example: The function can include a conversion to “feet” as an optional parameter.

RSLogix Studio 5000 Add-On Instruction [AOI] PLC Programming - Required Parameters

Step 6 - Build the Logic within the AOI

  • Step 6.1 - Open the Routine within the AOI in the IO Tree
  • Step 6.2 - Using the “MUL” instruction to convert the input into the output
RSLogix Studio 5000 Add-On Instruction [AOI] PLC Programming - AOI Ladder Logic Example

Step 7 - Use the AOI in the PLC Program

At this point, you’ve created the most basic AOI possible. It can be used in your PLC program. Before we dive into a more complex example, let’s go over two concepts: how to create an instance of an AOI and how to troubleshoot an AOI (access the right instance).

Implementing AOIs in PLC Programming

Within the “Controller Organizer”, under “Add-On Instructions”, all the AOI definitions will be found (as shown below). As previously mentioned, the programmer may choose to export any existing AOI or to import ones from a different program. The program must contain the AOI you plan to use in your code. Importing code without importing the definitions of AOIs used within it will create an error.

Note: the issue described above is often encountered when a programmer decides to copy/paste an array of ladder rungs (or other type of logic) from one controller into another.

RSLogix Studio 5000 Add-On Instruction [AOI] PLC Programming - Instructions in Program
RSLogix Studio 5000 Add-On Instruction [AOI] PLC Programming - Instructions in Program

To add an AOI into a program, follow the steps outlined below.

Step 1 - Open the Routine you’ll be programming

Step 2 - Insert any Instruction into the Rung

Step 3 - Double Click the Instruction (Not the Name) and Select the AOI

An alternative method is to type in the AOI instruction name.

RSLogix Studio 5000 Add-On Instruction [AOI] PLC Programming - New Instruction

Step 4 - Create an Instance Data-Type for the AOI

After the instruction has been added to the rung, the programmer must create a data-structure that will be referenced by the program. This is not something that needs to be done for basic instructions and is sometimes confusing to new users.

Give the instance a name (we typically add the “AOI_” prefix.) and right click to create an instance.

  • Step 4.1 - Specify the Data-Type (Ex: AOI_BasicCalculation)
  • Step 4.2 - Specify the Scope. Just like other data types, AOIs can be PLC or local scoped
RSLogix Studio 5000 Add-On Instruction [AOI] PLC Programming - New Instruction Instance
RSLogix Studio 5000 Add-On Instruction [AOI] PLC Programming - New Instruction Instance

Step 5 - Specify the Input and Output parameters within the Instruction

RSLogix Studio 5000 Add-On Instruction [AOI] PLC Programming - Instruction Parameters

Step 6 - Download the Program to the PLC & Go Online

Testing an AOI in PLC Programming

An Add-On Instruction will behave just like any other function in your code. The difference is that other instructions have been pre-defined by the manufacturer (Allen Bradley), while an AOI was created by an end user. The instruction we’ve created above can be easily used and tested within our code. We can either tie a sensor measurement in “Meters” in order to convert it to “Inches”, or we can leave the register as floating and change it ourselves. By changing the R_Inst[0] register which contains the number of meters, we get the following results for the various setpoints.

M = 1.54

RSLogix Studio 5000 Add-On Instruction [AOI] PLC Programming - Instruction Parameters Example 1
RSLogix Studio 5000 Add-On Instruction [AOI] PLC Programming - Instruction Parameters Example 1

M = 2.5

RSLogix Studio 5000 Add-On Instruction [AOI] PLC Programming - Instruction Parameters Example 2
RSLogix Studio 5000 Add-On Instruction [AOI] PLC Programming - Instruction Parameters Example 2

M = 245.8

RSLogix Studio 5000 Add-On Instruction [AOI] PLC Programming - Instruction Parameters Example 3
RSLogix Studio 5000 Add-On Instruction [AOI] PLC Programming - Instruction Parameters Example 3

As shown in the three examples above, the instruction will take the input in Meters and convert to Inches during a PLC scan. Based on this example, we can implement a variety of functions from simple to complex.

Creating Multiple Instances of an AOI Instruction in RSLogix / Studio 5000

As mentioned in the introduction, one of the advantages of Add-On Instructions in PLC Programming is that they can be used multiple times across the program; saving you time and helping you avoid mistakes in implementation. Let’s examine how we can create additional instances of the AOI that we developed above.

Step 1 - Create an Additional AOI Block

You may create a new rung below where we inserted the original AOI or in a completely separate routine.

Step 2 - Create a NEW Instance of the Instruction

Each AOI block requires a unique data structure in your program. The first instruction used the “AOI_m_to_in1” structure. The one we’ll create here is going to be using the “AOI_m_to_in2” structure. Note that you can use any name you wish. In the field, it’s common to give each one a descriptive name depending on the use of the instruction.

Similarly, we need to assign data points to our instruction (inputs and outputs). These can take on the same registers. However, just as it would be with an Allen Bradley instruction, it’s best to create unique registers.

We end up with the following implementation of the second instance of the AOI we built above.

RSLogix Studio 5000 Add-On Instruction [AOI] PLC Programming - Second Instance
RSLogix Studio 5000 Add-On Instruction [AOI] PLC Programming - Second Instance

Step 3 - Running the AOI

The AOI we’ve created will behave just like the first one. However, it will apply to the different set of tags that we’ve used for the inputs and outputs.

Troubleshooting an AOI Instance in  Allen Bradley RSLogix Studio 5000

The most common pushback we see from our clients is that AOIs are difficult for field engineers and technicians to troubleshoot. We believe that once you go through the steps of the process, it becomes second nature. In other words, it’s not more difficult than any other set of instructions. In fact, it becomes easier to make changes if necessary as it will apply to all instances of the AOIs already in place.

Step 1 - Open the Logic Implementation of the AOI

Navigate to the AOI you wish to troubleshoot / view in the “Controller Organizer” and open the Logic file of that Add-On Instruction.

RSLogix Studio 5000 Add-On Instruction [AOI] PLC Programming - AOI Logic
RSLogix Studio 5000 Add-On Instruction [AOI] PLC Programming - AOI Logic

Step 2 - Choose the Instance of the AOI to Troubleshoot

On the right hand side of the software, you’ll see a dropdown that will allow you to select from a list of currently active instances. By default, the displayed logic will only contain the “implementation” of the function. The “implementation” does not display any values and remains static.

RSLogix Studio 5000 Add-On Instruction [AOI] PLC Programming - AOI Definition

Step 3 - Troubleshoot the Logic

Once you’ve selected an instance, you’ll have access to the variables used within the instruction. It’s important to note that you won’t be able to edit the instructions used, but you can view their state, the values and the execution.

RSLogix Studio 5000 Add-On Instruction [AOI] PLC Programming - AOI Specific Instance

Advanced Implementation of an AOI

We’ve covered a basic implementation of an AOI Instruction. Although we plan to release a separate tutorial on advanced instruction, we believe that if you’ve implemented what we described here, you’ll be off to a good start. Besides what we’ve already covered, AOIs will typically contain UDT structures and advanced logic processing. As you’ve learned from our example, you can create a number of rungs and extend logic as you wish; the possibilities are endless. Furthermore, an Add-On Instruction can leverage versioning control; OEMs that update their equipment or functionalities, typically release new versions of their AOI. Therefore, the software implementation must match the version of the AOI for intended use.

Conclusion on Add-On Instructions in RSLogix Studio 5000

In this tutorial, we’ve covered why you may want to use AOIs in your PLC programming, what you need to know to implement them and how to troubleshoot them. We believe that these constructs are extremely useful and should be understood by most seasoned PLC programmers. If you have any questions on this topic or any other, don’t hesitate to post them on our community forums.

Back to tutorials

Related Tutorials

Advanced

Servo Motor Introduction & Kinetix Selection Guide

Servo Motors are an electro-mechanical device that combines a traditional motor with high precision positioning electronics. The advantage of a servo motor over an inductive motor is the ability to reliably position the motor within a tight tolerance and thus accomplish tasks that one could not with any other motor type. The electronics that are housed within the “servo motor” are complex. However, there are three main components you should be aware of: Servo Drive | Regulates the voltage, communicates with the PLC and the Servo Motor. Servo Encoder | The portion of the motor that is responsible for reliably tracking the position of the shaft. Servo Motor | The motor that rotates when a voltage is applied.

By
Vladimir Romanov
Beginner

Siemens PLC Programming | Getting Started with the S7-1200 Siemens PLC Training Kit

In this tutorial, you will learn about the Siemens PLC training kit, and how to get started with Siemens PLC programming.

By
Vladimir Romanov
Beginner

Complete Guide on Buying Your First Allen Bradley PLC for Programming

PLC Programming is challenging; it doesn't have to be costly. We recommend that those who are looking to get into this career invest in an entry level PLC that allows them to practice without breaking the bank. Once you land your first job, you may choose to purchase additional hardware. However, the emphasis of this tutorial is on those who are just getting started.

By
Vladimir Romanov