Micrologix 1000 - overflow problem (+32767)

Mbelanger

Member
Join Date
Jun 2007
Location
Montréal (Qc - Canada)
Posts
6
Hi everyone,

1st of all sorry for my bad english as you will see english is not my promary language. Im new to this forum and so far im very impress with the amount of usefull information i found.

Right now im stuck with a micrologix 1000 and i need to deal with data that will exceed 32767.

I was wondering is it possible to use Dint cause it would solve my problem if so. I read a lot of thing about enable overflow but i dont understand how to do it exactly.


Here a simple exemple of what im trying to do :


User ask for 120.12 inch via the HMI
12012 is put into an Interger (N7:0)
N7:0 * 10 = (would need a Dint)
then i would divide the Dint by 6.


Unfortunatly i need to make my multiplication before i divide.



thank you for your help.
 
Mbelanger,

Try and use a Float F8:xx, I think you should be able to use it in the 1000

look at my example also the second rung is the math overflow unlock that you should add to the last run of ladder 2 (main)

untitled1111.gif
 
unfortunatly F8:xx are not avaible in micrologix 1000 xcept if need to "enable" them some how to have access to F8:xx.

EDIT :

from help file
F8
Floating Point

This file stores a # with a range of 1.1754944e-38 to 3.40282347e+38.

SLC 5/03 OS301, OS302,
SLC 5/04 OS400, OS401 and
SLC 5/05

With the MicroLogix 1100, 1200 and 1500 controllers anytime a new file is added to the user program, it consumes 5 user words plus the number of user words determined by the file's type.
RSLogix 500 - Copyright Rockwell Software 2000, 2001, 2002

i doubt we can use float in micrologix 1000 :(
 
Last edited:
Try this - I don't have a MicroLogix 1000 available but this may work.

Background - the 'math register' is composed of two 'S' registers, S:13 and S:14. These store some interesting results of math operations.

Perform the multiply by 10, using a dummy integer register as a destination. Immediately clear the minor error flag which may have been set.

Next perform a division by 6 but the 'source A' will be S:13 which, with S:14, holds the correct 32 bit result from the multiply. Send the result to your destination.

You will still have to limit your initial entry to 19,660 or less to prevent overflowing your final destination.

[Edit] Check out the DDV command as the divide instruction instead of the standard DIV.
 
Last edited:
Unfortunatly i need to make my multiplication before i divide.

From a purely math stand point, this isn't correct. If you change you logic and do the division first, the problem goes away.

Another possibility is to break the whole numbers and the decimal into two different integer locations. You could do this in the HMI. Have one tag for the whole digits, and another for the decimal.
 
bernie_carlton said:
Try this - I don't have a MicroLogix 1000 available but this may work.

Background - the 'math register' is composed of two 'S' registers, S:13 and S:14. These store some interesting results of math operations.

Perform the multiply by 10, using a dummy integer register as a destination. Immediately clear the minor error flag which may have been set.

Next perform a division by 6 but the 'source A' will be S:13 which, with S:14, holds the correct 32 bit result from the multiply. Send the result to your destination.

You will still have to limit your initial entry to 19,660 or less to prevent overflowing your final destination.

[Edit] Check out the DDV command as the divide instruction instead of the standard DIV.


That should work, but you must also set the S:2/14 (math overflow selected) bit first. It can be set programatically or alternatively you can just set it in the status file and leave it set. I showed it set programatically in the example for clarity. You also need to include logic to perform the 32 bit division only if there is an overflow. If there is no overflow then you need to use the normal result of the multiplication.

A62807A.JPG


Ken raises a valid point X*10/6 is exactly the same as X/6*10. Why does your application require the multiplication first?
 
Last edited:
Mbelanger said:
Im new to this forum and so far im very impress with the amount of usefull information i found.

Mbelanger,

I agree, if you look at these answers (Bernie, Ken and Alaric)... this why I hang out on this site, these guys are good :D it makes problem solving so much faster when you have resources like this one :site:
 
Re: order of operations - with integers, dividing first risks losing the least significant digit's influence on the answer.

61 / 6 = 10 (remainder lost), times 10 = 100

61 times 10 = 610, divided by 6 = 101 (with remainder)

Ideal answer = 101.666666 repeating

The multiply THEN divide gets closer to the ideal answer.
 
Why i need to do multiplication before division ? Integer get round up/down after a division .


Exemple : (N7:0 = 100)

N7:0 * 10 = N7:1
N7:1 / 6 = N7:2

100 * 10 = 1000
1000 / 6 = 167 (round up from the real answer 166.6666)


---- vs ----


N7:0 /6 = N7:1
N7:1 * 10 = N7:2

100 / 6 = 17 (round up from 16.666666)
17 * 10 = 170

In the 1st exemple the final result is 167 while in the 2nd exemple it is 170. Of course if i could use floating memories it would solve the problem (like in micrologix 1200) but right now it round up/down every result.


For all those overflow thing (S:13 S:14 S:2/14 etc etc) im really not use to work with that at all. Thx Alaric for the screnshoot ill try to do that and will read more about those S:13/ S:14 fonction. Im sure that when ill understand exactly all those S:13 thing are, it will be much more easyer for me to figure out whats wrong.


Cant make any test right now but i just wanna thanks you all for the feedback its really appreciated.
 
I don't see the point in using the DIV instruction at all after a mulitply. The multiply should always have S:13 and S:14 ready for DDV. I would not bother with the DIV in Alaric's example.

Most 16 bit micros have a 16 bitx16 bit =32 bit multiply and a 32bit/16bit = 16 bit quotient and 16 bit remainder divide.

The SLC500s have 32 bit microcontrollers so there is no speed penalty for using the 32 bit numbers in S:13 and S:14. I have no idea what is used in the Micrologix so there may be a speed penalty for using the DDV.

If you want to sign extend a 16 bit number you can copy it into a L register if you have them. If not the mulitply by 1 and look in S:13 and S:14. It is wasteful but simple and simple often is more important. That just slipped. Speed is everything. :)
 
