DS2760 Propeller Code
Greg Norton
Posts: 70
As my way of learning Spin, I am attempting to interface my propeller to the DS2760 thermocouple module sold by Parallax. I'm part way there, but I have a couple of questions. Any help or feedback is appreciated.
Thanks.
Greg
Question 1
I'm trying to translate this bit of of the demo code for the BS2, and I think I have everything but the last statement "tCuV = ABS tCuV */ 4000". Can someone guide me with the equivalent bit of spin code here? I read this operator is multiply and return middle 16 bits. I haven't found an obvious equivalent in Spin.
This is the BS2 code:
My attempt is this (tCuv = tc_voltage):
Question 2
According to the DS2760 docs:
Ttc = LU(Vsb + LU(Tcj))
Where:
Ttc = thermocouple final temp
LU = look up function from a table
Vsb = Seebeck voltage read from current register on DS2760
Tcj = Cold Junction Temp read from temperature register on DS2760
Am I on the right track?
Thanks.
Greg
Question 1
I'm trying to translate this bit of of the demo code for the BS2, and I think I have everything but the last statement "tCuV = ABS tCuV */ 4000". Can someone guide me with the equivalent bit of spin code here? I read this operator is multiply and return middle 16 bits. I haven't found an obvious equivalent in Spin.
This is the BS2 code:
Read_TC_Volts: OWOUT OW, %0001, [noparse][[/noparse]SkipNet, RdReg, $0E] ' read current register OWIN OW, %0010, [noparse][[/noparse]tCuV.BYTE1, tCuV.BYTE0] Parallax, Inc. DS2760 Thermocouple Kit (#28022) 01/2004 7 sign = tCuV.BIT15 ' save sign bit tCuV = tCuV >> 3 ' correct alignment IF sign THEN tCuV = tCuV | $F000 ' pad 2's-compliment bits ENDIF tCuV = ABS tCuV */ 4000 ' x 15.625 uV RETURN
My attempt is this (tCuv = tc_voltage):
ow.reset ow.writeByte(SKIP_ROM) ow.writeByte(READ_DATA) ow.writeByte(I_REG_MSB) tc_voltage.byte := ow.readByte tc_voltage.byte[noparse][[/noparse]0] := ow.readByte tc_voltage ~>= 3 if (tc_voltage & $8000) tc_voltage |= $F000 <what goes here?> result := tc_voltage
Question 2
According to the DS2760 docs:
Where is the table for the "cold junction compensation voltage"? I have found tables for the thermocouple voltages, but I haven't figured out this compensation bit. I'm reading this as:BS2 Demo Code said...
Using the DS2760 we can measure the Seebeck voltage from the thermocouple with a resolution of 15.625 microvolts, then measure the cold junction temperature with a resolution of 0.125 degrees Celsius. A simple table look-up using the cold junction temperature will give us the cold junction compensation voltage. This is combined with the Seebeck voltage and, using a modified binary search algorithm, we can determine the compensated temperature from the thermocouple data table.
Ttc = LU(Vsb + LU(Tcj))
Where:
Ttc = thermocouple final temp
LU = look up function from a table
Vsb = Seebeck voltage read from current register on DS2760
Tcj = Cold Junction Temp read from temperature register on DS2760
Am I on the right track?
Comments
It is just a way to multiply times 15_5/8, which is equivalent to 4000/256. The Stamp */ 4000 operator has the divide by 256 implied. So you could do
tc_voltage := tc_voltage * 125 ~> 3 ' note sign extended divide by 8
or using the Prop ** operator, in which 0.625 is (2,684,354,560/4,294,967,296) with the division by 2^32 implied.
tc_voltage := (tc_voltage * 15) + (tc_voltage ** 2_684_354_560)
However I don't think the second formula will work when tc_voltage going in is negative, because ** does not manage the sign right for twos complement. Incidentally, I think there is a bug in the BASIC Stamp code in that regard too, because */ does not handle negative numbers correctly. In your spin code, I don't think it needs the business with the conditional on the sign bit. The Spin arithmetic ~> operator takes care of that.
Q2:
The cold junction compensation voltage is in fact a simply the voltage that comes from the table when you enter with the temperature of the cold junction. Add that to the voltage produced by the thermocouple, and look down the in the table to find the correct temperature of the thermocouple. Your reading is correct.
Ttc = Lookdown(Vtc + Vcj(Tcj)) '
...Vcj is a lookup given Tcj, maybe with interpolaltion.
...Ttc is a lookdown maybe with interpolation, given the sum of the voltages. Binary search is fastest.
If the cold junction happens to be at zero degrees Celsius, the compensation voltage will be zero and the voltages from the thermocouple will correspond exactly to the table. If the cold junction is at a higher temperature, the voltage Vtc will be lower than it would had the cold junction been at zero, and adding the compensation voltage brings it back into line with the table. These can also be computed with polynomials, the forward and reverse polynomials.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Greg
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Timothy D. Swieter, E.I.
www.brilldea.com·- Prop Blade, LED Painter, RGB LEDs, uOLED-IOC, eProto fo SunSPOT, BitScope
www.sxmicro.com - a blog·exploring the SX micro
www.tdswieter.com