Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
Goldfinch
PostPosted: Oct 07, 2008 - 08:50 AM
Rookie


Joined: Jun 04, 2008
Posts: 31


Hello! Does anybody use Simulink Real-Time Workshop Embedded Coder to generate c-code for AVR32 linux application? My program was successfully compiled but give NaN output instead of double value after some correct iterations on NGW100 board, while it successfully run on host maschine under Ubuntu 8.04 (compiled with gcc in eclipse) and under WinXP. I use avr32-linux-gcc compiler generated with Buildroot 2.2.0-rc6. Maybe there are key factors in c-code generator setup specially for AVR32 target? Thanks!
 
 View user's profile Send private message  
Reply with quote Back to top
squidgit
PostPosted: Oct 08, 2008 - 05:40 AM
Raving lunatic


Joined: Sep 14, 2003
Posts: 4228
Location: Queanbeyan, Australia

Update to buildroot 2.2.0 stable, there was a fix which for almost exactly what you say. I thought that fix was in -rc6 but I can't be sure..

-S.

_________________
Blag: http://www.niasdigital.com/blag
 
 View user's profile Send private message  
Reply with quote Back to top
Goldfinch
PostPosted: Oct 08, 2008 - 06:38 AM
Rookie


Joined: Jun 04, 2008
Posts: 31


I thought that latest Buildroot is 2.2.0-rc6. I confused with Buildroot versions.. Tell me please what is 2.2.0 stable and what rc6 means? I heard about NaN fix in latest Buildroot but I can't find any information about this problem on web. Atmel's support answered me with suggestion to debug program with gdb server but there are no words about avr32-linux-compiler version.
And what You mean saying about Buildroot update? Is it only avr32 compiler version update actual for me? Or I need new linux rootfs and kernel update? Thanks!
 
 View user's profile Send private message  
Reply with quote Back to top
eaanon01
PostPosted: Oct 08, 2008 - 06:40 AM
Posting Freak


Joined: Aug 22, 2002
Posts: 1586
Location: Arendal Norway

RC6 - Release Candidate 6 (this is from 20080918) while the stable version is from 20080925.

http://www.atmel.no/buildroot/buildroot-src.html
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
Goldfinch
PostPosted: Oct 08, 2008 - 09:55 AM
Rookie


Joined: Jun 04, 2008
Posts: 31


eaanon01, thanks for explanation!

squidgit wrote:
Update to buildroot 2.2.0 stable, there was a fix which for almost exactly what you say. I thought that fix was in -rc6 but I can't be sure..

-S.

squidgit, I compiled my project with avr32-linux-gcc generated with Buildroot 2.2.0 stable and 2.2.0-rc6 both but there is still NaN error.
 
 View user's profile Send private message  
Reply with quote Back to top
hce
PostPosted: Oct 08, 2008 - 12:38 PM
Raving lunatic


Joined: Jan 07, 2003
Posts: 4583
Location: Oslo, Norway

Can you reduce the failing code to a small test case? Hard to debug this without any code.
 
 View user's profile Send private message  
Reply with quote Back to top
Goldfinch
PostPosted: Oct 10, 2008 - 08:02 AM
Rookie


Joined: Jun 04, 2008
Posts: 31


I found the source of NaN problem. The code is:
Code:

    eml_N_sum = sqrt(eml_N_hor_sp * eml_N_hor_sp + eml_N_ver_sp * eml_N_ver_sp);
    rtb_Gam_sp = asin(eml_N_hor_sp * sqrt(eml_N_sum * eml_N_sum - eml_N_ver_sp *
      eml_N_ver_sp) / eml_N_sum);


When eml_N_hor_sp == 0 && eml_N_ver_sp != 0, then Sqrt counts eml_N_sum incorrectly, so after first sqrt
(eml_N_sum < eml_N_ver_sp)
(in WinXP host machine they are equal and there is no error!). Next command try to take sqrt from negative number and gives NaN.
 
 View user's profile Send private message  
Reply with quote Back to top
eaanon01
PostPosted: Oct 10, 2008 - 08:35 AM
Posting Freak


Joined: Aug 22, 2002
Posts: 1586
Location: Arendal Norway

I tried implementing this example in avr32studio(XP) but I got a strange error(strange for me at least).

Code:

#include <math.h>
...
{
double start=4;
sqrt(4);
sqrt(start);
...

Then I get the following error:
Code:
undefined reference to `sqrt' Test01 main.c

But only on the sqrt with a variable as input?
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
hce
PostPosted: Oct 10, 2008 - 08:51 AM
Raving lunatic


Joined: Jan 07, 2003
Posts: 4583
Location: Oslo, Norway

Did you link with "-lm"?
 
 View user's profile Send private message  
Reply with quote Back to top
Goldfinch
PostPosted: Oct 13, 2008 - 08:23 AM
Rookie


Joined: Jun 04, 2008
Posts: 31


Can You tell me is the function sqrt for AVR32 of double type? I can't understand where is the problem why sqrt of host machine works good but not on AVR32? Is it only architecture difference or math.h incompatibility?
 
 View user's profile Send private message  
Reply with quote Back to top
hce
PostPosted: Oct 13, 2008 - 08:33 AM
Raving lunatic


Joined: Jan 07, 2003
Posts: 4583
Location: Oslo, Norway

From libm/w_sqrt.c:
Quote:
double sqrt(double x)


Implemented in the libm/e_sqrt.c file, and it is a general implementation done in C, not architecture specific.
 
 View user's profile Send private message  
Reply with quote Back to top
Goldfinch
PostPosted: Oct 13, 2008 - 09:27 AM
Rookie


Joined: Jun 04, 2008
Posts: 31


Thanks! I had some doubts about double/float types of sqrt..

Now I've tested next code on AMD Athlon PC and AVR32:
Code:

  while ( i < 10000)
  {
   a = sqrt((double) i);
   b = sqrt((double) i);
   c = a * b;
   d = (double) i - c;
   fprintf(prntout, "%d; %.16f; %.16f; %.16f; %.16f; \n", i, a, b, c, d);
   printf("%d; %.16f; %.16f; %.16f; %.16f; \n", i, a, b, c, d);
   i = i + 1;
  }

Inaccuracy "d" on AMD is about +-2e-12 (plus minus) and on AVR32 is about +4e-6 (only plus). Is it correct test? Can anybody check this?
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits