Shop OBEX P1 Docs P2 Docs Learn Events
Thermometer DS1822 application — Parallax Forums

Thermometer DS1822 application

ArchiverArchiver Posts: 46,084
edited 2004-06-02 15:41 in General Discussion
Dear all,

I have a programming problem about the use of DS1822.
The following is the demo program of DS1820 (9bit), if I use DS1822
(9 to 12 bit) rather than DS1820, which part of the following
program should be amended?
Besdies, since the algebraic equation used in the program will not
work properly with negative temperature, what can I do if I need to
measure a negative temperature?

I will use an eprom to store the measured value (about 5000 data),
can you suggest any eprom that is suitable for this purpose?
Thank you very much!!


' This program demonstrates interfacing to a Dallas Semiconductor
DS1820 1-wire Digital
' 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,$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
Temp = Temp>>1*100-25+((CPerC*100-(CRem*100))/CPerC)
DEBUG HOME,DEC3 Temp/100,".",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-02 15:41
    The math for the DS1822 is almost the same as the DS1620, so this URL
    might help you out:
    http://www.emesystems.com/OL2d1620.htm

    That shows how to get the both high resolution and negative
    temperatures. The trick to get negative temperatures is that you
    have to do all the divisions on positive numbers and then restore the
    sign.

    The 24LC256 is a good eeprom, 32kbytes, I2C interface, well
    documented for use witht the Stamp. You might have enough room for
    your 5kwords of data in the BS2's own eeprom, which is 16k bytes
    total. The BS2pe has 32kbytes total.

    -- Tracy




    >Dear all,
    >
    >I have a programming problem about the use of DS1822.
    >The following is the demo program of DS1820 (9bit), if I use DS1822
    >(9 to 12 bit) rather than DS1820, which part of the following
    >program should be amended?
    >Besdies, since the algebraic equation used in the program will not
    >work properly with negative temperature, what can I do if I need to
    >measure a negative temperature?
    >
    >I will use an eprom to store the measured value (about 5000 data),
    >can you suggest any eprom that is suitable for this purpose?
    >Thank you very much!!
    >
    >
    >' This program demonstrates interfacing to a Dallas Semiconductor
    >DS1820 1-wire Digital
    >' 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,$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
    > Temp = Temp>>1*100-25+((CPerC*100-(CRem*100))/CPerC)
    > DEBUG HOME,DEC3 Temp/100,".",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
    >
    >
    >
    >To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    >from the same email address that you subscribed. Text in the
    >Subject and Body of the message will be ignored.
    >
    >Yahoo! Groups Links
    >
    >
    >
    >
Sign In or Register to comment.