Problem with simple AD routine
Tom L
Posts: 3
I am trying to run a simple AD routine as described in BAAD, version 1.3, chapter 3, using a BS2 and ADC0831. I have checked and double checked and torn down and rebuilt the circuit several times, as shown in figure 3-3. I have cut and pasted the code directly from the text and show it here for reference. What I see on the debug terminal is all 1's, no matter what position the pot is in. I can see the voltage changing (with a DVM) on pin 2 of the ADC when I rotate the pot, but no change on the screen.
I have tried different stamps, different chips, and different pots, all with the same results.
'
[ Title ]
' Basic Analog and Digital - PL3_1R0.bs2
' Program Listing 3.1 Revision 0.
' {$STAMP BS2}
' {$PBASIC 2.5}
'
[ Declarations ]
adcBits VAR Byte
v VAR Byte
r VAR Byte
v2 VAR Byte
v3 VAR Byte
'
[ Initialization ]
CS PIN 0
CLK PIN 1
DataOutput PIN 2
DEBUG CLS 'Start display.
'
[ Main Routine ]
DO
GOSUB ADC_Data
GOSUB Calc_Volts
GOSUB Display
LOOP
'
[ Subroutines ]
ADC_Data:
HIGH CS
LOW CS
LOW CLK
PULSOUT CLK, 210
SHIFTIN DataOutput,CLK,MSBPOST,[adcBits\8]
RETURN
Calc_Volts:
RETURN
Display:
DEBUG HOME
DEBUG "8-bit binary value: ", BIN8 adcBits
RETURN
I have tried different stamps, different chips, and different pots, all with the same results.
'
[ Title ]
' Basic Analog and Digital - PL3_1R0.bs2
' Program Listing 3.1 Revision 0.
' {$STAMP BS2}
' {$PBASIC 2.5}
'
[ Declarations ]
adcBits VAR Byte
v VAR Byte
r VAR Byte
v2 VAR Byte
v3 VAR Byte
'
[ Initialization ]
CS PIN 0
CLK PIN 1
DataOutput PIN 2
DEBUG CLS 'Start display.
'
[ Main Routine ]
DO
GOSUB ADC_Data
GOSUB Calc_Volts
GOSUB Display
LOOP
'
[ Subroutines ]
ADC_Data:
HIGH CS
LOW CS
LOW CLK
PULSOUT CLK, 210
SHIFTIN DataOutput,CLK,MSBPOST,[adcBits\8]
RETURN
Calc_Volts:
RETURN
Display:
DEBUG HOME
DEBUG "8-bit binary value: ", BIN8 adcBits
RETURN
Comments
I have tried it on a Homework Board, a BASIC Stamp 2 Carrier board, and a separate breadboard, using different wires, etc each time. I have the proper voltages at each pin on the ADC. I have tried 4 different ADC's (all purchased at the same time, however).
In your routine from BAAD, the PULSOUT provides this dummy clock pulse.
Where did you purchase the ADC0831s? Maybe they're bad.
Thanks for the suggestion, Mike...you were right!