CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Math.h just took up all my ROM. Any suggestions?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Arizona Chris



Joined: 20 Dec 2014
Posts: 69
Location: Arizona

View user's profile Send private message Visit poster's website

Math.h just took up all my ROM. Any suggestions?
PostPosted: Sun Jun 28, 2015 11:41 am     Reply with quote

Greetings all,

we had to include the math.h so we could use the arctan2() function, but then my code went from 40% full on the ROM to 80%. OH my. I just need the one function, not the whole darn library. Is there any way to just include the arctan2 function? Im out of code space on my 877a chip.

Chris
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Jun 28, 2015 12:03 pm     Reply with quote

Two quick solutions...
1) upgrade to a newer PIC. The 877 is a dinosaur like me, almost obsolete...

2) You should be able to 'cut and paste' the compiled arctan() function and call it from your program. I did this kind of thing decades ago with a Z80 based product. Didn't need the whole library, just a couple math functions.

I did 'think' that only the required math routines would be compiled though, maybe Mr. T or PCMP will reply with the facts...me, I'm still mopping up from 'the storm'.

Jay
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jun 28, 2015 1:37 pm     Reply with quote

Quote:
I did 'think' that only the required math routines would be compiled

That's correct. If you only use atan(), then only that math.h routine will
be compiled. I did that in a test program and got 16% program memory
usage. Using atan2(), I got 20% usage.
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Sun Jun 28, 2015 2:25 pm     Reply with quote

I posted here a reduced size atan function a while ago.

<http://www.ccsinfo.com/forum/viewtopic.php?t=50920&highlight=atan>

This is a lot smaller and quicker than the standard function.
Arizona Chris



Joined: 20 Dec 2014
Posts: 69
Location: Arizona

View user's profile Send private message Visit poster's website

math.h
PostPosted: Sun Jun 28, 2015 4:51 pm     Reply with quote

Does this mean that I can open math.c, then find the arctan2 function and copy just this part to my program - or do I need the header at the top as well?

Yes, I know I have ONE LAST 877a I am trying to use up! I bought a whole tube of the 887 chips and have on order the 40p dip version of the 16F1789 for future projects.

Chris
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jun 28, 2015 5:31 pm     Reply with quote

You have to read all the replies, not just part of the first one.
You have to notice the backpedaling on the musings.
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Mon Jun 29, 2015 1:58 am     Reply with quote

Also as a comment, think about the size you are getting.

PCM_programmer has already tested and shown that atan, only takes 16% of the ROM on your chip. I'd guess that when you added the actual atan, you added a whole line (or multiple lines), involving quite a bit more maths. Probably a few multiplications and divisions to actually get the number you want, or scale the result. Result the extra size.
You need to be looking at all these other factors, and thinking a bit. Though the library only includes the parts it wants, and once you have included the atan, using it again doesn't load a second copy, it does means all the setup code copying things to registers and from registers etc.. Look at your actual maths and see whether there is any way of simplifying (remember for instance that *0.1, will use less space than /10.0). Simple things like printf, using a floating point number can get quite bulky.

For example, a simple test with a float number being counted through a for..next loop, multiplied and printed (%6.2), takes just over 1Kbytes on a PIC. However take the same number (still doing the maths in float), and multiply it by 100, into an int32, and print this with '%6.2lw', and it saves space!...
Code:

  int32 temp; //val and val2 as floats

  while(1)
  {
     val2=val2*val;
     temp=val2*100;
     printf("%6.2lw\n",temp);
     delay_ms(1000);
  }

//versus
  while(1)
  {
     val2=val2*val;
     printf("%6.2f\n",val2);
     delay_ms(1000);
  }

Saves 94 bytes!...

Now coding (say) as:
Code:

   val2=val2*0.1;

//versus

   val2=val2/10;


saves 346 bytes!....

This extra usage for mundane things is often forgotten...
Arizona Chris



Joined: 20 Dec 2014
Posts: 69
Location: Arizona

View user's profile Send private message Visit poster's website

math
PostPosted: Mon Jun 29, 2015 6:29 am     Reply with quote

Thanks again all of you for your informative replies! Carefull extraction of uneeded functions allowed us to make just enough extra ROM to finish the job fine. in this case, an extra 10% made all the difference.

The best news on all of this is that I have now finished up our stock on the "dinosaur" 877a chips. Until we get another far more modern PIC in our hands (next week) we will be using up our supply of 887 chips. Maybe a mastadon, but NOT a dinosaur! ;)

Chris
gpsmikey



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

PostPosted: Mon Jun 29, 2015 9:03 am     Reply with quote

Depending on what you think your time is worth, it is often cheaper to simply throw the old stock out and replace it with newer chips for the next project instead of holding on to that little T-rex.

mikey
_________________
mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Mon Jun 29, 2015 1:04 pm     Reply with quote

my progression in 40 pin was
877->887 -> 18f4620 --> 18f46k22 Very Happy Very Happy

I've gotten quite used to doing anything reasonable to NOT use floats....
A favorite is to scale analog gains in power of 2 for a 16 bit ADC
then multiply the ADC word by 100 or 1000 - and use shifts of a a 32 bit unsigned integer, formatted with decimal placement to true value for printf output.

The last time i suffered with the advanced math routines was computing arctan of omega in a complex impedance device. Ultimately it made more sense to send an impedance and frequency value to the host PC and do the heavy math lifting elsewhere than in the MCU Very Happy Very Happy
Arizona Chris



Joined: 20 Dec 2014
Posts: 69
Location: Arizona

View user's profile Send private message Visit poster's website

Math.h
PostPosted: Fri Jul 03, 2015 6:40 pm     Reply with quote

asmboy - Thats a good point, I try not to use floats unless I really need the accuracy. In my case, I had to use arctan2() to get the compass bearing and speed was not an issue for a magnetometer.

I JUST got my new MachX programmer today - and WOW! So used to my old pic start plus from microchip - DB9 serial is soooo slow. No more T rex chips for me. I bought a tube of 887s and have on order some 16F1789 devices for my power house projects. I really like working with C, and the CCS-C always impresses me every time I learn something new. I'm picking it up really fast, as you can see from my Library upload on the magnetometer.

Chris
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group