Tracy need some advice
Guido
Posts: 195
Tracy,
I have been playing with this program that you gave me advice on. I am still having trouble displaying of tempF and TL logging when temperature reaches ·0 F. It kind of goes to decimal display. Could use some help if you have a chance.
GetTemperature:
HIGH Reset ' ALERT THE DS1620
SHIFTOUT DQ,Clock,LSBFIRST,[noparse][[/noparse]RdTmp]
SHIFTIN DQ,Clock,LSBPRE,[noparse][[/noparse]tempIn\9]
LOW Reset
tempC=tempIn*5 'Celsius value *10, resolution 0.5 degree
tempF = tempC + 1000 * 9 / 5 - 1800 + 320
tempIn.BYTE1 = -tempIn.BIT8 ' extend sign
SELECT tempF
CASE >TH
ADDR = 170
GOSUB Save
TH = tempF
CASE <TL
ADDR = 150
GOSUB Save
TL = tempF
ENDSELECT
RETURN
·
DEBUG HOME
DEBUG "CURRENT TEMP",CR
DEBUG REP "-"\TEMPF.BIT15,DEC TEMPF/10,".",DEC1 TEMPF," F ",CR
DEBUG "LOW TEMP",CR
DEBUG REP "-"\TL.BIT15,DEC TL/10,".",DEC1 TL," F ",CR
DEBUG "HIGH TEMP",CR
DEBUG REP "-"\TH.BIT15,DEC TH/10,".",DEC1 TH," F ",CR
I have been playing with this program that you gave me advice on. I am still having trouble displaying of tempF and TL logging when temperature reaches ·0 F. It kind of goes to decimal display. Could use some help if you have a chance.
GetTemperature:
HIGH Reset ' ALERT THE DS1620
SHIFTOUT DQ,Clock,LSBFIRST,[noparse][[/noparse]RdTmp]
SHIFTIN DQ,Clock,LSBPRE,[noparse][[/noparse]tempIn\9]
LOW Reset
tempC=tempIn*5 'Celsius value *10, resolution 0.5 degree
tempF = tempC + 1000 * 9 / 5 - 1800 + 320
tempIn.BYTE1 = -tempIn.BIT8 ' extend sign
SELECT tempF
CASE >TH
ADDR = 170
GOSUB Save
TH = tempF
CASE <TL
ADDR = 150
GOSUB Save
TL = tempF
ENDSELECT
RETURN
·
DEBUG HOME
DEBUG "CURRENT TEMP",CR
DEBUG REP "-"\TEMPF.BIT15,DEC TEMPF/10,".",DEC1 TEMPF," F ",CR
DEBUG "LOW TEMP",CR
DEBUG REP "-"\TL.BIT15,DEC TL/10,".",DEC1 TL," F ",CR
DEBUG "HIGH TEMP",CR
DEBUG REP "-"\TH.BIT15,DEC TH/10,".",DEC1 TH," F ",CR
Comments
The raw temperature, tempIn is a 9 bit number that uses the ninth bit as a sign. Move this statement,
... tempIn.BYTE1 = -tempIn.BIT8 ' extend sign
up to right after the shiftin. After that, the multiplication to get Celsius with resolution of 0.5 degree and the conversion to Fahrenheit are set up okay for negative (twos complement) numbers.
But the SELECT CASE statement will not work correctly when the Fahrenheit temperature is negative. Suppose the temperature is -1 degree Fahrenheit. To the Stamp, that is the same as 65535, so the SELECT CASE statement will treat that as a very large positive number, not a negative number. To make it work, you have to make all of the arguements positive in the CASE statements. Use a statement like this:
... rankine=tempF+4370 ' this is a positive number
... SELECT rankine
... CASE >TH+4370 ' compare positives
... ...
... CASE <TL+4370
... ...
Also, your DEBUG statement will not work as written for negative numbers. You have,
... DEBUG REP "-"\TEMPF.BIT15,DEC TEMPF/10,".",DEC1 TEMPF," F ",CR
But what you need is absolute values, like this:
... DEBUG REP "-"\tempF.BIT15,DEC ABS tempF/10,".",DEC1 ABS tempF," F ",CR
I hope that helps!
-- Tracy
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com