You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

---------->>>>>Get FREE PLC Programming Tips

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

PLC training tools sale

Reply
 
Thread Tools Display Modes
Old March 28th, 2003, 07:28 AM   #1
wirehead
Member
Canada

wirehead is offline
 
wirehead's Avatar
 
Join Date: Mar 2003
Posts: 7
Ab SLC FLOAT to Double Int Conversion

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.
  Reply With Quote
Old March 28th, 2003, 07:48 AM   #2
shahn4
Member
United States

shahn4 is offline
 
Join Date: Feb 2003
Location: Georgia
Posts: 104
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.
  Reply With Quote
Old March 28th, 2003, 07:52 AM   #3
wirehead
Member
Canada

wirehead is offline
 
wirehead's Avatar
 
Join Date: Mar 2003
Posts: 7
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?
  Reply With Quote
Old March 28th, 2003, 09:26 AM   #4
wirehead
Member
Canada

wirehead is offline
 
wirehead's Avatar
 
Join Date: Mar 2003
Posts: 7
Talking

----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
  Reply With Quote
Old March 28th, 2003, 09:28 AM   #5
seppoalanen
Member
Finland

seppoalanen is offline
 
seppoalanen's Avatar
 
Join Date: Jan 2003
Location: Finland
Posts: 1,132
CPT: Iteger dest = (float+0.5)
rounding is allways correct ?
  Reply With Quote
Old March 28th, 2003, 10:26 AM   #6
Mickey Mills
Member
United States

Mickey Mills is offline
 
Join Date: Mar 2003
Location: Valencia, Ca
Posts: 12
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
  Reply With Quote
Old March 28th, 2003, 11:27 AM   #7
93lt1
Member
United States

93lt1 is offline
 
93lt1's Avatar
 
Join Date: Apr 2002
Location: Mount Pleasant, Iowa
Posts: 994
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.
Attached Files
File Type: zip float to integer.zip (211.6 KB, 328 views)

Last edited by 93lt1; March 28th, 2003 at 11:30 AM.
  Reply With Quote
Old March 28th, 2003, 01:03 PM   #8
wirehead
Member
Canada

wirehead is offline
 
wirehead's Avatar
 
Join Date: Mar 2003
Posts: 7
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.
  Reply With Quote
Old March 28th, 2003, 01:14 PM   #9
93lt1
Member
United States

93lt1 is offline
 
93lt1's Avatar
 
Join Date: Apr 2002
Location: Mount Pleasant, Iowa
Posts: 994
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.
  Reply With Quote
Old March 28th, 2003, 01:50 PM   #10
wirehead
Member
Canada

wirehead is offline
 
wirehead's Avatar
 
Join Date: Mar 2003
Posts: 7
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.
Attached Files
File Type: zip example.zip (50.3 KB, 300 views)
  Reply With Quote
Old March 29th, 2003, 09:56 AM   #11
Mickey Mills
Member
United States

Mickey Mills is offline
 
Join Date: Mar 2003
Location: Valencia, Ca
Posts: 12
Sorry, on earier post should have sub 0.5
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
AB SLC 5/05 Ethernet MSG Errors mrdegold LIVE PLC Questions And Answers 7 January 20th, 2009 12:10 PM
AB CTC units..with 2 SLC 5/04 DH+ Russ LIVE PLC Questions And Answers 4 December 15th, 2004 04:02 PM
Double integer conversion Mtn_Bkng_Dave LIVE PLC Questions And Answers 0 April 21st, 2004 09:43 AM
Ideas needed for Siemens S7 program tesalmin LIVE PLC Questions And Answers 12 March 4th, 2004 12:40 PM
Ab Slc 5/04 New okiebob LIVE PLC Questions And Answers 2 September 5th, 2003 09:59 PM


All times are GMT -5. The time now is 12:38 PM.


.