SLC-500 FIFO Find Moving Average 1

Introduction to the SLC-500 FIFO Find Moving Average

We’ll use the SLC 500 FIFO to find the Moving Average of a value. The SLC-500 FIFO (First In – First Out) can be used to store data that needs to be retrieved later. For example: We can read a product code from 15 parts on a conveyor. When part goes down the line, we can later retrieve the product codes in order. This can also be used for displaying alarm history on an HMI, or to keep a moving average of an analog signal. I’ll use the moving average example in this post. This will explain how the FIFO instruction itself works. This post just shows an example on how to set up the FIFO instructions. You must change the way the logic is written to meet your own needs.

We use the FIFO Load instruction (FFL) to put data into our Data File. Think of this data file as a container. We will use the FIFO Unload instruction (FFU) to pull out the oldest data. I will use the Compute (CPT) instruction to calculate the moving average of our analog signal.

Write the Logic

First, we’ll create a self-running timer. The preset on this timer will be the sample rate for our FIFO.

The analog data is coming in on N7:0, so we will write the FIFO instruction as follows in this example. This loads a sample of the analog signal into the FIFO every second. We created file N50 (Integer file) with a length of at least 15 elements. We are using the next available control element of the R6 file. I’m using the R6:0 element to keep track of the length, position, and other bits related to the FIFO Load (FFL).

Next, let’s all all of the values together and divide by 15. This will calculate the average. I’m using a CPT instruction for this, so you can visibly see the math. Notice the “divide by” symbol is a vertical pipeline “|”. The answer will be placed into F8:0. This will represent our running average. In order to prevent the CPT from Calculating an incorrect value after the FIFO unloads, we’ll set the DN bit on the timer as a condition.

Likewise, I’ll set up the FIFO Unload (FFU) instruction using the same control element. We’ll wait until the FFL has loaded 15 elements before unloading it. Let’s use the DN bit of the control word for this.

Reset all data

Finally, I’ll write some logic to reset the control element and clear the FIFO, so we can start it all over again. In this case, you can toggle B3:0/1, or the first pass of the processor scan (S:1/15) will reset the data.

For more information on the SLC-500 processors, visit the Category Page!

— Ricky Bryce

Leave a comment

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

eighty four − = eighty two

One thought on “SLC-500 FIFO Find Moving Average