Shop OBEX P1 Docs P2 Docs Learn Events
DS1822 Temperature Sensing — Parallax Forums

DS1822 Temperature Sensing

ArchiverArchiver Posts: 46,084
edited 2004-06-16 16:06 in General Discussion
Dear all,

I'm writing a program for temperature sensing with the use of
DS1822. A sample program from web is listed below. In the program,
there is a "owin" command, (OWIN 0,2,
[noparse][[/noparse]Temp.LOWBYTE,Temp.HIGHBYTE,CRem,CRem,CRem,CRem,CRem,CPerC]). Does
anyone know that why there are so many "CRem"? what's the use of
those "CRem". I am quite confused and don't understand this command.

Besides, for the operation of DS 1822 with Basic Stamp, the stamp
should 1)issue skip ROM command, 2)issue write scratchpad command, 3)
sends three data bytes to scratchpad (TH, TL, and config). Can
anyone teach me how to convert this three command into PBasic
language????

I really have no idea. Please....
Thank all very much!!!


' Thermometer chip using the BS2p's 1-wire commands. Connect the
BS2p
to
the DS1820 as
' shown in the diagram in the OWIN or OWOUT command description.
' This code reads the Counts Remaing and Counts per Degree C
registers
in
the DS1820
' chip in order to provide a more accurate temperature reading (down
to
1/100th of a
' degree). It also calculates degrees Fahrenheit. NOTE: The
algebraic
equations used
' will not work properly with negative temperatures.

'{$STAMP BS2p} 'STAMP directive (specifies a BS2p)

Temp VAR Word 'Holds the temperature value
CRem VAR Byte 'Holds the counts remaining value
CPerC VAR Byte 'Holds the Counts per degree C value

Start:
OWOUT 0,1,[noparse][[/noparse]$CC,$4E,$96,$00,$7F]
OWOUT 0,1,[noparse][[/noparse]$CC,$44] 'Send Calculate Temperature command

CheckForDone: 'Wait until conversion is done
PAUSE 25
OWIN 0,4,[noparse][[/noparse]Temp] 'Here we just keep reading low pulses until
IF Temp = 0 THEN CheckForDone 'the DS1820 is done, then it returns
high.

OWOUT 0,1,[noparse][[/noparse]$CC,$BE] 'Send Read ScratchPad command
OWIN 0,2,
[noparse][[/noparse]Temp.LOWBYTE,Temp.HIGHBYTE,CRem,CRem,CRem,CRem,CRem,CPerC]

'Calculate temperature in degrees C
DEBUG ?Temp,?CRem,?CPerC,CR
Temp = Temp>>1*100-25+((CPerC*100-(CRem*100))/CPerC)
DEBUG ?Temp,CR
'DEBUG HOME,DEC3 Temp/100,".",DEC2 Temp-(Temp/100*100)," C",CR
DEBUG DEC3 Temp/1000,".",DEC2 Temp-(Temp/100*100)," C",CR

'Calculate temperature in degrees F
'Temp = Temp*/461+3200
'DEBUG DEC3 Temp/100,".",DEC2 Temp-(Temp/100*100)," F"
GOTO Start

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2004-06-16 16:06
    The repeated use of the variable CRem in the OWIN statement is
    simply a means to read past and discard (overwrite) unwanted data to
    reach the desired data. In this case, count_remain and count_per _c
    are the 7th and 8th bytes in the sequential byte stream sent as a
    result of the DS1820 read scratchpad command. Your Stamp must store
    the data somewhere in order to read it in, so it just writes new
    data to the same location until the desired data arrives--an
    efficient use of variable space. BTW count_remain and count_per _c
    have no significance for the '1822, so there's not much point in
    reading those bytes in for your application.

    > ...Besides, for the operation of DS 1822 with Basic Stamp, the
    > stamp should 1)issue skip ROM command, 2)issue write scratchpad
    > command, 3) sends three data bytes to scratchpad (TH, TL, and
    > config)...

    That's precisely what the following line in the program does:

    > OWOUT 0,1,[noparse][[/noparse]$CC,$4E,$96,$00,$7F]

    However, there is no write scratchpad command so the data in the
    scratchpad never makes it to the EEPROM and this command is without
    effect.

    Also, there is no strong pull-up capability with the BS2p, so make
    sure you're not using parasite power for your '1822.

    Regards,

    Steve
Sign In or Register to comment.