DS1626 Temp chip
Tex4u
Posts: 30
I have been trying to get the DS1626 to work with my BS2.· I have·code from a site for the DS1620 that I have tried to modify.· The·data from the DS1626 is currently reads·178·F.· It is actually about 76 F.·
Here is my code as·I have messed with it.· All help is appreciated.
Thanks,
Frank
' {$STAMP BS2}
' {$PBASIC 2.5}
'DS1626x.bs2
x··· VAR Word························ ' define a general purpose variable
sign VAR x.BIT15····················· ' sign bit of x
degC VAR Word························ ' define a variable to hold degrees Celsius
degF VAR Word························ ' to hold degrees Fahrenheit
HIGH 14······························ ' select the DS1626 "Pin 14=RST"
SHIFTOUT 12,13,LSBFIRST,[noparse][[/noparse]81]········· ' "start convertions" "Pin 12=DQ, Pin 13=CLK"
LOW 14······························· ' do the command
· PAUSE 1000························· ' wait for the conversion
Again:······························· ' going to loop once per second
· HIGH 14···························· ' select the DS1626
· SHIFTOUT 12,13,LSBFIRST,[noparse][[/noparse]170]······ ' send the "get data" command
· SHIFTIN 12,13,LSBPRE,[noparse][[/noparse]x\12]········ ' get the data, including sign
· LOW 14····························· ' end the command
· x.BYTE1 = -x.BIT12················· ' extend the sign to 16 bits
· degC=x*5··························· ' convert to 'C*10 (resolution 0.5 'C)
····································· ' & show the result on the PC screen
· DEBUG CRSRXY, 0,0,· "DegC= ",REP "-"\degc.BIT15,DEC ABS degC/10,".",DEC1 ABS degC
· degF= degC+2732*9/50-459··········· 'C*10 to 'F (first to Kelvin*10)
· DEBUG· CRSRXY, 0,2,"DegF= ", SDEC degf· ' show it as a whole number with sign
· PAUSE 1000························· ' 2 second pause
GOTO Again··························· ' read & display temperature again
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The more I look for common sense in the world...
what I find is how un-common it is.
·
Here is my code as·I have messed with it.· All help is appreciated.
Thanks,
Frank
' {$STAMP BS2}
' {$PBASIC 2.5}
'DS1626x.bs2
x··· VAR Word························ ' define a general purpose variable
sign VAR x.BIT15····················· ' sign bit of x
degC VAR Word························ ' define a variable to hold degrees Celsius
degF VAR Word························ ' to hold degrees Fahrenheit
HIGH 14······························ ' select the DS1626 "Pin 14=RST"
SHIFTOUT 12,13,LSBFIRST,[noparse][[/noparse]81]········· ' "start convertions" "Pin 12=DQ, Pin 13=CLK"
LOW 14······························· ' do the command
· PAUSE 1000························· ' wait for the conversion
Again:······························· ' going to loop once per second
· HIGH 14···························· ' select the DS1626
· SHIFTOUT 12,13,LSBFIRST,[noparse][[/noparse]170]······ ' send the "get data" command
· SHIFTIN 12,13,LSBPRE,[noparse][[/noparse]x\12]········ ' get the data, including sign
· LOW 14····························· ' end the command
· x.BYTE1 = -x.BIT12················· ' extend the sign to 16 bits
· degC=x*5··························· ' convert to 'C*10 (resolution 0.5 'C)
····································· ' & show the result on the PC screen
· DEBUG CRSRXY, 0,0,· "DegC= ",REP "-"\degc.BIT15,DEC ABS degC/10,".",DEC1 ABS degC
· degF= degC+2732*9/50-459··········· 'C*10 to 'F (first to Kelvin*10)
· DEBUG· CRSRXY, 0,2,"DegF= ", SDEC degf· ' show it as a whole number with sign
· PAUSE 1000························· ' 2 second pause
GOTO Again··························· ' read & display temperature again
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The more I look for common sense in the world...
what I find is how un-common it is.
·
Comments
In 12 bit mode, each bit represents 0.0625 degC. So instead of multiply time 0.5, you have to multiply the raw reading times 0.0625. The program you have above muliplies *5 to get 0.5 degC resolution.
In 12 bit mode, the DS1626 outputs a raw count of 2000 when the temperature is 125 degC. Suppose you want to display that as 125.0, or in general, scale it to display units of 0.1. Use this conversion equation:
degC = x ** 40960
Note that 40960/65536 = 0.625. You could alternatively scale it to get 0.01 degree resolution.
Also, the program above does not do configuration (command=$0C), to put the device in 12 bit, continuous conversion mode. That may be the default, or it may be done in a separate one time program, because those settings are non-volatile.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Just one more question. Can you tell me what this line of code does?
x.BYTE1 = -x.BIT12 ' extend the sign to 16 bits
I am guessing that it takes the high byte of the variable x and sets it equal to the opposite of bit12? I don't know what that would do or what it has to do with "extending the sign to 16 bits". I had to remark this line out for my code to convert the temp into the right number.
Thanks again,
Coming along slowly.
Frank
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The more I look for common sense in the world...
what I find is how un-common it is.
·
x.nib3 = -x.bit11 ' extend sign
The purpose of the statement is to make high 4 bits of x high if bit11 is high.
x.bit11 is the sign bit for the data returned by the DS1626, so -1 degC comes in as,
%0000111111111111
But -1 in twos complement on the Stamp has to be
%1111111111111111
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com