Shop OBEX P1 Docs P2 Docs Learn Events
Problem with simple AD routine — Parallax Forums

Problem with simple AD routine

Tom LTom L Posts: 3
edited 2011-12-13 10:56 in Learn with BlocklyProp
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

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-12-13 09:24
    I don't see anything wrong with your program which is essentially identical to that in the tutorial. I don't see anything wrong with the diagram for the ADC0831 and the Stamp shown in the tutorial. Even though you've tried several different combinations of Stamp, ADC, and pots, it doesn't seem to work. Could one of your wires be broken? If you're using a breadboard area, could you try a different section of the breadboard? Is your ADC0831 plugged in correctly? The dot (looking down from over the chip) should designate pin #1.
  • Tom LTom L Posts: 3
    edited 2011-12-13 10:01
    Thanks for the reply.

    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).
  • Mike GreenMike Green Posts: 23,101
    edited 2011-12-13 10:38
    Here's another ADC0831 read routine from the StampWorks tutorial:
    read_0831:
      LOW CS
      SHIFTIN DataIn, Clock, MSBPOST, [result\9]
      HIGH CS
      RETURN
    
    The first bit is a dummy bit and should be received as a zero. It can be discarded.

    In your routine from BAAD, the PULSOUT provides this dummy clock pulse.

    Where did you purchase the ADC0831s? Maybe they're bad.
  • Tom LTom L Posts: 3
    edited 2011-12-13 10:56
    It must have been a bad wire. I have no idea which one, and I can't even imagine how I managed to get the same results after tearing the circuit down and rebuilding it a dozen times. I noticed that I would get spurious output if I jiggled the board, so I rebuilt the circuit using all new wire. It works!

    Thanks for the suggestion, Mike...you were right!
Sign In or Register to comment.