Challenging Math Problem with MicroLogix

Archie

Member
Join Date
May 2002
Location
Orangeburg, SC
Posts
1,944
I was working on a project and ran into a problem that seemed very simple at first, but became quite a challenge to implement in RSLogix 500. Although I did come up with solution, it seemed like a lot of ladder code, so I wanted to see how others would do this.

I have a long integer (L9:0) that needs to be broken into 2 integers (N7:0, N7:1). The divisor is 10,000. Some examples:

L9:0= 78200
result:
N7:0= 7
N7:1= 8200

L9:0= -553333
result:
N7:0= -55
N7:1= -3333

L9:0= 649999
result:
N7:0= 64
N7:1= 9999
 
Archie,

I never knew how to braek a double integer into two singles. Please post your method. Even if it is a lot of ladder, at least you have something that will do the job. Right now, I have zilch, and I need to do that for a project.
 
DDV is not available on MLX processors, however IIR if you DIV L9:0 by 10,000 and make the destination register S:13 then you can get the result and remainder in S:14. I believe this is detailed in the instruction set reference manual.


edit: I confirmed that from the manual. See under the DIV instruction.
If the Sources are single
words and the Destination is directly addressed to S:13 (math register),
then the quotient is stored in S:14 and the remainder is stored in S:13.
 
Last edited:
I just found exactly the same answer, Alaric. I thought there was a modulus command, but it's not available in 500.
 
Archie,

Here's a method in RSLogix 500. It's a little clunky, don't know if it's any better than what you had, but here it is:

View attachment LARGE NUMBER DIVIDE.zip

Cheers,
Dustin

EDIT: I didn't have a micrologix handy to try this on, so I had to use a SLC 5/04, which didn't have the "L" register DINT, so I had to use Float, but the principle is the same
🍻
 
This was the way I ended up doing it. I should have mentioned it was a 1400, so I was able to use the CPT instruction. I ran into issues because the divisions rounded and not truncated, so I had to do a compare to see if it rounded a positive or rounded a negative

RSLogixMath.jpg
 
Thanks, guys. Archie, Did you mean to have one more MOV at the end to move L9:29 to N7:1?
 
L9:0= -553333
result:
N7:0= -55
N7:1= -3333

Just wondering what you are using this for. Someone mentioned Modbus but that doesn't make sense to me. If it is for a display, then my guess would be that only the 55 in the example above would be negative and not both parts so it seems they are being put back together on the other side....?
 
Just wondering what you are using this for. Someone mentioned Modbus but that doesn't make sense to me.
The MicroLogix is communicating to an Automation Direct servo drive over Modbus. The position commands are stored in 2 registers. One is the number of pulses and the other is the number of revolutions. There are 10,000 pulses per revolution.
 
may be the solution

in this program when i enter 123 so by the help of these tools i can dis attache one's ,ten's ,and hundred's. value in different places

and i think by doing some more operation we can complete this task i will tried on long integer but it fails i dont know why i will try it again.

untitled1.jpg untitled2.jpg integer value.jpg
 
Never tried this, not at my workstation right now,

But just wondering, if convert to string -> split -> convert back to integer ?
 

Similar Topics

I know there are many other ways to accomplish this, But I have to use parts on hand. to make it easy for others to service. So here is my...
Replies
1
Views
1,579
Hi Experts, We have a problem here with the Simatic S5 CPU 928B which doesnt go into RUN mode. Machine was not in use for over a year and my...
Replies
21
Views
7,414
Hello again everyone, About a month ago I bought 90 micro plc and a 12vdc power supply off of ebay. I got an old panel that was being thrown...
Replies
3
Views
1,735
I have an expression in a structured text routine of a Logix controller that looks more or less like the following: ResultInteger := Integer1 *...
Replies
13
Views
374
This application has a motor with encoder feedback that drives a linear actuator that moves in/out, and is at roughly 45 degs from horiz. As the...
Replies
19
Views
1,358
Back
Top Bottom