Originally Posted by
Dave
Jim, I have converted much of my code from old projects using the 18F4620 to 18F46K22's. I have a few questions. What are you doing with the RESET line to the part? Are you looking at the DONE bit for the conversion to complete? If I could see the section of code you are using for configuring the part and reading it I can probably help.
Code:
'DS1620 Constants:
RdTmp CON $AA 'read temperature
WrHi CON $01 'write TH (high temp)
WrLo CON $02 'write TL (low temp)
RdHi CON $A1 'read TH
RdLo CON $A2 'read TL
RdCntr CON $A0 'read counter
RdSlope CON $A9 'read slope
StartC CON $EE 'start conversion
StopC CON $22 'stop conversion
WrCfg CON $0C 'write config register
RdCfg CON $AC 'read config register
THi CON 85 'high temp alarm
TLo CON 40 'low temp alarm
'DS1620 Variables:
tempIn VAR Word ' Raw temperature + Temporary conversion var
tsign VAR tempIn.BIT8 ' 1 = negative temperature
tC VAR Word ' Celsius Temp
tF VAR Word ' Fahrenheit Temp
tF2 VAR Word ' Fahrenheit Temp
HIGH TRS1 ' Initialize DS1620 Temp Sensors (Once at program start)
SHIFTOUT TDAT, TCLK, LSBFIRST, [WrCfg, %10] 'Use with CPU; free-run
LOW TRS1
PAUSE 10
HIGH TRS1
SHIFTOUT TDAT, TCLK, LSBFIRST, [StartC] 'Start conversions
LOW TRS1
HIGH TRS2 'Alert the DS1620 #2
SHIFTOUT TDAT, TCLK, LSBFIRST, [WrCfg, %10] 'Use with CPU; free-run
LOW TRS2
PAUSE 10
HIGH TRS2
SHIFTOUT TDAT, TCLK, LSBFIRST, [StartC] 'Start conversions
LOW TRS2
Read_DS1620:
HIGH TRS1 ' Alert the DS1620
Pause 5
SHIFTOUT TDAT, TCLK, LSBFIRST, [RdTmp] ' Command to read temp
SHIFTIN TDAT, TCLK, LSBPRE, [tempIn\9] ' Read it in as 9 bit word
LOW TRS1 ' Release the DS1620
tempIn.BYTE1 = -tsign ' Extend sign bit
tC = tempIn * 5 ' Convert to tenths
IF (tC.BIT15 = 0) THEN ' Temp C is positive
tF = tC */ $01CC + 320 ' Convert to F
ELSE ' Temp C is negative
tF = 320 - ((ABS tC) */ $01CC) ' Convert to F
ENDIF
Pause 10
HIGH TRS2 ' Alert the DS1620-2
Pause 5
SHIFTOUT TDAT, TCLK, LSBFIRST, [RdTmp] ' Command to read temp
SHIFTIN TDAT, TCLK, LSBPRE, [tempIn\9] ' Read it in as 9 bit word
LOW TRS2 ' Release the DS1620-2
tempIn.BYTE1 = -tsign ' Extend sign bit
tC = tempIn * 5 ' Convert to tenths
IF (tC.BIT15 = 0) THEN ' Temp C is positive
tF2 = tC */ $01CC + 320 ' Convert to F
ELSE ' Temp C is negative
tF2 = 320 - ((ABS tC) */ $01CC) ' Convert to F
ENDIF
RETURN
Bookmarks