![]() |
||
|
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc. |
||
| ||
New Here? Please read this important info!!!
|
|||||||
![]() |
If you're really looking to learn about PLCs, you NEED our book... "Your Personal PLC Tutor - A Guide to Understanding PLCs" Easy to read and uses 'plain' language!
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Member
![]() Join Date: Feb 2006
Location: Houston, Texas
Posts: 1
|
does anyone have an example on how to convert a double precision (64bit) floating point number to single precision in a SLC500. i am polling an "accuload" with modbus and populating four integer files that make up the dp number. how do i get it to sp fp?
|
|
|
|
#2 |
|
Member
|
It can be done - but I have never done it and though I wish I had the time to tinker with it now, I don't.
If you aren't familiar with the floating point format used in the SLC, see this AB technote first: http://domino.automation.rockwell.co...1?OpenDocument Here is a really cool utility that lets you see exactly how a floating point number is represented in binary. http://babbage.cs.qc.edu/courses/cs341/IEEE-754.html http://en.wikipedia.org/wiki/IEEE_fl...point_standard Last edited by Alaric; February 9th, 2006 at 11:54 AM. Reason: fix the technote link |
|
|
|
#3 |
|
Member
|
I started thinking about how to do this after work and so this is what I banged out.
I tested it on a SLC5/05 and it seems to work OK for numbers such as PI, 999.99, 3.402823466E+38, 2, and 0. I think it will work for all double floats that are in the valid number range for a single float. If the number is bigger than 3.4032823E38 then this is not going to work - it will return infinity. There is probably a better way to do it - but it appears to work. At least you can see how to do it. This routine truncates the mantissa at 23 bits, IT DOES NOT ROUND. Use it at your own risk - no warranty to accuracy is made. Make sure you get your words in the right order into N207:0 thru N207:3. (note: Ignore Rung 31. It was there for testing and it doesn't do anything for the conversion. I forgot to take it out before making the PDF and I'm too tired to redo it). |
|
|
|
#4 |
|
Member
|
I had another thought on this particular problem. This is a simpler but more limited solution.
If you are absolutely sure that your double will not have an exponent larger than 38 or smaller than -38 then you can make it really simple. Just map the bits from a 64 bit field to a 32 bit field (two consecutive integers) as shown and then use COP to move the two integers to a float. This doesnt provide any range checking but it is simple to do. 63 -> 31 62 -> 30 61 -> ignore 60 -> ignore 59 -> ignore 58 -> 29 57 -> 28 56 -> 27 55 -> 26 54 -> 25 53 -> 24 52 -> 23 51 -> 22 50 -> 21 49 -> 20 48 -> 19 47 -> 18 46 -> 17 45 -> 16 44 -> 15 43 -> 14 42 -> 13 41 -> 12 40 -> 11 39 -> 10 38 -> 9 37 -> 8 36 -> 7 35 -> 6 34 -> 5 33 -> 4 32 -> 3 31 -> 2 30 -> 1 29 -> 0 28 -> ignore 27 -> ignore 26 -> ignore 25 -> ignore 24 -> ignore 23 -> ignore 22 -> ignore 21 -> ignore 20 -> ignore 19 -> ignore 18 -> ignore 17 -> ignore 16 -> ignore 15 -> ignore 14 -> ignore 13 -> ignore 12 -> ignore 11 -> ignore 10 -> ignore 9 -> ignore 8 -> ignore 7 -> ignore 6 -> ignore 5 -> ignore 4 -> ignore 3 -> ignore 2 -> ignore 1 -> ignore 0 -> ignore |
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Topics
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Siemens S5 Floating Point Format | deyoungkr | LIVE PLC Questions And Answers | 5 | December 14th, 2007 03:51 PM |
| RE- compose IEEE Floating Point Number | Scorpip | LIVE PLC Questions And Answers | 6 | October 25th, 2005 07:00 PM |
| PID Question | ToddM | LIVE PLC Questions And Answers | 41 | July 11th, 2005 11:23 PM |
| What is “D” in PID? ... fundamentals of Derivative | Ron Beaufort | LIVE PLC Questions And Answers | 20 | March 2nd, 2005 01:26 AM |
| Convert Floating point to Interger | Scorpio | LIVE PLC Questions And Answers | 6 | April 1st, 2004 10:28 AM |