Tom L
12-13-2011, 12:22 AM
I am trying to run a simple AD routine as described in BAAD, version 1.3 (http://www.parallax.com/Portals/0/Downloads/docs/books/edu/BAADv1.3.pdf), 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