ControlLogix Average Instruction (AVE)


Introduction to the ControlLogix Average Instruction (AVE)

The ControlLogix Average Instruction (AVE) will find the average of a file. The file will simply be a group of numeric tags within an array. For example, we can use the AVE instruction to smooth out a noisy process variable to find the average speed of a motor, or the average temperature of a bearing. In a way, we could also use this as a rate limiter if you don’t have access to function block logic. Another example is to find average flow rate to display to an operator.

Create theTags

Before we begin, there are a few tags we’ll need to create. I’m just going to create these under “Program Tags”.

First, we’ll need a timer. This will trigger our message instruction. I’m just going to name this “MyTimer”. This will be a self running timer that resets itself every 5 minutes.

Next, we’ll need a control file. The purpose of the control file is to act as a “work space” for the average instruction to operate. This tag stores the status of the instruction, length, and position. This tag will have the “CONTROL” data type.

Let’s also create a tag to store the result. This tag will have the REAL data type, and we’ll just name it “MyAverageDestination”.

We also need a tag to store our samples so the processor can average them. We’ll name this tag “MyAverageArray”. This tag will be an array of 100 REAL values (REAL[100]).

Additionally, we’ll need a tag to store the result of the average instruction. I’ll create this as “MessageDestination”.

Write Your Logic

First, we’ll add our self-running timer. This will reset itself every 5 minutes. The purpose of this timer is to give us a pulse. We’ll use this pulse to trigger the AVErage instruction.

At this point, we’ll set up the average instruction itself. The dimension to vary (dimension to use) will be zero since this is a 1 dimensional array. This is an immediate value, so you can also enter the value of 1 or 2 if you have multidimensional arrays to index through a different dimension by (Length) amount of times. For example, If we index through dimension 0 ten times, you will be indexing through the first 10 elements if your length is 10. On the other hand, if you enter dimension 1, then you will average array[0,0], then array[1,0] etc…

The destination is where we store the average of the array.

The control file stores the status of the instruction. This includes the length, position, and other status bits such as ENable, DoNe, and ERror. Keep in mind that we only trigger this instruction once every 10 minutes. In this case, it would be pointless to do this more often, since we will only log data every 5 minutes.

At this point, you can enter random values into the MyAverageArray, and see the result of the average operation.

As you can see, if I enter the value of 100 in two of the elements, and 50 in another, the total average will be 2.5.

Populate the Array for the ControlLogix Average Instruction (AVE)

One way to populate the array is to use the FIFO or LIFO instructions. For the purpose of this post, we’ll just keep things simple. We’ll use indirect addressing to populate the array. Since the AVErage instruction is not weighted, it does not matter how we populate this array. All we care about is that the last 100 samples are in the array to get an average.

Let’s create a tag called AveragePointer. The data type will be DINT. After that, we’ll add the following logic to store samples into the array. Here, I’m just getting the outside temperature from NodeRed (OpenWeatherMapNode), and averaging the outside temperature.

Now you can look at the destination of the average instruction to see your average over time.

For more information, visit the ControlLogix Category Page!

— Ricky Bryce

Leave a comment

Your email address will not be published. Required fields are marked *