BS2 and DS1620 Setting TL & TH
planewrench
Posts: 3
I want to configure the DS1620 for stand alone operation. First I'd like to write new TH and TL to the DS1620. I have adapted source code from your website for this purpose, but I don't seem to be having much luck - the code is writing new TL & TH and then I'm reading TL & TH along with the current temp and it loops around. TL reads 7 and TH 122 and I can't seem to get it to·write correctly.·I would appreciate some help and direction. Thank you
' Applied Sensors - DS1620Configuration.bs2
' Configure the DS1620 for CPU continuous conversion.
'{$STAMP BS2}
'{$PBASIC 2.5}
' 0: No CPU, continuous conversion
' 1: No CPU, one-shot conversion
' 2: Yes CPU, continuous conversion
' 3: Yes CPU, one-shot conversion
degC VAR Byte ' Variable to hold degrees Celsius.
x VAR Byte ' General purpose variable, byte.
TH VAR Byte ' Variable to hold degrees Celsius.
y VAR Byte ' General purpose variable, byte.
TL VAR Byte ' Variable to hold degrees Celsius.
DO ' Going to display once per second.
LOW 13 ' Puts the DS1620 in the waiting state.
FREQOUT 0, 1000, 3800 ' Sound shows us the program is running.
HIGH 13 ' Tells the DS1620 that a command is coming.
SHIFTOUT 15, 14, LSBFIRST, [noparse][[/noparse]12,2] ' Command to set DS1620 configuration.
LOW 13 ' Completes the command cycle.
HIGH 13 ' Tells the DS1620 that a command is coming.
SHIFTOUT 15, 14, LSBFIRST, [noparse][[/noparse]$00,30] ' Command to set DS1620 TH to 30.
LOW 13 ' Completes the command cycle.
HIGH 13 ' Tells the DS1620 that a command is coming.
SHIFTOUT 15, 14, LSBFIRST, [noparse][[/noparse]$02,25] ' Command to set DS1620 TL to 25.
LOW 13 ' Completes the command cycle.
HIGH 13 ' Select the DS1620.
SHIFTOUT 15, 14, LSBFIRST, [noparse][[/noparse]161] ' Send the "get data" command.
SHIFTIN 15, 14, LSBPRE, [noparse][[/noparse]x] ' Get the data.
LOW 13 ' End the command.
TH = x / 2 ' Convert the data to degrees C.
DEBUG ? TH ' Show the result on the PC screen.
PAUSE 1000 ' 1 second pause.
HIGH 13 ' Select the DS1620.
SHIFTOUT 15, 14, LSBFIRST, [noparse][[/noparse]162] ' Send the "get data" command.
SHIFTIN 15, 14, LSBPRE, [noparse][[/noparse]y] ' Get the data.
LOW 13 ' End the command.
TL = y / 2 ' Convert the data to degrees C.
DEBUG ? TL ' Show the result on the PC screen.
PAUSE 1000 ' 1 second pause.
HIGH 13 ' Select the DS1620.
SHIFTOUT 15, 14, LSBFIRST, [noparse][[/noparse]238] ' Send the "start conversions" command.
LOW 13 ' Do the command.
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 / 2 ' Convert the data to degrees C.
DEBUG ? degC ' Show the result on the PC screen.
PAUSE 1000 ' 1 second pause.
LOOP ' Read & display temperature again.
' Applied Sensors - DS1620Configuration.bs2
' Configure the DS1620 for CPU continuous conversion.
'{$STAMP BS2}
'{$PBASIC 2.5}
' 0: No CPU, continuous conversion
' 1: No CPU, one-shot conversion
' 2: Yes CPU, continuous conversion
' 3: Yes CPU, one-shot conversion
degC VAR Byte ' Variable to hold degrees Celsius.
x VAR Byte ' General purpose variable, byte.
TH VAR Byte ' Variable to hold degrees Celsius.
y VAR Byte ' General purpose variable, byte.
TL VAR Byte ' Variable to hold degrees Celsius.
DO ' Going to display once per second.
LOW 13 ' Puts the DS1620 in the waiting state.
FREQOUT 0, 1000, 3800 ' Sound shows us the program is running.
HIGH 13 ' Tells the DS1620 that a command is coming.
SHIFTOUT 15, 14, LSBFIRST, [noparse][[/noparse]12,2] ' Command to set DS1620 configuration.
LOW 13 ' Completes the command cycle.
HIGH 13 ' Tells the DS1620 that a command is coming.
SHIFTOUT 15, 14, LSBFIRST, [noparse][[/noparse]$00,30] ' Command to set DS1620 TH to 30.
LOW 13 ' Completes the command cycle.
HIGH 13 ' Tells the DS1620 that a command is coming.
SHIFTOUT 15, 14, LSBFIRST, [noparse][[/noparse]$02,25] ' Command to set DS1620 TL to 25.
LOW 13 ' Completes the command cycle.
HIGH 13 ' Select the DS1620.
SHIFTOUT 15, 14, LSBFIRST, [noparse][[/noparse]161] ' Send the "get data" command.
SHIFTIN 15, 14, LSBPRE, [noparse][[/noparse]x] ' Get the data.
LOW 13 ' End the command.
TH = x / 2 ' Convert the data to degrees C.
DEBUG ? TH ' Show the result on the PC screen.
PAUSE 1000 ' 1 second pause.
HIGH 13 ' Select the DS1620.
SHIFTOUT 15, 14, LSBFIRST, [noparse][[/noparse]162] ' Send the "get data" command.
SHIFTIN 15, 14, LSBPRE, [noparse][[/noparse]y] ' Get the data.
LOW 13 ' End the command.
TL = y / 2 ' Convert the data to degrees C.
DEBUG ? TL ' Show the result on the PC screen.
PAUSE 1000 ' 1 second pause.
HIGH 13 ' Select the DS1620.
SHIFTOUT 15, 14, LSBFIRST, [noparse][[/noparse]238] ' Send the "start conversions" command.
LOW 13 ' Do the command.
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 / 2 ' Convert the data to degrees C.
DEBUG ? degC ' Show the result on the PC screen.
PAUSE 1000 ' 1 second pause.
LOOP ' Read & display temperature again.
Comments
By my datasheet for the DS1620, you should send a·$1 to set TH, you are sending a $0.· As this is an undefined command, this my be causing a problem, though I doubt it.
The datasheet also states that you need to wait at least 10ms between writes to the EEprom (which you are doing when setting TL and TH).· I do not remember how fast the BS's are, but you may want to put a pause after all writes to the EEprom.
Nate
Disclaimer - free advice is worth what you paid for it, sometimes less.
[noparse][[/noparse]code]high 13
shiftout 15,14,lsbfirst,[noparse][[/noparse]2,-11\9] ' lower threshold=-11/2=-5.5 deg C
' the twos complement number is sent correctly as 9 bits
low 13
pause 10 ' let it write
'
' set the upper threshold= +7.5 deg C
high 13
shiftout 15,14,lsbfirst,[noparse][[/noparse]1,15\9] ' upper threshold=15/2=7.5 deg C
low 13
pause 10[noparse][[/noparse]code]
Note that it sends 9 bits. I recall hazily that 9 bits are required, for both positive and negative values. Also, the value you send is the threshold * 2.. And, as Nate pointed out, the PAUSE 10 is required after every command that writes to the DS1620 eeprom. In fact after changing the configuration, (command 12), it is a good idea to reset power the device off and then on again to be sure the configuration takes effect.
additional info here:
www.emesystems.com/OL2d1620.htm#thermostat
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
' {$STAMP BS2}
' {$PBASIC 2.5}
' Program: DS1620.BS2 (interface DS1620 digital thermometer)
' This program interfaces the DS1620 Digital Thermometer to
' the BS2. Input and output routines can be combined to set
' the '1620 for thermometer or thermostat operation, read
' or write nonvolatile temperature setpoints and configuration
' data. In addition to using the BS2's new Shiftin and Shiftout
' instructions to communicate with the 1620, this program uses
' new math and display operators that work with signed integers.
' This makes it relatively easy to convert between degrees C and
' F and to display both positive and negative temperature
' readings. Note that after math operations on negative numbers
' it's necessary to "extend the sign bits." All this means is
' setting all of the bits to the left of actual value to 1s.
' Also note the use of the new */ (pronounced 'star-slash')
' operator. This works like multiplying by an integer (0-255)
' and a fraction (in units of 1/255). For example, to multiply
' 17 by Pi (approx 3.1416) would be written "17 */ $0324."
' The second value is written in hex to emphasize that it's being
' split into bytes: $03 is the integer and $24/$FF is the fraction.
' In the C-to-F conversion below, we multiply the C value by 1.8
' with "*/ $01CC" since $CC/$FF (204/255) = 0.8.
' ===================== Define Pins and Variables ================
DQ·· CON·· 2·· ' Pin 2 <=> DQ.
CLK·· CON·· 1·· ' Pin 1· => CLK.
RST·· CON·· 0·· ' Pin 0· => RST (high = active).
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·· %10·· ' Config bit: serial thermometer mode.
NoCPU·· CON·· %00·· ' 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 ============================
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,CLK,LSBFIRST,[noparse][[/noparse]Wconfig,NoCPU]·· ' ..temp conversions.
LOW RST········ ' Done--deactivate.
PAUSE 50····· ' Wait for the EEPROM to self-program.
HIGH RST····· ' Activate the '1620 and set it for continuous..
SHIFTOUT DQ,CLK,LSBFIRST,[noparse][[/noparse]WhiT,$23]·· ' Write TH.
LOW RST········ ' Done--deactivate.
PAUSE 1000····· ' Wait for the EEPROM to self-program.
HIGH RST····· ' Activate the '1620 and set it for continuous..
SHIFTOUT DQ,CLK,LSBFIRST,[noparse][[/noparse]WloT,$14]·· ' Write TL.
LOW RST········ ' Done--deactivate.
PAUSE 1000····· ' Wait for the EEPROM to self-program.
HIGH RST····· ' Now activate it again and send the..
SHIFTOUT DQ,CLK,LSBFIRST,[noparse][[/noparse]StartC]·· ' Send start-conversion protocol.
LOW RST········ ' Done--deactivate.
' 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,CLK,LSBFIRST,[noparse][[/noparse]Rtemp]·· ' Request to read temperature.
· SHIFTIN DQ,CLK,LSBPRE,[noparse][[/noparse]DSdata\9]·· ' Get the temperature reading.
· LOW RST
· 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 SDEC DSdata," degrees F",CR·· ' Show signed temperature in F.
GOTO again··········· ' Repeat forever.
Please post the program that gave you·7 and 122·readings for TL and TH that incorporated the changes Tracy (9 bits,·double the desired·setpoint)·and I (correct command code, insert pauses)·suggested.· Also, did that program give the correct temperature, and did the temperature change if you heated or cooled the DS1620?·
The latest program may be having problems because you are setting the mode to "no CPU" before you set TL and TH.· But this·program does not read the TL and TH, so I am not sure how you determined how TL and TH went to 0.·
Nate
PS - If you post your program as an attachment, it is easy for people trying to help to make changes and then sent to modified program back to you for testing.
Post Edited (Nate) : 9/3/2006 1:26:28 PM GMT
SHIFTOUT DQ,CLK,LSBFIRST,[noparse][[/noparse]WloT,$28\9] ' Write TL.
not
SHIFTOUT DQ,CLK,LSBFIRST,[noparse][[/noparse]WloT,$14] ' Write TL.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Norm Childs