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

float point

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







float point
PostPosted: Fri Oct 11, 2002 6:08 am     Reply with quote

I use the PIC16F877.
I must do the following expression:

long i,ppm;

ppm=(i-205)*0.244200244*10;

but this operation take up so much FLASH program.
How can I do this operation with float point and take up less FLASH program?

thank you
___________________________
This message was ported from CCS's old forum
Original Post ID: 7730
Sherpa Doug
Guest







Re: float point
PostPosted: Fri Oct 11, 2002 6:50 am     Reply with quote

:=I use the PIC16F877.
:=I must do the following expression:
:=
:=long i,ppm;
:=
:=ppm=(i-205)*0.244200244*10;
:=
:=but this operation take up so much FLASH program.
:=How can I do this operation with float point and take up less FLASH program?
:=
:=thank you

How about
ppm = ((int32)(i-205)*2442)/1000

Can you product really tell .244200244 from .2442 ?

___________________________
This message was ported from CCS's old forum
Original Post ID: 7734
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

Re: float point
PostPosted: Fri Oct 11, 2002 4:16 pm     Reply with quote

How accurate does ppm need to be?


How much of an error can you live with?

with a 0\% error, then
ppm=(i-205)*0.244200244*10;

ROM used: 263 (3\%)
Largest free fragment is 2048
RAM used: 15 (9\%) at main() level
28 (16\%) worst case

with a 2.3\% error, then
ppm=(i-205)*10/4;
ROM used: 64 (1\%)
Largest free fragment is 2048
RAM used: 12 (7\%) at main() level
16 (9\%) worst case

with a 0.08\% error, then
ppm=(i-205)*61/25;
ROM used: 108 (1\%)
Largest free fragment is 2048
RAM used: 12 (7\%) at main() level
17 (10\%) worst case

with a 1.7\% error, then
ppm=(i-205)*12/5;
ROM used: 108 (1\%)
Largest free fragment is 2048
RAM used: 12 (7\%) at main() level
17 (10\%) worst case



You will have to make sure that (i-205) does not overflow if you use one of the examples. Multiplying by 61 or 12 could cause you to overflow. Also note that your final result is an integer so the error might be less than you expect.

Regards,
Mark

:=I use the PIC16F877.
:=I must do the following expression:
:=
:=long i,ppm;
:=
:=ppm=(i-205)*0.244200244*10;
:=
:=but this operation take up so much FLASH program.
:=How can I do this operation with float point and take up less FLASH program?
:=
:=thank you
___________________________
This message was ported from CCS's old forum
Original Post ID: 7757
TSchultz



Joined: 08 Sep 2003
Posts: 66
Location: Toronto, Canada

View user's profile Send private message

RE: float point
PostPosted: Tue Oct 15, 2002 6:39 am     Reply with quote

:=How accurate does ppm need to be?
:=
:=
:=How much of an error can you live with?
:=
:=with a 0\% error, then
:= ppm=(i-205)*0.244200244*10;
:=
:= ROM used: 263 (3\%)
:= Largest free fragment is 2048
:= RAM used: 15 (9\%) at main() level
:= 28 (16\%) worst case
:=
:=with a 2.3\% error, then
:= ppm=(i-205)*10/4;
:= ROM used: 64 (1\%)
:= Largest free fragment is 2048
:= RAM used: 12 (7\%) at main() level
:= 16 (9\%) worst case
:=
:=with a 0.08\% error, then
:= ppm=(i-205)*61/25;
:= ROM used: 108 (1\%)
:= Largest free fragment is 2048
:= RAM used: 12 (7\%) at main() level
:= 17 (10\%) worst case
:=
:=with a 1.7\% error, then
:= ppm=(i-205)*12/5;
:= ROM used: 108 (1\%)
:= Largest free fragment is 2048
:= RAM used: 12 (7\%) at main() level
:= 17 (10\%) worst case
:=
:=
:=
:=You will have to make sure that (i-205) does not overflow if you use one of the examples. Multiplying by 61 or 12 could cause you to overflow. Also note that your final result is an integer so the error might be less than you expect.
:=
:=Regards,
:=Mark
:=
:=:=I use the PIC16F877.
:=:=I must do the following expression:
:=:=
:=:=long i,ppm;
:=:=
:=:=ppm=(i-205)*0.244200244*10;
:=:=
:=:=but this operation take up so much FLASH program.
:=:=How can I do this operation with float point and take up less FLASH program?
:=:=
:=:=thank you

You could also get a 0.18\% error and drop the division if you tried;

ppm=(i-205)*39/16

The divide by 16 could be done using a shift saving precious code space and CPU time.

Like before though this does assume that the value of i is alsways small enough to be multiplied by 39 without causing an overflow.

- Troy
___________________________
This message was ported from CCS's old forum
Original Post ID: 7836
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