PDA

View Full Version : DS1602 High-res code from NV



Orion
07-30-2005, 10:52 PM
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, [StartC]····· ' start conversion
· LOW DsRst
· DO
··· HIGH DsRst
··· SHIFTOUT DsDQ, DsClk, LSBFIRST, [RdCfg]···· ' read config register
··· SHIFTIN DsDQ, DsClk, LSBPRE, [tempIn\8]
··· LOW DsRst
· LOOP UNTIL (tempIn.BIT7 = 1)················· ' wait until conversion done
· HIGH DsRst
· SHIFTOUT DsDQ, DsClk, LSBFIRST, [RdTmp]······ ' read temp
· SHIFTIN DsDQ, DsClk, LSBPRE, [tempIn\9]
· LOW DsRst
· HIGH DsRst
· SHIFTOUT DsDQ, DsClk, LSBFIRST, [RdCntr]····· ' read counter
· SHIFTIN DsDQ, DsClk, LSBPRE, [cRem\9]
· LOW DsRst
· HIGH DsRst
· SHIFTOUT DsDQ, DsClk, LSBFIRST, [RdSlope]···· ' read slope
· SHIFTIN DsDQ, DsClk, LSBPRE, [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

dandreae
07-30-2005, 11:06 PM
Here is a link to an application note "under the download section" that may help you test the chip and see if it is still performing correctly:· http://www.parallax.com/detail.asp?product_id=604-00002

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 (mailto:dandreae@parallax.com)
http://www.parallax.com



Post Edited (Dave Andreae (Parallax)) : 7/30/2005 4:11:55 PM GMT

Jon Williams
07-30-2005, 11:28 PM
How are you testing?

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

Orion
07-30-2005, 11:38 PM
Sensor is inside a freezer that I'm trying to keep 31<>32.5. Currently I keep the last reading and the current is compared. If the reading should have a difference of more than 1.50F it’s discarded and the last is used. Sensor is on about 4 feet of cat5 soldered at both ends with the stamp outside at room temp. Same wiring as in the article. As I said before it has no problems with temps outside of 32.00 & 31.55. Currently I have stampdaq logging all the values for tempIn, cRem, slope, tC, and tF hopefully this will shed some light on this.

Jon Williams
07-30-2005, 11:40 PM
Can you post some of those raw values? I'd like to run the calculations manually and try Tracy's equation as well.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax

Orion
07-30-2005, 11:46 PM
Still working though the math be here are some #s

tempIn, cRem, slope, tC
0,94,127,0 fine
0,98,127,65533 bad
0,97,127,65534 bad
0,99,127,65533 bad

Orion
07-31-2005, 12:03 AM
hmm
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

Tracy Allen
07-31-2005, 12:22 AM
I think I see the problem. It is possible for the first equation below to come out negative (from the tC-25), so that the division by 5 in the second equation does not work. That is a 0.25 degree trouble band.

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 (http://www.emesystems.com)

Jon Williams
07-31-2005, 12:26 AM
I've sorted it out -- I believe -- and it makes sense.· Any temperature between 32 (0 C) and 31.5 (-0.5 C) will be reported with a positive sign bit in tempIn (due to the estimation by the DS1620),·but the result using slope and cRem could be negative.· By checking the sign of the hi-res result (in C), we can correct the equation:

··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

Orion
07-31-2005, 12:44 AM
will try out heres some more #s. It's looks like it takes .5C before tempin goes -

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

Orion
07-31-2005, 12:49 AM
No problem Jon, thank you! I thought it was me and it was going to take all weekend to fix.

Thanks again to both of you.

Jon Williams
07-31-2005, 01:00 AM
I'm sure that I can speak for my friend, Tracy, in saying that it is our pleasure to help.· And again, thank you for reporting the problem.· After a bit of reconsideration I found that I could streamline my hi-res code using a trick Tracy employs for extending the sign bits of tempIn.· Here's the core of the calculations that go at the end of Get_HR_Temp:

· 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

Orion
08-03-2005, 04:19 AM
Just an FYI, both you code fixes work great from -1F to 80F.