Sign in to follow this  
Followers 0
Praymond

SLC 500 Floating point limit?

8 posts in this topic

I am using an ADD instruction to count up a floating point register by five everytime a contact is made. For some reason at about 20,000,000 it starts counting by two's instead of five's. This happend before but it seemed like it was closer to 40,000,000 then. What am I missing here?

Share this post


Link to post
Share on other sites
Usually the complaint is that when the value of a Floating Point number gets very large, adding 1 to it appears to stop incrementing the total. Since you are incrementing by 5, your symptom is different. This is an artifact of how IEEE 754 Floating Point data handling works, and is common to every PLC and computer that uses 32-bit Floating Point math. Floating Point is only an approximation. You need to use a long integer data type (ControlLogix and modern MicroLogix controllers have these) or use a set of Integer counters. What are you doing with the value; are you displaying it, or performing further math on it ?

Share this post


Link to post
Share on other sites
Thanks for the insight. I am just displaying the number in a field in iFix . It is a flow totalizer.

Share this post


Link to post
Share on other sites
You can use the SLC-5/0x 32-bit math feature to carefully do 32-bit addition. When you set S:2/14 = 1, the result of an ADD instruction is the truncated low word in 16-bit unsigned format. If you view the integer register as though it was an Unsigned 16-bit Integer, you can count to 65535. In RSLinx/RSView you do this by specifying the data type at the end of an OPC link, like "u16" or "u32". The value of the register you're incrementing appears to the OPC device as an unsigned 16-bit integer, but to RSLogix 500 it still appears to be signed, so between 32767 and 65535 the value appears "negative". You need to detect the rollover from "negative" to "positive" and increment the next word by 1. You can use the Zero Bit (S:2/1) if the increment is 1, but you'll need different logic if it's a different increment value. In my test, this is my data link to the HMI: =RSLINX|Long_Integer!'N7:0,L2,C1,s32'

Share this post


Link to post
Share on other sites
I was able to test a three-rung counter that can add up to 7FFFFFFF = 2,147,483,647. Your HMI needs to be able to read two contiguous Integers (N7:2 and N7:3) as though they were a single Long Integer.

Share this post


Link to post
Share on other sites
Ken, the best way is to use a carry bit from the status. I don't remember which bit is the carry bit is. ADD N7:2 N7:0 N7:0 XIC Carry ADD 1 N7:1 N7:1 ADD N7:3 N7:1 N7:1 I am assuming the total is in (N7:1,N7:0) and the value to be added (N7:3,N7:2). Any overflow error must be cleared after the XIC but NOT after the last add if you want to detect overflowing the 32 bit it DINT. This can easily be extended to 64 bit math if necessary. ADD N7:4 N7:0 N7:0 XIC Carry ADD 1 N7:1 N7:1 ADD N7:5 N7:1 N7:1 XIC Carry ADD 1 N7:2 N7:2 ADD N7:6 N7:2 N7:2 XIC Carry ADD 1 N7:3 N7:3 ADD N7:7 N7:3 N7:3 It is then possible to convert to a floating point to display on a HMI. Obviously the least significant words will become too small relative to the total to affect the display but it will keep the total incrementing properly. The carry bit is lonely and feels ignored. :)

Share this post


Link to post
Share on other sites
For the SLC 500 it is S:0/0 ; And for the PLC 5 it is also S:0/0. With the Logix 5000 it is the tag S:C. The help files provide examples in Logix 5000.

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