Math Instruction for RSLogix

spice_miner

Member
Join Date
Aug 2006
Location
Iowa
Posts
45
Quick question about the order of execution of math instructions. Which ones execute first, second and so on? I have a rung that looks like it would cause problems. It is in a subroutine that gets called when the operator changes package size. When the rung is true it subtracts and multiplies to the same file N30:25. I will attempt to post a bitmap of the rung.

math.jpg
 
The order of execution is as its written SUB-MUL-DIV.(in your above snap shot)
 
Last edited:
In the rung you show the execution is from top to bottom. If you view the value of N30:25 you will only see the result after the MUL command in all the displayed locations. If you want to see the result after the subtract as a seperate value you will have to use a different variable location for the DEST of the subtract and as the SOURCE A of the multiply.
 
Here is a trick you can use if you are ever in doubt.

If you double click in the area where the rung number is you can open the mnemonic editor. Here you can see the exact order of all of the rung code in a single line. The rung will execute in the exact order as shown in the mnemonic editor line. In your case you will see (bold formatting added for clarity)

BST SUB N30:25 N30:50 N30:25 NXB MUL N30:25 2 N30:25 NXB DIV N30:25 103 N32:51 BND

As you scan down the line the first math instruction encountered is the SUB, then the MUL, and last the DIV.
 
Thanks for the fast replies. I was wondering about the order of execution of math instructions in general also. Some programs always add frist then subtract so on and so on regardless of the order it is written. I try using the mnemonic editor occasionally but I struggle with it mostly trying to remember all the abbreviations. Thanks guys!
 
I believe the order is

Assuming you have 1 math instruction with multiple math functions in it, the order is as follows:

multiplication, division, modulus, addition, subtraction.

For example, the expression 5 + 2 * 4 / 2 would be compute as 5+2*2, 5+4=9. However, this sytax will not be accepted by the instruction as it is impoper, and you'd have to enter it like this 5 + (2*(4/2)) to get the same result. So, really, the answer to your question is that it doesn't matter what the order is, you need to provide the correct syntax needed to perform the operation like you need it to be performed. The instruction will work from the inside out.
 
Just to clarify...

What our distinguished colleague Russ means by saying "1 math instruction with multiple math functions in it" is the CPT (compute) instruction in an AB processor.

CPT N32:51 (2*(N30:25-N30:50))|103 is equivalent to the OP.

The order for the CPT expression is
( )
ABS, Trig functions, Log functions, BCD conversion
SQR
** (XPY)
- negative sign, NOT
*, | (divide)
-, + addition/subtraction
AND
XOR
OR

If you use separate SUB, MUL, DIV instructions the operation order will be the order of the instructions.
 
Last edited:

Similar Topics

Hello, hope everyone is doing well. I'm programming on RS Logix 5000 / Studio 5000. Is there a way to do math inside an instruction using tag...
Replies
4
Views
2,848
Hi guys, I am trying to create a very basic totalizer in Logix; I need to keep track of runtime for pumps, their number of starts too; I need...
Replies
7
Views
4,313
Hi guys, I have a stupid question, I used a lot of Math & Compare instruction (MUL, CPT, .. )in my PLC, will it harm or one day PLC will cause...
Replies
8
Views
2,660
Hello all, I am fairly new to Allen Bradley programming so bear with me.. ( I have prgogrammed microcontrollers and computers before). Im working...
Replies
45
Views
11,909
I've decided, having some extra time on my hands, to learn some more about some of the AB instructions that I do not use often. Some of these...
Replies
19
Views
11,394
Back
Top Bottom