Sign in to follow this  
Followers 0
dkennedy2004

64 bit IEEE double-precision Question

38 posts in this topic

Hi All, I am reading from 4 registers in RSLogix5000 which correspond to a volume reading on a flow computer. The 1st register contains the integer value 16548 = 40A4 Hex The 2nd register contains the integer value -10041 = D8C7 Hex The 3rd register contains the integer value -20972 = AE14 Hex The 4th register contains the integer value 31457 = 7AE1 Hex Now, when I combine the Hex values: 40A4D8C7AE147AE1 and place them in this form http://www.markworld.com/showfloat.html where it says "double-precision IEEE number as 16 hex digits" and hit convert out pops the decimal equivalent 2668.388 which is what is on my flow computer and the exact number I want. Now my problem is how do you get RSLogix5000 to perform this calculation? I cant seem to figure how to do it! Thanks in advance David Edited by dkennedy2004

Share this post


Link to post
Share on other sites
I use this site: http://babbage.cs.qc.edu/courses/cs341/IEEE-754.html Where did these numbers come from? The SLC500 didn't generate these. Can't what ever generated the 64 bit float generate a 32 bit float instead? That would be the easiest. Otherwise You need to read the IEEE 754 specification to find out the difference in the exponent and mantisa fields between the 32 bit and 64 bit floats. This conversion will be messy but not hard.

Share this post


Link to post
Share on other sites
probably received through fieldbus or serial connection from flowmeter... http://en.wikipedia.org/wiki/IEEE_754 i would check if this range is needed and if not, can transmitter can be configured for different output type (is this maybe also a totalizer?) if this is not possible but the range allows i would first try to simply fit it into a single precission float using simple bit manipulation and masks: highest bit is sign -> just copy it... transfer used parts of exponent (8-bit) and mantisa (23-bit), them copy (COP) whole 32-bit result into an F8 register. if that doesn't produce desired result, write whole thing from scratch (sample code available in C)

Share this post


Link to post
Share on other sites
Hi, Im reading the values over Modbus communications and Im afraid I dont have the option to reconfigure the transmitter to change the output so Im gonna have to invistigate the IEEE 754 standard a lot more. I find all this number manipulation a bit daunting,pardon the pun, so any help would be great in performing the tasks in RSLogix5000. Like for example how do you create a F8 register in RSlogix as suggested? Thanks David

Share this post


Link to post
Share on other sites
Check Out this Link for IEE 754 Info If I can translate it to Logix 5000 later I will.

Share this post


Link to post
Share on other sites
Will have a look at that link.Cheers. It would be unreal if you could do it in Logix5000, not that im being lazy. Its just that all this bit manipulation I feel could be beyond me.Im just used to creating valve blocks etc in PLC code.Fairly basic David

Share this post


Link to post
Share on other sites
seam simple, it should be just three places bitshift and restore sign (xic ote) then copy DINT to REAL. or... do it backwards, type the floating point RESULT into a REAL and copy this to DINT, then compare bit positions with your 64-bit value comming from flowmeter.

Share this post


Link to post
Share on other sites
Here is solution: I'll put comments tomorrow. One thing is missing: It is necessary to analyze if exponent is within 8 bit limits or conversion is impossible. Edited by Contr_Conn

Share this post


Link to post
Share on other sites
Good show! Those bit distribute instructions are handy. I would have used shifts, masks and 'or'ed the results together.

Share this post


Link to post
Share on other sites
Beat Out Again -- Almost had it. See if this Looks Like what you are talking about Conn. IEE_754.ACD Edited by BobLfoot

Share this post


Link to post
Share on other sites
Hi Again, Just one more thing.Any chance BobLfoot you could post your code as code done on version 13 RSLogix because I dont have the newer version and im curious as to your method and cant open it.Thats if it isnt too much trouble to do so Cheers David

Share this post


Link to post
Share on other sites
BobLfoot's code does about the same as mine and plus checks for exponent value. Few things to smplify in Bob's code: Because mantissa in Float-32 is much shorter, only 3 bits used from Integer3 and integer 4 is not used at all.So rung2 BTDs can me simplified. or 6 BTDs (Rung 2 and 3) can be replaced with one COP and 2 BTDs You don't have to separate mantissa at all, you can dumpt it to directly to the result as no changes required. Only exponent needs to be re-calculated

Share this post


Link to post
Share on other sites
IT was a small program and not bad to do. Might Check and make sure it works. I don't have a test plaform right now. IEE_754_ver13.ACD

Share this post


Link to post
Share on other sites
GRT>255 is not enough, must check negative end as well (just in case!) I would do 2 steps: E1=E-1023 LIM -127 E1 127 E1=E1+127

Share this post


Link to post
Share on other sites
Thanks Conn This type math was always a little weak even though I have a B.S. in math

Share this post


Link to post
Share on other sites
Hi, Ive managed to get the numbers out using Conns method which is much appreciated but when I run Bobs it seems to give me a Not Convertable output and the real value doesnt come out.Attached is my running code.Ideally i would like to provide this checking that ye are suggesting.Also in my code MCMReadData[142] is the first integer and MCMReadData[143] is second etc etc by the way. Thanks

Share this post


Link to post
Share on other sites
MCMReadData[142] has large negative number that rases flags right away. Are you sure you not swapping integers (first-last) I see it has D8C7 that is second INT! MCMReadData[142 ] should be 40A4 if Bob's calculation used. Edited by Contr_Conn

Share this post


Link to post
Share on other sites
Brilliant,i got the program reproducing what i want. It was a silly mistake on my part.I owe ye Conn and Bob a few pints of Guinness if ye ever visit ireland! Just one more attachment so could ye make sure that im performing the check adequately as suggested in Conns code and im good to go. Cheers Edited by dkennedy2004

Share this post


Link to post
Share on other sites
In the CLX the BTD is a nice slick way to do it. Here is a link to a conversion I did in a thread on another forum for doing the same thing in a SLC500. It may help in understanding what is going on, for what its worth. http://www.plctalk.net/qanda/showthread.php?t=20575

Share this post


Link to post
Share on other sites
I don't know how you got it working, but these highlited instructions are completely wrong!

Share this post


Link to post
Share on other sites
Simplified based on Alaric's feedback Edited by Contr_Conn

Share this post


Link to post
Share on other sites
The only thing to watch out for with the simplified version is that there is no range checking on the exponent. If the exponent is greater than 38 or less than -38 then the simplified conversion will be bogus. However I think that the times when a measured process value needs an exponent greater than 38 would be very rare so for most applicaitons we don't need to care about it, but the thing to watch out for is very small near zero numbers which have an exponent less than -38. You may want to trap for those and just write a zero to the result. Edited by Alaric

Share this post


Link to post
Share on other sites
I think I need to explain why we are talking about exponent <=38 while testing exponent field for < 128 Exponent field in FLOAT-32 is 7 bits plus sign, so highest number that fits there is +/- 127 2^127 is about 10^38 and this is used to display floats So if we are checking exponental binary portion of the FLOAT-64 (bits 52-62), we should check for value +/-127 in these bits. Technically we need bits 59-61 of FLOAT-64 to be zero to perform valid conversion and this can be done with 3 XIC instructructions only. Edited by Contr_Conn

Share this post


Link to post
Share on other sites
This explains conversion It is time for a technote ;)

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