EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

Floating point IEEE 754 to Microchip conversion. SOS!!!

Started by Nick Alexeev September 1, 2003
Colleagues,

My PIC has to talk to the GPS rerceiver, and GPS transmitts data as
IEEE 754 floats. I'm trying to write conversion routine in C (CCS
compiler), but it does not work. Could you post a working conversion
routine?

Thanks!

Sincerely,
Nick



try to use union, like this:

union
{ float f;
unsigned char c[4];
} UN;

UN un;

un.c[0] = 0x??; // LSB
un.c[1] = 0x??;
un.c[2] = 0x??;
un.c[3] = 0x??; // MSB

printf ("Float = %f ", un.f); ----- Original Message -----
From: "Nick Alexeev" <>
To: <>
Sent: Monday, September 01, 2003 9:17 PM
Subject: [piclist] Floating point IEEE 754 to Microchip conversion. SOS!!! > Colleagues,
>
> My PIC has to talk to the GPS rerceiver, and GPS transmitts data as
> IEEE 754 floats. I'm trying to write conversion routine in C (CCS
> compiler), but it does not work. Could you post a working conversion
> routine?
>
> Thanks!
>
> Sincerely,
> Nick >
> to unsubscribe, go to http://www.yahoogroups.com and follow the
instructions
>
> ">http://docs.yahoo.com/info/terms/ >
> Esta mensagem foi verificada pelo E-mail Protegido Terra.
> Scan engine: VirusScan / Atualizado em 28/08/2003 / Vers: 1.3.13
> Proteja o seu e-mail Terra: http://www.emailprotegido.terra.com.br/
>





--- In , "Nick Alexeev" <kender_a@y...> wrote:
> Colleagues,
>
> My PIC has to talk to the GPS rerceiver, and GPS transmitts data as
> IEEE 754 floats. I'm trying to write conversion routine in C (CCS
> compiler), but it does not work. Could you post a working conversion
> routine?
>
> Thanks!
>
> Sincerely,
> Nick

If you find out what the Microchip FP format is and post it here
I will try to point you in the right direction regarding converting
from IEEE 754 to Microchip format.

XCSB deals with IEEE 754 format floating point numbers as standard.

Regards
Sergio Masci

http://www.xcprod.com/titan/XCSB - optimising structured PIC BASIC
compiler



Hi Marcio,

Thank you for your input. Unfortunately the problem is more complex.
IEEE 754 float and Microchip float use different formats to store the
fraction and exponent. Micorchip's app note AN575 explains the
difference (page 3), but I was not smart enough to write a working
conversion routine.

Thanks again!

Nick

P.S. App note can be found at

http://www.microchip.com/download/appnote/library/00575.pdf ** END

--- In , "Marcio" <mzaquela@t...> wrote:
> try to use union, like this:
>
> union
> { float f;
> unsigned char c[4];
> } UN;
>
> UN un;
>
> un.c[0] = 0x??; // LSB
> un.c[1] = 0x??;
> un.c[2] = 0x??;
> un.c[3] = 0x??; // MSB
>
> printf ("Float = %f ", un.f); > ----- Original Message -----
> From: "Nick Alexeev" <kender_a@y...>
> To: <>
> Sent: Monday, September 01, 2003 9:17 PM
> Subject: [piclist] Floating point IEEE 754 to Microchip conversion.
SOS!!!
>
> > Colleagues,
> >
> > My PIC has to talk to the GPS rerceiver, and GPS transmitts data
as IEEE 754 floats. I'm trying to write conversion routine in C (CCS
> > compiler), but it does not work. Could you post a working
conversion routine?
> >
> > Thanks!
> >
> > Sincerely,
> > Nick
> >
> >
> >


On Tuesday 02 Sep 2003 1:17 am, Nick Alexeev wrote:
> Colleagues,
>
> My PIC has to talk to the GPS rerceiver, and GPS transmitts data as
> IEEE 754 floats. I'm trying to write conversion routine in C (CCS
> compiler), but it does not work.

What are you trying to convert them TO?

Ian



