' {$STAMP BS2pe} ' {$PBASIC 2.5} ' {$PORT COM5} '*********************************** '* Near Space Easy Pin Definitions * '*********************************** LCD CON 0 CS CON 1 DIO CON 2 CLK CON 3 Commit CON 4 S1 CON 5 S2 CON 6 S3 CON 7 GPS CON 8 MicroTrak CON 9 D6 CON 10 D5 CON 11 D4 CON 12 D3 CON 13 D2 CON 14 D1 CON 15 '*********************************** '* Near Space Easy Variables * '*********************************** SkipBanks CON 0 ' skip recording in these banks, there's data/table is stored in them GPSAltitude CON 1 ' 0 means gps altitude not recorded, 1 means gps Altitude recorded GPSTime CON 1 ' 0 means gps time not recorded, 1 means gps time recorded Analogs CON 0 ' number of analog sensors on mission Digitals CON 0 ' number of digital instruments needing data recorded Message CON 1 ' 0 means no message logged, 1 means a message is logged MissionWait CON 60000 ' pause (in ms) between getting data HighResAltitude CON 25300 ' secondary mt beacon high altitude LowResAltitude CON 500 ' secondary mt beacon low altitude LCDInstruction CON 254 ' instruction to lcd command LCDClear CON 1 ' clear the lcd command LCDLine1 CON 128 ' write at lcd line 1 command LCDLine2 CON 192 ' write at lcd line 2 command N2400 CON 16780 ' 2400 baud true logic (lcd) I4800 CON 16572 ' 4800 baud inverted logic (gps) Record VAR Word ' number of data records recorded Flights VAR Record ' record variable borrowed for just a moment MaxAltitude VAR Word ' maximum altitude reached WordVariable VAR Word ' general use word-size variable ByteVariable VAR Byte ' general use byte-size variable Index VAR Byte ' general use counting variable MemoryBanks VAR Index ' number of memory banks required to save data MemoryBank VAR Nib ' memory bank currently being written to MaxAnalog VAR Nib ' number of analog channels being used Below10k VAR Bit ' 0 = above 10,000 ft, 1 = below 10,000 ft GoodGPS VAR Bit ' 0 = no GPS data, 1 = getting GPS data Ascent VAR Bit ' 0 = in descent, 1 = in ascent '*********************************** '* Near Space Easy Program * '*********************************** NearSpace_Easy: GOSUB PreFlight Wait_for_Commit: GOSUB GetAltitude IF GoodGPS THEN SEROUT LCD,N2400,[LCDInstruction,LCDClear] SEROUT LCD,N2400,["Waiting"] SEROUT LCD,N2400,[LCDInstruction,LCDLine2] SEROUT LCD,N2400,["GPS Operating"] IF IN4 = 1 THEN Launch GOTO Wait_for_Commit ELSE GOSUB BadGPS GOTO Wait_for_Commit ENDIF Launch: SEROUT LCD,N2400,[LCDInstruction,LCDClear] Record = 0 GOSUB GetAltitude IF GoodGPS THEN MaxAltitude = WordVariable GOTO Mission ELSE GOSUB BadGPS PAUSE 10000 ENDIF Mission: IF Record < 2047 THEN Record = Record + 1 ' increment the number of recorded records MemoryBank = SkipBanks ' start recording data in the first available memory bank GOSUB Altitude ' get the gps altitude STORE 0 IF GoodGPS = 0 THEN ' if the gps has failed GOSUB GPSEmergency ' gps emergency ELSE ENDIF GOSUB Time ' get the gps time 'IF Below10k THEN SEROUT LCD,N2400,[LCDInstruction,LCDLine1] SEROUT LCD,N2400,["Record: ", DEC Record] SEROUT LCD,N2400,[LCDInstruction,LCDLine2] SEROUT LCD,N2400,["MaxAlt: ", DEC MaxAltitude, " m"] 'ELSE ' SEROUT LCD,N2400,[LCDInstruction,LCDClear] 'ENDIF GOSUB Analog GOSUB Digital IF ascent THEN ' if still ascending ByteVariable = "A" ' write a message of A ELSE ' if not still ascending ByteVariable = "D" ' write a message of D ENDIF GOSUB RecordData ' store the message STORE 0 WRITE 7,Record ' update of completed records recorded PAUSE MissionWait GOTO Mission ELSE ' finished recording 2k of records GOTO End_Mission ENDIF '*********************************** '* Near Space Easy Subroutines * '*********************************** PreFlight: HIGH MicroTrak ' transmit packets at primary rate HIGH CS Below10k = 1 Ascent = 1 STORE 0 READ 0, Flights ' update number of missions this hitchiker has flown Flights = Flights + 1 WRITE 0,Flights WRITE 1,SkipBanks WRITE 2,GPSAltitude ' indicate if a gps altitude is recorded WRITE 3,GPSTime ' indicate if gps time is recorded WRITE 4,Analogs ' number of analog experiments on this mission WRITE 5,Digitals ' number of digital experiments on this mission WRITE 6,Message ' indicates if a message is logged Experiment_PreFlight: RETURN BadGPS: SEROUT LCD,N2400,[LCDInstruction,LCDClear] SEROUT LCD,N2400,["No GPS"] RETURN Altitude: IF GPSAltitude THEN GOSUB GetAltitude IF GoodGPS THEN ByteVariable = WordVariable.BYTE1 GOSUB RecordData ByteVariable = WordVariable.BYTE0 GOSUB RecordData IF WordVariable > 3050 THEN ' if above 10k feet Below10k = 0 ' set bit saying above 10k feet ELSE ' or else Below10k = 1 ' set bit saying above 10k feet ENDIF IF WordVariable > (MaxAltitude + 50) THEN ' if higher than last altitude by 50 MaxAltitude = WordVariable ' update new maximum altitude Ascent = 1 ' and update ascent to rising IF WordVariable > HighResAltitude THEN ' if altitude above fast beacon altitude LOW MicroTrak ' switch to secondary microtrak beacon ELSE ' or if below fast beacon altitude HIGH MicroTrak ' switch to primary microtrak beacon ENDIF ELSE ' if not 50 m above highest recorded altitude Ascent = 0 ' set ascent bit to descend IF WordVariable < LowResAltitude THEN ' if near landing altitude LOW MicroTrak ' turn on secondary microtrak beacon ELSE ' if above near landing altitude HIGH MicroTrak ' turn off secondary microtrak beacon ENDIF ENDIF ELSE ' bad GPS ByteVariable = 0 GOSUB RecordData ByteVariable = 0 GOSUB RecordData ENDIF ELSE ' altitude not recorded ENDIF RETURN GetAltitude: GoodGPS = 1 SERIN GPS,I4800,10000,GPSError,[WAIT ("GGA"),SKIP 42, DEC WordVariable] 'Etrex GPS settings GOTO GetAltitudeReturn GPSError: GoodGPS = 0 GetAltitudeReturn: RETURN Time: IF GPSTime THEN SERIN GPS,I4800,10000,NoTime,[WAIT ("GGA"),SKIP 5, DEC2 ByteVariable] 'Etrex GPS settings GOTO RecordTime NoTime: ByteVariable = 0 RecordTime: GOSUB RecordData ELSE ENDIF RETURN Analog: FOR Index = 1 TO Analogs LOOKUP Index,[%00000,%11000,%11100,%11001,%11101,%11010,%11110,%11011,%11111],ByteVariable LOW CLK LOW CS SHIFTOUT DIO, CLK, 1, [ByteVariable\5] SHIFTIN DIO, CLK, MSBPOST, [ByteVariable\8] HIGH CS GOSUB RecordData NEXT RETURN Digital: Geiger: COUNT D1,10000,ByteVariable GOSUB RecordData End_Digital: RETURN RecordData: MemoryBank = MemoryBank + 1 STORE MemoryBank WRITE Record,ByteVariable RETURN GPSEmergency: RETURN End_Mission: END