ControlLogix File Arithmetic Logic


Introduction to ControlLogix File Arithmetic Logic (FAL)

ControlLogix File Arithmetic Logic (FAL) allows us to perform math on an array of elements. For example, I have an array of elements that are in Celsius. We want to convert this entire array to Fahrenheit. We don’t need to perform the calculation over and over again for every single element. The FAL instruction allows us to do this all at once.

File Arithmetic Logic

In this post, we’ll cover the operation of the FAL instruction. We’ll also go over the different modes of operation.

Create Your Tags

Before we begin, let’s set up a few tags. We’ll create an array of 5 Celsius tags. These will have the REAL data type. Keep in mind that the REAL data type allows for decimal points. Similarly, we need an array of 5 Fahrenheit tags. Again, these will have the REAL Data Type. Additionally, we need a CONTROL tag for the FAL to operate. The Control tag simply keeps track of the FAL’s status and position.

At this point, we’ll go to “Monitor Tags”. We’ll populate the Celsius array with random values. This might simulate data from a Thermocouple module that is returning Celsius values.

Write Your Logic

We are ready to add the FAL Instruction to our logic. We’ll trigger the FAL with an XIO of FALControl’s DN bit. In other words, when the instruction is DoNe, it will restart itself.

Control, Length, Position, and Mode

Remember, FALControl is the instruction’s workspace. This keeps track of the status bits such as ENable, DoNe, and ERror. Additionally, it will keep track of the FAL’s position. This position is important in our expression and destination. We need to use this position to index through the arrays.

Our Length is 5. We have 5 elements to pull from the source, and store to the destination. The position will increment automatically as the instruction executes. For now, we’ll leave this at zero.

As far as the mode of operation: There are 3 modes. If you double click the pull down tab for “Mode”, you only see two options though. These two options are “INcremental”, and “ALL”. There is a third mode, which is “Numeric”. This will limit the number of operations per scan. If you desire to use Numeric mode, simply enter a numeric value into this field.

We will do all of the operations each scan. For this reason, we’ll set the mode to “ALL”.

Expression and Destination

Next, let’s skip down tot he Expression…. We’ll come back to talk about the destination. Effectively, the FAL will execute 5 operations per scan, since our mode is set to “ALL”, and our length is 5. The position increments for each of these operations. The position will run from 0 to 4. Our expression Celsius[0]*1.8+32.contains an Indirect Address that looks at this position. Therefore, for the first operation, the expression is effectively Celsius[0]*1.8+32. For the next operation, the position increments. Therefore, the expression is effectively Celsius[1]*1.8+32. Then Celsius[2]*1.8+32, and so on until the position reaches 4.

As for the destination, it works in a similar way. For the first operation, when we perform the calculation on Celsius[0], we store the result to Fahrenheit[0], then for the next operation, we store the result of Celsius[1]’s conversion to Fahrenheit[1]. Then from Celsius[2] to Fahrenheit[2], and so on until the position reaches 4.

Effectively, we have an element to element conversion as the position increases. We are indexing both the expression, and the destination.

Other ways to use the FAL

Occasionally, I see programs where the mode is incremental, and they do not index the expression. In other words, the expression references a single tag. They only index the destination. Setting the FAL up this way would be good for creating a “Data Log”. You might trigger the FAL every 10 seconds to log a value to the destination array. Keep in mind, if you use the FAL this way, the mode is usually INCremental. You are taking samples of a single tag.

Another way to use the FAL is to index the expression, but the destination is a static tag. Again, usage in this way would probably be INCremental. You might use this in conjunction with a “Next” button on your MMI. The operator can scroll through bearing temperatures.

Test Your Work

At this point, we’ll finalize the edits.

At this point, we’ll go to Controller Tags. Go to “Monitor Tags”, and let’s see if the values are converting.

Dealing with Errors for ControlLogix File Arithmetic Logic

In the event that you have an error in an operation, the FAL stops and sets the ERror bit. Let’s experiment with this. To Demonstration, I’m going to change the expression, so that we divide by 0.

As you can see, the FAL sets the Error Bit.

In this case, the expression itself caused the division by zero error. In some cases, though, it might be the data in the array that caused the error. Simply look at the data the expression was doing math on when we got the error. By the position, you can see which element of the array was being operated on.

Summary for ControlLogix File Arithmetic Logic

In Short, the FAL instruction performs math operations on entire arrays. Just be sure to include the position in the expression and destination if you want to index them both. Although the name sounds intimidating, it’s actually fairly easy to set up. You just need to understand how the indexing works with indirect addressing.

For more information, visit the ControlLogix Category Page!

— Ricky Bryce

Leave a comment

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