Shop OBEX P1 Docs P2 Docs Learn Events
Tracy — Parallax Forums

Tracy

GuidoGuido Posts: 195
edited 2004-10-15 06:23 in BASIC Stamp
Tracy,
First off I want to Thank You for your help. I have really streamed lined my code with your example. I do have two problems. The first problem, I can not get the Low Temperature to work, will only display the tenths...The second problem is that the High Temperature will not hold the tenths?
Any Information will be greatly appreciated.
Thank You Again
Guido

Comments

  • Tracy AllenTracy Allen Posts: 6,658
    edited 2004-10-04 16:26
    You're welcome. There is a small structural problem with the program, in that it calls the subroutine "getTemperature", but then there is no RETURN. Nevertheless it is still exectuting all the code, I think, so that does not explain the display problem.

    The minimum and maximum need to be intitialized before "main".
    TH = 0
    TL = 9999 ' this so that the MAX function can work


    The DEBUG statements for TL and TH need to that TL and TF in both the integer part and in the fractional part. As it stands, there is a cut and paste error with "tempf" in the tenths position.

    Use the following to allow correct display of twos complement, x:

    DEBUG REP "-"\x.bit15,DEC ABS x/10,".",DEC1 ABS x," F ",CR

    You can't use SDEC when the numbers are negative, because the division by 10 does not work correctly on twos complement numbers.

    A further note on the MAX operator. (z = x MAX y) This is the same as (IF x > y THEN z = y ELSE z = x). So for example, if x = 752, representing 75.2 degrees Fahrenheit, and y = 9999, the initial value, then z = 752. If the temperature subsequently goes down to 70.1, then (z = 701 MAX 752) amd z = 701. So z is the minimum value. It is counterintuitive to use the MAX operator to find the minimum, but that is the way it works.

    Adding 1024 and subtracting it again at the end has the same end result: z = (701 + 1024) MAX (753 + 1024) - 1024 is the same as z = 1725 MAX 1777 - 1024 is the same as 1725 - 1024 and that is the end result 701. The purpose of offsetting by 1024 is to make the formula work even when the temperature is negative. There is nothing special about the number 1024. You could use 1000, or 10000 or 300, so long as it is a number greater than the most negative temperature your system will see.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • GuidoGuido Posts: 195
    edited 2004-10-05 14:34
    Tracy,
    Thank you, after reading it several times it made sense. I finally actually got it going and saved about 5% of the code.
    Thank You Again
    Guido
  • GuidoGuido Posts: 195
    edited 2004-10-10 17:15
    Tracy,

    Thank You again for your help. I have attached a simple Temperature code for the DS1620. The question I have is you mentioned using this new code would give me .1 accuracy.......seems I only get .9. Is this normal?

    Thank You Again!!!
    Guido
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2004-10-10 20:57
    Guido,

    Resolution is limited by the 9-bit value that you read out from the sensor. That is 0.5 degree Celsius per bit, or 0.9 degree Fahrenheit. The display routine I suggested displays the tenths of a degree, so that you can see the smallest possible changes, but it does not actually read to 0.1 degree accuracy. Sorry for the confusion.

    If you want to pursue it, you can in fact extract much higher resolution from the sensor and track incredibly small changes in temperature, like 0.01 degree Celsius. It takes more programming work though. I have a tutorial posted at this URL:
    www.owlogic.com/OL2d1620.htm

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Jonny555Jonny555 Posts: 46
    edited 2004-10-10 21:19
    Thanks Tracy that was very interesting, I had not even noticed a mention of .01 degree·resolution in the 1620 spec sheet. I will definately update my code!

    Jonny
  • GuidoGuido Posts: 195
    edited 2004-10-15 06:23
    Tracy,

    Thank You again for the information.....Getting close with everyones help! I still have one problem I can not figure out as far as programming from your TH or TL equations.

    TL=(TEMPF + 1024) MAX (TL+1024) - 1024
    TH=(TEMPF + 1024) MIN (TH+1024) -1024

    IF TEMPF/10 => TH/10 AND TH/10 <> TH/10 THEN U:
    IF TEMPF/10 =< TL/10 AND TL/10 <> TL/10 THEN V:
    RETURN

    I am trying to have a one shot at High and Low Temperature Readings. Here is an example above, I have tried every different combination and still can't seem to lock it in. Basically if the Low temperature is equal to the low temperature I do not want to keep writing it in. the =< for low and => for High sends it continously until temperature is out of range...Even tried else no helpppppp! Thought about using a flag, but no way to reset it.....

    Any ideas?
Sign In or Register to comment.