Double 64 Bits WinAvr

Last post
25 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dear all,
I am Simone from the University of Rome 'Tor Vergata'.

I am using the compiler WinAvr in order to program the ATMEL microcontroller AT90USB646. The problem I am facing with is that I need the 'Double' type at 64 bits (8 Bytes), but the GCC in AVR version handles 'Double' as 'Float' (4 Bytes). Can you suggest me some library or in alternative any solutions in order to solve my issue?

Thanks.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Nope, but if you end up writing this the avr-gcc project would dearly like it contributed.

There are other "accurate maths" libs that don't integrate completely into the compiler (like adding a type and supporting +-*/) but that provide a number of add_number(), sub_number() style functions. IBM has a "decimal library" you should be able to find that might be used (assuming the AVR has sufficient resource to support it)

EDIT the IBM work appears to be located here:

http://speleotrove.com/decimal/

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Perhaps if you told us why you need such precision we could point you in other directions, such as fixed point math. There are not many applications on micros that require doubles or even floats. Most things can be handled just fine with integer or fixed point alternatives.

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The application regards the GPS pseudorange, that is the number of meters between the satellite and the receiver. Such distance is something as 20 million, so to reach the precision of the millimeter I need at least a number like this: xxxxxxx.xxx

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

xxxxxxx.xxx is the format of the number

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I see 9 decimal digits. 32 bit floats are good for about 8.5 - is that not enough? You might be out by a millimeter or two.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Such distance is something as 20 million, so to reach the precision of the millimeter I need at least a number like this: xxxxxxx.xxx

I guess I didn't know that mm accuracy from GPS was practical. ;)

20 million meters => 2 billion millimeters. Fits nicely into a 32-bit integer (signed or not).

So us simple old guys would just do all the work in integer/millimeters.

Lee

You can put lipstick on a pig, but it is still a pig.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

20 million meters => 2 billion millimeters

Problems with the metric system :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

(LOL)

[not enough fingers and toes]

You can put lipstick on a pig, but it is still a pig.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Presumably this is why God invented centimeters?

