BASIC analog and digital
Matthew
Posts: 200
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!
·
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
·
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
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 Williams
Applications Engineer, Parallax
Dallas, TX· USA
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas, TX· USA
Now THAT felt goood!