Shop OBEX P1 Docs P2 Docs Learn Events
Date Time and Temp — Parallax Forums

Date Time and Temp

Mike WMike W Posts: 105
edited 2008-05-08 18:55 in General Discussion
I have added a DS1620 to my clock project and I am having a problem getting a good tempreature.

I used CNVRT_F a C to F conversion I found on the forum, but I am not sure I am getting a good read from the DS1620. The GET_TEMP subrutine

The clock protion of the program works fine

I have tried to optimize the program as best as I could, It uses a lot of program space.

I attached the program "Clock_12_rev2_tmp.SXB"

It's to big to post.

If anyone could look it over, I could use the help.

Mike

Comments

  • Mike WMike W Posts: 105
    edited 2008-04-26 18:39
    I would like to start out that I realize that I dont post good questions

    I feel I dont give enough information ot I am not to the point

    I am trying to do better

    my goal was to set the DS1620 to work with a CPU in one shot mode.

    Start a tempreature conversion and wait for conversion to complete by monitoring bit 7 of the configuration register.

    Then read the tempreature, first 8 bits to degC, the ninth bit into signC, and then gosub to CNVRT_F to convert to Fahrenheit.

    here is the subrutine

    INT_DS:

    DS_Reset = 1 ' select device

    SHIFTOUT DS_I_O, DS_Clock, LSBFIRST, WriteConfig '

    SHIFTOUT DS_I_O, DS_Clock, LSBFIRST, %00000011 ' (%00000010-CPU, continuious)(%00000011-CPU, one-shot)

    DS_Reset = 0 ' deselect device

    WAIT_MS 10 ' allow DS1620 EE to write

    RETURN

    '

    GET_TEMP:

    DS_Reset = 1 '

    SHIFTOUT DS_I_O, DS_Clock, LSBFIRST, StartConvert ' start conversion

    DS_Reset = 0 '

    WAIT_MS 10 ' pause before shiftout

    DO '

    DS_Reset = 1 '

    SHIFTOUT DS_I_O, DS_Clock, LSBFIRST, ReadConfig '

    SHIFTIN DS_I_O, DS_Clock, LSBPRE, tmpB1 '

    DS_Reset = 0 '

    LOOP UNTIL tmpB1.7 = 1 ' Wait for conversion to complete

    WAIT_MS 10 ' pause before shiftout

    DS_Reset = 1 '

    SHIFTOUT DS_I_O, DS_Clock, LSBFIRST, ReadTemp '

    SHIFTIN DS_I_O, DS_Clock, LSBPRE, degC ' get temp 8 bits

    SHIFTIN DS_I_O, DS_Clock, LSBPRE, signC\1 ' get sign 1 bit

    DS_Reset = 0 '

    degC = degC + degC.0 ' round up

    degC = degC >> 1 ' remove half bit

    degC = degC - 3 ' I don't know why it just works better

    CNVRT_F degC '

    RETURN

    '

    My question concerns these lines of code.

    these two lines came from the SX THERMOMETER example program in the help file.

    I dont totally understand them i just used them as they were

    degC = degC + degC.0 ' round up

    degC = degC >> 1 ' remove half bit

    I added this line because my readings were always higher than my reference by 8 to 10 degeers

    between the range of 70 - 80 degrees F this works (displays the correct temp in that range) but I am not sure if it is a fix, or just a trick.

    degC = degC - 3 ' I don't know why it just works better

    is there an error or something wrong with my code or could it be a inaccurate chip

    attached is the full program "Clock_12_time_date_temp.SXB"

    mike

  • John CoutureJohn Couture Posts: 370
    edited 2008-04-27 21:13
    The DS1620 provides·9 bits of output using two 8 bit registers.

    The LSB represents only 0.5 degrees C.

    The degC.0 is rounding the reading DOWN to an integer C amount and then the >> 1 shifts the reading so that you have a nice integer that you can display. If you didn't do that your reading would be twice what it should be. The -3 is the equivalent of subtracting 1.5C from your reading. However, if you do not do the shift then your reading is going to be off.

    The MSB (the 9th bit) is actually a sign bit. You could check this bit and if = 1 then the temperature is below freezing.

    Because you can read up to 125C these sensors are perfect for atmospheric readings and it would be rare that you get above 50 deg C (122 deg F).

    Remember that when reading wind temperature, the temperature can vary by a couple of degrees several times a minute. Thus, sacrificing the half of a degree is generally not a problem.

    Edited:

    Oops, forgot to post datasheet·reference

    http://pdfserv.maxim-ic.com/en/ds/DS1620.pdf

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    John J. Couture

    San Diego Miramar College

    Post Edited (John Couture) : 4/27/2008 9:36:21 PM GMT
  • Mike WMike W Posts: 105
    edited 2008-05-01 21:21
    Next issue

    the resolution I am getting reading the DS1620 is 1.8 ºF instead of .9ºF as the data sheet says.

    I have tried one shot and continuious mode I even tried another new chip same thing.

    I tried·getting the tempreature once a minute,·twice a minute and continuious readings always

    the same 1.8 ºF·instead if .9ºF.

    How can I change/fix this this.

    mike
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-05-02 21:06
    Mike,

    The Digital Thermostat code for the BS2 at the following link offers 1 degree of resolution. I was having the same problem and it was due to the math being done on the BASIC Stamp. Tracy Allen showed me a way to convert to Kelvin First to save some loss. I hope this helps. Take care.

    http://forums.parallax.com/showthread.php?p=519605

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • Mike WMike W Posts: 105
    edited 2008-05-08 18:55
    Here is what I came up with. It displays degrees Fahrenheit, whole degrees only no fraction.
    I am still using the CNVRT_F subroutine from the C_to_F__V3 mike-cook posted.
    I changed the first few lines that got rid of the fractional part.
    After converting to Fahrenheit, degrees F advances 1 degree every .5 degrees C.
    from the thermometers I have to check it by it seems to work ok.
    ·
    I have a question about these lines of code.
    They advance the clock registers to set the clock when a button is pushed.
    Is there any way to optimize this routine to save program memory and achieve the same result.
    ·
    SET_CLOCK:

    ·DO·················································································· '
    ·· IF BtnMins = 0 THEN······················································ ' minutes
    · INC Mins········································································· '
    ··· Mins = Mins // 60····························································' minutes = 0 to 59
    · LCD_OUT LcdLine0_11····· ······················· ··········· ··········· '
    · GET_DEC Mins································································
    ··· WAIT_MS 250·································································
    ·LOOP UNTIL BtnMins = 1···················································
    ·· ENDIF············································································
    ·DEC2BCD Mins································································
    ·Mins = tmpB2··········································································
    '

    ·DO··················································································· '
    ··· IF BtnHrs = 0 THEN························································ ' hours
    · INC Hrs············································································ '
    ·· Hrs = Hrs / 13································································· ' hours 1 to 12
    ·· Hrs = __REMAINDER | Hrs·············································· '
    ···· IF Hrs = 12 THEN························································· '
    ···· tmp1 = ~tmp1·············· ······················· ··········· ··········· ' change AM PM
    ···· ENDIF·················································································
    · LCD_OUT LcdLine0_8···································································
    · GET_DEC Hrs········································································
    ··· WAIT_MS 250··································································
    ·LOOP UNTIL BtnHrs = 1·······················································
    ·· ENDIF···················································································
    ·DEC2BCD Hrs·········································································
    ·Hrs = tmpB2············································································
    · Hrs_Bit_5 = tmp1················ ······················· ··········· ··········· ' change am pm bit
    · Hrs_Bit_7 = 1· ······················· ······················· ··········· ··········· ' has to stay 1·· for 12 hr···········
    '

    ·
    ·
    Thanks,
    ·
    Mike
Sign In or Register to comment.