Shop OBEX P1 Docs P2 Docs Learn Events
DS1620 -BS2e-code - How to turn on a light using a thermometer ? — Parallax Forums

DS1620 -BS2e-code - How to turn on a light using a thermometer ?

guy20sanjoseguy20sanjose Posts: 13
edited 2011-10-01 09:35 in Accessories
:smile:
Hello
I'm using a bs2e on a board of education and a DS1620 thermometer. I'd like to know how to write some code to the program below to turn a light on and of with setting temp points. Any help is appreciated.

' {$STAMP BS2e}
' {$PBASIC 2.5}
'
[ Program Description ]
'
' This program measures temperature using the Dallas Semiconductor DS1620
' temperature sensor. Resolution is 0.5 degrees Celsius.
'
[ I/O Definitions ]
Page 162 • StampWorks
DQ CON 0 ' DS1620.1 (data I/O)
Clock CON 1 ' DS1620.2
Reset CON 2 ' DS1620.3
'
[ Constants ]
RdTmp CON $AA ' read temperature
WrHi CON $01 ' write TH (high temp)
WrLo CON $02 ' write TL (low temp)
RdHi CON $A1 ' read TH
RdLo CON $A2 ' read TL
RdCntr CON $A0 ' read counter
RdSlope CON $A9 ' read slope
StartC CON $EE ' start conversion
StopC CON $22 ' stop conversion
WrCfg CON $0C ' write config register
RdCfg CON $AC ' read config register
DegSym CON 186 ' degrees symbol
'
[ Variables ]
tempIn VAR Word ' raw temperature
sign VAR tempIn.BIT8 ' 1 = negative temperature
tC VAR Word ' Celsius
tF VAR Word ' Fahrenheit
tHi VAR Word
tLo VAR Word
'
[ Initialization ]
Setup:
HIGH Reset ' alert the DS1620
SHIFTOUT DQ, Clock, LSBFIRST, [WrCfg, %10] ' use with CPU; free-run
LOW Reset
PAUSE 10
HIGH Reset
SHIFTOUT DQ, Clock, LSBFIRST, [StartC] ' start conversions
LOW Reset
DEBUG CLS,
"DS1620 ", CR,
"
"

'
[ Program Code ]
Main:
DO
GOSUB Read_DS1620 ' get the temperature
Display_C:
DEBUG CRSRXY, 0, 2,
(tC.BIT15 * 13 + " "),
DEC (ABS tC / 10), ".", DEC1 (ABS tC),
DegSym, " C", CLREOL
Display_F:
DEBUG CRSRXY, 0, 3,
(tF.BIT15 * 13 + " "),
DEC (ABS tF / 10), ".", DEC1 (ABS tF),
DegSym, " F", CLREOL
PAUSE 1000 ' delay between readings
LOOP
'
[ Subroutines ]
Read_DS1620:
HIGH Reset ' alert the DS1620
SHIFTOUT DQ, Clock, LSBFIRST, [RdTmp] ' give command to read temp
SHIFTIN DQ, Clock, LSBPRE, [tempIn\9] ' read it in
LOW Reset ' release the DS1620
tempIn.BYTE1 = -sign ' extend sign bit
tC = tempIn * 5 ' convert to tenths
IF (tC.BIT15 = 0) THEN ' temp C is positive
tF = tC */ $01CC + 320 ' convert to F
ELSE ' temp C is negative
tF = 320 - ((ABS tC) */ $01CC) ' convert to F
ENDIF

ENDIF
RETURN

How to turn a light on when tF > 88 F, turn off when tF < 88 F ? What code and where do I need to add?
Thank again.

Comments

  • Tracy AllenTracy Allen Posts: 6,658
    edited 2011-09-28 20:52
    There is a little tutorial at, http://www.emesystems.com/OL2d1620.htm#thermostat
  • guy20sanjoseguy20sanjose Posts: 13
    edited 2011-09-30 12:04
    Thanks Tracy
    I don't understand this code:

    SHIFTOUT 15,14,LSBFIRST,[1,15\9] ' upper threshold=15/2=7.5 deg C

    How do I make change to it to make it upper threshold = 28 deg C ?
    Please help
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2011-10-01 09:35
    Take your desired temperature, 28 deg C, and multiply it times two. That's 56. Plug that into the SHIFTOUT command (adjusted for whatever pins you are using):

    SHIFTOUT 15,14,LSBFIRST,[1,56\9] ' upper threshold=56/2=28 deg C

    The \9 after the 56 simply tells the Stamp to shift out 9 bits. That is what is required by the DS1620, so that it can do temperatures both above and below freezing.
Sign In or Register to comment.