ControlLogix CASE / OF Statement


Introduction to ControlLogix CASE / OF Statement

The ControlLogix CASE / OF Statement allows a specific block of code to execute. The block of code that executes depends on the value of a tag. This can also be an expression that returns a value.

You can use this statement in Structured Text. An example of this would be an alarm code. Based on a specific alarm code, we can execute a block of logic. This logic would be the action we might take when a specific alarm occurs. For example, you could shutdown a certain section of your equipment. You could also update an operator display.

Another example would be in a type of sequencer operation. In this case, we can increment a tag. The value of the tag represents the step of a sequencer. Each block of code would be the actions you want to take during that step.

It’s important to realize that you might want to use structured text sparingly. Some technicians find this type of logic difficult to troubleshoot.

Set up a Structured Text Routine

First, we’ll create a Structured Text routine. We will right-click on a program. After that, choose “New Routine”. Be sure to name your routine. The type of routine will be “Structured Text”. It’s important to realize that we need a JSR in the main routine. The JSR allows subroutines to execute.

Don’t forget that if you created a new program, you need to declare a main routine. Do this in the properties of the program. This is on the “Configuration” Tab.

When finished, our tree should look similar to this:

Add the ControlLogix CASE / OF Statement

At this point, we are ready to add some logic. Before we begin, let’s create a couple tags. Remember the purpose of this exercise is to understand the CASE / OF Statement. The logic will be of no practical value at this point. It’s simply to show you how the instruction works.

First, lets create a couple tags. Create “MyCase” as DINT. In the same way, we’ll create a tag called “MyValue”. Again, this will have a DINT data type.

Our objective will be for us to manually place a value into MyCase. After that, MyValue will immediately change, depending on the value we chose for that case. For example, we’ll change MyValue to 10, when MyCase = 1. Likewise, MyValue will contain the value of 20 when MyCase = 2. Again, this is just to prove out the operation of the Case / Of statement in the simplest way possible. In reality, you would execute certain blocks of logic during each case instead of just setting a single value.

Let’s give it a try!

We’ll configure the logic in our “Example” Routine as follows:

As you can see, we are looking at the tag “MyCase”. Obviously, when this is 0, we write the value of 0 to MyValue. Likewise, if the MyCase = 1, then we write the value of 10 to MyValue.

Let’s go to our program tags to test our work.

When MyValue = 1:

Again, When MyValue = 2:

Finally, back to 0:

Let’s try something different. I’m going to change MyCase to the value of 10. Remember, we have no logic that executes with this value. The value will remain at 0.

Summary

In Summary, use the ControlLogix CASE / OF Statement when you want a certain block of logic to execute. We base this on a value or expression. As long as this value is listed as a case in the construct, only that block of logic will execute. If the case is not listed in the construct, then no logic executes. For a more detailed explanation of each structured text command, take a look at Rockwell’s user manual. This manual is strictly for Structured Text Routines.

For more information on ControlLogix, visit the category page!

— Ricky Bryce

For Customized automation training, visit my employer's website at http://atifortraining.com!

Leave a comment

Your email address will not be published.

twenty seven  −  17  =