Reputation: 21
Before I ask the question, I will give the background of the problem.
My PIC 18F assembler routine solves Rntc to T°C relation. But the precision at best is 3 digits.
The NTC reference resistance I used in the assembler example, is 10000 ohms corresponding to a Temperature of 25°C.
With only 3 digits available, the equation solution is =xF6 ,d246 Showing on the display of T, the decimal point between 24 and 6.
The time to calculate T, including Newton approximation is about 800us. This calculation time looks much better than MPlab C
The assembler routine to calculate the sqrt of the equation y = 9.228*x*x-840.852*x+25236.82 runs into the problem of scaling b2-4ac ...the numbers overflow my 24bit maths suite when I attempt to include the decimals e.g. I have to use a=9 . b=840 c=25236
Q1 using integers, is there some trick to calculate the above numbers using 24bit maths ?
Upvotes: 2
Views: 335
Reputation: 20027
I don't think one really needs much more than about 10 bits of precision.
The equation sqrt(a* x^2 + b*x + c)
, x=178..1196 gives pretty much linear response. One doesn't even have to go to a piecewise linear approximation using look up tables.
The linear equation would be y=3.03x-129
EDIT: the equation can be further simplified by noticing that 0.03*x ~= 8/256 * x;
thus y=a+(a<<1)+(a>>5) - 131; // 8/256 = 0.03125 to be precise.
The constant is modified to 131 to fine tune the error to ~zero mean.
The plots show the relative error (left) and absolute error (right) for 180<x<1200
Upvotes: 5