CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Floating point help

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
may26baf



Joined: 04 Oct 2006
Posts: 7

View user's profile Send private message

Floating point help
PostPosted: Wed Oct 11, 2006 6:23 am     Reply with quote

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
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Wed Oct 11, 2006 6:51 am     Reply with quote

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.
Guest








PostPosted: Wed Oct 11, 2006 7:30 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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