I'll e-mail you the format shortly - as my compiler help describes it.

byte1 EEEEEEEE
byte2 SFFFFFFF
byte3 FFFFFFFF
byte4 FFFFFFFF

Where E is exponent, S is the sign bit, F is fraction.

Nick

>
> If you find out what the Microchip FP format is and post it here
> I will try to point you in the right direction regarding converting
> from IEEE 754 to Microchip format.
>
> XCSB deals with IEEE 754 format floating point numbers as standard.
>
> Regards
> Sergio Masci
>
> http://www.xcprod.com/titan/XCSB - optimising structured PIC BASIC
> compiler




According to Microchip App Note AN575 page 3, the Microchip FP format
is:

(big endian destination)
e7 e6 e5 e4 e3 e2 e1 e0
s0 f22 f21 f20 f19 f18 f17 f16
f15 f14 f13 f12 f11 f10 f9 f8
f7 f6 f5 f4 f3 f2 f1 f0

(little endian destination)
f7 f6 f5 f4 f3 f2 f1 f0
f15 f14 f13 f12 f11 f10 f9 f8
s0 f22 f21 f20 f19 f18 f17 f16
e7 e6 e5 e4 e3 e2 e1 e0

IEEE 754 single format (32 bit) is defined as:

(big endian source)
s0 e7 e6 e5 e4 e3 e2 e1
e0 f22 f21 f20 f19 f18 f17 f16
f15 f14 f13 f12 f11 f10 f9 f8
f7 f6 f5 f4 f3 f2 f1 f0

(little endian source)
f7 f6 f5 f4 f3 f2 f1 f0
f15 f14 f13 f12 f11 f10 f9 f8
e0 f22 f21 f20 f19 f18 f17 f16
s0 e7 e6 e5 e4 e3 e2 e1 The thing that might faul you up is the order in which the source is
retrived from the GPS and stored in memory. f7..f0 could be stored in
byte 0 (little endian) or in byte 3 (big endian) to simplify things
store it using the same convention as MC uses to store FP

So to convert IEEE 754 to MC

big endian conversion

* take bytes 1, 2 and 3 of the source and store them in the
destination.

* take bit 7 of byte 0 (s0) of the source and store it in bit 7 of
byte 1 of the destination.

* take byte 0 of the source, shift it one place left and store it
in byte 0 of the destination.

* take bit 7 of byte 1 (e0) of the source and store it in bit 0 of
byte 0 of the destination.

little endian conversion

* take bytes 0, 1 and 2 of the source and store them in the
destination.

* take bit 7 of byte 3 (s0) of the source and store it in bit 7 of
byte 2 of the destination.

* take byte 3 of the source, shift it one place left and store it in
byte 3 of the destination.

* take bit 7 of byte 2 (e0) of the source and store it in bit 0 of
byte 3 of the destination.

Hope this helps

Regards
Sergio Masci

http://www.xcprod.com/titan/XCSB - optimising structured PIC BASIC compiler ----- Original Message -----
From: Nick Alexeev <>
To: <>
Sent: Wednesday, September 03, 2003 2:15 AM
Subject: [piclist] Re: Floating point IEEE 754 to Microchip conversion.
SOS!!! > I'll e-mail you the format shortly - as my compiler help describes it.
>
> byte1 EEEEEEEE
> byte2 SFFFFFFF
> byte3 FFFFFFFF
> byte4 FFFFFFFF
>
> Where E is exponent, S is the sign bit, F is fraction.
>
> Nick
>
> >
> > If you find out what the Microchip FP format is and post it here
> > I will try to point you in the right direction regarding converting
> > from IEEE 754 to Microchip format.
> >
> > XCSB deals with IEEE 754 format floating point numbers as standard.
> >
> > Regards
> > Sergio Masci
> >
> > http://www.xcprod.com/titan/XCSB - optimising structured PIC BASIC
> > compiler >
> to unsubscribe, go to http://www.yahoogroups.com and follow the
instructions
>
> ">http://docs.yahoo.com/info/terms/ >





The 2024 Embedded Online Conference