View previous topic :: View next topic |
Author |
Message |
MicroManiac
Joined: 21 Aug 2008 Posts: 34
|
Floating Point Transmission |
Posted: Tue Jan 06, 2009 4:40 am |
|
|
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
|
Re: Floating Point Transmission |
Posted: Tue Jan 06, 2009 6:37 am |
|
|
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
|
|
Posted: Tue Jan 06, 2009 7:09 am |
|
|
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
|
|
Posted: Tue Jan 06, 2009 7:55 am |
|
|
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
|
|
Posted: Tue Jan 06, 2009 8:15 am |
|
|
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
|
|
Posted: Tue Jan 06, 2009 8:42 am |
|
|
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
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
|
|
Posted: Tue Jan 06, 2009 8:44 am |
|
|
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
|
|
|
|