' {$STAMP BS2} ' {$PBASIC 2.5} X VAR Byte 'Declarations adcBits VAR Word ' psi VAR Word ' smalladc VAR Word ' smallpsi VAR Word ' CS PIN 0 'Declarations for the ADC chip interface. CLK PIN 1 ' DataOutput PIN 2 ' Main: DO SERIN 16, 84, Out, [DEC X] 'Reads any serial data on Pin 16. Out: IF X = 1 THEN 'This opens the fill valve by sending power for .65 seconds. HIGH 3 : PAUSE 650 : LOW 3 : X = 0 : GOTO Main ' ELSEIF X = 2 THEN 'This closes the fill valve by sending power for .65 seconds. HIGH 4 : PAUSE 650 : LOW 4 : GOTO Main ' ELSEIF X = 3 THEN 'This is the line cutter pyro circuit. HIGH 5 : PAUSE 1000 : LOW 5 : GOTO Main ' ELSEIF X = 4 THEN 'The preheater pyro circuit. HIGH 6 : PAUSE 1000 : LOW 6 : GOTO Main ' ELSEIF X = 5 THEN 'The engine valve pyro circuit. HIGH 7 : PAUSE 1000 : LOW 7 : GOTO Main ' ELSEIF X = 6 THEN 'This sets all BS2 outputs to the low state. LOW 3: LOW 4 : LOW 5 : LOW 6 : LOW 7 : GOTO Main ' ELSEIF X = 7 THEN 'This line sends the program to the Sendata subroutine. GOSUB Senddata ' ELSEIF X = 8 THEN 'Sends the program to the Continuity test for the linecutter. GOSUB Continuitylinecutter ' ELSEIF X = 9 THEN 'Sends the program to the continuity test for the preheater. GOSUB Continuitypreheater ' ELSEIF X = 10 THEN 'Sends the program to the continuity test for the engine valve. GOSUB Continuityenginevalve ' ELSEIF X = 11 THEN 'Sends the program to the N2O pressure sub. GOSUB N2Opressure ' ELSE : GOTO Main 'If no options are selected the program goes back to the main routine. ENDIF LOOP Senddata: 'This subroutine sends the valve position data 'back to the PC application based on the pin state INPUT 8 '(high or low) of pins 8 and 9. INPUT 9 IF (IN8 = 1) THEN 'I'm using Pin 16 on the BS2, which is an internal SEROUT 16, 84, [" Valve is Open"] 'pin designed for RS232 communication. If any other 'pin were used, a line shifter device would be needed ELSEIF (IN9 = 1) THEN 'to convert the output to RS232 levels. SEROUT 16, 84, [" Valve is Closed"] ELSEIF (IN8 AND IN9 = 0) THEN SEROUT 16, 84, [" Unknown Postion"] ENDIF RETURN Continuitylinecutter: 'The next three subroutines are for continuity INPUT 10 'tests on the pyro circuits. From the PC application 'a command is sent to the BS2 which sends the program IF (IN10 = 1) THEN 'to these subroutines. The BS2 reads the pin state SEROUT 16, 84, [" Line Cutter Good"] 'and sends a text line indicating the continuity status 'of the circuit. ELSEIF (IN10 = 0) THEN SEROUT 16, 84, [" Line Cutter Bad"] ENDIF RETURN Continuitypreheater: INPUT 11 IF (IN11 = 1) THEN SEROUT 16, 84, [" Preheater Good"] ELSEIF (IN11 = 0) THEN SEROUT 16, 84, [" Preheater Bad"] ENDIF RETURN Continuityenginevalve: INPUT 12 IF (IN12 = 1) THEN SEROUT 16, 84, [" Flight Valve Good"] ELSEIF (IN12 = 0) THEN SEROUT 16, 84, [" Flight Valve Bad"] ENDIF RETURN N2Opressure: HIGH CS 'This subroutine initializes the ADC, then LOW CS 'gathers the data from the "shiftin" command. LOW CLK 'The ADC value is converted from decimal to intger PULSOUT CLK, 210 'math, converted to psi, then the data is sent out SHIFTIN DataOutput,CLK,MSBPOST,[adcbits\13] 'to the application using the "serout" command. smalladc = adcbits / 10 smallpsi = 24 * smalladc psi = smallpsi / 10 SEROUT 16, 84, [" PSI ", DEC4 psi] RETURN