View Single Post
  #25   Spotlight this post!  
Unread 30-04-2003, 09:14
seanwitte seanwitte is offline
Registered User
None #0116
Team Role: Engineer
 
Join Date: Nov 2002
Location: Herndon, VA
Posts: 378
seanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant future
Send a message via AIM to seanwitte
need an ADC

You will need an ADC. PICs are great, but there is an upfront investment in equipment. If you already have a Stamp then you can buy an inexpensive ADC to do the conversion for you.

A suitable part is the ADC0831 8-bit serial analog-to-digital converter. This is the part used by Parallax in their examples. Get an 8-pin socket and solder it straight to the Stamp carrier board. The converted value is passed into the Stamp using synchronous serial communications. The code below will read the converted value:

Code:
'This code is for the ADC0831 serial 8-bit ADC
'constants defining which Stamp pins are  connected to the ADC
ADC_CS		CON	0	'CS on the ADC (pin 1)
ADC_CLK		CON	1	'CLK on the ADC (pin 7)
ADC_D0		CON	2	'D0 on the ADC (pin 6)

'variable holding converted analog value
ADCVal		VAR	BYTE

'************************************************
' SUBROUTINE:	GetADCVal
' PURPOSE:	Shift in the value from the ADC 
'		connected to the ADC_CS, ADC_CLK,
'		and ADC_D0 pins on the stamp.
' OUTPUT:	Sets the value of variable ADCVal
' REF:		Based on code from Parallax, Inc.
'************************************************
GetADCVal:
	'pulse the chip select line to start conv.
	HIGH ADC_CS
	LOW ADC_CS

	'bring the clock line low, then send one
	'pulse to wake up the ADC and make it 
	'ready to shift out
	LOW ADC_CLK
	PULSOUT ADC_CLK, 210

	'shift in data, most significant bit first
	SHIFTIN ADC_D0, ADC_CLK, MSBPOST, [ADCVal\8]
RETURN
The data sheet for the ADC will tell you which pin is which. You'll only need to make three connections from the stamp to the ADC, defined by the contstants in the code. Just make a call to GetADCVal to grab the current reading from the ADC.