Introduction to ControlLogix Processor Status Flags
ControlLogix Processor Status Flags will tell us when certain events occur during our instruction execution. In this section, we’ll discuss the purpose of each of these status flags, and how we might use them in our logic.
It’s important to realize that you will always have access to these status flags in your logic. You do not need to execute a GSV instruction to access these flags.
If you’ve done any programming in Assembly language, you understand how to use the processor status flags. The ControlLogix status flags are very similar to the status flags in a standard computer processor. There is a flag for Overflow (S:V), Zero (S:Z), Carry (S:C), and Negative (S:N). Additionally, you have a status flag for minor faults (S:minor), and a status flag for the first scan of a task (S:FS)
S:FS — First Scan
The S:FS bit is true the first time a task executes. After that, the first scan bit shuts off. You can use this first scan bit to initialize your processor on power up, or after going from program to run mode. An example of where you might use this is for clearing log files or other data when you first enter run mode. Some older I/O modules also need to be initialized (configured) when the processor starts up. This is probably the most common status flag that you are using in your projects. A good resource for this is the Information and Status manual.
S:Z — Zero Flag
When the result of a math operation is zero, the processor will set the S:Z flag. An example of where you would use this is when a math operation indicates that a bin is empty. Once we see that the bin is empty, we can take other action, such as loading product from another bin. We don’t see this in use very often anymore though. Typically a programmer will just use an EQU statement in logic to compare a result to zero. However, by using this flag, you will use less memory and scan time though.
S:V — Overflow Flag
S:V becomes true when the result of a math operation exceeds the maximum signed value of a tag. For example, a signed DINT can only store 2,147,483,647. After that, it will overflow and become negative. If the S:V flag is true, then you know that the result of your math is not accurate. At least as long as you express that result as a signed integer.
S:C — Carry Flag
I will have to disagree with the information and status manual on this one. While this may be true for first grade math, computers do not think that way. The manual states that adding 3+9 will cause a carry of 1. I’ve tried this, and at least with DINT’s this is incorrect. Computers think in binary. They will automatically carry the 1’s through their word length. If the word length is not long enough, we need to carry an extra bit. This is when S:C goes true.
To understand the purpose of a carry flag, let’s go back to the 8 bit processor days. In an 8 bit processor, your maximum unsigned value was only 255. Of course, we cannot do much with this. For many values, we will at least need a 16 bit integer. The maximum value of a 16 bit unsigned integer is 65536.
In Assembly language we will separate the source and destination into low bytes and high order bytes. If the math of the low order byte exceeds 255, it would set the carry flag. When we add together the high order bytes, we would simply add the carry to them as well to get an accurate 16 bit value. A carry would just mean that we needed an extra bit to be high. (The carry essentially becomes the 9th bit).
Since most all data types that I know of in ControlLogix are signed, and because the values can be so large, we probably would not have much use for this bit. However, it does set if we need a 33rd bit to express the full unsigned value. An example of what would set this bit is -1 + 1. As humans we see the result as zero. On the other hand, the ControlLogix sees a -1 as all bits being high. If all 32 bits are high already in a DINT, and we add 1, we will get a carry. Once again, the effect is still zero as long as we do not consider the carry.
S:N — Negative Flag
If the result of a math operation produces a negative number, it sets the S:N Flag. This is similar to the S:Z flag, but sets when the result of a math instruction is less than zero.
To elaborate a little on the S:N and S:Z flags, I’ll go back to early processors again. Imagine we need to execute a loop 5 times. We can easily do this with higher level languages such as C++, or BASIC. However, when it comes down to the instruction the processor itself supports, we would use these flags to create loops. We might set the X register to 5 for example.
Every time our logic executes we would decrement X by 1. At the bottom of the loop, we check the status flags. If X is negative or zero (depending on our preference), we know the loop is complete, and do not have to jump back up to execute the loop again.
For example, if I add -5 to 2, then we have a negative flag.
S: Minor — (ControlLogix Processor Status Flags)
This bit is true when a minor fault occurs in the logic. As far as the status flags though, an overflow condition S:V will set this flag as well when it goes from false to true.
Summary of ontrolLogix Processor Status Flags
In short, the only flag you will likely see in most projects is the first scan flag, S:FS. You may also see S:Minor from time to time. Usually, when detecting if a math operation generated a negative or zero value, programmers will use a compare instruction. Even though this takes a little more memory and scan time, it’s what most people are used to. Especially when troubleshooting. As always, it’s your responsibility to verify the accuracy of this information, and prove it out yourself before implementing it in any way.
For more information, visit the ControlLogix Category Page!
— Ricky Bryce