Listing 1—This is ZSAT II’s
main control loop. Launch Detect is determined when the accelerometer output goes
above a hex value of 0x5A.
*******************************************************************
Wait for "Launch" control loop
*******************************************************************
if (go_for_launch) //Flag set by Palm IrDA port - "Arm for Flight"
{
*******************************************************************
Get ground reference
*******************************************************************
//Pressure on ADC 0
//ACC X (up) on ADC 1
//ACC Y (Side) on ADC 2
read_save_allsensor_data(0); //Get base line start save at
//address 0
//Save four bytes
do
{
ACTL = 0xA1; //Start channel 1 conversion ACC X
while (ACTL & 0x80); //Wait for conversion to complete data_hi = ADHR; //Read X data
}
while(data_hi <= 0x5A); //Wait for launch detect
*******************************************************************
We have Launch Detect
*******************************************************************
PAO |= 0x02; //Turn on LED
//Launch
addr_loc =4; //Next address to save at
do
{
ACTL = 0xA0; //Start channel 0 conversion
while (ACTL & 0x80);
data_hi = ADHR;
set_spi_wr_en();
SPI_Write(data_hi,addr_loc);
read_spi_status();
do
{
read_spi_status();
}while (spistatus & 0x01);
addr_loc++;
ACTL = 0xA1; //Start channel 1 conversion
while (ACTL & 0x80);
data_hi = ADHR;
set_spi_wr_en();
SPI_Write(data_hi,addr_loc);
read_spi_status();
do
{
read_spi_status();
}while (spistatus & 0x01);
addr_loc++;
}while(addr_loc <= 0x3FFF); //Keep reading pressure until
//memory is full
PAO &= 0x0D; //Turn off LED, memory full
go_for_launch = 0; //Tell upper layers flight is over
}
}