DS1620 again
aj_ax24
Posts: 16
Here is the code i have for my non cpu continuous mode temp sensing.· It only reads every 2 degrees though.· EX.·it reads 69 degrees F and then if i apply heat it will go to 71 and skip over 70.· then if i keep applying heat it jumps to 73 then to 75.· I have seen it at 76 but only once.· Also it seems to stick on 71 when im cooling to a lower temp.· IF anyone has any ideas it would be much appreciated.· I am almost done with the project and this is the last opstical.· Thanks.
aj
' {$STAMP BS2}
' {$PBASIC 2.5}
·' ===================== Define Pins and Variables ================
DQ····· CON 4·············· ' Pin 2 <=> DQ.
CLKT···· CON 2·············· ' Pin 1 => CLK.
RST···· CON 1·············· ' Pin 0 => RST (high = active).
COOL·· CON· 8
HEAT·· CON 9
DSdata· VAR Word········ ' Word variable to hold 9-bit data.
Sign··· VAR DSdata.BIT8· ' Sign bit of raw temperature data.
T_sign· VAR Bit········· ' Saved sign bit for converted temperature.
' ===================== Define DS1620 Constants ===================
' >>> Constants for configuring the DS1620
Rconfig CON $AC················ ' Protocol for 'Read Configuration.'
Wconfig CON $0C················ ' Protocol for 'Write Configuration.'
CPU···· CON %00················ ' Config bit: serial thermometer mode.
NoCPU·· CON %10················ ' Config bit: standalone thermostat mode.
OneShot CON %01················ ' Config bit: one conversion per start request.
Cont··· CON %00················ ' Config bit: continuous conversions after start.
' >>> Constants for serial thermometer applications.
StartC· CON $EE················· ' Protocol for 'Start Conversion.'
StopC·· CON $22·················· ' Protocol for 'Stop Conversion.'
Rtemp·· CON $AA·················· ' Protocol for 'Read Temperature.'
' >>> Constants for programming thermostat functions.
RhiT··· CON $A1··················· ' Protocol for 'Read High-Temperature Setting.'
WhiT··· CON $01··················· ' Protocol for 'Write High-Temperature Setting.'
RloT··· CON $A2··················· ' Protocol for 'Read Low-Temperature Setting.'
WloT··· CON $02··················· ' Protocol for 'Write Low-Temperature Setting.'
' ===================== Begin Program ============================
Begin:
LOW···· RST·································· ' Deactivate '1620 for now.
HIGH··· CLK·································· ' Put clock in starting state.
PAUSE·· 100·································· ' Let things settle down a moment.
HIGH··· RST·································· ' Activate the '1620 and set it for continuous..
SHIFTOUT DQ,CLKT,LSBFIRST,[noparse][[/noparse]Wconfig,NoCPU+Cont]·· ' ..temp conversions.
PAUSE 50
LOW···· RST·································· ' Done--deactivate.
PAUSE·· 50··································· ' Wait for the EEPROM to self-program.
HIGH··· RST·································· ' Now activate it again and..
SHIFTOUT DQ,CLKT,LSBFIRST,[noparse][[/noparse]StartC]············ ' Send start-conversion protocol.
LOW···· RST·································· ' Done--deactivate.
RETURN
' The loop below continuously reads the latest temperature from
' the DS1620.
again:
PAUSE 1000································· ' Wait a second between readings.
HIGH RST··································· ' Activate the '1620.
SHIFTOUT DQ,CLKT,LSBFIRST,[noparse][[/noparse]Rtemp]··········· ' Request to read temperature.
SHIFTIN DQ,CLKT,LSBPRE,[noparse][[/noparse]DSdata\9]··········· ' Get the temperature reading.
LOW RST
··········································· 'SHOW THAT SHIFTIN COMMAND RECIEVED
PAUSE 500·································· 'DATA AND PROGRAM IS WORKING
T_sign = Sign······························ ' Save the sign bit of the reading.
DSdata = DSdata/2·························· ' Scale reading to whole degrees C.
IF T_sign = 0 THEN no_neg1
DSdata = DSdata | $FF00···················· ' Extend sign bits for negative temps.
no_neg1:
'DEBUG SDEC DSdata," degrees C",CR·········· ' Show signed temperature in C.
DSdata = (DSdata */ $01CC)················· ' Multiply by 1.8.
IF T_sign = 0 THEN no_neg2················· ' If negative, extend sign bits.
DSdata = DSdata | $FF00
no_neg2:
DSdata = DSdata + 32······················· ' Complete the conversion.
DEBUG· DEC DSdata," degrees F",CR
·········· ' Show signed temperature in F.
aj
' {$STAMP BS2}
' {$PBASIC 2.5}
·' ===================== Define Pins and Variables ================
DQ····· CON 4·············· ' Pin 2 <=> DQ.
CLKT···· CON 2·············· ' Pin 1 => CLK.
RST···· CON 1·············· ' Pin 0 => RST (high = active).
COOL·· CON· 8
HEAT·· CON 9
DSdata· VAR Word········ ' Word variable to hold 9-bit data.
Sign··· VAR DSdata.BIT8· ' Sign bit of raw temperature data.
T_sign· VAR Bit········· ' Saved sign bit for converted temperature.
' ===================== Define DS1620 Constants ===================
' >>> Constants for configuring the DS1620
Rconfig CON $AC················ ' Protocol for 'Read Configuration.'
Wconfig CON $0C················ ' Protocol for 'Write Configuration.'
CPU···· CON %00················ ' Config bit: serial thermometer mode.
NoCPU·· CON %10················ ' Config bit: standalone thermostat mode.
OneShot CON %01················ ' Config bit: one conversion per start request.
Cont··· CON %00················ ' Config bit: continuous conversions after start.
' >>> Constants for serial thermometer applications.
StartC· CON $EE················· ' Protocol for 'Start Conversion.'
StopC·· CON $22·················· ' Protocol for 'Stop Conversion.'
Rtemp·· CON $AA·················· ' Protocol for 'Read Temperature.'
' >>> Constants for programming thermostat functions.
RhiT··· CON $A1··················· ' Protocol for 'Read High-Temperature Setting.'
WhiT··· CON $01··················· ' Protocol for 'Write High-Temperature Setting.'
RloT··· CON $A2··················· ' Protocol for 'Read Low-Temperature Setting.'
WloT··· CON $02··················· ' Protocol for 'Write Low-Temperature Setting.'
' ===================== Begin Program ============================
Begin:
LOW···· RST·································· ' Deactivate '1620 for now.
HIGH··· CLK·································· ' Put clock in starting state.
PAUSE·· 100·································· ' Let things settle down a moment.
HIGH··· RST·································· ' Activate the '1620 and set it for continuous..
SHIFTOUT DQ,CLKT,LSBFIRST,[noparse][[/noparse]Wconfig,NoCPU+Cont]·· ' ..temp conversions.
PAUSE 50
LOW···· RST·································· ' Done--deactivate.
PAUSE·· 50··································· ' Wait for the EEPROM to self-program.
HIGH··· RST·································· ' Now activate it again and..
SHIFTOUT DQ,CLKT,LSBFIRST,[noparse][[/noparse]StartC]············ ' Send start-conversion protocol.
LOW···· RST·································· ' Done--deactivate.
RETURN
' The loop below continuously reads the latest temperature from
' the DS1620.
again:
PAUSE 1000································· ' Wait a second between readings.
HIGH RST··································· ' Activate the '1620.
SHIFTOUT DQ,CLKT,LSBFIRST,[noparse][[/noparse]Rtemp]··········· ' Request to read temperature.
SHIFTIN DQ,CLKT,LSBPRE,[noparse][[/noparse]DSdata\9]··········· ' Get the temperature reading.
LOW RST
··········································· 'SHOW THAT SHIFTIN COMMAND RECIEVED
PAUSE 500·································· 'DATA AND PROGRAM IS WORKING
T_sign = Sign······························ ' Save the sign bit of the reading.
DSdata = DSdata/2·························· ' Scale reading to whole degrees C.
IF T_sign = 0 THEN no_neg1
DSdata = DSdata | $FF00···················· ' Extend sign bits for negative temps.
no_neg1:
'DEBUG SDEC DSdata," degrees C",CR·········· ' Show signed temperature in C.
DSdata = (DSdata */ $01CC)················· ' Multiply by 1.8.
IF T_sign = 0 THEN no_neg2················· ' If negative, extend sign bits.
DSdata = DSdata | $FF00
no_neg2:
DSdata = DSdata + 32······················· ' Complete the conversion.
DEBUG· DEC DSdata," degrees F",CR
·········· ' Show signed temperature in F.
Comments
·· The reason for this is that your conversion routines are automatically losing half the resolution of the temp.· Then when you convert to 'F' you are getting 1.9 degree resolution, or there abouts.· I got some help from Dr. Tracy Allen on this a while back and have attached the code I used in my Digital Thermostat.· You should be able to adapt it instead.· It will give you 1 degree of resolution in 'F'.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Begin:
LOW···· RST·································· ' Deactivate '1620 for now.
HIGH··· CLK·································· ' Put clock in starting state.
PAUSE·· 100·································· ' Let things settle down a moment.
HIGH··· RST·································· ' Activate the '1620 and set it for continuous..
SHIFTOUT DQ,CLKT,LSBFIRST,[noparse][[/noparse]Wconfig,NoCPU+Cont]·· ' ..temp conversions.
PAUSE 50
LOW···· RST·································· ' Done--deactivate.
PAUSE·· 50··································· ' Wait for the EEPROM to self-program.
HIGH··· RST·································· ' Now activate it again and..
SHIFTOUT DQ,CLKT,LSBFIRST,[noparse][[/noparse]StartC]············ ' Send start-conversion protocol.
LOW···· RST·································· ' Done--deactivate.
RETURN
' The loop below continuously reads the latest temperature from
' the DS1620.
again:
PAUSE 1000································· ' Wait a second between readings.
HIGH RST··································· ' Activate the '1620.
SHIFTOUT DQ,CLKT,LSBFIRST,[noparse][[/noparse]Rtemp]··········· ' Request to read temperature.
SHIFTIN DQ,CLKT,LSBPRE,[noparse][[/noparse]DSdata\9]··········· ' Get the temperature reading.
LOW RST
··········································· 'SHOW THAT SHIFTIN COMMAND RECIEVED
PAUSE 500·································· 'DATA AND PROGRAM IS WORKING
T_sign = Sign······························ ' Save the sign bit of the reading.
DSdata = DSdata/2·························· ' Scale reading to whole degrees C.
IF T_sign = 0 THEN no_neg1
DSdata = DSdata | $FF00···················· ' Extend sign bits for negative temps.
no_neg1:
'DEBUG SDEC DSdata," degrees C",CR·········· ' Show signed temperature in C.
tempIn.BYTE1 = -tempIn.BIT8···················· ' Extend Sign To 16 Bits
tempC = DSdata * 5····························· ' Convert To C * 5 (Resolution 0.5 C)
tempF = tempC + 2732 * 9 / 50 - 459············ ' C * 10 to F (First To Kelvin * 10)
·GOTO main
any pointers
thanks
AJ
· Please try to be more clear in your explanations..."It isn't working quite right" doesn't tell me what's going on.· But I will make an educated guess based on experience.· You probably don't have the variables declared properly at the beginning, but since that part isn't posted I can't be sure.·
·· The label main referenced in your code doesn't exist either.· Presumably that part wasn't posted.· Also, please attach your code instead of pasting it each time, since it makes following the thread difficult when you have to scroll past several pages of code.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Post Edited (Chris Savage (Parallax)) : 4/20/2005 7:38:55 PM GMT
AJ
·· The .5 degree resolution is in the Celsius mode.· In Farenheit mode, it's only .9 degrees resolution.· 1 degree is as close as you're going to get using this method.· You should no longer see it skipping numbers in your temps though.· I have been using the code as posted, and it does work.· Those routines were courtesy of Dr. Tracy Allen and were tested.· What exactly are you getting for your display?· In your original post you were concerned with missing numbers and this should take care of that.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
If you are looking for even more resolution from the DS1620, on my web page I have code for reading the temperature to 1/100 degree Celsius.
www.emesystems.com/OL2d1620.htm
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com