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 support@ccsinfo.com

floating point subtraction

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



Joined: 25 Nov 2006
Posts: 9

View user's profile Send private message

floating point subtraction
PostPosted: Thu Nov 30, 2006 2:31 pm     Reply with quote

can any one help me....a simple floating point subtraction is consuming 20% of rom...i am using pcm and 16f72
float a,b,c;
a=b-c;
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Nov 30, 2006 2:35 pm     Reply with quote

That PIC has only 2K ROM words available. Don't use floating point in
small PICs.

See this link:
http://www.ccsinfo.com/forum/viewtopic.php?t=26306&highlight=8K
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Nov 30, 2006 5:05 pm     Reply with quote

All starting software engineers run into the same problems using floating point arithmetic when creating their first program on a processor with little memory. They discover one or more of the following:
A) Floating point arithmetic takes a lot of program space.
B) Floating point arithmetic is slow.
C) You get unexpected rounding errors, for example a value of 0.999999 when expecting 1.00000.


A common way to avoid these problems is to apply a technique called 'scaled integers'. This means that you are doing all the arithmetic in integers by multiplying the original data with a factor 10, 1000 or whatever number of digits accuracy you need. Only in displaying the data you add a decimal point.
For example when calculating the distance between two points you can say it is 1.45m + 12,23m = 13.68m
But calculating in centimeters it is all integers: 145cm + 1223cm = 1368cm = 13.68m
Working with integers like this is using less memory, is faster and you get predictable rounding errors.

Also have a look at http://www.ccsinfo.com/forum/viewtopic.php?t=28946&highlight=scaled+integer
roykyn



Joined: 25 Nov 2006
Posts: 9

View user's profile Send private message

PostPosted: Sun Dec 03, 2006 12:10 pm     Reply with quote

i know that the prob can be solved by increasing rom size....is there any other ideas....like this one
http://www.ccsinfo.com/forum/viewtopic.php?t=29034&highlight=
Sherpa Doug
Guest







PostPosted: Sun Dec 03, 2006 8:58 pm     Reply with quote

Usually the best way is to avoid using floating point at all. Tell us more about your application and we can probably help you. Also read ckielstra's message carefully. Scaled integers are very powerful and very fast.
roykyn



Joined: 25 Nov 2006
Posts: 9

View user's profile Send private message

PostPosted: Mon Dec 04, 2006 2:07 pm     Reply with quote

i am building a LC meter......
http://www.aade.com/LCinst/lcm2b.htm

http://www.antrak.org.tr/gazete/111998/barbar.htm

http://f6bon.albert.free.fr/lcmetre.html

http://veron-meppel.atvrepeater.com/html/zelfbouw/lc-meter/lc_meter.htm

http://users.cableaz.com/~cappels/dproj/lgm/lgm.html

http://utenti.lycos.it/ik0gmm/resume.html

http://www.cqham.ru/lcmeter2.htm

http://www.hw.cz/constrc/lc_metr/

http://www.df3dcb.de/Elektronik/LC-Meter/lc-meter.html

http://www.sprut.de/electronic/pic/projekte/lcmeter/lcmeter.htm

http://ironbark.bendigo.latrobe.edu.au/~rice/lc/

http://www.oz5vf.dk/byggeprojekter/lc-meter/lc-meter.html

http://www.hw.cz/constrc/lc_metr/

http://xavier.fenard.free.fr/LCMeter.htm

http://www.qsl.net/iz7ath/web/02_brew/21_LCMeter01/

http://www.geocities.com/ttarsorg/contributors/homebrew-lc-meter-2.pdf

http://perso.wanadoo.fr/f6gog-web/files/brew.htm

http://www.touchinglittlelives.org/meter/

http://www.digital-measure.com

http://electronics-diy.com/lc_meter.php
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Mon Dec 04, 2006 8:36 pm     Reply with quote

That looks like an interesting little device. Basically an oscillator whose frequency is a function of the device being measured. So your measurement enters the software world as an integer count. And you want to end up with integer digits on a LCD display. Why not keep it in integers in the middle? Can you calculate inductance in nHy or uHy depending on the mode? How about calculating capacitance in centi-pF. 100,000 cpF = 1mFd. Then you just have to find out where to put the decimal point on the display.
_________________
The search for better is endless. Instead simply find very good and get the job done.
roykyn



Joined: 25 Nov 2006
Posts: 9

View user's profile Send private message

PostPosted: Sat Dec 09, 2006 12:19 pm     Reply with quote

i have 2 do all the calculations...to find the value of L or C it has only one subtraction....
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