(does it really matter if your missile guidance system drops the bottom 2 cm's to the left?)

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Not wholly your fault. The OP said 20 million, then gave a format that is not capable of that amount.

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What about the mm precision? Even the enhanced stuff gets down to a few cm AFAIK.

Anyway, the satellites' orbits seem to be about 20km then it would be 20 million meters, right? ;)

You can put lipstick on a pig, but it is still a pig.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:
What about the mm precision? Even the enhanced stuff gets down to a few cm AFAIK.

Anyway, the satellites' orbits seem to be about 20km then it would be 20 million meters, right? ;)

100 miles above sea level is a *low* earth orbit.
A 20km orbit isn't going to last very long.

Is it racist to discriminate against someone who changes species?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:
Anyway, the satellites' orbits seem to be about 20km then it would be 20 million meters, right? ;)
The metric system is really difficult, isn't it? :D

20 million meters = 20,000 km

Stefan Ernst

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

100 miles above sea level is a *low* earth orbit.
A 20km orbit isn't going to last very long.

Darn metric system lol 20k km...
http://www.kowoma.de/en/gps/orbits.htm
Quote:
The mean distance from the middle of the earth is 26560 km. With a mean earth radius of 6360 km, the height of the orbits is then about 20200 km. Orbits in this height are referred to as MEO – medium earth orbit. In comparison, geostationary satellites like ASTRA or Meteosat – satellites orbit the earth at 42300 km, which is about twice the distance of GPS satellites.

You can put lipstick on a pig, but it is still a pig.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I don't say this applies for this case, but sometimes when dealing with a variable which absolute value is big but its variations are relatively small, it pays off to apply a constant offset to the whole calculation. The satellites' orbit does not change a lot, it maybe fits within +-100km, so applying an offset of -20000km allows to achieve two orders of magnitude (roughly 7 bits) better resolution with variables of the same width.

The major drawback of this and similar techniques is, that it requires thinking.

JW

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

wek wrote:
The satellites' orbit does not change a lot, it maybe fits within +-100km, so applying an offset of -20000km allows to achieve two orders of magnitude (roughly 7 bits) better resolution with variables of the same width.

The major drawback of this and similar techniques is, that it requires thinking.

Yes, but the thinking bit gets quite difficult when the problems you're trying to solve get at all non-trivial. The 3D geometry involved in getting a GPS fix requires an error analysis much more sophisticated than simple scaling, offset and resolution. I'm not saying it can't be done without doubles, but that it might be quite hard. It is certainly much harder than
Quote:
20 million meters => 2 billion millimeters. Fits nicely into a 32-bit integer (signed or not). So us simple old guys would just do all the work in integer/millimeters.
would seem to suggest. Such a simplistic approach will, I think, simply not work. I seem to remember that even with the 50+ bits of precision of doubles you have to take care with the implementation of GPS not to squander accuracy in the calculations.

Christopher Hicks
==
[EDIT: Having re-read the original post, I see that the problem may not be as complicated as I have assumed. Perhaps the position fix is already obtained by third-party code in a receiver module, or some such.]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

cicciociccio wrote:
The application regards the GPS pseudorange, that is the number of meters between the satellite and the receiver. Such distance is something as 20 million, so to reach the precision of the millimeter I need at least a number like this: xxxxxxx.xxx

If you want to crunch your own GPS Solution, I'd steer clear of an AVR - it would be a world of pain and suffering. A 32-bit processor like an AVR or AVR32 should be able to do it comfortably.

Do you **really** want to do an iterative non-linear least squares solution on a 16MHz 8-bit processor?

-- Damien

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

cmhicks wrote:
wek wrote:
The major drawback of this and similar techniques is, that it requires thinking.
Yes, but the thinking bit gets quite difficult when the problems you're trying to solve get at all non-trivial.
Exactly this is why I started my post with:
wek wrote:
I don't say this applies for this case,

But, in general, thinking seldom hurts.

JW

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

> I see 9 decimal digits. 32 bit floats are good for about 8.5

Well, they are usually stated as 6...7 digits of precision.

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.
Please read the `General information...' article before.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
> I see 9 decimal digits. 32 bit floats are good for about 8.5

Well, they are usually stated as 6...7 digits of precision.


IEEE754 is 24 bits, so a little over 7 decimal digits at best.

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello Simone,

I have just finished fix64 library for AvrCo Multitasking Pascal compiler e-lab.de/AVRco/index_en.html. It handles s31.32 fixed point numbers and covers range from -2147483648.000000000 to 2147483647.999999999. I guess that covers your demands quite well. It is not yet officially in AvrCo but it will be pretty soon. Standard compiler version will support all standard operators and conversions so code will look the same as when floating point numbers are used, and professional version will cover much more functions.

Here is complete list of functions implemented:
Fix64ToString(), Fix64ToStrFmt(), Fix64Sgn(), Fix64Sign(), FloatToFix64(), Fix64ToFloat(), Fix64Sqr(), Fix64Sqrt(), Fix64Mod(), Fix64ModInt(), Fix64Lower(), Fix64Higher(), Fix64Abs(), Fix64ValueTrimLimit(), Fix64ValueInRange(), Fix64Sin(), Fix64Cos(), Fix64SinD(), Fix64CosD(), Fix64SinCos(), Fix64RadToDeg(), Fix64DegToRad(), Fix64Quadrant(), Fix64Tan(), Fix64TanD(), Fix64Frac(), Fix64Int(), Fix64Trunc(), Fix64Odd(), Fix64Even(), Fix64Round(), Fix64ArcTan(), Fix64ArcTanD(), Fix64ArcSin(), Fix64ArcSinD(), Fix64ArcCos(), Fix64ArcCosD(), Fix64ArcTan(), Fix64ArcTanD(), Fix64ArcTan2(), Fix64ArcTan2D(), Fix64Within(), Fix64ValueInTolerance(), Fix64ValueInToleranceP(), Fix64Cot(), Fix64CotD(), Fix64ArcCot(), Fix64ArcCotD(), Fix64IsPowOfTwo(), Fix64Ln(), Fix64Log10(), Fix64Log(), Fix64Exp(), Fix64Power(), Fix64PowerInt(), Fix64Integrate(), Fix64Sinh(), Fix64Cosh(), Fix64Tanh(), Fix64ArSinh(), Fix64ArCosh(), Fix64ArTanh(), Fix64Sec(), Fix64Cosec().

Last year I have made a free AFP - Arbitrary Fixed Point library for fix32 math and published it here as a project. It has much less functions then fix64 commercial implementation but you can get the picture of what's going on. You can take a look at it here:
http://www.avrfreaks.net/index.php?module=Freaks%20Academy&func=viewItem&item_type=project&item_id=2351
and nice screenshot of some of the fix32 features can be seen here:
http://www.avrfreaks.net/modules/FreaksFiles/files/3985/screenshot.gif

Besides GPS and astronomy, a common use for such precision is often undervalued flow metering. For example, you measure natural gas flow in a pipe few times per second, and you just add it cumulative to some total, and of course you use standard 32 bit floating point for this. Then, after many months your customer calls you and says that your nicely calibrated readings are giving wrong totals when daily, weekly or monthly reports are made. That happens because 32 bit floating point can not handle situation when really small numbers are beeing added to really big numbers. That's where fix64 comes to the rescue. :D

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avra wrote:
I have just finished fix64 library for AvrCo Multitasking Pascal compiler e-lab.de/AVRco/index_en.html. It handles s31.32 fixed point numbers and covers range from -2147483648.000000000 to 2147483647.999999999. I guess that covers your demands quite well.

I fear, it covers not the point, that it must be called from C code and compileable using Winavr. :cry:

Peter

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

danni wrote:
I fear, it covers not the point, that it must be called from C code and compileable using Winavr.

This is from the original post:
cicciociccio wrote:
Can you suggest me some library or in alternative any solutions in order to solve my issue?

Besides, looking at free sources of fix32, he can implement C version of just +,-,*,/ for his own fix64 quite easy (if that is all he needs, and probably it is such a case). For example, I don't think that this is unreadable to an average C programer:
function fixAdd(const a, b: TFix): TFix;
begin // add a and b with fixed point math
  Return (a + b);
end;

function fixMul(const a, b: TFix): TFix;
begin // multiply a and b with fixed point math
  Return (longint((int64(a) * int64(b)) shr fixFractBits));
end;
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This thread (German) has an avr-gcc package
64 Bit float Emulator in C, IEEE754 compatibel

http://www.mikrocontroller.net/topic/85256

You would need this archive http://www.mikrocontroller.net/attachment/43913/IEEE754_double.zip
And replace avr_f64.c in the archive with this one http://www.mikrocontroller.net/attachment/51020/avr_f64.c

I just made a "test compile" , and it's around 21K Flash / 310 B Ram on a Mega32

/Bingo