Ab SLC FLOAT to Double Int Conversion

wirehead

Member
Join Date
Mar 2003
Posts
7
Hi Guys and gals.

Google lead me to this site a few days ago, and I must say its pretty cool.

I've got a project on the go right now. I'm using a AB SLC 5/03 with an SST profibus scanner card. All is good, i've gotten far in getting my Siemens Posmo A servo drives working with the AB system.

I've ran into a small brainteaser that might give some of you a nice challenge.

I need to take a FLOAT number value (positive of negative) and convert it into a double integer word which is copied into the High and low int registers of the servos, whereby I load these values into traversing blocks, setpoints etc.

The servos use a fixed decimal point, so to store 29.232 in the servos, you multiply it by 10,000 and then 'split it' into two int registers.

29.232 x 10,000 = 293 320

292 320 in hex = 479C8

Split hex word and you got

high int = 0004 (hex)
low int = 79C8 (hex)

If I load these two int values into the respective registers i'm good. Its getting these values from the FLOAT thats got me stumped. Becase the SLC is 16 bit, i'm hitting walls with every strategy i've come up with. I discovered that diving a real number will not leave the MOD and quotient in S:13 and S:14. Arghh.

The real kicker is this. How do I take a number, with a decimeal point that is going to vary (since I am writing a function in the plc for use for all FLOAT->DINT conversions to handle a decimal point all over the place and yet

SPLIT the FLOAT value. Ie take 29.232 and spit out 29 and the 0.232 sperately. That if solved lets my math work.
Ideas?

Rockwells support hasn't addressed this scenairo with their examples, and I dug through the archives here first before asking.
 
I had an application four years ago where I was trying to display a max length of 999999 stored in floating register to a panel view.
I stored the result of math instructions where the parameter were floats points in integer registers. It rounds off the results to the nearst integer and then MSB is stored in the next intger.

For example: CPT instructions Dest-N10:217, Expression (F9;2xF9:3). In this case the reuslt will be stored in N10:217 and N10:218.
 
I cannot afford to 'round up' or 'round down' the numbers. Losing decimal places isn't as bad.

If I can translated what i've done step by step in my post in plc code, or do the equivelent actions in another way, i'm good.

I'm not sure your method will accomodate the large numbers I have to work with?
 
----Solution----

Say you want 29.232 written into a Posmo unit (which takes a 32 bit integer and divides by 10,000 to get used value)

29.232 x 10,000 = 292 320

Take 292 320 and Divide by 65536. Write the result into a FLOAT (F8:0)

We now have 4.4604492 in floa F8:0.

To split this part we take and subtract 0.5 from this value and store in an N7:0 register. This will round the value, giving us 4 in N7:0

4 is what we write to the high int word going to the Posmo.

Now take the F8:0 and subtract the N7:0 and write the result to F8:1. Multiply this value by 65536. This gives us 30175.

Write this to N7:1. This is our low INT to the Posmo.

The proceedure slighly changes when dealing with negative values, storing negative results (signed) in the plc but otherwise the method works.

A veteran of programming here came up with the final solution, breaking the 4.4604492 number apart. I had forgoten this simple rounding trick.

Cheers
 
To complete seppoalanen's thought
ADD 0.5 to 29.232 dest integer file this leaves 29
then sub that new integer file from 29.232 this leaves .232
mul this by 1000 dest intger file leves 232.
One file with 29 and one with 232

Mickey
 
Try COPying the floats into integers. This method chops the 32 bit floating numbers into two 16 bit integers. I had similar difficulties writing to an AB 1394 servo drive. Check out LAD 5 in the attached RSLogix500 file That I used.
 
Last edited:
Copying the floats copies their mantissa formated binary directly, so you end up with a non-translated binary image of what the FLOAT was, and not a translated integer value.

In the likely case of your project (thanks for posting though!) the AB unit understands mantissa binary float numbers.

The Siemens Posmo A unit instead needs 32 bit integer numbers, so a direct copy does not work.
 
When I was doing this project, I searched every manual I could find and I never did find out what "format" the chopped floats take on as an integer. I guess you explained it....Thank you.
 
Okay, I sat down and finished both peices of logic (included in this file)

One ladder file takes a FLOAT and multiply it by 10,000 and convert it to a 32 bit integer value (split up between two INT's in the plc which I copy over profibus)

and

the second ladder file takes a 32 bit integer and converts it to a FLOAT value (dividing 32 bit integer value) by 10,000.

It handles negative and positive numbers. This was done a SLC 5/03.

Enjoy.
 

Similar Topics

Hello, I'm taking in two 16 bit ints from the field via modbus, one low order and one high order to combine into their proper 32-bit form. I've...
Replies
1
Views
1,250
I have a Float that is F45:10 and I need to convert it to an integer to display on an HMI that is in VB.net and we can't change. I look on the AB...
Replies
8
Views
9,334
Hi Guys, i read alot of post about converting from float to int and back again but apparently i cant get it to work... *** ISSUE*** my issue is...
Replies
9
Views
2,095
I am trying to convert a 10 digit batch ID number from a Factory Talk View SE 7.0 screen to my SLC 504 PLC so that I can use the ID to designate a...
Replies
6
Views
2,250
OK, having a brain **** here, anyone remember if it's possible to read a floating point value from a 5/04 from a controllogix? Trying to do this...
Replies
6
Views
3,481
Back
Top Bottom