Friday, November 21, 2008

Working with floating point in TinyOS

There are two ways to represent float in nesc.
One way, is to do it through by convention using the exponent and mantissa,
where you need to use 2^exponent. The function that does that is called powf().
The problem with using that function is that it is reaaaaallly slow.
[QUOTE]
----8<---- span="">
DbgOut_P20_ON;
r = logf((float)v / 10000.0); // takes up about 10 ms (!!)
DbgOut_P20_OFF;
----8<---- span="">

and a
----8<---- span="">
DbgOut_P20_ON;
r = powf(10,(float)v / 10000.0); // takes up about 32 ms (!!!!!!)
DbgOut_P20_OFF;
----8<---- span="">
[/QUOTE]

In case you need to have fast response, this function might not be your choice.
One way to optimize the speed of those operations are:
"I'd like to mention that pow(a,b) is MUCH harder to implement than
exp(b). Use the latter whenever possible. In particular, if a is
fixed, use exp(b * log(a)) rather than pow(a,b). (In fact, that's a
common low-precision implementation technique even when a is not fixed.)

Also note that keeping logarithms in fixed-point format is often
convenient, and shaves a bit of overhead from the code when you
don't have hardware floating-point. "

One quite dirty trick to show real numbers in nesc is to define fix point.
for example in 16 bits, you say 12 bits are the bits before the decimal point, and 4 bits are bits after the point. a(12bits) + ( b(4bits)/16 ).
This dirty trick is good in case one wants working with float go faster, without need for much precision.

Wednesday, November 5, 2008

File Sharing between to PCs under Windows

Several times I badly needed the connection between to PCs and I never actually managed to make it working :(

One thing I always forget to set is that both PCs have the same Workgroup, besides the part where you set your folder to be shared among PCs in the network.