'******************************************************* '* Test code for Near Space UltraLight Flight Computer * '* L. Paul Verhage 21 June 2009 * '* * '******************************************************* symbol MissionPause = 5000 ' pause during mission loop symbol UsedAnalogs = 4 ' number of analog channels used symbol Reserved0 = W0 ' DON'T USE symbol Reserved1 = W1 ' DON'T USE symbol Reserved2 = W2 ' DON'T USE symbol Reading = W3 ' result from data collecting symbol Record = W4 ' address to store next byte in memory symbol RecNum = W5 ' record number - indicates start of new record symbol Index = B12 ' loop counter W6 symbol GPS_Check = B13 ' number of bad gps readings W6 symbol Analog_Channel = B14 ' sets the analog channel of current reading W7 Begin: pause 1000 ' settle down time RecNum = 100 ' set to 100 to maintain three digits hsersetup b4800_4,%00 ' setup hardware serial input for gps i2cslave %10100000,i2cfast,i2cword ' set memory speed to 400 kHz and one word records if pin6 = 1 then Download ' downoad data if commit pin is not in place Record = 0 ' start at memory address zero Wait_to_Commit: if pin6 = 0 then Wait_to_Commit ' wait for commit pin to be pulled BalloonSat_UltraLight: if Record > 4091 then End_BalloonSat_UltraLight' go to max memory gosub Record_Number GPS_Check = 1 gosub GPS gosub Analog gosub Digital gosub Cameras ' gosub Servos pause MissionPause goto BalloonSat_UltraLight Record_Number: ' store record number Reading = RecNum gosub Store_Data RecNum = RecNum + 1 return GPS: ' dump a gps gga sentence into scratch pad hserin [4000,Bad_GPS],0,1,("L") hserin [4000,Bad_GPS],0,1,("B") hserin [4000,Bad_GPS],0,1,("C") hserin [4000,Bad_GPS],0,1,("W") hserin [4000,Bad_GPS],0,61,("A") Scan_GPS: ' confirm it's a good sentence by finding the M for Index = 40 to 55 get Index,b0 if b0 = "M" then Confirm_Altitude_Fix next if GPS_Check = 5 then Bad_GPS GPS_Check = GPS_Check + 1 goto GPS Confirm_Altitude_Fix: ' go back two characters and makes sure there's altitude data Index = Index - 2 get Index,b0 if b0 = "," then GPS Get_Time: ' in minutes/seconds get 3,b0,b1,b2,b3 b0 = b0 - 48 Reading = b0 Reading = Reading *10 b1 = b1 - 48 Reading = Reading + b1 Reading = Reading * 10 b2 = b2 - 48 Reading = Reading + b2 Reading = Reading * 10 b3 = b3 - 48 Reading = Reading + b3 gosub Store_Data ' store time stamp Get_Altitude: ' in meters get 42,b0,b1,b2,b3,b4,b5 b0 = b0 - 48 Reading = b0 if b1 = 46 then Altitude_Done b1 = b1 - 48 Reading = Reading * 10 Reading = Reading + b1 if b2 = 46 then Altitude_Done b2 = b2 - 48 Reading = Reading * 10 Reading = Reading + b2 if b3 = 46 then Altitude_Done b3 = b3 - 48 Reading = Reading * 10 Reading = Reading + b3 if b4 = 46 then Altitude_Done b4 = b4 - 48 Reading = Reading * 10 Reading = Reading + b4 Altitude_Done: ' store altitude data gosub Store_Data return Bad_GPS: ' record XX's if good data can't be found for Index = 1 to 2 B6 = "X" B7 = "X" gosub Store_Data next return Analog: ' get analog voltages for Index = 1 to UsedAnalogs Analog_Channel = Index - 1 readadc10 Analog_Channel,Reading gosub Store_Data ' store analog voltages next return Digital: ' do digital experient count 2,10000,Reading gosub Store_Data ' store results return Servos: ' do the servos trick servo 0,100 pause 1000 servo 0,200 return Cameras: ' tourist - take some pictures high 3 pause 1500 low 3 ' high 4 ' pause 1500 ' low 4 return Store_Data: low 2 ' un-write protect memory writei2c Record,(B6,B7) pause 10 Record = Record + 2 high 2 return Download: sertxd ("Start,") for Record = 0 to 4091 step 2 readi2c Record,(B6,B7) sertxd (#Reading, ",") next End_BalloonSat_UltraLight: end