Shop OBEX P1 Docs P2 Docs Learn Events
BASIC analog and digital — Parallax Forums

BASIC analog and digital

MatthewMatthew Posts: 200
edited 2005-01-02 03:10 in Learn with BlocklyProp
I'm having some trouble with the first excerise in Chapter 3: Basic Analog to Digital Conversion.

The problem is that the debug window only show the binary values of the voltage in a small range. If you turn the knob, you'll only see '1111111' or '0000000'
If you turn very very very slowly between where it switches from '1111111' to '0000000', then you'll be able to see different binary numbers. But that's like in a 1mm window.

So here's what I have everything connected to:
on the ADC-
1 - P0
2 - the wiper on the potentiometer
3 - VSS
4 - VSS
5 - VSS
6 - P2
7 - P1
8 - VDD

on the potentiometer-
wiper - P2
other pin - VSS
other other pin - VDD

My code looks as follows:
'
[noparse][[/noparse] Title ]
' Basic Analog and Digital - PL3_1R0.bs2
' Program Listing 3.1 Revision 0.
' {$STAMP BS2}
' {$PBASIC 2.5}
'
[noparse][[/noparse] Declarations ]
adcBits VAR Byte
v······ VAR Byte
r······ VAR Byte
v2····· VAR Byte
v3····· VAR Byte
'
[noparse][[/noparse] Initialization ]
CS···················· PIN· 0
CLK··················· PIN· 1
DataOutput············ PIN· 2
DEBUG CLS
'
[noparse][[/noparse] Main Routine ]
DO
· GOSUB ADC_Data
· GOSUB Calc_Volts
· GOSUB Display
LOOP
'
[noparse][[/noparse] Subroutines ]
ADC_Data:
· HIGH CS
· LOW CS
· LOW CLK
· PULSOUT CLK, 210
· SHIFTIN DataOutput,CLK,MSBPOST, [noparse][[/noparse]adcBits\8]
RETURN
Calc_Volts:
RETURN
Display:
· DEBUG HOME
· DEBUG "8-pit binary value:····· ", BIN8 adcBits
RETURN


Any help would be greatly apreceited!



·

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-12-31 19:12
    I think you've got an error in your code.· Your ADC_Data·routine should look like this:
    ·
    ADC_Data:
      LOW CS
      LOW CLK
      PULSOUT CLK, 210
      SHIFTIN DataOutput,CLK,MSBPOST, [noparse][[/noparse]adcBits\8]
      HIGH CS
      RETURN
    


    In truth, the LOW CLK line only needs to appear once -- in the startup secton of your program.· It's redundant to have it in the subroutine.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office


    Post Edited (Jon Williams) : 12/31/2004 7:15:06 PM GMT
  • MatthewMatthew Posts: 200
    edited 2005-01-01 20:04
    Jon,

    Thanks for your help, but it is not working. The Stamp is only reading '0000000' or '1111111' for almost 99% of the time. In the tiny threshold where it switches from '0000000' to '1111111' (or vice versa), something such as '1110101' will appear and change rapidly to something like '1110001'.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-01-01 20:15
    Well, then, I would suspect that you have a problem with connections.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • MatthewMatthew Posts: 200
    edited 2005-01-02 00:21
    Connections as in wire not properly plugged in, or connections as in things are connected in the wrong places?
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-01-02 01:56
    As in the circuit not wired per the schematic.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • MatthewMatthew Posts: 200
    edited 2005-01-02 03:10
    Ahhhh!! Much better... I did check the circuit twice before hand, but I guess I wasn't careful enough.

    Now THAT felt goood!
Sign In or Register to comment.