Is there a SPIN version of Float Log?
I've been using Float32 for the FLog function, but it means I start the PASM cog for essentially a single instruction. Seems very inefficient. FloatMath does everything else I need in SPIN except Logs I'm sure someone has written the Float Log in SPIN.
Who has it!?
Who has it!?
FLT.start
temp := FLT.FRound(FLT.FAdd(FLT.FMul(-379.223, FLT.Log(FLT.FFloat(rtime))), 4054.36))
FLT.stop
Seems a bit wasteful. 
Comments
Maybe someone can help unroll the PASM code?
thanks,
Jonathan
An approximation would be just fine (even a quite loose approximation), I only need readouts in 5-degree increments (i.e. "temp is between 65 and 70", or "...105 and 110").
I am running this project on a battery so I am trying to use as little power as possible, hence my oposition to launching another cog. I also don't mind if it's slow. I'm already running at 40MHz and trying to squeeze some things down so I can run it at 20MHz.
Note: since you already have a multiplier, that could simplify when worked into this equation (since the multiplication is basically a factor of 2^23, and a conversion from base 2 to base e).
Jonathan
It gives me an error of about a degree, but that is well within specification.
Thanks!
Jonathan
ln(x) * -379.223 + 4054.36
Example: x = 6000, result is 755, which equates to 75.5F
The log would produce such a small/imprecise number, I think I loose too much right in the first operation. The multiply and add wouldn't be an issue.
The same input would produce 1022 (102.2F) -- that's a bit of an error.
I'm no mathematician, is there some way to apply the multiply to x before the log?
Edit: a more correct range: 350 to 13000
f = (4324267 + 268 * v) / (2133 + v)
I think it's within about 5 degrees over the 350 to 13000 range.
Jonathan
PUB rcToTemp (rcval) : temp '' thanks to Tracy Allen rcval := Log2(rcval) << 1 ** 1488522235 ' log2 to ln, 12 bit mantissa rcval **= 1048576000 ' binary to decimal fixed point RETURN (rcval * -37922 + 405486000) / 100000 ' calc & discard extra digits. PUB Log2 (value) | characteristic, mantissa '' thanks to Tracy Allen characteristic := >| value - 1 mantissa := value >< characteristic >< 12 ' left justify to 12 bits, bitlog: mantissa := WORD[$C000 + mantissa] ' fractional part of log2(x), 16 bits mantissa mantissa := (mantissa + 8) >> 4 ' round off to make it a 12 bit mantissa for our purposes (reduces precision!) RETURN characteristic << 12 + mantissaI always forget about the ROM tables. [8^/
Jonathan
-Phil