32 bit floating point in "packets" of 8 bits

32 bit floating point in "packets" of 8 bits

Post by jaime.aran » Sat, 09 Oct 2004 17:20:43


Hello,

I'd like to have your suggestios for the following:

How would you transmit 32 bit floating point data from an 8 bit device
(8 bit microcontroller, UART, etc) to a 32 bit floating point DSP?

One idea that comes to my mind is in packets of 8 bits, with three
packets for the mantissa and 1 packet for the exponent, and
"rebuilding" the number in the DSP with shifts and or's. That would be
fairly easy to do in assembly. The question is: how to do that IN _C_
(on the DSP side)? What about C datatypes? How to rebuild a floating
point number from ints in C?

Regards,

JaaC
 
 
 

32 bit floating point in "packets" of 8 bits

Post by Wolfgan » Sat, 09 Oct 2004 22:54:14

Look under keywords like "pointer" and "cast".
You can make a pointer to a 32bit value, cast it as a pointer to a 8bit value and
access the 32bit's value byte by byte.

Gook luck, Wolfgang

"Jaime Andres Aranguren Cardona" < XXXX@XXXXX.COM > schrieb im Newsbeitrag

 
 
 

32 bit floating point in "packets" of 8 bits

Post by Markus Man » Sun, 10 Oct 2004 00:51:12

Jaime Andres Aranguren Cardona schrieb:



Well, you could use a union. Something like:

union Byte2Float {
float f32;
char f_uart [4];
};

You should check the byte-ordering of floats with your compiler though.

Regards
Markus
 
 
 

32 bit floating point in "packets" of 8 bits

Post by an2o » Sun, 10 Oct 2004 22:27:56


Hi Jaime,

the SHARCs have special 8-to-32 bit packing modes for the external
port DMA. You just store the 32bit float in 4 consecutive bytes in the
memory. The external port DMA will do the rest, ie. the floats will
appear in the internal DSP memory without any need to rebuild them
from the core program.

Regards,
Andor
 
 
 

32 bit floating point in "packets" of 8 bits

Post by Tim Wescot » Mon, 11 Oct 2004 02:21:06


Pay attention to your processor's word size. That union won't work on
either a TI or and AD 16-bit fixed point processor, because a "char" is
16 bits (and I suspect that you'd have the same problem with the
Motorola/Freescale DSP fixed-point chips as well). What _will_ work
would be:

union OctetToFloat
{
float f32;
struct
{
int b0 : 8;
int b1 : 8;
int b2 : 8;
int b3 : 8;
} bits;
};

This has the very big drawback that you are using bitfields which
renders your code almost entirely non-portable. An alternative would be
to shift and mask. You could do this in a for loop but you would still
have to know the word ordering in your processor. In this case you'd
still be non-portable but at least you may be able to handle it with a
define.

--

Tim Wescott
Wescott Design Services
http://www.yqcomputer.com/
 
 
 

32 bit floating point in "packets" of 8 bits

Post by Jaime Andr » Tue, 12 Oct 2004 07:40:49

"Andor" < XXXX@XXXXX.COM > escribi?en el mensaje



Hi Andor,

Thanks for pointing this out. This would be an excellent solution, if I just
wanted to tansmit "raw" data to the DSP, and if I had the peripheral (an
UART, at this moment) wired for using the External Port (I'm not using any
of the /DMARx, /DMAGx, ACK, etc). But for my app speed for transmitting data
is not a concern, mainly because it's control data, instead of "signal"
data, and the peripheral is wired to D0-7 and asserts /IRQ0 everytime it has
a byte to transmit.

Kindest regards,

(Remove "nospam" from e-mail address)
 
 
 

32 bit floating point in "packets" of 8 bits

Post by jaime.aran » Tue, 12 Oct 2004 12:49:22

> Hi Jaime,

Hey Andor, nice! What makes you think that I'm using SHARCs, BTW?


JaaC
 
 
 

32 bit floating point in "packets" of 8 bits

Post by an2o » Tue, 12 Oct 2004 19:31:35


Well, most of your posts in comp.dsp refer to ADI DSPs. In case I was
wrong, please ignore.

As to your original problem: if it is easy in assembler, why not just
write a small inline c-callable assembler routine?

Regards,
Andor
 
 
 

32 bit floating point in "packets" of 8 bits

Post by Jaime Andr » Wed, 13 Oct 2004 01:30:44

"Andor" < XXXX@XXXXX.COM > escribi?en el mensaje



No, man! You were absolutely right. Indeed, I liked it very much the fact
that you noticed it.


I'm trying to keep the program as much "C" as possible. I already wrote some
code to this this job, based on the suggestions received here, and will test
it in a few minutes. However, if it becomes tricky, I'd just write my
c-callable assembler routine.


Regards,

(Remove "nospam" from e-mail address)