![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
may26baf
Joined: 04 Oct 2006 Posts: 7
|
Floating point help |
Posted: Wed Oct 11, 2006 6:23 am |
|
|
I'm trying to send raw floating point values from my PIC to my PC via serial connection. The problem I seem to be having however is in how those numbers are calculated. For example, the value 0.0001 on the PIC is 0x17b75171 but that same floating point value on my PC is 0x17b7d138.
Why are these values different, and how do I compensate for that difference?
Thanks much.
Brian Franklin |
|
![](templates/subSilver/images/spacer.gif) |
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
|
Posted: Wed Oct 11, 2006 6:51 am |
|
|
If you are using a Microsoft application it might be hot dogging.
Do a similar test with a neg number to see if the implied one is replaced with the sign to get 24 bit precision.
Single precision is a 24 bit (mantissa and sign) and an 8 bit exponent( offset to encode positive and negative powers). There may be little endian big endian issues and with Microsoft code there is hot dogging to be aware of. The binary mantissa is normalized so unaltered it will always have leading 1. Hot dogging is replacing the 1( which is always implied) with the sign to acquire 24 bit precision instead of 23 bit. |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Wed Oct 11, 2006 7:30 am |
|
|
The internal values are stored differently on the PIC. The actual data used is basically the same, but parts of it are held in different bits of the 32bit value.
Code: |
void toccs(int8 *Value) {
//program to convert a 4 bytes 'word' from IEEE to CCS format
int1 sign;
sign = shift_left(&Value[1],1,0);
sign = shift_left(&Value[0],1,sign);
shift_right(&Value[1],1,sign);
}
void toIEEE(int8 *Value) {
//complement to the above
int1 sign;
sign = shift_left(&Value[1], 1, 0);
sign = shift_right(&Value[0], 1, sign);
shift_right(&Value[1], 1, sign);
}
|
If you call 'toIEEE', with a pointer to a CCS float, it'll change the layout into the IEEE format used on the PC. Conversely, call 'toCCS', with a pointer to a value in IEEE short format (as used on the PC), and the code will turn it into a CCS float.
I have used this both in the PIC to convert before transmission, and in a PC to convert afterwards.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|