' Reads an ADS7818 12-bit adc. Output is to EXCEL if the StampDAQ micro ' has been installed. For this program, the transmitting antenna is rotating ' receiving antenna is connected to a PC via a BS2 microcontroller. ' ' {$STAMP BS2} ' {$PBASIC 2.5} ' November 1, 2006 ' ' ADS7818 Pin 7 (clock) goes to BS2 Pin 2 ' ADS7818 Pin 6 (data) goes to BS2 Pin 1 ' ADS7818 Pin 5 (convert) goes to BS2 Pin 0 ' ' Define Inputs and Outputs OUTPUT 2 'clock pulse, normal low OUTPUT 0 'convert when goes low, normal high INPUT 1 'data in - read 13 bits due to wasted clock pulse INPUT 3 'used to gate the output on Pin 0 ' ' Define Variables and Constants AdcBits VAR Word '12-Bit ADC result Junk VAR Word 'Wasted, used to complete clocking I VAR Byte 'Used as a counter to average ADC reads Average VAR Word 'The average of 10 ADC reads PinRead VAR Bit 'Use to check Pin 3 for a high signal '************************************************************************** ' Define StampDAQ Data Structure sPin CON 16 'Serial Pin - P16, Programming port Baud CON 84 'Baud mode for a rate of 9600, 8-N-1 PAUSE 1000 'Allow data communications to stabilize SEROUT sPin,Baud,[CR] 'Send a lone CR to ensure StampDAQ buffer is ready '************************************************************************** ' Setup Columns in EXCEL for the EEPROM output Configure: SEROUT sPin,Baud,[CR,"LABEL,TIME,Point,Voltage",CR] 'Label 2 columns: Data # and Voltage SEROUT sPin,Baud,["CLEARDATA",CR] 'Clear all data columns (A-J) in Excel ' ' Begin Main FOR I = 1 TO 150 SERIN 3, 16468, [WAIT ("!")] 'Circle: ' PinRead = IN3 ' IF PinRead = 0 THEN Circle Junk = 5 'Waste a clock cycle for the transmitter to output the zeros HIGH 0 'Start conversion bit high, serial out when it goes low LOW 0 SHIFTIN 1, 2, MSBPOST, [AdcBits\13,Junk\3] HIGH 0 'Send String with data for Excel ******************** SEROUT sPin,Baud,["DATA,TIME,", DEC I,",", DEC AdcBits,CR] PAUSE 500 NEXT STOP END