Shop OBEX P1 Docs P2 Docs Learn Events
Simple thermometer using the DS1620 — Parallax Forums

Simple thermometer using the DS1620

C.MoherC.Moher Posts: 35
edited 2007-04-20 04:48 in BASIC Stamp
'Code modified from "Applied Sensors" course at :
'http://www.parallax.com/dl/docs/books/edu/WebAppliedSensors-v1.4.pdf
'for full +/- 0.5 C resolution and display. See Page 11 and 12 of this PDF for circuit diagrams.
'This represents·a solution·to Challenge Question 3 on Page 24 of the guide.

' Applied Sensors - DS1620.bs2
' Obtain temperature readings from the DS1620.
'{$STAMP BS2}
'{$PBASIC 2.5}
x VAR·Byte '· General purpose variable, Byte.
degC VAR·Byte ' Variable to hold degrees Celsius.
' Note: DS1620 has been preprogrammed for mode 2.
OUTS=%0000000000000000 ' Define the initial state of all pins,
'FEDCBA9876543210
DIRS=%1111111111111111 ' as low outputs.
FREQOUT 0, 1000, 2000 ' Beep to signal that it is running.
HIGH 13 ' Select the DS1620.
SHIFTOUT 15, 14, LSBFIRST, [noparse][[/noparse]238] ' Send the "start conversions" command.
LOW 13 ' Do the command.
DO ' Going to display once per second.
HIGH 13 ' Select the DS1620.
SHIFTOUT 15, 14, LSBFIRST, [noparse][[/noparse]170] ' Send the "get data" command.
SHIFTIN 15, 14, LSBPRE, [noparse][[/noparse]x] ' Get the data.
LOW 13 ' End the command.
degC = x * 5·· ' Since the DS1620 has already doubled the actual reading,a further·*5 will be a ten-fold 'increase.·e.g.·22.5 degrees is doubled to 45 to comply with DS1620's integer only output·and·* by a further 'factor of 5 yields 225 (overall a ten-fold increase of our originally measured temperature 22.5.)
DEBUG· "The temperature is ", DEC degC/10, ".", DEC1 degC ," degrees celcius.", CR
' here we reduced the number in our example back down to 22.5 but·the .5 is·truncated off before it's 'displayed and·only 22 is outputted to the debug screen. It is followed by the decimal point "."
' finally Dec1 takes the 225 and outputs only the 1st digit i.e. the 5 in our example. We now have full 0.5 'resolution displayed.

PAUSE 1000 ' 1 second pause.
LOOP ' Read & display temperature again.

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-04-20 04:48
    This thread is being moved from the Completed Projects Forum to the BASIC Stamps Forum.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
Sign In or Register to comment.