Is there a SPIN version of Float Log?
Bobb Fwed
Posts: 1,119
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.stopSeems 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
I always forget about the ROM tables. [8^/
Jonathan
-Phil