'*** KPA II *** '*** PicAxe 08M *** '*** Memory $50 (80) to $7F (127) '*** Pin | Function '*** ----+---------- '*** 1 | +5V '*** 2 | SerialIn '*** 3 | In4, Out4, ADC4 '*** 4 | In3, InfraIn '*** 5 | In2, Out2, ADC2, PWM2, Tune '*** 6 | In1, Out1, ADC1 '*** 7 | Out0, SerialOut, InfraOut '*** 8 | 0V (ground return) '*** PicAxe 18X *** '*** Memory $50 (80) to $7F (127), and $C0 (192) to $EF (239) '*** Pin | Function '*** ----+---------- '*** 1 | In2, ADC2 '*** 2 | Serial Out '*** 3 | Serial In '*** 4 | Reset '*** 5 | 0V (ground return) '*** 6 | Out0 '*** 7 | Out1, I2C-SDA '*** 8 | Out2 '*** 9 | Out3, PWM3 '*** 10 | Out4, I2C-SCL '*** 11 | Out5 '*** 12 | Out6 '*** 13 | Out7 '*** 14 | +5V '*** 15 | In6, KBD-CLK '*** 16 | In7, KBD-DAT '*** 17 | In0, ADC0, INFRAIN '*** 18 | In1, ADC1 '*** '*** readadc10 0, w0 loads down pin0!!!!! '*** Byte to Word Relationship *** '*** w0 = b1 : b0 '*** w1 = b3 : b2 '*** w2 = b5 : b4 '*** w3 = b7 : b6 '*** w4 = b9 : b8 '*** w5 = b11 : b10 '*** w6 = b13 : b12 '*** W0 (b1:b0) Break down *** '*** b0 = bit7: bit6: bit5: bit4: bit3: bit2: bit1: bit0 '*** b1 = bit15: bit14: bit13: bit12: bit11: bit10: bit9: bit8 '***************************************************************************************************** '***************************************************************************************************** '***************************************************************************************************** '*** Data Format is ... '*** SSSS|Count|,Altitude|,WindSpeed|,Temp|CRLF '*** Where '*** S = Synch Byte (sent four times) '*** Count = Record Number (Increments each Transmission) '*** Altitude = Raw Altitude Data '*** WindSpeed = Raw Wind Speed Data '*** Temp = Raw Temperature Data '*** CRLF = Carrage return/Line Feed '*** "," = Field Separator '*** '***------------------------------------------------------------------------------ '*** Would like to go to a system where the CPU sends the following Data four times... '*** "SSSS" " Sync Bytes '*** @"(A\d{5})" : Altitude '*** @"(B\d{5})" : Battery '*** @"(C\d{5})" : Count '*** @"(T\d{5})" : Temperature '*** @"(W\d{5})" : Wind Speed '*** CRLF : Carrage return/Line Feed '*** '***************************************************************************************************** '***************************************************************************************************** '***************************************************************************************************** #picaxe 18x #gosubs 255 #simspeed 0 '#terminal 600 '*** Addresses *** symbol STORE_COUNT_ADDRESS = $50 symbol STORE_ALTITUDE_ADDRESS = $52 symbol STORE_WINDSPEED_ADDRESS = $54 symbol STORE_TEMPERATURE_ADDRESS = $56 symbol STORE_RANDOM_ADDRESS = $58 symbol PP_STACK_POINTER = $EF '$EF down to (length_of_stack) is Reserved '*** Input Pins *** symbol BATTERY_SENSOR_PIN = 0 symbol ALTITUDE_SENSOR_PIN = 1 symbol WINDSPEED_SENSOR_PIN = 2 symbol WINDSPEED_LEVEL_PIN = pin2 symbol WINDSPEED_BIAS_MODE_PIN = pin7 symbol TEMPERATURE_SENSOR_PIN = 6 '*** Output Pins *** symbol XMITTER_PIN = 0 symbol WINDSPEED_LED_PIN = outpin1 symbol CAMERA_TRIGGER_PIN = 4 '*** Parameters *** symbol ALTITUDE_CYCLES = 63 '*** Normally 63 (for 0 to 63) symbol WINDSPEED_PERIOD = 10000 '*** Camera Parameters *** symbol CAMERA_TRIGGER_ON_PULSE = 145 symbol CAMERA_TRIGGER_OFF_PULSE = 170 symbol CAMERA_TRIGGER_PERIOD = 500 '*** Serial Port Parameters *** symbol BAUD_MODE = N600 '*** Valid = N/T 600/1200/2400/4800 symbol SYNC_BYTE = $55'$AA '*** Bits = 10101010 10101010 symbol SYNC_BYTE_COUNT = 4 symbol CR_BYTE = $0D symbol LF_BYTE = $0A symbol TRANSMIT_X_TIMES = 4 '***************************************************************************************************** '***************************************************************************************************** '***************************************************************************************************** Initialize: gosub Stack_Initialize servo CAMERA_TRIGGER_PIN, CAMERA_TRIGGER_OFF_PULSE pause 1000 low CAMERA_TRIGGER_PIN serout XMITTER_PIN, BAUD_MODE, (SYNC_BYTE, SYNC_BYTE, "KAP2 Controller Ready", CR_BYTE, LF_BYTE) sertxd (SYNC_BYTE, SYNC_BYTE, "KAP2 Controller Ready", CR_BYTE, LF_BYTE) '*** Initialize Counter *** w0 = 0 poke STORE_COUNT_ADDRESS, word w0 '***************************************************************************************************** Main: do '*** Loop if in Wind Speed Bias Mode *** do while WINDSPEED_BIAS_MODE_PIN = 0 WINDSPEED_LED_PIN = not WINDSPEED_LEVEL_PIN w0 = WINDSPEED_LEVEL_PIN serout XMITTER_PIN, BAUD_MODE, ("WS=", #w0 , CR_BYTE, LF_BYTE) sertxd (SYNC_BYTE, SYNC_BYTE, "WS=", #w0 , CR_BYTE, LF_BYTE) loop WINDSPEED_LED_PIN = 0 '*** Trigger Camera *** gosub Trigger_Camera '*** Increment Counter *** peek STORE_COUNT_ADDRESS, word w0 w0 = w0 + 1 poke STORE_COUNT_ADDRESS, word w0 '*** Measure Altitude *** gosub Measure_Altitude poke STORE_ALTITUDE_ADDRESS, word w0 '*** Measure WindSpeed *** gosub Measure_WindSpeed poke STORE_WINDSPEED_ADDRESS, word w0 '*** Measure Temperature *** gosub Measure_Temperature poke STORE_TEMPERATURE_ADDRESS, word w0 '*** Send Data four Times *** for w1 = 1 to TRANSMIT_X_TIMES '*** Send Synch Bytes *** for w2 = 1 to SYNC_BYTE_COUNT serout XMITTER_PIN, BAUD_MODE, (SYNC_BYTE) sertxd (SYNC_BYTE) next w2 '*** Send Count *** peek STORE_COUNT_ADDRESS, word w0 gosub Send_Data '*** Send Altitude *** serout XMITTER_PIN, BAUD_MODE, (",") sertxd (",") peek STORE_ALTITUDE_ADDRESS, word w0 gosub Send_Data '*** Send WindSpeed *** serout XMITTER_PIN, BAUD_MODE, (",") sertxd (",") peek STORE_WINDSPEED_ADDRESS, word w0 gosub Send_Data '*** Send Temperature + CRLF **** serout XMITTER_PIN, BAUD_MODE, (",") sertxd (",") peek STORE_TEMPERATURE_ADDRESS, word w0 gosub Send_Data serout XMITTER_PIN, BAUD_MODE, (CR_BYTE, LF_BYTE) sertxd (CR_BYTE, LF_BYTE) '*** Measure Battery & Send (Different Format) *** gosub Measure_Battery serout XMITTER_PIN, BAUD_MODE, ("Batt") sertxd ("Batt") gosub Send_Data serout XMITTER_PIN, BAUD_MODE, (CR_BYTE, LF_BYTE) sertxd (CR_BYTE, LF_BYTE) '*** Pause (fixed minimum) + Random *** '*** (Proper Bandwidth usage dictates that everyone waits a random '*** amount of time so they don't keep stepping on each other.) *** peek STORE_RANDOM_ADDRESS, word w0 random w0 poke STORE_RANDOM_ADDRESS, word w0 w6 = 2 * b0 + 500 pause w6 ' sertxd ("w6=", #w6, CR_BYTE, LF_BYTE) next w1 ' pause 10000 loop '***************************************************************************************************** '***************************************************************************************************** '***************************************************************************************************** '*** Do whatever KAP Controllers do here *** Trigger_Camera: servo CAMERA_TRIGGER_PIN, CAMERA_TRIGGER_ON_PULSE pause CAMERA_TRIGGER_PERIOD servo CAMERA_TRIGGER_PIN, CAMERA_TRIGGER_OFF_PULSE pause CAMERA_TRIGGER_PERIOD low CAMERA_TRIGGER_PIN '***************************************************************************************************** '*** w0 = Measure_Altitude(ALTITUDE_SENSOR_PIN) '*** Average 64 readings w/ No PWM *** Measure_Altitude: w6 = w1 gosub Stack_Push_Word w6 = w2 gosub Stack_Push_Word w0 = 0 for w1 = 0 to ALTITUDE_CYCLES readadc10 ALTITUDE_SENSOR_PIN, w2 w0 = w0 + w2 next w1 gosub Stack_Pop_Word w2 = w6 gosub Stack_Pop_Word w1 = w6 return '***************************************************************************************************** '*** w0 = Measure_WindSpeed(WINDSPEED_SENSOR_PIN, WINDSPEED_PERIOD) Measure_WindSpeed: count WINDSPEED_SENSOR_PIN, WINDSPEED_PERIOD, w0 return '***************************************************************************************************** '*** w0 = Measure_Temperature(TEMPERATURE_SENSOR_PIN) Measure_Temperature: readtemp12 TEMPERATURE_SENSOR_PIN, w0 return '***************************************************************************************************** '*** w0 = Measure_Battery(BATTERY_SENSOR_PIN) Measure_Battery: readadc10 BATTERY_SENSOR_PIN, w0 return '***************************************************************************************************** '*** w0 = Send_Data(w0) Send_Data: w6 = w1 'b2, b3 gosub Stack_Push_Word w6 = w2 'b3, b5 gosub Stack_Push_Word w6 = w3 'b6, __ gosub Stack_Push_Word bintoascii w0, b2, b3, b4, b5, b6 serout XMITTER_PIN, BAUD_MODE, (b2, b3, b4, b5, b6) sertxd (b2, b3, b4, b5, b6) gosub Stack_Pop_Word w3 = w6 gosub Stack_Pop_Word w2 = w6 gosub Stack_Pop_Word w1 = w6 return '***************************************************************************************************** '***************************************************************************************************** '***************************************************************************************************** '***************************************************************************************************** Stack_Initialize: poke PP_STACK_POINTER, PP_STACK_POINTER return '****************************************************************************** Stack_Push_Byte: '*** Data to Push is in b13 '*** Uses b12 peek PP_STACK_POINTER, b12 b12 = b12 - 1 poke b12, b13 poke PP_STACK_POINTER, b12 return '****************************************************************************** Stack_Pop_Byte: '*** Data is Popped into b13 '*** Uses b12 peek PP_STACK_POINTER, b12 peek b12, b13 b12 = b12 + 1 poke PP_STACK_POINTER, b12 return '****************************************************************************** Stack_Push_Word: '*** Data to Push is in w6 '*** Uses b11 peek PP_STACK_POINTER, b11 b11 = b11 - 2 poke b11, word w6 poke PP_STACK_POINTER, b11 return '****************************************************************************** Stack_Pop_Word: '*** Data is Popped into w6 '*** Uses b11 peek PP_STACK_POINTER, b11 peek b11, word w6 b11 = b11 + 2 poke PP_STACK_POINTER, b11 return '****************************************************************************** '***************************************************************************************************** '*****************************************************************************************************