Shop OBEX P1 Docs P2 Docs Learn Events
temperatur sensor SMT 160-30 — Parallax Forums

temperatur sensor SMT 160-30

ArchiverArchiver Posts: 46,084
edited 2002-02-25 01:55 in General Discussion
Hi Jon,
Your subroutine gave me god inspirations
the main problem was that I lost to much reminder in the divisions
it means to much accuracy and the temperature was shown in 2 degree steps

I have a question about Your formula:
tempC = (tempC * 2) + (tempC ** $20AE) ' = tempC * 2.12765
I use it and it works fine but i don't realy understand it.
the ** gives back the high 16 bits hex 20AE = 8366
but how this multiplication really happen I don't see.....
Could You give me a light ?
Thanks Heinz



The spec sheet says this:

"So to achieve the wished accuracy it is necessary to sample over more than
one sensor period. This way of working has also the advantage to filter
noise."

Here's a subroutine that takes five samples and returns the temperature:

Get_SMT160_Temp:
tHigh = 0
tLow = 0

FOR x = 1 TO 5
PULSIN Tpin, 1, pWidth
tHigh = tHigh + (pWidth / 5)
PULSIN Tpin, 0, pWidth
tHigh = tLow + (pWidth / 5)
NEXT

' temperature = (duty - 32) / 0.47

tempC = (tHigh * 100) / tLow ' calc duty cycle
tempC = (tempC - 32)
tempC = (tempC * 2) + (tempC ** $20AE) ' = tempC * 2.12765
RETURN

The PULSIN accuracy of the BS2p is 0.75 uS -- way beyond what you need to
read this sensor accurately. According the spec, an accuracy of 50 mS will
give a temperature accuracty of 0.1C.

Please not that I don't have a sensor to test with, I wrote this code
against
the spec sheet. HTH.

-- Jon Williams
-- Parallax


In a message dated 2/21/02 9:14:13 AM Central Standard Time,
hschwenk@g...
writes:


> I use stamp2p
> and try to ad an temp-sensor
> the SMT 160 is an Pulse-width modulated temp-sensor
> frequency is between 1 and 4 kHz
> The duty cycl is direct proportional to the temperature.
> So I thought it is very easy to use with the pulsin command
>
> td var word
> tp var word
>
> pulsin 1,1,td
> pulsin 1,0,tp
>
> and some calculations and finish..............
> but..
> when I use debug "td= ",dec td," tp= ",dec tp,cr
> I get : td= 146 tp= 223 (about 18°C)
> The problem now is:
> W i t h o u t changing the temperature I get sometimes
> "td" and "tp" changed from 146 to 151
> = 5* 0,75µSec ... it is too much
> after my calculations I got a different of 1-2°C
> W i t h o u t changing the temperature !!
>




[noparse][[/noparse]Non-text portions of this message have been removed]


