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 Transmission

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



Joined: 21 Aug 2008
Posts: 34

View user's profile Send private message Send e-mail MSN Messenger

Floating Point Transmission
PostPosted: Tue Jan 06, 2009 4:40 am     Reply with quote

Hello,
does anyone have any idea how i can send variables of type float or double via the usb while preserving the decimal point?
Thank you

Regards
_________________
"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction."
Albert Einstein
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

Re: Floating Point Transmission
PostPosted: Tue Jan 06, 2009 6:37 am     Reply with quote

What are you sending the variables to? If it is not a PIC programmed by the same compiler, then you cannot be sure the internal binary format of the variable is compatible. In general, if you are sending to a totally different program (like a receiving program on a PC) then it is safer to format the variable as string (using sprint or something similar). It uses more characters, but it is more easily understood across diverse platforms.

I just realized that you said "via USB", which makes it unlikely you are sending to another PIC. In that case, I would say it is even more strongly suggested that you use decimal string format.
_________________
Robert Scott
Real-Time Specialties
Embedded Systems Consulting
MicroManiac



Joined: 21 Aug 2008
Posts: 34

View user's profile Send private message Send e-mail MSN Messenger

PostPosted: Tue Jan 06, 2009 7:09 am     Reply with quote

Well, i am a newbie regarding this matter.
Can you please elaborate more on your idea, or you can send me some pointers in order to start writing the code.
Thank you
_________________
"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction."
Albert Einstein
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

PostPosted: Tue Jan 06, 2009 7:55 am     Reply with quote

Quote:
...Can you please elaborate more on your idea, or you can send me some pointers in order to start writing the code...

How about you first elaborate on why you want to send floating point variables over a USB interface. If you are contemplating the implementation of a USB device with a PIC, that is a strange place for a newbie to start.
_________________
Robert Scott
Real-Time Specialties
Embedded Systems Consulting
MicroManiac



Joined: 21 Aug 2008
Posts: 34

View user's profile Send private message Send e-mail MSN Messenger

PostPosted: Tue Jan 06, 2009 8:15 am     Reply with quote

ok
I am not a newbie using Microchip product and developing usb devices, i am a newbie sending floating point via any interface.
I have some intensive calculations that needs to be done on the embedded level.
After these calculations are finished, i need to send the result via the USB to the PC, this is why i need to send floating point units via the USB
The data will be somehow similar to calculating the average of several points.
_________________
"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction."
Albert Einstein
PICoHolic



Joined: 04 Jan 2005
Posts: 224

View user's profile Send private message

PostPosted: Tue Jan 06, 2009 8:42 am     Reply with quote

If the float representation is similar to the CCS's just send the 4 bytes as raw data ..

Note: there are several representations for float

Good luck Smile


Last edited by PICoHolic on Tue Jan 06, 2009 8:46 am; edited 1 time in total
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Tue Jan 06, 2009 8:44 am     Reply with quote

A serial port, whether RS232 or USB, just sends a stream of bytes. These bytes can represent numbers or strings or any number of data formats. A floating point number is just another data format. Have the PIC turn the float into bytes, send the bytes serially, and the processor on the other end will have to turn the bytes into its version of a float.
_________________
The search for better is endless. Instead simply find very good and get the job done.
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

PostPosted: Tue Jan 06, 2009 8:46 am     Reply with quote

You're getting some good advice on http://forum.microchip.com/tm.aspx?m=394373&mpage=1&. Just follow it.

Last edited by RLScott on Tue Jan 06, 2009 8:48 am; edited 1 time in total
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