PDA

View Full Version : A fun math problem



Tom Gonser
- 12th June 2005, 20:54
meters = 44330.769 * (1 - (Millibars / 1013.25) ^ 0.190262525939031)

This converts millibars in pressure to meters given a simple atmosphere. Since the PIC does not have FP, and this point REALLY floats, how can a PIC do this?

Or can it at all? If we were just dealing with .xxx, then you could x1000, but we are dealing with .xxxxxxxxxxxxx!! Do we just multiply by 100000000000 I don't think so.

The accuracy to 15 decimal places is needed because of the very small pressure movements inpact on estimated altitude.

Hmmm...

mister_e
- 12th June 2005, 23:24
My simple solution, do a spread sheet and store the results in a external EEPROM. Once it`s done just reading the results from the EEPROM.

YEAH i can heard some here ;) It's just an idea not the only one.

Tom Gonser
- 12th June 2005, 23:32
Except that I need to do this every time I get a new MB reading which can be as fast as 100ms....

mister_e
- 12th June 2005, 23:53
and then??? reading from a eeprom is really much faster than this.

Once the spread sheet is created and loaded into the EEPROM, you just need to read the results from. The longer part of the job will be to produce the spread sheet and load it to the EEPROM.

But if you have some VB programming ability, that will make things easy. In VB you can create your own .BIN file with your own format. Once it's done, you have two(or more) choice:

use your favourite EEPROM programer to dump the file to your EEPROM
create a VB program to send data to your PIC, then from your PIC to your EEPROM

Personnaly, i'll prefer the second one if the hardware permit to do it.

Tom Gonser
- 13th June 2005, 00:19
OK.. I guess I am not tracking..

How does one load a VB program into a PIC? I was under the impression the only things that could execute on a PIC were compiled code from PBP or some such compiler. I'd be VERY interested to know how I could load other things into a PIC or EEPROM or whatever.

I have the spreadsheet (Attached) It is very simple. If it is easier I am sure I can make a .BIN file using VB..

Very curious...

mister_e
- 13th June 2005, 02:55
i wasn't clear enough sorry. What i figure is to do a VB program wich will do the the whole calculation for you with a specified range and increment of Millibar or Meter value. Once the calculation are done, this program will store all result in a .BIN file. Once the file is created and saved to your hard disk, you use your EEPROM programmer to load this .BIN file into an external EEPROM attach to your PIC.

After that, your PIC will just need to read the value of the calculation to your EEPROM by using the millibar variable as a kind of 'EEPROM address pointer'

For sure a PIC can't run a VB program. But you can do a VB program that will communicate to your PIC via the COM port.

what is the range of your millibar value?
How many decimal you want to have in the result???

If you need any info about VB let me know in PM.

Tom Gonser
- 13th June 2005, 05:02
Oh, I see.

There is no PC connected to the unit, so there is no way to compute this. The PIC has to do all the work, and transmit the converted MB to Meters or Feet....

Darrel Taylor
- 13th June 2005, 06:13
Maybe I can try to translate from Canadian to English. (Just kidding Steve)

Steve's idea is to pre-calculate every value before hand using the PC. It could be done with VB or you could do it in excel if you wanted. Those values are then stored in an external eeprom as one great big look-up table.

Then later when the pic is running, when it needs to convert the numbers, it doesn't have to do any calculations. Just look up the answer from the eeprom. The PC doesn't need to be hooked up to the PIC during normal operation.

Assuming you wanted a range of 600-1100 milibars with 1 decimal place, you could store the whole thing in a 16kbyte eeprom. If you needed 2 decimals it would take a 128kbyte eeprom (yikes).

To calculate the given formula in real time, you would need at least 48-bit math (due to the decimals requested) so there really aren't many other options.

I even tried a 3rd order Power Polynomial formula to try to approximate the numbers, and it came up with an error of +/- 100 feet at the high and low ends. (Not too good)

HTH,
   Darrel

Tom Gonser
- 13th June 2005, 06:34
Now I get it!

Thanks folks for helping me see the options here. Since the number of feet between 0 and 30,000 would require me to store 30,000 locations, this does not seem feasable on a PIC.

I now understand how it would work however, and options might be to store 3000 locations and increment every 10, etc. However, for this application I think I will chalk it up to 'not in scope'..

Thanks,

Tom

Darrel Taylor
- 13th June 2005, 06:48
Not quite yet.

You would be storing them according to millibars not feet.

With a range of 600.0 to 1100.0 there are 5000 locations. Each value uses 2 bytes' for a total of 10,000 bytes.

If the range is 2 decimals 600.00 to 1100.00 there are 50,000 locations that would require 100kbytes.

Definately "Within Scope".

Don't give up yet.

Darrel

Ingvar
- 13th June 2005, 12:01
Hi Tom,

Ihelped a guy named Steve Turner once, he had the same problem. Since he made a pretty good job of explaining his project on his site, i will not do it again. Just follow this link .....

http://www.steveonweb.com/alt.php

/Ingvar