ok i finally copy and paste the screen shoot and here the result


If N7:0 = 3276
Result = 5460 (3276 * 10 = 32760 / 6 = 5460)

But if N7:0 = 3277
Result = 910 (not even sur to understand what happen here)



ok i think i really need to understand how all those overflowing thing work ... dam cant believe micrologix 1000 dont support DINT ... no FLOAT ok but no DINT is disapointing :(
 
If we were using any other processor...

Peter Nachtwey said:
I don't see the point in using the DIV instruction at all after a mulitply...



I didn't try this out on an actual ML1000 (I've tried to avoid owning one of those) but the way I read the online help the result of a MUL is only stored in 32 bit math register when there is an overflow. Therefore it would be necessary to check that the overflow occured so that you know whether to divide the math register by 6 or the MUL destination word by 6. The OP can try it out and see for sure. If the math register is updated even if an overflow doesn't occur then the fourth rung and the S:0/1 condtion on the third rung are unnecessary.

Unfortunately, the ML1K doesn't have a long integer data type available. Its a bottom dweller with a fixed data table and program file configuraiton. I have a 1200 that I keep at my desk to try things out on, and were the OP using a ML1100, 1200, or 1500 then he could use a long integer data file. But the ML1100, 1200, and 1500 don't even support the DDV instruction because of their 32 bit capability so I can't test the suggested program. Maybe the OP can try it out for us and give us some feedback on how it works - could be a good exercise for him to understand the math register.
 
Mbelanger said:
ok i finally copy and paste the screen shoot and here the result


If N7:0 = 3276
Result = 5460 (3276 * 10 = 32760 / 6 = 5460)

But if N7:0 = 3277
Result = 910 (not even sur to understand what happen here)



ok i think i really need to understand how all those overflowing thing work ... dam cant believe micrologix 1000 dont support DINT ... no FLOAT ok but no DINT is disapointing :(

I see what is going on.

As long as N7:0 is less than 3276 then the overflow bit S:0/1 remains clear and the program skips the DDV in the third rung and and does normal 16 bit division in the fourth rung. A value of 3277 or greater will cause the overflow bit to be set so that the DDV in the third rung executes. The problem occurs there because the DDV resets the overflow bit S:0/1, so now the fourth rung DIV executes even though we don't want it to - I definitely missed something there.

So taking a clue from Peter, lets just try and see if the math register is loaded for all multiplicaton results or only for overflow results.

Delete the XIC S:0/1 from the third rung. Delete the fourth rung altogether. See if that works.
 
Alaric said:
I didn't try this out on an actual ML1000 (I've tried to avoid owning one of those) but the way I read the online help the result of a MUL is only stored in 32 bit math register when there is an overflow. Therefore it would be necessary to check that the overflow occured so that you know whether to divide the math register by 6 or the MUL destination word by 6.
You are right but this is just brain dead. I don't know of any microcontrollers or DSP that mulitply and conditionaly do a 32 bit bit mulitply.
 

Similar Topics

"Hello! Good day! Excuse me, I have a question regarding the 1761-NET-ENI. RSLinx has already detected it but it's not connecting to the PLC...
Replies
4
Views
159
Hi all, We have a very old pit pump system running on Micrologix 1000. Now, whenever there is an alarm for high conductivity, we want that alarm...
Replies
5
Views
1,268
Looking at a Micrologix 1000 1761-L32AWA, I tried to connect using the 1761-CBL-PM02 through a Serial to USB converter (This setup was used...
Replies
2
Views
992
Hello All I am trying to convert a ML1000 program for use in a ML1400. I didn't create the original program & documentation is non existent...
Replies
14
Views
4,423
Hey Folks, I have a customer with an older machine that is controlled with a MicroLogix 1000. The machine just quit working. The power light is...
Replies
22
Views
10,605
Back
Top Bottom