SW21-EX28-ADC0831-Simple-Vref.BS2 Question
Please explain HEX value in this DEMO· and there is DEC value for the·DEBUG command to be read
' =========================================================================
'
'·· File....... SW21-EX28-ADC0831-Simple-Vref.BS2
'·· Purpose.... Servo control and positioning with a potentiomenter
'·· Author..... (C) 2000 - 2005, Parallax, Inc.
'·· E-mail..... support@parallax.com
'·· Started....
'·· Updated.... 01 SEP 2005
'
'·· {$STAMP BS2}
'·· {$PBASIC 2.5}
'
' =========================================================================
'
[noparse][[/noparse] Program Description ]
'
' This program deomstrates reading a variable voltage with an ADC0831
' analog-to-digital convertor chip. This program uses a Vref input of
' 2.55 volts (Vdd) for a bit resolution of 10 millivolts.
'
[noparse][[/noparse] I/O Definitions ]
CS············· PIN···· 0······················ ' chip select (ADC0831.1)
Clock·········· PIN···· 1······················ ' clock (ADC0831.7)
DataIn········· PIN···· 2······················ ' data (ADC0831.6)
'
[noparse][[/noparse] Constants ]
Cnts2Mv········ CON···· $0A00·················· ' x 10 (to millivolts)·
'
[noparse][[/noparse] Variables ]
result········· VAR···· Byte··················· ' result of conversion
mVolts········· VAR···· Word··················· ' millivolts
'
[noparse][[/noparse] Initialization ]
Reset:
· DEBUG CLS,··································· ' create report screen
······· "ADC....· ", CR,
······· "volts... "
'
[noparse][[/noparse] Program Code ]
Main:
· DO
··· GOSUB Read_0831···························· ' read the ADC
···· mVolts = result */ Cnts2Mv················· ' convert to millivolts
··· DEBUG HOME,································ ' report
········· CRSRXY, 9, 0, DEC result, CLREOL,
········· CRSRXY, 9, 1, DEC· mVolts DIG 3,
······················· ".", DEC3 mVolts
··· PAUSE 100
·LOOP
'
[noparse][[/noparse] Subroutines ]
Read_0831:
· LOW CS······································· ' enable ADC
· SHIFTIN DataIn, Clock, MSBPOST, [noparse][[/noparse]result\9]··· ' read ADC
· HIGH CS······································ ' disable ADC
· RETURN
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any·
·that you may have and all of your time finding them ![smile.gif](http://forums.parallax.com/images/smilies/smile.gif)
·
·
·
·
Sam
' =========================================================================
'
'·· File....... SW21-EX28-ADC0831-Simple-Vref.BS2
'·· Purpose.... Servo control and positioning with a potentiomenter
'·· Author..... (C) 2000 - 2005, Parallax, Inc.
'·· E-mail..... support@parallax.com
'·· Started....
'·· Updated.... 01 SEP 2005
'
'·· {$STAMP BS2}
'·· {$PBASIC 2.5}
'
' =========================================================================
'
[noparse][[/noparse] Program Description ]
'
' This program deomstrates reading a variable voltage with an ADC0831
' analog-to-digital convertor chip. This program uses a Vref input of
' 2.55 volts (Vdd) for a bit resolution of 10 millivolts.
'
[noparse][[/noparse] I/O Definitions ]
CS············· PIN···· 0······················ ' chip select (ADC0831.1)
Clock·········· PIN···· 1······················ ' clock (ADC0831.7)
DataIn········· PIN···· 2······················ ' data (ADC0831.6)
'
[noparse][[/noparse] Constants ]
Cnts2Mv········ CON···· $0A00·················· ' x 10 (to millivolts)·
'
[noparse][[/noparse] Variables ]
result········· VAR···· Byte··················· ' result of conversion
mVolts········· VAR···· Word··················· ' millivolts
'
[noparse][[/noparse] Initialization ]
Reset:
· DEBUG CLS,··································· ' create report screen
······· "ADC....· ", CR,
······· "volts... "
'
[noparse][[/noparse] Program Code ]
Main:
· DO
··· GOSUB Read_0831···························· ' read the ADC
···· mVolts = result */ Cnts2Mv················· ' convert to millivolts
··· DEBUG HOME,································ ' report
········· CRSRXY, 9, 0, DEC result, CLREOL,
········· CRSRXY, 9, 1, DEC· mVolts DIG 3,
······················· ".", DEC3 mVolts
··· PAUSE 100
·LOOP
'
[noparse][[/noparse] Subroutines ]
Read_0831:
· LOW CS······································· ' enable ADC
· SHIFTIN DataIn, Clock, MSBPOST, [noparse][[/noparse]result\9]··· ' read ADC
· HIGH CS······································ ' disable ADC
· RETURN
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any·
![idea.gif](http://forums.parallax.com/images/smilies/idea.gif)
![smile.gif](http://forums.parallax.com/images/smilies/smile.gif)
·
·
·
·
Sam
Comments
Hex "A" is decimal 10. The ADC reading is 8 bits ( 0 - 255 ), so with a 2.55V reference each bit is 10mV ( 0.010V ) To convert the binary number from the ADC to millivolts you need to multiply it by 10 (ie. 2V would read as 200, times 10 = 2000).
The result is still stored as a binary number ( 7D0 in the case of 2000mV ), so the debug statements convert that to a decimal value before outputting it.
I did not know that the output from the ADC was in binary number format
Thanks for the Info
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any·
·
·
·
·
Sam