Sign in to follow this  
Followers 0
eric_lau

RSLogix500 Math Overflow Fault

5 posts in this topic

Hi all, I have a micrologix. And now in this micrologix, i need to write a code (Logix 500) for dividing one 32-bit float to two 16-bit Int. Here is my logic: Let F20:0 is the 32-bit float. Case 1: If F20:0 >= 65536, div F20:0 by 65536.0 =>N7:0 and div F20:0 by 65536.0 => F11:0 then, If N7:0 > F11:0, add F11:0 by 1.0 and then sub F11:0 by N7:0 => F11:0 else sub F11:0 by N7:0 => F11:0 then, If F11:0 > 0.5, sub N7:0 by 1 => N7:0 then, Mul N7:0 by 65536 => F19.0 then, Sub F20:0 by F19:0 => F19:0 then, if F19:0 <= 32767, Mov F19:0 to N7:1 else Sub F19:0 by 65536 => N7:1 Case 2: If F20:0 < 65536, Mov 0 to N7:0 then, If F20:0 <= 32767, Mov F20:0 to N7:1 else Sub F20:0 by 65536 => N7:1 After the implementation, this code works for a period and then Math Overflow Fault occur!! I have no idea which part generate the fault!! Once the Math Overflow Fault occur, micrologix will stop function!! Anyone help?? Thanks a lot!! Edited by eric_lau

Share this post


Link to post
Share on other sites
Any DIV instruction could trigger the Math Overflow Fault. The CPU dumps the division "leftover" produce into a limited capacity virtual bin, the so called Math Overflow Trap! It is a good practice to add at the end of the routine containing the math a rung with a "hot" CLR S:5/0 (Math Overflow Trap) instruction. This way, during every scan, the useless data is being deleted before the bin becomes full, triggering a Processor Fault. Edited by dmargineau

Share this post


Link to post
Share on other sites
Try just using DIV. Read the following paragraph from the help file on the DIV instruction: Set the destination to an integer location (N). Make sure to have S:2/14 set. Check the math registers (S:13, S:14) immediately after the DIV.

Share this post


Link to post
Share on other sites
The MicroLogix supports 32 bit integers. Is there a reason you can't use them? Create a new data file select the Long data type.

Share this post


Link to post
Share on other sites
Actually, I found out that there is a case which will generate a number smaller than -32768. I believe this is the root cause of the overflow!! After I modified the problem to prevent this case, everything work fine so far!! I am not sure that part too because I was asked to fix the problem. I'm not the original developer.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0