natural log function
Archiver
Posts: 46,084
Hi, I want to convert a voltage to a temperature and the equation I'm
using is -50*LN(voltage)+198
Can anyone help me with the code to do this equation on the stamp2
since the stamp can only do integer arithmetic I'm having a hard time.
Thanks
using is -50*LN(voltage)+198
Can anyone help me with the code to do this equation on the stamp2
since the stamp can only do integer arithmetic I'm having a hard time.
Thanks
Comments
best as possible and use one of several linearized equations......Not being a
stamp expert that is how I would start...or a giant look up table.
I am sure some stamp experts will chime is with a better idea.
ken
==========================
Hi, I want to convert a voltage to a temperature and the equation I'm
using is -50*LN(voltage)+198
Can anyone help me with the code to do this equation on the stamp2
since the stamp can only do integer arithmetic I'm having a hard time.
Thanks
[noparse][[/noparse]Non-text portions of this message have been removed]
>Hi, I want to convert a voltage to a temperature and the equation I'm
>using is -50*LN(voltage)+198
>
>Can anyone help me with the code to do this equation on the stamp2
>since the stamp can only do integer arithmetic I'm having a hard time.
>
>Thanks
You may find some of the information here to be of interest in doing math on the Basic Stamp:
http://www.emesystems.com/BS2index.htm#math
Regards,
Bruce Bates
voltage is coming from an A/D converter with 8 bits. You could store a
lookup table with 256 entries that simply "knows" the answer to the equation
(of course, you still have to use integers -- maybe 152 is really 15.2,
though).
If you want to do floating point, look at our PAK-II, IX, and XII
coprocessors. All have natural log and the IX and XII also have A/D
converters. The PAK-II and IX use SHIFTIN/SHIFTOUT in a very efficient
protocol. The PAK-XII uses RS232 and works sort of like an RPN calculator --
very easy to use. Read more at http://www.awce.com/pak2.htm and
http://www.awce.com/pak12.htm
Tracy may have some other ideas on cheating LN :-)
Regards,
Al Williams
AWC
http://www.awce.com
Original Message
From: vilet_bounnam [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=q5R7DUK-A5tIaC2cENJYgRZV6_qc3FnWzfJRgliQsLjICyJdQeqeXgHX45dX8oo_KRUiwX6tlk0Rk5viDGh-]vilet_bounnam@y...[/url
Sent: Sunday, May 23, 2004 9:04 PM
To: basicstamps@yahoogroups.com
Subject: [noparse][[/noparse]basicstamps] natural log function
Hi, I want to convert a voltage to a temperature and the equation I'm using
is -50*LN(voltage)+198
Can anyone help me with the code to do this equation on the stamp2 since the
stamp can only do integer arithmetic I'm having a hard time.
Thanks
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.
Yahoo! Groups Links
lookup table.
On Mon, 24 May 2004, vilet_bounnam wrote:
> Hi, I want to convert a voltage to a temperature and the equation I'm
> using is -50*LN(voltage)+198
>
> Can anyone help me with the code to do this equation on the stamp2
> since the stamp can only do integer arithmetic I'm having a hard time.
>
> Thanks
>
>
>
>
> 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.
>
> Yahoo! Groups Links
>
>
>
>
>
>
Sean T. Lamont, CTO / Chief NetNerd, Abstract Software, Inc. (ServNet)
Seattle - Bellingham - Vancouver - Portland - Everett - Tacoma - Bremerton
email: lamont@a... WWW: http://www.serv.net
"Do not fear mistakes, There Are None" - Miles Davis
I'm inputing 8 channels from the max186 and currently I have 5 tables
and am using up 98% of the EEPROM memory on the stamp.
--- In basicstamps@yahoogroups.com, "Sean T. Lamont .lost."
<lamont@a...> wrote:
>
> How granular do you need to be? You could just encode it in ram and
use a
> lookup table.
>
> On Mon, 24 May 2004, vilet_bounnam wrote:
>
> > Hi, I want to convert a voltage to a temperature and the equation I'm
> > using is -50*LN(voltage)+198
> >
> > Can anyone help me with the code to do this equation on the stamp2
> > since the stamp can only do integer arithmetic I'm having a hard time.
> >
> > Thanks
> >
> >
> >
> >
> > 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.
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
> >
>
> Sean T. Lamont, CTO / Chief NetNerd, Abstract Software, Inc. (ServNet)
> Seattle - Bellingham - Vancouver - Portland - Everett - Tacoma -
Bremerton
> email: lamont@a... WWW: http://www.serv.net
> "Do not fear mistakes, There Are None" - Miles Davis
> since the stamp can only do integer arithmetic I'm having a hard time.
>-50*LN(voltage)+198
If voltage is less than 5, the temperature comes out at greater than
117. Is that equation right, you are working at high temperatures?
The max186 will give an answer in millivolts, so the equation becomes,
temperature = -50 * LN(millivolts/1000) + 198
= -50 * (LN(millivolts) - LN(1000)) + 198
= -50 * (LN(millivolts) - 6.91) + 198
= -50 * LN(millivolts) + 544
= -35 * LG(millivolts) + 544
The last step converts from natural log to binary (base 2) log.
LN(x) = 0.69315 * LG(x). All that serves to make integer values that
the Stamp can deal with. From there you have a number of
possibilities, including direct calculation of log base 2:
http://www.emesystems.com/BS2math3.htm#Logcalc
All of the compact methods, including the bitlog function and the
table lookups, rely on the "periodic" characteristics of the
logarithm function (as seen on log graph paper). You can separate the
characteristic from the mantissa. The characteristic is the integer
part of the logarithm, and the Stamp has a built-in function "NCD" to
calculate that.
-- Tracy
car. I did come across your webpage Tracy and played around with
your Log function but how do I deal with the -50 or -35 that I have
to multiply before the LN function?
-Thanks
--- In basicstamps@yahoogroups.com, Tracy Allen <tracy@e...> wrote:
> >Can anyone help me with the (max186) code to do this equation on
the stamp2
> > since the stamp can only do integer arithmetic I'm having a hard
time.
> >-50*LN(voltage)+198
>
> If voltage is less than 5, the temperature comes out at greater
than
> 117. Is that equation right, you are working at high temperatures?
>
> The max186 will give an answer in millivolts, so the equation
becomes,
> temperature = -50 * LN(millivolts/1000) + 198
> = -50 * (LN(millivolts) - LN(1000)) + 198
> = -50 * (LN(millivolts) - 6.91) + 198
> = -50 * LN(millivolts) + 544
> = -35 * LG(millivolts) + 544
> The last step converts from natural log to binary (base 2) log.
> LN(x) = 0.69315 * LG(x). All that serves to make integer values
that
> the Stamp can deal with. From there you have a number of
> possibilities, including direct calculation of log base 2:
> http://www.emesystems.com/BS2math3.htm#Logcalc
>
>
> All of the compact methods, including the bitlog function and the
> table lookups, rely on the "periodic" characteristics of the
> logarithm function (as seen on log graph paper). You can separate
the
> characteristic from the mantissa. The characteristic is the
integer
> part of the logarithm, and the Stamp has a built-in function "NCD"
to
> calculate that.
>
>
> -- Tracy
arithmetic. I.e.,
y = -35 * x + 544
is a perfectly good statement for the Stamp, so long as x is in the
range of +/-933 so that the product falls in the range of +/- 32678.
Or you can just rewrite it as
y = 544 - (35 * x)
-- Tracy
>Yes I am working with High temperatures, the readings will be from a
>car. I did come across your webpage Tracy and played around with
>your Log function but how do I deal with the -50 or -35 that I have
>to multiply before the LN function?
>
>-Thanks
>
>--- In basicstamps@yahoogroups.com, Tracy Allen <tracy@e...> wrote:
>> >Can anyone help me with the (max186) code to do this equation on
>the stamp2
>> > since the stamp can only do integer arithmetic I'm having a hard
>time.
>> >-50*LN(voltage)+198
>>
>> If voltage is less than 5, the temperature comes out at greater
>than
>> 117. Is that equation right, you are working at high temperatures?
>>
>> The max186 will give an answer in millivolts, so the equation
>becomes,
>> temperature = -50 * LN(millivolts/1000) + 198
>> = -50 * (LN(millivolts) - LN(1000)) + 198
>> = -50 * (LN(millivolts) - 6.91) + 198
>> = -50 * LN(millivolts) + 544
>> = -35 * LG(millivolts) + 544
>> The last step converts from natural log to binary (base 2) log.
>> LN(x) = 0.69315 * LG(x). All that serves to make integer values
>that
>> the Stamp can deal with. From there you have a number of
>> possibilities, including direct calculation of log base 2:
>> http://www.emesystems.com/BS2math3.htm#Logcalc
>>
>>
>> All of the compact methods, including the bitlog function and the
>> table lookups, rely on the "periodic" characteristics of the
>> logarithm function (as seen on log graph paper). You can separate
>the
>> characteristic from the mantissa. The characteristic is the
>integer
>> part of the logarithm, and the Stamp has a built-in function "NCD"
>to
>> calculate that.
>>
>>
>
> > -- Tracy
from others, but if you're still considering alternatives I thought I should point out how
easy this is with the Floating Point Coprocessor that Parallax recently announced (see
Message #44641).
The constants -50 and 198 would be loaded in your setup routines. The conversion loop
would then look like the following:
fA = Result 'load the 12-bit voltage reading to umFPU
fLow = voltage ' and converts to floating point
GOSUB Load_FloatWord
GOSUB Fset
GOSUB Flog 'calculate natural logarithm
fB = ConstantM50 'multiply by -50
GOSUB Fmultiply
fB = Constant198 'add 198
GOSUB Fadd
GOSUB Ffix 'convert to integer
GOSUB Lget ' and get result
It's another alternative to consider.
Regards,
Cam
--- In basicstamps@yahoogroups.com, "vilet_bounnam" <vilet_bounnam@y...> wrote:
> Hi, I want to convert a voltage to a temperature and the equation I'm
> using is -50*LN(voltage)+198
>
> Can anyone help me with the code to do this equation on the stamp2
> since the stamp can only do integer arithmetic I'm having a hard time.
>
> Thanks