Shop OBEX P1 Docs P2 Docs Learn Events
How does hex $139C convert to millivolts? (Example from Stamp works experiment — Parallax Forums

How does hex $139C convert to millivolts? (Example from Stamp works experiment

jdkikijdkiki Posts: 3
edited 2008-01-10 23:23 in BASIC Stamp
' A D converter.bs2
' {$STAMP BS2px}
' {$PBASIC 2.5}
'
Program Description
' This program demonstrates reading a variable voltage with ADC0831
' analog-digital converter chip. This program uses a Vref input of
' 5.000 volts (vdd) for a bit resolution of 19.6 millivolts
'
( I/O definitions)
CS····· PIN·· 0········· ' chip select
Clock·· PIN·· 1········· ' clock (ADC0831.7)
DataIn· PIN·· 2········· ' data (ADC0831.6)
'
(Constants)
Cnts2Mv··· CON··· $139C····· '· x·· 19.6 (millivolts)·· $139C (hex)= 5020???
'
(Variables)
result·· VAR· Byte········ ' result of conversion
mVolts··· VAR· Word········ ' millivolts
'
(Initialization)
RESET:
· DEBUG CLS,················· ' create report screen
· "ADC... ", CR,
· "volts... "
'
( 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



Post Edited By Moderator (Chris Savage (Parallax)) : 1/10/2008 9:48:13 PM GMT

Comments

  • JDJD Posts: 570
    edited 2008-01-10 23:23
    jdkiki,
    ·
    The $139C value is the same as 5020 in decimal format; and 19.6 approximately 1/256 of that value. The operator */ multiplies the result by this value to get the conversion. There is further explanation of the function of */ operator as well as ** operator and how they are used in the “What's A Microcontroller” text page 95 & 243.
    ·
    Whats a Microcontroller? Text:
    http://www.parallax.com/Portals/0/Downloads/docs/books/edu/Wamv2_2.pdf
    ·
    I hope this helps,

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Joshua Donelson

    www.parallax.com
Sign In or Register to comment.