PLC Program Commands: Performing Array Functions Part 1
Arrays can streamline data storage and math operations, but they can be difficult to understand for a beginning programmer. Learn the background of array instructions in the Rockwell Studio 5000 software.
Using the FAL (File Arithmetic and Logic) Instruction in Studio 5000
The File Arithmetic and Logic (FAL) Instruction is used to perform a single, mathematical function on every position of an array in a uniform pattern. Let’s make a quick example: assume you have an array of 32 circumferences and need the radius of each one. If you used a compute instruction, you’d have to create an instruction to address each of the 32 array positions individually. However, if you used a single FAL instruction, you could simply apply this one calculation to all positions of the array at once, then store the result of each array position in a new array.
FAL Structure Tags
Let’s take a look at what is needed to make the FAL work. First, as is usual with most of our array instructions, you need a control tag. A control tag has its own datatype that houses all the data required for the instruction to know where it is and what it needs to do with the array.
FAL Control Tag
The control tag has critical components like the ‘.POS’ tag that keeps track of the current position of the instruction as it works inside the array. Other components we will use later are the length ‘.LEN’ and found ‘.FD’ tags. When we plug our control tag into our instruction, we use the Length entry space directly below to tell the instruction how long the array is that we need to perform the arithmetic operation on.
Important Note: You cannot use a control tag that is part of an array of control tags for any instruction that uses the ‘.POS’ function. You cannot nest the control pointer inside the array pointer in the instruction.
FAL Length Tag
The next component of the FAL is the Length. We do not interact with this in most cases. It is used by the FAL control tag to keep track of where it is as it performs its function on the array.
FAL Mode Tag
The next component is the Mode. This one is a little different than most tags and data you are used to. There are three different modes to choose from. The first mode is called ‘ALL’, and when you use it, it performs the function on ALL the array positions on one scan. We are only manipulating an array of five pieces of data, so we can use ALL mode.
What if we had 314 pieces of data in this array? We could easily overwhelm our control and throw off the scan time needed for critical functions! In this case, we can use the ‘INC’ mode to perform like a one-shot or enter a number to specify how many pieces of the array should be done on each scan. If you entered 10 for the abovementioned case, you would spread the computation over 32 scans. This might be much easier for the controller to execute.
FAL Destination (Dest) Tag
The next piece of information is the Destination. The destination tag needs to be an array that has enough spaces for the source array that we will put in later. Below, in the logic snapshot, I have 5 array positions so I used a Length of 5, a Destination array with 5 DINTs, and a source array with 5 DINTs. That way everything has a matching size and there are no conflicts. Note that the Pointer of the array in my logic is actually a function of the FALControl.POS —the position of wherever the instruction is currently performing a function. If you plug a static number in here, it will overwrite every number and won’t work. You have to have the variable array pointer that is tied to this specific instruction.
FAL Expression Tag
Finally, we have our Expression. Our expression must contain the array we want to manipulate and the math function we will be using on it. It is important here, again, that you use the Position of the Control tag so that you perform each function on the correct number as it goes through the array.
For a list of available operators in these math instructions, you’ll need to consult the Help portion and ensure your controller is capable of all the math functions you need. This will feel quite similar to most operations available in the compute (CPT) functions. The syntax of the operations follow generally accepted syntax, multiply *, divide /, add +, and so on.
Let’s examine the instruction in the logic below:
Figure 1. Example of File Arithmetic and Logic (FAL) instruction syntax in a ladder rung. Author’s image
When I hit the trigger, let’s look at what happens between the source array and the destination array. As you can see in my logic, I multiply every source array position by 2 and then drop the result into the matching array position in the destination array. Works like a charm!
Figure 2. Following along with the previous example, the FALSourceArray on the left side, and, after dividing by 2, the destination array on the right. Author’s image
Remember these key things when it comes to the FAL instruction:
You must use the Control Position tags in your source and destination arrays
You cannot use a Control tag that is part of an array of Control tags
Use the Mode to regulate how much time your controller is allowed to devote to this instruction in a scan cycle
Using the FLL (File Fill) Instruction in Studio 5000
Ready for something a little simpler? We can do that with the FLL instruction. If you drop an FLL into your logic, you’ll notice that, while it manipulates arrays, it does not have a control bit. The goal of the FLL is not to perform a function on each individual element of the array, but rather to load a single value into EVERY element of the array.
FLL Source Tag
First, you need a piece of source data. I am going to use a static 0 value, but you could use a DINT tag or even a float. If you do use a variable tag, remember that it needs to match up with the data type of the array so that you don’t end up losing data. If you try to move a REAL into a DINT, you’ll drop off the decimal places and end up with incorrect values.
FLL Destination (Dest) Tag
The second thing you will need is an array to fill. You’ll plug this array into the Dest position in the instruction with the starting element. I am starting with position 0 as you can see below in the brackets.
FLL Length Tag
The last thing you need to do is tell the FLL instruction how long the array is that you need to be filled. My array is 5 elements long, so I am going to plug in the number 5.
Here’s what it looks like in live logic.
Figure 3. Example of File Fill (FLL) instruction syntax in a ladder rung. Author’s image
Let’s look at what happens when we hit Trigger.2 and activate this instruction. On the left is the array when we started. I hit Trigger.2 and it filled the array with the source number. On the right is the resulting array. It’s filled with zeros and ready to go!
Figure 4. Again following along with the previous ladder example, the FLLArray on the left side has now been filled with 0, just as the FLL instruction in the logic directed. Author’s image
Array Manipulation Instructions in Ladder Logic
This is the first of several articles that will cover advanced array manipulation in Studio 5000. By the time we’re done, you’ll have the knowledge you need to jump in and start programming arrays like a pro. Keep learning!
Featured image adapted and used courtesy of Rockwell Automation
If you enjoyed this article, check out the rest of the PLC programming article sequence:
Want to test your knowledge of PLCs? You think you N.O. a lot about ladder logic? Are you a normally-open or normally-closed minded engineer?
Check out our PLC Programming worksheet!