Searching \ for '[PIC]: Can you crack this formula with a PIC ?' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/devices.htm?key=pic
Search entire site for: 'Can you crack this formula with a PIC ?'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: Can you crack this formula with a PIC ?'
2000\10\26@131127 by Darren Logan

picon face
It's a formula to calculate water vapour pressure given a temperature in Deg C

float calculateWaterWVP(float Temp)
{
   float a,tempInK,c,d,e,wvp;

   tempInK = Temp + 273.15;
   a = -6096.9385 * (1/tempInK);
   c = -2.711193 * 0.01 * tempInK;
   d = 1.673952 * 0.00001 * (tempInK * tempInK);
   e = 2.433502 * (log(tempInK)/log(10)/0.434294509);


   wvp = exp(a + 21.2409642 + c + d + e);
   return wvp;

}  */

If you can do this, you get a medal !

(Accuracy of result = 1% or better)

Regards,
Darren

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.




2000\10\26@150110 by Spehro Pefhany

picon face
At 01:08 PM 10/26/00 EDT, you wrote:
>It's a formula to calculate water vapour pressure given a temperature in
Deg C
{Quote hidden}

How nonlinear is this function OVER THE RANGE OF INTEREST?

How much resolution do you need (for display, it may be unacceptable
to have poor resolution, even if the accuracy is ok)?

Since this is a SISO function of temperature, I'd be tempted to use
either a lookup table with linear interpolation or a polynomial fit to
the analytical function above. Using 16-32 bit fixed point integer
math, depending.

Best regards,


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Spehro Pefhany --"it's the network..."            "The Journey is the reward"
spam_OUTspeffTakeThisOuTspaminterlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com
Contributions invited->The AVR-gcc FAQ is at: http://www.bluecollarlinux.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.




2000\10\26@192954 by James Korman

flavicon
face
> How nonlinear is this function OVER THE RANGE OF INTEREST?
Very non-linear, exponential!

Try this instead

This one for temps above freezing. Note temps in Cel.
VaporPressure := 6.11*Power(10,(T*7.5)/(T+237.3))

this one for temps below freezing IF you want the frost point!
VaporPressure := 6.11*Power(10,(T*9.5)/(T+265.5))

These are pretty good over the meteorlogical range of temps (-40 to 50
Cel.)

BTW, the vapor pressure is no better than the accuracy of the
temperature
measurement!

Jim Korman

Spehro Pefhany wrote:
{Quote hidden}

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.




2000\10\27@151125 by Peter L. Peres

picon face
Hi,

I was impressed by HiTech C's compilation of this. But.

1% is doable with 8 bits, i.e. table output can be on 8 bits. Input
accuracy does not relate to this linearly however. In particular you lose
precision in the log operation. So your input precision could be 10% to
obtain output 1% under certain circumstances.

On the other hand, I'd run the little program:

for(temp = MIN_TEMP; temp <= MAX_TEMP; temp += TEMP_STEP)
 printf("%-10f\t%-10f\n",i,calculateWaterWVP(temp));

to obtain a pretty table that will speak volumes about what you need to
do. You can modify the program to calculate the (output) table values
themselves and to obtain the required input precision for each table
domain (the precision will vary because of your nonlinear dependency -
esp. the log operation). The easiest way to do this is to have a variable
float temp0 = MIN_TEMP-1; and for each calculated value display only if
the reduced (to 1%) value is different from temp0, then set temp0 so the
calculated temp. This will remove all the intermediary results from the
table, giving the domain boundaries for the table.

In the end you will likely end up with a table that may be largish
depending on your temperature domain or use several interpolation points,
as Scott has said. This being said, maybe you need to purchase HITECH C ?
;-)

Peter

PS: I do not work for them.
PS2: Of course you run this on a PC not on a PIC.

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
use listservspamKILLspammitvma.mit.edu?body=SET%20PICList%20DIGEST




More... (looser matching)
- Last day of these posts
- In 2000 , 2001 only
- Today
- New search...