DS2760 doubt
jabezsdavid
Posts: 11
when I compile this temperature program, I am to get output as out of range. I deleted some lines from the program which I got it DS2760 thermocouple kit. could some one tell what went wrong in this program given below.
'
[noparse][[/noparse] Initialization ]
Check_Device:
OWOUT OW, %0001, [noparse][[/noparse]ReadNet]
OWIN OW, %0010, [noparse][[/noparse]SPSTR 8]
GET idx, char
IF (char<>$30)THEN
DEBUG "No DS2760 found."
STOP
ENDIF
'
[noparse][[/noparse] Program Code ]
Main:
DO
GOSUB Read_TC_Volts
GOSUB Read_CJ_Temp
READ(tmpCJ * 2),cjComp
IF sign THEN
IF (tCuV < cjComp) THEN
cjComp = cjComp - tCuV
ELSE
cjComp = 0
ENDIF
ELSE
cjComp = cjComp + tCuV
ENDIF
LOOKUP type, [noparse][[/noparse]1023, 1023, 400], tblHi
GOSUB TC_Lookup
tempF = tempC * 9 / 5 + 32
IF (error = 0) THEN
DEBUG CRSRXY, 0, 7,
"Temp °C..... ", SDEC tempC, CLREOL
DEBUG CRSRXY, 0, 8,
"Temp °F..... ", SDEC tempF, CLREOL
ELSE
DEBUG CRSRXY, 0, 7,
"Temp °C..... Out of Range", CLREOL
DEBUG CRSRXY, 0, 8,
"Temp °F..... Out of Range", CLREOL
ENDIF
PAUSE 1000
LOOP
END
Read_Vin:
OWOUT OW, %0001, [noparse][[/noparse]SkipNet, RdReg, $0C]
OWIN OW, %0010, [noparse][[/noparse]vIn.BYTE1, vIn.BYTE0]
IF (vIn.BIT15) THEN
vIn = 0
ELSE
vIn = vIn >> 5 */ $4E1
ENDIF
RETURN
Read_TC_Volts:
OWOUT OW, %0001, [noparse][[/noparse]SkipNet, RdReg, $0E]
OWIN OW, %0010, [noparse][[/noparse]tCuV.BYTE1, tCuV.BYTE0]
sign = tCuV.BIT15
tCuV = tCuV >> 3
IF sign THEN
tCuV = tCuV | $F000
ENDIF
tCuV = ABS tCuV */ 4000
RETURN
Read_CJ_Temp:
OWOUT OW, %0001, [noparse][[/noparse]SkipNet, RdReg, $18]
OWIN OW, %0010, [noparse][[/noparse]tmpCJ.BYTE1, tmpCJ.BYTE0]
IF (tmpCJ.BIT15) THEN
tmpCJ = 0
ELSE
tmpCJ = tmpCJ.HIGHBYTE
ENDIF
RETURN
TC_Lookup:
tblLo = 0
tempC = 22
READ (tblHi * 2), Word testVal
IF (cjComp > testVal) THEN
error = 1
ELSE
DO
eePntr = (tblLo + tblHi) / 2
READ (eePntr * 2), Word testVal
IF (cjComp = testVal) THEN
EXIT
ELSEIF (cjComp < testVal) THEN
tblHi = eePntr
ELSE
tblLo = eePntr
ENDIF
IF ((tblHi - tblLo) < 2) THEN
eePntr = tblLo
EXIT
ENDIF
LOOP
tempC = eePntr
ENDIF
RETURN
'
[noparse][[/noparse] Initialization ]
Check_Device:
OWOUT OW, %0001, [noparse][[/noparse]ReadNet]
OWIN OW, %0010, [noparse][[/noparse]SPSTR 8]
GET idx, char
IF (char<>$30)THEN
DEBUG "No DS2760 found."
STOP
ENDIF
'
[noparse][[/noparse] Program Code ]
Main:
DO
GOSUB Read_TC_Volts
GOSUB Read_CJ_Temp
READ(tmpCJ * 2),cjComp
IF sign THEN
IF (tCuV < cjComp) THEN
cjComp = cjComp - tCuV
ELSE
cjComp = 0
ENDIF
ELSE
cjComp = cjComp + tCuV
ENDIF
LOOKUP type, [noparse][[/noparse]1023, 1023, 400], tblHi
GOSUB TC_Lookup
tempF = tempC * 9 / 5 + 32
IF (error = 0) THEN
DEBUG CRSRXY, 0, 7,
"Temp °C..... ", SDEC tempC, CLREOL
DEBUG CRSRXY, 0, 8,
"Temp °F..... ", SDEC tempF, CLREOL
ELSE
DEBUG CRSRXY, 0, 7,
"Temp °C..... Out of Range", CLREOL
DEBUG CRSRXY, 0, 8,
"Temp °F..... Out of Range", CLREOL
ENDIF
PAUSE 1000
LOOP
END
Read_Vin:
OWOUT OW, %0001, [noparse][[/noparse]SkipNet, RdReg, $0C]
OWIN OW, %0010, [noparse][[/noparse]vIn.BYTE1, vIn.BYTE0]
IF (vIn.BIT15) THEN
vIn = 0
ELSE
vIn = vIn >> 5 */ $4E1
ENDIF
RETURN
Read_TC_Volts:
OWOUT OW, %0001, [noparse][[/noparse]SkipNet, RdReg, $0E]
OWIN OW, %0010, [noparse][[/noparse]tCuV.BYTE1, tCuV.BYTE0]
sign = tCuV.BIT15
tCuV = tCuV >> 3
IF sign THEN
tCuV = tCuV | $F000
ENDIF
tCuV = ABS tCuV */ 4000
RETURN
Read_CJ_Temp:
OWOUT OW, %0001, [noparse][[/noparse]SkipNet, RdReg, $18]
OWIN OW, %0010, [noparse][[/noparse]tmpCJ.BYTE1, tmpCJ.BYTE0]
IF (tmpCJ.BIT15) THEN
tmpCJ = 0
ELSE
tmpCJ = tmpCJ.HIGHBYTE
ENDIF
RETURN
TC_Lookup:
tblLo = 0
tempC = 22
READ (tblHi * 2), Word testVal
IF (cjComp > testVal) THEN
error = 1
ELSE
DO
eePntr = (tblLo + tblHi) / 2
READ (eePntr * 2), Word testVal
IF (cjComp = testVal) THEN
EXIT
ELSEIF (cjComp < testVal) THEN
tblHi = eePntr
ELSE
tblLo = eePntr
ENDIF
IF ((tblHi - tblLo) < 2) THEN
eePntr = tblLo
EXIT
ENDIF
LOOP
tempC = eePntr
ENDIF
RETURN
Comments
one thing that will help forum members help you is for you to place your code between two "code tags". They look like this except you need to take out the spaces
[noparse][[/noparse] code ]
[noparse][[/noparse] / code ]
What happens when you run the demo code without making modifications and making sure all slots get loaded?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
·
Menu:
DEBUG CLS,
"===============================", CR,
" DS2760 Thermocouple Interface ", CR,
"===============================", CR,
CR,
"Select TC Type (1 - 3)", CR,
CR,
"(1) K - Chromel/Alumel", CR,
"(2) J - Iron/Constantan", CR,
"(3) T - Copper/Constantan", CR,
CR,
">>> "
DEBUGIN DEC1 type
IF (type < 1) OR (type > 3) THEN Menu
DEBUG CRSRXY, 0, 3, CLRDN
STORE type
Show_SN:
DEBUG CRSRXY, 0, 4, "Device SN... "
FOR idx = 0 TO 7
GET idx, char
DEBUG HEX2 char
NEXT
Show_Type:
DEBUG CRSRXY, 0, 6, "TC Type..... "
LOOKUP (type - 1), [noparse][[/noparse]"KJT"], char
DEBUG char