RsLogix 500 - Math and Math Errors - ADD, SUB, MUL, DIV

The math instructions are similar to a calculator.  Add, subtract, multiply, divide, etc. with the same order of operation.  

However, there are two very important cautions that must be understood. 

  • Create a new program, put the following two rungs in, download, and go online with the following program. 
  • DO NOT press any buttons yet.



Rung 0 uses the ONS instruction you learned in RsLogix 500 - Flip Flop - One Shots ONS OSR OSF lesson which executes the ADD instruction once every time that the Green Button is pressed.  Rung 1 does not have the ONS.  Press the Green Button and release it as fast as you can, once.  You should now see N7:0 at 1 but N7:1 will be at a higher number.  Without the ONS the ADD instruction in Rung 1 was executed on each scan.  In the example below, the PLC scanned 161 times while the Green Button was pressed.



Now press the Green Button for approximately 25 seconds until the processor status says "FAULTED".  You have just created a Math Overflow Trap.  All data types have size constraints.  In the case of the N7 integer, the range is -32,768 to 32,767.  If you look at the value in N7:1 it is 32,767.  When the ADD instruction tried to add 1 to N7:1 it set a Math Overflow Trap faulting the PLC since it can't put a value of 32,768 into the data file.



There are two common ways to prevent this.  Our preferred method is to add constraints which prevent this such as the LES instruction that has been place in front of the ADD instruction below.



The other way is to place an OTU addressing S:5/0 Overlflow Trap at the end of your program.  This will prevent the processor from faulting from any Math Overflow fault.  We try to never state hard rules but this is a method that overall we disagree with.  While this could prevent overflows from hundreds of instructions, it makes discovering that you have a Math Overflow more difficult.


Go back to the RsLogix 500 - The Big RED Fault - Finding, Understanding, and Clearing lesson for help clearing the fault.  Don't forget to set N7:1 back to 0 so it doesn't fault right away again.


Once you have cleared the fault, go to the "Compute/Math" tab of the instructions where you can find other math instructions.




The math instructions will expand your programming capabilities but are also a large cause of programming faults in programs.  Next continue to the RsLogix 500 - Reading wiring diagrams and understanding electrical symbols lesson.

Next Steps

Go to the Allen Bradley RsLogix 500 PLC Training PLC Training Getting Started Lesson series to select your next lesson.  There are also many other Lesson Series on PLC Programming and Industrial Automation.