Shop OBEX P1 Docs P2 Docs Learn Events
temperatur sensor SMT 160-30 V E R Y clear — Parallax Forums

temperatur sensor SMT 160-30 V E R Y clear

ArchiverArchiver Posts: 46,084
edited 2002-02-24 12:35 in General Discussion
Hi Tracy
a big thank to You!
Your explaining it very clear
I got it!
Your -binary division loop- is so
simple now...
to get this result I needed more then
20 lines of code to divide step by step multiply by 10
and divide the reminder...
now it looks so easy fantastic !
Your homepage is very informative and
helps to get deeper understanding

have a nice Sunday
regards Heinz



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 !!
>>> >


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/
Sign In or Register to comment.