View previous topic :: View next topic |
Author |
Message |
enrico Guest
|
float point |
Posted: Fri Oct 11, 2002 6:08 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Sherpa Doug Guest
|
Re: float point |
Posted: Fri Oct 11, 2002 6:50 am |
|
|
:=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 |
|
![](templates/subSilver/images/spacer.gif) |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
Re: float point |
Posted: Fri Oct 11, 2002 4:16 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
TSchultz
Joined: 08 Sep 2003 Posts: 66 Location: Toronto, Canada
|
RE: float point |
Posted: Tue Oct 15, 2002 6:39 am |
|
|
:=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 |
|
![](templates/subSilver/images/spacer.gif) |
|