Once your altimeter has measured the pressure using its sensor, and brought your rocket safely to the ground, then you want to know how high it went. It can take some time for the data to be downloaded and maybe the unit isnt even a recording unit so there is nothing to download. That is where reporting of altitude after launch comes into play. The biggest issue with this is that it is generally too much work to have the altimeter calculate altitude.
As an example here is the formula for calculating altitude from a 12bit
ADC:
where ADC is the ADC value and ALT is the altitude value
ALT=((((((ADC * 0.0012207) - 0.204) / 0.0459 + 15) * 0.14504) / 14.696) ^ (1 / 5.255876) - 1) * -145442
This appears to be a bit much for an altimeter. To that end I was trying to find a better way and I heard rumor of people using lookup tables. Here is my implementation.
Ya, or something like that.
I started with the above formula in Excel and
I added some columns to it so I could generate the lookup tables required. I
wound up with two tables, one with 14 entries of 16bits and one with 14 entries
of 8bits each.
This is the table I came up with:
| # | Altitude table | Coefficient table | DAC values | Estimated altitude | Calculated altitude |
| E | -1220 | 7 | 0xE80 | -324 | -310.8301139 |
| D | 623 | 7 | 0xD80 | 1519 | 1583.389785 |
| C | 2571 | 8 | 0xC80 | 3595 | 3590.119668 |
| B | 4640 | 8 | 0xB80 | 5664 | 5725.487469 |
| A | 6847 | 9 | 0xA80 | 7999 | 8009.522096 |
| 9 | 9214 | 9 | 0x980 | 10366 | 10467.55454 |
| 8 | 11771 | 10 | 0x880 | 13051 | 13132.32121 |
| 7 | 14555 | 11 | 0x780 | 15963 | 16047.24459 |
| 6 | 17616 | 13 | 0x680 | 19280 | 19271.79385 |
| 5 | 21025 | 15 | 0x580 | 22945 | 22890.76389 |
| 4 | 24885 | 17 | 0x480 | 27061 | 27031.56561 |
| 3 | 29357 | 20 | 0x380 | 31917 | 31899.75662 |
| 2 | 34710 | 26 | 0x280 | 38038 | 37862.8104 |
| 1 | 41465 | 36 | 0x180 | 46073 | 45693.94198 |
Here is the formula to calculate altitude:
Altitude value =
0xC80
u = ADC upper
byte =0xC
l = ADC lower byte = 0x80
A[]=Altitude table from
above
C[]=Coeffiecient table from above
ALT = (C[u] * l)+A[u]
This yields:
3595=(8*128)+2571
This value of 3595 is within 5feet of the calculated value of 3590.1.
To
me this is acceptable and if I want higher accuracy in the calculation I will
download the values and use the PC.
When I went to incorporate this into the PIC the C compiler could only handle 8bit arrays. Ok fine so I made an array for the upper byte and one for the lower byte. Upon inspection I found that I can use the upper byte only to create the coeffiecient.
That saves some code space. Just subtract two eight bit values and you have
the coeffiecient requred.
The current equation is:
AU[]=Altitude table upper byte
AL[]=Altitude table lower byte
u = ADC
upper byte =0xC
l = ADC lower byte = 0x80
alt=((AU[u-1]-AU[u])*l)+(AU[u]<<8)+AL[u]
So with a DAC value of 0xC80 we get:
3590=((0x12-0xA)*0x80)+0xA00+0x6
Of course the bitshift 8(AU[u]<<8) wont be needed since I can just copy that value into the upper byte.