' ********************************************************************** ' ** Altimeter software, V1.01, 15 Nov 01 ** ' ** ** ' ** When altimeter is switched on, the user has thirty seconds to ** ' ** put the switch into the desired position (if it isn't already). ** ' ** 1) LAUNCH: ** ' ** Waits five minutes, to allow for getting the altimeter into the ** ' ** rocket, getting the rocket onto the launch pad, etc. It then ** ' ** takes 10 readings at ground level, and waits for lift-off to be ** ' ** detected. It then takes readings until the external EEPROM is ** ' ** full. Five minute countdown can be aborted by moving switch back ** ' ** to STAND-BY. ** ' ** 2) STAND-BY: ** ' ** Do nothing, until a switch is altered. ** ' ** 3) TRANSMIT: ** ' ** Transmit data held in both internal and external EEPROM via ** ' ** RS232. ** ' ********************************************************************** DEFINE OSC 20 ' 20MHz oscillator DEFINE DEBUG_REG PORTB DEFINE DEBUG_BIT 5 ' Serial output pin is RB5 DEFINE DEBUG_BAUD 9600 DEFINE DEBUG_MODE 1 ' Standard serial output INCLUDE "modedefs.bas" ' *** Pin definitions *** ADC_CS var PORTB.1 ' adc chip select pin ADC_SCLK var PORTB.0 ' adc serial clock pin ADC_DATAOUT var PORTB.2 ' adc data out pin ADC_DATAIN var PORTB.3 ' adc data in pin G_SWITCH var PORTA.3 ' g-switch pin SWITCH1 var PORTA.2 ' launch mode switch pin SWITCH3 var PORTA.4 ' download flight data switch pin EEPROM_SCLK var PORTA.0 ' eeprom serial clock pin EEPROM_DATA var PORTA.1 ' eeprom serial data pin LED var PORTB.6 ' LED pin ' *** Variable definitions *** channel var byte ' adc channel adc_value var word ' value read from adc int_address var byte ' internal eeprom address ext_address var word ' external eeprom address eepromdata var byte ' data to be sent to or read from eeprom i var word ' general purpose loop counter ' *** Constant definitions *** BARO con 142 ' MPX4115 on CH0 XL con 206 ' ADXL190 on CH1 TEMP con 254 ' AD22100 on CH7 EEPROM_READ con %10100001 ' Control codes for external EEPROM_WRITE con %10100000 ' I2C eeprom R/W operations ' *** Main Program *** ' Flash LED for 30s for i=1 to 60 high LED pause 250 low LED pause 250 next i check_switch_status: if SWITCH1 then begin_countdown if SWITCH3 then transmit_data goto check_switch_status begin_countdown: sleep 300 ' wait 5 minutes to get altimeter ' in rocket, rocket on pad, etc... ' ***ABORT*** if (SWITCH1 = 0) AND (SWITCH3 = 0) then check_switch_status ' *** Read and store ground level data prior to launch in internal eeprom int_address = 0 for i=1 to 10 ' 10 readings per channel; could be increased when using ' 16F628 because of increased internal EEPROM memory channel = BARO gosub Read_ADC gosub Store_Ground_Data channel = XL gosub Read_ADC gosub Store_Ground_Data channel = TEMP gosub Read_ADC gosub Store_Ground_Data next i ' *** Wait for lift-off high LED ' LED lights to indicate ' altimeter is armed. wait_for_launch: if G_SWITCH=0 then wait_for_launch ext_address = 0 ' *** Read and store flight data launch_detected: for i=1 to 5461 channel = BARO gosub Read_ADC gosub Store_Flight_Data channel = XL gosub Read_ADC gosub Store_Flight_Data channel = TEMP gosub Read_ADC gosub Store_Flight_Data toggle LED pause 7 ' 0.007seconds - should give sample rate of 25Hz next i low LED end ' eeprom is full; switch off. ' *** Send data out serial port transmit_data: ' *** ground level data int_address = 0 for i = 1 to 10 read int_address, adc_value.highbyte int_address = int_address + 1 read int_address, adc_value.lowbyte int_address = int_address + 1 debug dec adc_value, 9 read int_address, adc_value.highbyte int_address = int_address + 1 read int_address, adc_value.lowbyte int_address = int_address + 1 debug dec adc_value, 9 read int_address, adc_value.highbyte int_address = int_address + 1 read int_address, adc_value.lowbyte int_address = int_address + 1 debug dec adc_value, 13 next i debug 13 ' *** flight data ext_address = 0 for i=1 to 5461 gosub Read_EEPROM adc_value.highbyte = eepromdata ext_address = ext_address + 1 gosub Read_EEPROM adc_value.lowbyte = eepromdata ext_address = ext_address + 1 debug dec adc_value, 9 gosub Read_EEPROM adc_value.highbyte = eepromdata ext_address = ext_address + 1 gosub Read_EEPROM adc_value.lowbyte = eepromdata ext_address = ext_address + 1 debug dec adc_value, 9 gosub Read_EEPROM adc_value.highbyte = eepromdata ext_address = ext_address + 1 gosub Read_EEPROM adc_value.lowbyte = eepromdata ext_address = ext_address + 1 debug dec adc_value, 13 toggle LED next i low LED end ' eeprom data is downloaded; switch off. ' ****************************************** ' ** Subroutines ** ' ****************************************** Read_ADC: low ADC_CS shiftout ADC_DATAOUT, ADC_SCLK, MSBFIRST, [channel] shiftin ADC_DATAIN, ADC_SCLK, MSBPOST, [adc_value\12] high ADC_CS return Store_Ground_Data: write int_address, adc_value.highbyte int_address = int_address + 1 write int_address, adc_value.lowbyte int_address = int_address + 1 return Store_Flight_Data: eepromdata = adc_value.highbyte gosub Write_EEPROM ext_address = ext_address + 1 eepromdata = adc_value.lowbyte gosub Write_EEPROM ext_address = ext_address + 1 return Write_EEPROM: i2cwrite EEPROM_DATA, EEPROM_SCLK, EEPROM_WRITE, ext_address, [eepromdata] pause 5 return Read_EEPROM: i2cread EEPROM_DATA, EEPROM_SCLK, EEPROM_READ, ext_address, [eepromdata] pause 5 return