Code:
DEFINE OSC 20
INCLUDE "DT_Analog.pbp" ; DT's 16-bit Analog Module
DEFINE ADC_BITS 10 '10 BIT A/D CONVERSION RESULT
DEFINE ADC_CLOCK 2 '
DEFINE ADC_SAMPLEUS 5 'SET SAMPLE TIME IN MICROSECONDS
CMCON = 7 'TURN COMPARATORS OFF
TRISIO = %000100 'Set GSIO 0 INPUTS, others to OUTPUT
ANSEL = %00100100 '
ADCON0.7 = 1 'Right Justify for 10-bit
ADCON0 = %10001001
ADbits = 14 ; set to 14-bit resolution
DEFINE DEBUG_REG GPIO
DEFINE DEBUG_BIT 0
DEFINE DEBUGIN_BIT 1
DEFINE DEBUG_BAUD 2400
DEFINE DEBUG_MODE 0
ALTresult var word 'lookup table output
tempALT var word 'base altitude of lookup from table
ADtemp var byte 'lookup table input
ALTdifference var word 'difference of two nearby altitudes
finalALT var word 'final calculated altitude in feet
;---------------------------------------------------------------------------
Main:
ADchan = 2 ; Do only AN2 channel
GOSUB GetADC ; Get A/D value
ADtemp = (ADvalue/100) - 60 ' get to table acceptable value for lookup
gosub lookmeup
tempALT = ALTresult 'save first result for use in math
ADtemp = ADtemp - 1 'run another lookup for nearby altitude for diff calc
gosub lookmeup
ALTdifference = ALTresult - tempALT 'get difference in nearby alt
finalALT = tempalt - (((ADvalue//100)* ALTdifference)/100)
'use difference to calculate slope & adjust altitude accordingly
debug "Alt= ",DEC finalALT," A/D= ",DEC ADvalue," "
pause 1000
GOTO Main:
End
lookmeup:
lookup2 ADtemp,[_
17646,17327,17011,16699,16389,16083,15780,15480,15183,14888,14597,14308,14022,_
13739,13458,13179,12903,12630,12359,12090,11823,11559,11297,11037,10779,10524,_
10270,10018,9769,9521,9275,9031,8789,8549,8310,8074,7838,7605,7373,7143,6915,_
6688,6463,6239,6017,5796,5577,5359,5143,4928,4715,4502,4292,4082,3874,3667,_
3462,3257,3054,2852,2652,2452,2254,2057,1861,1666,1472,1280,1088,898,708,520,_
332,146],ALTresult
return
Bookmarks