To UNSUBSCRIBE, just send mail to:
basicstamps-unsubscribe@yahoogroups.com
from the same email address that you subscribed. Text in the Subject and
Body of the message will be ignored.


Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2002-02-23 19:39
    Hello Heinz

    The ** and the */ operators are the BASIC Stamps' way to multiply by
    a fraction. The ** operator is also used in double precision
    calculations, because it returns the high 16 bits of a
    multiplication.

    Consider what happens when you multiply C = A ** B. The product of A
    times B is effectively divided by 65536, using integer division, with
    the fractional part (lower 16 bits) dropped. So if you have a number
    you need to multiply times 0.12765, you can approximate 0.12765 by
    the fraction 8366/65536.
    say 10000 * 0.12765 = 1276
    is the same as 10000 * (8366/65536) = 1276
    and on the Stamp:
    C = 10000 ** 8366 ' the division by 65536 is implied.

    or to multiply times 2.1276 as Jon suggested, you have:
    C = (10000 * 2) + (10000 ** 8366) ' C=21276 is the result

    I looked at the SMT160 data sheet and see that the minimum frequency
    from the SMT160 is 1 khz (and as high as 4 khz). The duty cycle is
    about 32% at 0 degrees C and 93% at 130 degrees C. That means that
    the count from the PULSIN command will never be greater than 500 on
    the BS2 or 1333 counts on the BS2p. So in the averaging routine
    there is no need to divide by 5 (which throws away resolution):

    tHigh=0:tLow=0
    FOR x = 1 TO 5
    PULSIN Tpin, 1, pWidth
    tHigh = tHigh + pWidth
    PULSIN Tpin, 0, pWidth
    tLow = tLow + pWidth
    NEXT

    The maximum value of tHigh or tLow is now 2500 on the BS2 or 6665 on
    the BS2p. I think the duty cycle they refer to should be the ratio
    of the high time to the total time, but I do not see that
    specifically stated in the data sheet:
    duty=tHigh/(tHigh+tLow)
    This is always a number between zero and one. Is that the Smartec
    formula for duty cycle, do you think?

    The most accurate way to calculate the ratio is by use of a long
    division routine. Here it is, so you can see it is not too
    complicated:

    tTotal = tHigh+tLow
    '
    binary division loop
    for J=15 to 0 ' 16 bits
    tHigh=tHigh//tTotal<<1 ' remainder*2
    duty.bit0(J)=tHigh/tTotal ' next bit
    next

    What that gives you is the duty cycle as a number from 0 to 65535,
    which has an implied denominator of 65536, ready for a ** operation.
    I use now the formula from Smartec: degC=(duty - 0.32)*212.76, but I
    rearrange it as follows to get resolution to 1/100 degree C, and also
    to have correct treatment of negative temperatures: degC = duty *
    21276 - 6808. In Stamp math that is:
    degC = duty ** 21276 - 6808

    That is temperature in 1/100 degree Celsius. I have not actually
    tried it with a Smartec sensor. Like Jon, I am only going on the
    data sheet.

    -- regards,
    Thomas Tracy Allen Ph.D.
    electronically monitored ecosystems
    mailto:tracy@e...
    http://www.emesystems.com/BS2index.htm <<--- more math tutorial here.





    >Hi Jon,
    >Your subroutine gave me god inspirations
    >the main problem was that I lost to much reminder in the divisions
    >it means to much accuracy and the temperature was shown in 2 degree steps
    >
    >I have a question about Your formula:
    >tempC = (tempC * 2) + (tempC ** $20AE) ' = tempC * 2.12765
    >I use it and it works fine but i don't realy understand it.
    >the ** gives back the high 16 bits hex 20AE = 8366
    >but how this multiplication really happen I don't see.....
    >Could You give me a light ?
    >Thanks Heinz
    >
    >
    >>
    >>The spec sheet says this:
    >>
    >>"So to achieve the wished accuracy it is necessary to sample over more than
    >>one sensor period. This way of working has also the advantage to filter
    >>noise."
    >>
    >>Here's a subroutine that takes five samples and returns the temperature:
    >>
    >>Get_SMT160_Temp:
    >> tHigh = 0
    >> tLow = 0
    >>
    >> FOR x = 1 TO 5
    >> PULSIN Tpin, 1, pWidth
    >> tHigh = tHigh + (pWidth / 5)
    >> PULSIN Tpin, 0, pWidth
    >> tHigh = tLow + (pWidth / 5)
    >> NEXT
    >>
    >> ' temperature = (duty - 32) / 0.47
    >>
    >> tempC = (tHigh * 100) / tLow ' calc duty cycle
    >> tempC = (tempC - 32)
    >> tempC = (tempC * 2) + (tempC ** $20AE) ' = tempC * 2.12765
    >> RETURN
    >>
    >>The PULSIN accuracy of the BS2p is 0.75 uS -- way beyond what you need to
    >>read this sensor accurately. According the spec, an accuracy of 50 mS will
    >>give a temperature accuracty of 0.1C.
    >>
    >>Please not that I don't have a sensor to test with, I wrote this code
    >>against
    >>the spec sheet. HTH.
    >>
    >>-- Jon Williams
    >>-- Parallax
    >>
    >>
    >>In a message dated 2/21/02 9:14:13 AM Central Standard Time,
    >>hschwenk@g...
    >>writes:
    >>> > I use stamp2p
    >>> > and try to ad an temp-sensor
    >>> > the SMT 160 is an Pulse-width modulated temp-sensor
    >>> > frequency is between 1 and 4 kHz
    >>> > The duty cycl is direct proportional to the temperature.
    >>> > So I thought it is very easy to use with the pulsin command
    >>> >
    >>> > td var word
    >>> > tp var word
    >>> >
    >>> > pulsin 1,1,td
    >>> > pulsin 1,0,tp
    >>> >
    >>> > and some calculations and finish..............
    >>> > but..
    >>> > when I use debug "td= ",dec td," tp= ",dec tp,cr
    >>> > I get : td= 146 tp= 223 (about 18°C)
    >>> > The problem now is:
    >>> > W i t h o u t changing the temperature I get sometimes
    >>> > "td" and "tp" changed from 146 to 151
    >>> > = 5* 0,75µSec ... it is too much
    >>> > after my calculations I got a different of 1-2°C
    >>> > W i t h o u t changing the temperature !!
    >>> >
  • ArchiverArchiver Posts: 46,084
    edited 2002-02-24 03:58
    Heinz:

    You know ... I work for Parallax and I really don't know how to explain it
    (I'll have to ask Chip [noparse][[/noparse]BASIC Stamp designer] when I go out to the main
    office in a few weeks).

    What I can tell you is this: The ** operator is like multiplying by a
    fractional value (that must be less than 1). The units in the ** parameter
    are 1/65536. So, if you want to multiply a number by, for example, 0.12765
    you do this:

    0.12765 x 65536 = 8366

    Hopefully that line of code now makes sense.

    I downloaded the specs for your part ... but they're not very clear. They
    say you can get 0.5C resolution with an input accuracy that is a lot less
    than the Stamp provides. I'd have to test the part myself to fully
    understand it but don't know if they're available in the States (haven't
    checked).

    Now ... for some really good help for using Stamps and maintaining sensor
    accuracy, you should visit Tracy Allen's site. He makes weather data loggers
    and needs good accuracy (he's a Ph.D. and knows his stuff).

    Here's the link: http://www.emesystems.com/BS2index.htm

    Good luck.

    -- Jon Williams
    -- Parallax
    -- Dallas, TX USA

    In a message dated 2/23/02 11:53:28 AM Central Standard Time,
    hschwenk@g... writes:


    > Hi Jon,
    > Your subroutine gave me god inspirations
    > the main problem was that I lost to much reminder in the divisions
    > it means to much accuracy and the temperature was shown in 2 degree steps
    >
    > I have a question about Your formula:
    > tempC = (tempC * 2) + (tempC ** $20AE) ' = tempC * 2.12765
    > I use it and it works fine but i don't realy understand it.
    > the ** gives back the high 16 bits hex 20AE = 8366
    > but how this multiplication really happen I don't see.....
    > Could You give me a light ?
    >




    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2002-02-24 05:37
    I've tried samples of the TMP-03 and TMP-04 from Analog Devices.
    Those are similar to the Smartec MT16030, in that the temperature is
    converted into a ratio of time intervals.

    <http://www.analog.com/productSelection/descriptions/tmp03_4.html>

    <http://www.smartec.nl/index.htm?/smart2.htm>

    -- Tracy
  • ArchiverArchiver Posts: 46,084
    edited 2002-02-24 12:35
    Hi Jon,
    thanks for Your reply and effort!
    Tracy gave a very god explanation
    He has a god clear way to explain.

    All my question marks are eliminated.
    have a nice Sunday
    regards Heinz




    > Heinz:
    >
    > You know ... I work for Parallax and I really don't know how to explain it
    > (I'll have to ask Chip [noparse][[/noparse]BASIC Stamp designer] when I go out to the main
    > office in a few weeks).
    >
    > What I can tell you is this: The ** operator is like multiplying by a
    > fractional value (that must be less than 1). The units in the **
    parameter
    > are 1/65536. So, if you want to multiply a number by, for example,
    0.12765
    > you do this:
    >
    > 0.12765 x 65536 = 8366
    >
    > Hopefully that line of code now makes sense.
    >
    > I downloaded the specs for your part ... but they're not very clear. They
    > say you can get 0.5C resolution with an input accuracy that is a lot less
    > than the Stamp provides. I'd have to test the part myself to fully
    > understand it but don't know if they're available in the States (haven't
    > checked).
    >
    > Now ... for some really good help for using Stamps and maintaining sensor
    > accuracy, you should visit Tracy Allen's site. He makes weather data
    loggers
    > and needs good accuracy (he's a Ph.D. and knows his stuff).
    >
    > Here's the link: http://www.emesystems.com/BS2index.htm
    >
    > Good luck.
    >
    > -- Jon Williams
    > -- Parallax
    > -- Dallas, TX USA
    >
    > In a message dated 2/23/02 11:53:28 AM Central Standard Time,
    > hschwenk@g... writes:
    >
    >
    > > Hi Jon,
    > > Your subroutine gave me god inspirations
    > > the main problem was that I lost to much reminder in the divisions
    > > it means to much accuracy and the temperature was shown in 2 degree
    steps
    > >
    > > I have a question about Your formula:
    > > tempC = (tempC * 2) + (tempC ** $20AE) ' = tempC * 2.12765
    > > I use it and it works fine but i don't realy understand it.
    > > the ** gives back the high 16 bits hex 20AE = 8366
    > > but how this multiplication really happen I don't see.....
    > > Could You give me a light ?
    > >
    >
    >
    >
    >
    > [noparse][[/noparse]Non-text portions of this message have been removed]
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the Subject and
    Body of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2002-02-25 01:55
    >Hi Jon,
    >thanks for Your reply and effort!
    >Tracy gave a very god explanation
    >He has a god clear way to explain.
    >
    >All my question marks are eliminated.
    >have a nice Sunday
    >regards Heinz


    Thanks, Heinz. I am humbled. So many question marks! Maybe a
    "good" explanation, albeit of a smallish "god"; I am sure He
    understands it (((much)^much)^much...) better than I do!

    -- Tracy
Sign In or Register to comment.