Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Electronic Equipment > Microcontrollers 8bit > Space optimizin...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 2 Topic 786 of 862
Post > Topic >>

Space optimizing : C++, mega8, math.h

by "Henning Mortensen" <henning@[EMAIL PROTECTED] > May 21, 2007 at 09:24 PM

Hi again,

I'm having problems getting room for the code in my ATmega8. I found that 
working with 32 bit int's wasn't enough, but now I changed et all to 64
bit 
int's the code grew about 50% from about 80% of the mega8's space to about

120% :(
I found that most of the space is lost in the following code where I use 
fabs and sqrt. If I remove thoes lines the code is fills about 99%...

Anybody knows how to optimize the code to use less space, of a feature in 
AVR studio (GCC) to optimize.
Speed is NOT im****tant, space is.

"C:\WinAVR\bin\..\lib\gcc\avr\3.4.6\..\..\..\..\avr\bin\ld.exe: region
text 
is full (cnc.elf section .text)" :(

Thanks
 - Henning

void moveto(uint64_t nyx,uint64_t nyy,uint64_t nyz)
{
 long int dx;
 long int dy;
 long int dz;

 double Rho;
 double enX;
 double enY;
 double enZ;

 double x;
 double y;
 double z;

 dx = nyx - globalx;
 dy = nyy - globaly;
 dz = nyz - globalz;

 Rho = sqrt((double)(dx * dx) + (double)(dy * dy) + (double)(dz * dz));

 enX = (double)dx / Rho;
 enY = (double)dy / Rho;
 enZ = (double)dz / Rho;

 x=0;
 y=0;
 z=0;

 int R = 0;

 for (R=0;R<=Rho;R++)
 {
  x += enX;
  y += enY;
  z += enZ;

  if (fabs(x) >= 1)
  {
   if (x<0)
   {
    x++;
    globalx --;
    MStep(Motorx,negative);
   }
   else
   {
    x--;
    globalx ++;
    MStep(Motorx,positive);
   }
  }
  if (fabs(y) >= 1)
  {
   if (y<0)
   {
    y++;
    globaly --;
    MStep(Motory,negative);
   }
   else
   {
    y--;
    globaly ++;
    MStep(Motory,positive);
   }
  }
  if (fabs(z) >= 1)
  {
   if (z<0)
   {
    z++;
    globalz --;
    MStep(Motorz,negative);
   }
   else
   {
    z--;
    globalz ++;
    MStep(Motorz,positive);
   }
  }
 }
}
 




 2 Posts in Topic:
Space optimizing : C++, mega8, math.h
"Henning Mortensen&q  2007-05-21 21:24:17 
Re: Space optimizing : C++, mega8, math.h
"Henning Mortensen&q  2007-05-23 07:09:20 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Nov 20 18:28:25 CST 2008.