DS1602 High-res code from NV
Orion
Posts: 236
I'm having a issue running the ds1602 with the code from NV123 File DS1602_HR.BS2.· http://www.parallax.com/dl/docs/cols/nv/vol6/col/nv123.pdf
When 3200< tF >3155 the code gives back tF as 6262.· At all other temps the reading is good, it just happens below 32.00F and above 31.55F.· Is there a problem with the math of the code when the ds1620 is just below freezing, or do I have a IC thats about to die??·
GetTemp:
HIGH DsRst
· SHIFTOUT DsDQ, DsClk, LSBFIRST, [noparse][[/noparse]StartC]····· ' start conversion
· LOW DsRst
· DO
··· HIGH DsRst
··· SHIFTOUT DsDQ, DsClk, LSBFIRST, [noparse][[/noparse]RdCfg]···· ' read config register
··· SHIFTIN DsDQ, DsClk, LSBPRE, [noparse][[/noparse]tempIn\8]
··· LOW DsRst
· LOOP UNTIL (tempIn.BIT7 = 1)················· ' wait until conversion done
· HIGH DsRst
· SHIFTOUT DsDQ, DsClk, LSBFIRST, [noparse][[/noparse]RdTmp]······ ' read temp
· SHIFTIN DsDQ, DsClk, LSBPRE, [noparse][[/noparse]tempIn\9]
· LOW DsRst
· HIGH DsRst
· SHIFTOUT DsDQ, DsClk, LSBFIRST, [noparse][[/noparse]RdCntr]····· ' read counter
· SHIFTIN DsDQ, DsClk, LSBPRE, [noparse][[/noparse]cRem\9]
· LOW DsRst
· HIGH DsRst
· SHIFTOUT DsDQ, DsClk, LSBFIRST, [noparse][[/noparse]RdSlope]···· ' read slope
· SHIFTIN DsDQ, DsClk, LSBPRE, [noparse][[/noparse]slope\9]
· LOW DsRst
· IF (sign = 0) THEN··························· ' positive?
··· tC = (tempIn / 2) * 100···················· ' yes, conver to 100ths
··· tC = tC - 25 + (slope - cRem * 100 / slope) ' fix fractional temp
··· tF = tC * 9 / 5 + 3200····················· ' convert to Fahr
· ELSE
··· tC = (tempIn / 2) | $FF00 * 100············ ' fix neg bits, make 100ths
··· tC = tC - 25 + (slope - cRem * 100 / slope) ' fix fractional temp
··· tF = 3200 - ((ABS tC) * 9 / 5)············· ' convert to Fahr
· ENDIF
·DEBUG·DEC tF,CR
RETURN
Post Edited (Orion) : 7/30/2005 3:58:36 PM GMT
When 3200< tF >3155 the code gives back tF as 6262.· At all other temps the reading is good, it just happens below 32.00F and above 31.55F.· Is there a problem with the math of the code when the ds1620 is just below freezing, or do I have a IC thats about to die??·
GetTemp:
HIGH DsRst
· SHIFTOUT DsDQ, DsClk, LSBFIRST, [noparse][[/noparse]StartC]····· ' start conversion
· LOW DsRst
· DO
··· HIGH DsRst
··· SHIFTOUT DsDQ, DsClk, LSBFIRST, [noparse][[/noparse]RdCfg]···· ' read config register
··· SHIFTIN DsDQ, DsClk, LSBPRE, [noparse][[/noparse]tempIn\8]
··· LOW DsRst
· LOOP UNTIL (tempIn.BIT7 = 1)················· ' wait until conversion done
· HIGH DsRst
· SHIFTOUT DsDQ, DsClk, LSBFIRST, [noparse][[/noparse]RdTmp]······ ' read temp
· SHIFTIN DsDQ, DsClk, LSBPRE, [noparse][[/noparse]tempIn\9]
· LOW DsRst
· HIGH DsRst
· SHIFTOUT DsDQ, DsClk, LSBFIRST, [noparse][[/noparse]RdCntr]····· ' read counter
· SHIFTIN DsDQ, DsClk, LSBPRE, [noparse][[/noparse]cRem\9]
· LOW DsRst
· HIGH DsRst
· SHIFTOUT DsDQ, DsClk, LSBFIRST, [noparse][[/noparse]RdSlope]···· ' read slope
· SHIFTIN DsDQ, DsClk, LSBPRE, [noparse][[/noparse]slope\9]
· LOW DsRst
· IF (sign = 0) THEN··························· ' positive?
··· tC = (tempIn / 2) * 100···················· ' yes, conver to 100ths
··· tC = tC - 25 + (slope - cRem * 100 / slope) ' fix fractional temp
··· tF = tC * 9 / 5 + 3200····················· ' convert to Fahr
· ELSE
··· tC = (tempIn / 2) | $FF00 * 100············ ' fix neg bits, make 100ths
··· tC = tC - 25 + (slope - cRem * 100 / slope) ' fix fractional temp
··· tF = 3200 - ((ABS tC) * 9 / 5)············· ' convert to Fahr
· ENDIF
·DEBUG·DEC tF,CR
RETURN
Post Edited (Orion) : 7/30/2005 3:58:36 PM GMT
Comments
I forgot to add that you can copy and paste the code out of the PDF file using the select text button in the tool bar.
Dave
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Dave Andreae
Tech Support
dandreae@parallax.com
Http://www.parallax.com
Post Edited (Dave Andreae (Parallax)) : 7/30/2005 4:11:55 PM GMT
Dr. Tracy Allen uses a slightly different set of equations -- though the result should be the same.· See this link for info:
http://www.emesystems.com/OL2d1620.htm
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Post Edited (Jon Williams (Parallax)) : 7/30/2005 4:32:05 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
tempIn, cRem, slope, tC
0,94,127,0 fine
0,98,127,65533 bad
0,97,127,65534 bad
0,99,127,65533 bad
tempIn, cRem, slope
0,97,127
tC=0-25+(127-97*100/127)
tC=-1.377 by my calc
I must be missing something in stamp order of ops or something if its getting 65534. These were outputing with the dec fomatter via serin switched to sdec on tempIn and tC and will look again
tC = tC - 25 + (slope - cRem * 100 / slope) ' fix fractional temp <--- -25 can leave tC negative
tF = tC * 9 / 5 + 3200 ' convert to Fahr <--- negative is trouble with /5
My equation to do that was,
x=slope-remain*100/slope ' compute 1/100ths degree <--- this is the same as the one in () above
degC=degC+550/10*100+x-5525 ' adjust temperature to 1/100ths
The temperature is offset +55.0 degrees Celsius to make is positive definite, and then add in the count remaining, and then subtract back out the 55.25 degrees (with the 0.25 degree offset). The operation /10*100 truncates the 0.5 degree bit per Dallas app note 105.
To convert Celsius to Fahrenheit (valid for negative temperatures 2s complement),
degF = degC + 10000 * 9 / 5 -18000 + 3200
That uses the same offset trick, adding 10000 to make the numbers positive, subsequently subtracting 18000 to remove the offset after the division, then adding the 32.00 degrees to complete the conversion to +/- xxx.xx degrees Fahrenheit. The constants can be combined. I left them separate to show what is going on.
Hey Jon, I thought you were taking the rest of Saturday off! me too. See ya!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
··IF (sign = 0) THEN··························· ' positive?
··· tC = (tempIn / 2) * 100···················· ' yes, conver to 100ths
··· tC = tC - 25 + (slope - cRem * 100 / slope) ' fix fractional temp
··· IF (tC.BIT15 = 0) THEN····················· ' positive?
····· tF = tC * 9 / 5 + 3200··················· ' convert to Fahr
··· ELSE
····· tF = 3200 - ((ABS tC) * 9 / 5)
··· ENDIF
· ELSE
··· tC = (tempIn·/ 2) | $FF00 * 100·········· · ' fix neg bits, make 100ths
··· tC = tC - 25 + (slope - cRem * 100 / slope) ' fix fractional temp
··· tF = 3200 - ((ABS tC) * 9 / 5)············· ' convert to Fahr
· ENDIF
The code in red is the fix.· I've attached my test program that uses your data.· Thanks for the feedback -- I'm adding Hi-Res DS1620 code to StampWorks so this fix comes just in time.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Post Edited (Jon Williams (Parallax)) : 7/30/2005 5:33:48 PM GMT
tempIN,cRem,slope,tC,tF
1,62,127,26,3246
0,82,127,10,3218
0,89,127,4,3207
0,93,127,1,3201
0,100,127,-4,16300
0,105,127,-8,16292
0,121,127,-21,16269
511,3,127,-28,3150
511,10,127,-33,3141
511,15,127,-37,3134
Thanks again to both of you.
· tempIn = tempIn >> 1························· ' remove half bit
· tempIn.BYTE1 = -tempIn.BIT7·················· ' extend (shifted) sign
· tC = tempIn * 100···························· ' convert to 100ths
· tC = tC - 25 + (slope - cRem * 100 / slope)·· ' fix fractional temp
· IF (tC.BIT15 = 0) THEN
··· tF = tC * 9 / 5 + 3200····················· ' convert pos C to Fahr
· ELSE
··· tF = 3200 - ((ABS tC) * 9 / 5)············· ' convert neg C to Fahr
· ENDIF
· RETURN
As you can see, redundant code has been removed.· I added your new readings to the program and everything looks good.· It's attached for you to run for yourself (it has a better output so you can see raw and calculated data).· Please let me know if you ever plug-in data that returns bad results.· I've edited this post twice to tweak the equation, so anything is possible.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Post Edited (Jon Williams (Parallax)) : 7/30/2005 6:46:59 PM GMT