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 February 20th, 2008, 07:54 AM   #1
James Fillmore
Lifetime Supporting Member
United States

James Fillmore is offline
 
Join Date: Sep 2004
Location: Detroit, MI
Posts: 40
SLC500 - need to convert FP to integer

Need to convert a floating point register thats the total of "seconds since midnight" (would only be like 84,000 max) to integers so I can then do an integer to string conversion and print on a barcode label. I do know how to concantenate (SP?) the strings so if I could take say 82,550 and turn it into 2 integers, 82 and 550 that would be ideal.

Thanks!
  Reply With Quote
Old February 20th, 2008, 09:37 AM   #2
TConnolly
Lifetime Supporting Member
United States

TConnolly is offline
 
TConnolly's Avatar
 
Join Date: Apr 2005
Location: Salt Lake City
Posts: 5,975
Multiply by .001, subtract .50 and put the result in an integer. The SLC automatically rounds when converting a float to an integer, so subtracting .5 makes the rounding work in your favor. Now multiply the integer by 1000.0 (note that 1000.0 is a float, not an integer), subtract it from the original float, and put that result in the second integer.

F8:0 = 82550
CPT N7:0 (F8:0*.001)-0.5) <-N7:0 = 82
CPT N7:1 (F8:0-(N7:0*1000.0) <-N7:1 = 550

But I have to ask, when computing seconds from midnight why use a float in the first place, why not start with two integers?
__________________
True craftsmanship is only one more power tool away.

That's the beauty of processors, they don't have emotions they just run code - The PLC Kid.

Last edited by TConnolly; February 20th, 2008 at 09:40 AM.
  Reply With Quote
Old February 20th, 2008, 09:38 AM   #3
James Fillmore
Lifetime Supporting Member
United States

James Fillmore is offline
 
Join Date: Sep 2004
Location: Detroit, MI
Posts: 40
I spent the last hour reading over MANY posts and have found no simple solution to this question. AB's knowledge base has a very simplistics version on converting 999.999 to 2 integers that hold 999 and the fractional 999.

But to take a large floating point number (thats greater that the 32,??? thats greater an N7 word can hold) and convert that to 2 integer to be used for HMI display, or in my case converting to strings and printing, doesn't appear to be an easy task.

AB's COP instructing (I'm using a 5/03) lets me COP F8:0 to N7:0 and N7:1. But when I put say 33000 in F8:0 I get 18176 in N7:0 and -6144 in N7:1. How to I convert THOSE to nmbers that mean something?

I'd like N7:0 to contain 33 and N7:1 to contain 000. Ideally 2 groups of digit that represet xxx (greater than 1000) and xxx (less than 1000)

If I do a simplistic divide by 1000 to a large value like 83545 and put the answer in a N (integer) word I get 84. Is there some obvious method that I'm overlooking to prevent it from rounding? If there was then I would have the upper digits (greater than 1000). I could then multiply this answer by 1000 suptract it from the original floating point value and get the lower 3 digits (less than 1000). Seems easy enough. What am I missing/doing wrong?
  Reply With Quote
Old February 20th, 2008, 09:44 AM   #4
TConnolly
Lifetime Supporting Member
United States

TConnolly is offline
 
TConnolly's Avatar
 
Join Date: Apr 2005
Location: Salt Lake City
Posts: 5,975
Quote:
Originally Posted by James Fillmore
AB's COP instructing (I'm using a 5/03) lets me COP F8:0 to N7:0 and N7:1. But when I put say 33000 in F8:0 I get 18176 in N7:0 and -6144 in N7:1. How to I convert THOSE to nmbers that mean something?
Those numbers do mean somthing - they are the bit pattern of a 32 bit IEEE-754 floating point number. But when you try to display it using a decimal radix for integers, the computer interprets them as two 16 bit integers instead. I've covered working direcly with floats in several posts, but thats not what is necessary here. See my previous post.
__________________
True craftsmanship is only one more power tool away.

That's the beauty of processors, they don't have emotions they just run code - The PLC Kid.
  Reply With Quote
Old February 20th, 2008, 09:45 AM   #5
James Fillmore
Lifetime Supporting Member
United States

James Fillmore is offline
 
Join Date: Sep 2004
Location: Detroit, MI
Posts: 40
Thats the trick!!! You guys rock!
  Reply With Quote
Old February 20th, 2008, 09:48 AM   #6
kamenges
Member
United States

kamenges is offline
 
kamenges's Avatar
 
Join Date: Nov 2002
Location: Brillion, WI
Posts: 3,131
Alaric already answered your real question (quite well by the way) so I'll leave that alone.


The COP command performs a byte for byte copy from the source to the destination. The floating point number is an IEEE 754 floating point number. They byte-for-byte copy will leave you with integers that contain what appear to be garbage but are in fact the original bytes from the float.

Keith
  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
convert float into integer in S7 Berra LIVE PLC Questions And Answers 6 November 28th, 2007 01:29 PM
Migrating VB6 IDEA app to VB.Net Extrasoft LIVE PLC Questions And Answers 5 November 4th, 2007 06:13 AM
[S5-155U CPU948]HEX convert to Integer ?? apple LIVE PLC Questions And Answers 3 July 9th, 2006 02:05 PM
Convert from ControlLogix to SLC500 possible ? JesperMP LIVE PLC Questions And Answers 4 March 30th, 2006 11:42 AM
SLC500 Converting integer to Ascii ejessen LIVE PLC Questions And Answers 16 January 25th, 2004 10:50 AM


All times are GMT -5. The time now is 05:50 PM.


.