Ds2760
dberkstresser
Posts: 5
Hi, I am trying to read a DS2760 thermocouple using the propeller chip. I have figured some of it out but translating code in a language I don't know into a language I just started learning is tough. I have the chip data-sheet from Maxim and the example program written for the BS2p.
I am reading the cold junction temp fine. (I think)
I am getting the data for the TC volts but I am having trouble formatting it.
Also, I can't figure out how the table lookup is working, this will probably be client-side code so I just need pseudo-code or an explanation. I have the tables, I just need to know how to interpret them.
TC Volts: I read 2 bytes using the 1-wire module, then reverse them for some reason (thats how the bs2p one works?), bit-shift them right 3, and print as an integer?
Anyway, here is the relevant section of my hacked OW-SearchDemo file. Any help would be greatly appreciated.
Thanks,
Dan
Post Edited (dberkstresser) : 3/29/2007 9:05:11 PM GMT
I am reading the cold junction temp fine. (I think)
I am getting the data for the TC volts but I am having trouble formatting it.
Also, I can't figure out how the table lookup is working, this will probably be client-side code so I just need pseudo-code or an explanation. I have the tables, I just need to know how to interpret them.
TC Volts: I read 2 bytes using the 1-wire module, then reverse them for some reason (thats how the bs2p one works?), bit-shift them right 3, and print as an integer?
Anyway, here is the relevant section of my hacked OW-SearchDemo file. Any help would be greatly appreciated.
Thanks,
Dan
PUB main | n, i, p term.start(12) ' start TV terminal Serial.start(1,0,0,9600) ' Rx,Tx, Mode, Baud ow.start(OW_DATA) ' start 1-wire object, pin 0 repeat setColor(6) displayString(0, 0, string(" Temperature Monitor Test ")) setColor(0) ow.reset ow.writeByte($CC) ow.writeByte($69) ow.writeByte($18) temp1 := ow.readByte temp2 := ow.readByte ow.reset ow.writeByte($CC) ow.writeByte($69) ow.writeByte($0E) tc_volt1:=ow.readByte tc_volt2:=ow.readByte tc_volt.byte[noparse][[/noparse] 1]:=tc_volt1 tc_volt.byte[noparse][[/noparse]0]:=tc_volt2 tc_volt:=tc_volt >> 3 displayString(5, 13, Num.ToStr(tc_volt1, Num#BIN)) displayString(6, 13, Num.ToStr(tc_volt2, Num#BIN)) displayString(7, 13, Num.ToStr(tc_volt, Num#BIN)) displayString(8, 13, Num.ToStr(tc_volt, Num#DEC)) tempF := f.FAdd(f.FMul(f.FFloat(temp1), 1.8), 32.0) displayString(5, 3, string("CJ Temp")) displayString(6, 3, string("Deg C:")) displayString(7, 3, Num.ToStr(temp1, Num#DEC)) displayString(8, 3, string("Deg F:")) displayString(9, 3, fp.FloatToString(tempF)) Serial.Str(string("!NB0W00:")) 'Assign Pink Variable 01: tempF Serial.Str(fp.FloatToString(tempF)) Serial.tx(CLS) waitcnt(12_000_000 + cnt)
Post Edited (dberkstresser) : 3/29/2007 9:05:11 PM GMT
Comments
The following might work for you
Scott
FYI: I had to change
PUB Setup(background,units_,thermocouple_type_,sample_count_,data_pin_)
to
PUB Setup(background_,units_,thermocouple_type_,sample_count_,data_pin_)
and comment out this:
else
background:=true
cognew(MainCog(temperature_), @Stack)
..to get it to compile. You may want to merge the first change at least into your code.
PUB Temperature:temp | c
c:=Sample
if c == 0
c:=Sample_CJ_Temp
I noticed that the contents of the lookup table got lost in the [noparse][[/noparse] code] box. Maybe that was just my system, Firefox on a Mac? It did come through in part in the email version, so I know it is (I think) a table for the typeK thermocouple.
A different table would be required for typeT or typeJ. Simply declaring a different type won't work, although typeT is quite close to typeK near room temperature. Dan, you asked about the table lookup and how to translate it to the server side. The steps in any software based algorithm for thermocouples are:
1) Measure the temperature of the reference junction. (Usually a simple translation from voltage)
2) Look up the voltage that your thermocouple would produce at that temperature in relation to an ice reference.
This can either be a table lookup, or a polynomial calculation. Interpolate if necessary.
The table Scott provided and the one in the Parallax docs give the voltage output as a function of Celsius temperature, for example, 39 microvolts output at +1 degree Celsius, and so on up to around 1000 degrees Celsius.
3) Read the voltage produced by the thermocouple, which will be the temperature with the reference junction at the temperature determined in step 1.
4) Add the voltage from step 2 to the voltage in step 3. That will give the voltage that the thermocouple would have produced if its reference junction had actually been at zero Celsius.
5) Look up the temperature that corresponds to that voltage. For that, you either need a separate table of temperatures as a function of voltage, or you need to do a reverse lookup in the same table you used in step 2. The latter is the usual way to do it, and the algorithm is a binary search to find the value in the table that is closest to the calculated voltage. Or interpolate between two values. This can also be done by calculation using an inverse polynomial.
There are references that have the tables for the different thermocouple types as well as both the forward and reverse polynomials. As Scott mentioned in another email, EXCEL can be a great help to convert the tables to DATA or LOOKUP.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
on the object exchange when there is some free time...
It was Firefox on Windows that did the post.
You are correct, each thermocouple type needs a different calibration table. I think
I have them all in a file some place.
This is some of my first spin code. Pretty messy...
Scott