Micrologix 1200 Divide without rouning up

alphav

Supporting Member
Join Date
Sep 2007
Location
Ontario
Posts
35
Hello all

Are there a way to DIV in a Micrologix 1200 or 1500 using LONG 32bit integers without rounding up.

regards,
scott
_________________
 
There is some abmiguity in the documentation.

One technote says to use the address S:13, the math register, as the dstination. S:14 will contain the unrounded quotient, S:13 will have the remainder.

But, the manual seems to indicate that if the source words are longs then the result will be rounded. But it doesn't say anything about a long divided by an int.

All I can suggest is that you try it out. Then please let us know it if worked (or didn't work) for future reference.
 
I tryed that, but S:13 and S:14 locations are always empty "0". After the division I also tryed to move S:13 and S:14 to another address, but with the same result.....
 
What is the range of numbers you are using in your longs?

There is a sweet trick you can do with floating point numbers as long as the numbers are not so large that IEEE754 float resolution becomes an issue.

DIV F8:0 F8:1 F8:2 Floating point division.
SUB F8:2 .5 N7:0 Sub .5, save in integer for unrounded result.

Of course, your ML must be series C to support floating point.
 
Another way:
if the source A absolute value is >= half source B absolute value, decrease the source A absolute value by half source B absolute value before division.

This however, only sounds simple and eventally requires about 10 instructions, so Alaric's method should be preferred.
 
Last edited:
The trick is to sense when a value has been rounded up, then subtract 1 when it has. Put the divide result into a float. Then move the float value to a long integer location. If the int is grt than the float, it was rounded up--subtract one. (AB rounds floats up > .5 for math or moves)
 

Similar Topics

Hi everyone, I'm working on a project where I need to exchange data between a Siemens S7-1200 PLC and an Allen-Bradley MicroLogix 1400 PLC. The...
Replies
8
Views
637
I have a MicroLogix 1200 that has an 8 input and a 16 output. Every 6 months-year I get a fault and when online go to error it is something like...
Replies
3
Views
504
Have a bad output on a Micrologix 1200. Moved wire over to an available output, changed program to associate with new output. downloaded program...
Replies
8
Views
752
I need help achieving the following task: ML1200 sending 4 to 20 mA thru analog output ch0 to a DC speed controller analog input(4 to 20 mA) my...
Replies
3
Views
669
Hi there I am new with this thing and i don't know how to connect Allen Bradley Micrologix 1200 PLC to Raspberry Pi using USB to RS485 in NodeRED...
Replies
3
Views
2,272
Back
Top Bottom