Parsing recommendations
Farmer Scott
Posts: 30
Guys...
I need some advice.· Spent about 8 hours last night trying to figure out a reasonable way to convert·the result from a DS1631 I2C temperature sensor into a float and pass the resulting long to the calling function.
Any ideas?· At this point, I'm really open for anything...
The return from DS1631 is 2 bytes, MSB is xyyyyyyy, LSB is zzzz0000, where x is a sign bit, y is the integer portion and z is the fractional portion.
I'm about to the point of change platforms, so any help would certainly be appreciated...
Thanks,
Scott
I need some advice.· Spent about 8 hours last night trying to figure out a reasonable way to convert·the result from a DS1631 I2C temperature sensor into a float and pass the resulting long to the calling function.
Any ideas?· At this point, I'm really open for anything...
The return from DS1631 is 2 bytes, MSB is xyyyyyyy, LSB is zzzz0000, where x is a sign bit, y is the integer portion and z is the fractional portion.
I'm about to the point of change platforms, so any help would certainly be appreciated...
Thanks,
Scott
Comments
value := (((MSB << 8) | LSB) << 16) ~> 20 ' Position the value and extend the sign
If the name of your floating point object is "f", you'd then do
value := f.FDiv(f.FFloat(value) ,16.0) ' Convert to floating point and scale value
Do you live and breath propeller syntax?
WOW... It would have taken me QUITE some time for that little bit of code you "poofed" in minutes...
Nice... simple... and sweet...
I like...
[noparse]:)[/noparse]
KK
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Propeller + Hardware - extra bits for the bit bucket =· 1 Coffeeless KaosKidd
·
'f' object...I've been attempting to use FloatMath.spin from Chips Float Demo on the object exchange.· Is this the object you're referring to?
Scott
No, I've programmed in enough languages and with enough different computers over the years, that Spin and the Propeller are not that different from other things I've seen. I do have a Propeller Manual handy and it opens easily to certain sections like the one describing the different Spin operators.
Post Edited (Mike Green) : 5/29/2008 3:55:25 PM GMT
(MSB << 8) | LSB) - This instructions takes MSB, shifts it left 8 bits (7 becomes 15, 6 becomes 14...), and logical OR's it with LSB, in essence making MSB word 1, and LSB word 0?
<< 16) - This instruction shifts the result of the first instruction to the left 16 bits (15 becomes 31, 14 becomes 30...). This is necessary to get the sign bit into the proper position.
~> 20 - This instruction shifts everything back to the right 20 bits (31 becomes 11, 30 becomes 10), and maintains the sign value in bits 12 through 31 (so if it was 1, bits 12 through 31 will be 1, same for 0).
The result would be something like %0001100011010000 becoming %0000000110001101 (16 least significant bits only).
Am I even remotely close to correct so far?