Keep the maximum and minimum readings from DS1620
![Moskog](https://forums.parallax.com/uploads/userpics/YDMRIZWSNI67/nM5W1YOCC13O1.jpg)
Hello again.
I am thinking about keeping the max and min readings from a ds1620 temperature device, lets say I would like to·display the coldest temperature·that was read last night, and the hottest reading the following day.
Today I send the binary numbers read from the ds1620 from the outside bs2 through the parallax tx and rx devices to my·kitchen bs2 that·computes and display the celcius reading on a lcd display.
Temperature readings are updated every second on the lcd.
So I guess.. that the easiest way to handle temperature numbers is by first converting to Kelvin. I found a description on that made by dr. Tracy Allen.
The do all computing and storing, keeping track of the max and min readings while the temperature still is in Kelvin, then converting back to Celsius only just before displaying.
Am I right in this or is there easier ways (for the bs2)·like·staying with the·ds1620 binarys all the way to handle max and minimums before displaying?
Any comments will be appreciated.
I am thinking about keeping the max and min readings from a ds1620 temperature device, lets say I would like to·display the coldest temperature·that was read last night, and the hottest reading the following day.
Today I send the binary numbers read from the ds1620 from the outside bs2 through the parallax tx and rx devices to my·kitchen bs2 that·computes and display the celcius reading on a lcd display.
Temperature readings are updated every second on the lcd.
So I guess.. that the easiest way to handle temperature numbers is by first converting to Kelvin. I found a description on that made by dr. Tracy Allen.
The do all computing and storing, keeping track of the max and min readings while the temperature still is in Kelvin, then converting back to Celsius only just before displaying.
Am I right in this or is there easier ways (for the bs2)·like·staying with the·ds1620 binarys all the way to handle max and minimums before displaying?
Any comments will be appreciated.
Comments
newTemp = (ds1620Temp + 128) & $1FF
You can keep a maximum and minimum by doing
if newTemp < minTemp then minTemp = newTemp
if newTemp > maxTemp then maxTemp = newTemp
minTemp has to be initialized to 255 and maxTemp has to be initialized to 0
To convert back to a 2's complement temperature in 1/2 degrees Celsius, do
displayTemp = newTemp - 128
It can be either
newTemp = (ds1620Temp + 546) ' to convert degC*2 to Kelvin
or
newTemp = (ds1620Temp + 128) ' to convert degC*2 to an intermediate positive definite form.
Eiither one, or a host of other constants, will work just fine. Then subtract the same constant after the MIN and MAX calculations. Or the adjusted constant after, say, a Fahrenheit conversion.
A shorter way to calculate the minimum and maximum temperatures uses the Stamp's own MIN and MAX operators.
minTemp = minTemp MAX newTemp
maxTemp = maxTemp MIN newTemp
It may seem strange to use the MIN operator to calculate the maximum temperature and the MAX operator to calculate the minimum, but that is because of the way the Stamp operators are defined, more like old analog computer floor and ceiling operators (see the manual). The values have to be initialized as Mike says.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Just one question, the variable "ds1620Temp" thats the whole string coming out of the ds1620, I mean all 9 bits, right?
Tracy Allen. I been watching the code and the LCD for several nights but cant seem to figure out whats wrong.
I have one question, in the "newTemp = (theTemp + 128) & $1FF", what does "& $1FF" really do?
When the temperature is 0 Celsius the display shows +0.0C (temperature now), the Max shows +0.0C but the Minimum toggles between +0.0C and +64.0C for each loop of the code.
If the temperature goes below zero then the Max is toggling.
Why does it toggle?
I have a very stripped code attached (took away all other code not related to temperature) just to make it more readable. On this code you can simulate 0C, +25C and -25C and use the debug screen.
I am sure there are some real bad errors but I cant figure out what it is.
Any help will be appreciated!
What's happening is that the DS1620 provides values from $100 to $1FF corresponding to temperatures from -128.0C to -0.5C and values from $000 to $0FF corresponding to temperatures from 0C to +127.5C. What you want is a positive number ranging from $000 to $1FF corresponding to temperatures from -128.0C to +127.5C. The idea is that you shift the whole number range upwards by 128C. Unfortunately, I forgot that the units were in 0.5C rather than 1.0C and gave you the wrong constant to add. The $1FF keeps everything in 9-bit arithmetic by masking off the other bits.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Post Edited (Tracy Allen) : 12/5/2008 8:24:42 AM GMT
In Mikes,
newTemp = (theTemp + $100) & $1FF
it is easy to see that if theTemp from the sensor is positive, the value of newTemp will be in the range of $100 to $1FF, that is to say, 256 to 511 in decimal. How about when theTemp going in is negative? Say $1FF (-0.5 degree), then newTemp = ($1FF + $100) & $1FF = $2FF & $1FF = $0FF, which is 255 in decimal, which is as it should be, one less than the shifted value of zero. The negative temperature values fall into place from 0 to 255, less than the originally positive values. The &1FF is necessary to drop the carry/borrow and keep it in 9 bits. When converted to 16 bits, the "&" is not necessary, because the 16 bit word automatically drops the carry/borrow.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Today its about -13 Celsius here in Norway and I had to get out and heat the ds1620 with a heat gun, then get back into the kitchen to check if things worked correctly. The Low did stay at -13.5C and the High·climed·to +7.0C and stayed there while the ds1620 temperature again fell down to -12.5C like it is now.
·
Testing on the kichen table, Up left on LCD is temperature now, "Nord-øst" means north-east wind direction. Next line "Vindstille" means calm, 0.0 meters/sec.·Line 3·shows Max wind speed.·Line 4·shows Max temperature and Min temperature, (High - Low).
The bs2 is almost full,· no more space for further program extentions. Maybe a bs2e would be a good solution?
Thanks anyway for all help this time!
If you do go for a multislot Stamp, I'd recommend the BS2pe over the BS2e. The BS2pe has several additional commands that you may find worthwhile, among them, ones that make interface to I2C and OneWire devices easy, and also the STORE command that allows your program to READ and WRITE across slot boundaries, and also more scratchpad RAM for variables.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Ok, BS2pe sounds to be a good choice, thanks so much for that advice.
Still -13 C here.. and a little windy too, felt good to stay inside and do pbasics today. One feet of snow in the valley, up to three or more in the hills. That's today's weather report from mid-Norway.
Could you Please·post your working code for this project
Thank so much
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any·
·
·
·
·
Sam
As this project is still under construction I'm not sure I will post the code on the forum yet, but I can send it to you as a private message so you can take a look.