Completely OT!: help with base-2 division
Trevor Page
trevor at resonance.fsnet.co.uk
Sun Feb 20 14:51:17 CET 2000
Hi,
This is a very off - topic question, so I would request that, if anyone
could possibly help me in any way at all, please reply to me privately.
Thanks!
This message relates to my final year project.
Basically, I need some help regarding binary division. I know there will
possibly be a few of you on the list who will be experienced with this sort
of thing, and may be able to offer me some advice. I've tried elsewhere but
not had that much luck. Any help would be much appreciated.
Here's the problem.
I need to perform the calculation: K = A1/B1
And following this: B2 = A2/K
(Ax = ADC reading , K = sensor constant, Bx = analyte concentration.)
The first calculation is to perform a calibration process. The A1 value
comes from the analogue to digital converter, measuring the concentration of
analyte in a liquid sample. B1 is the known concentration of that sample.
>From these, the processor can work out K, which is the volt per unit
concentration gradient for the sensor in use. (the sensitivity of the sensor
is previously not known prior to calibration).
The second division is to calculate the unknown concentration, given the ADC
reading from the sensor and the sensitivity gradient, K, for that sensor.
>From these values, the actual concentration (B2) is calculated.
Now those specific details are not really relevant, but here is the problem:
The final value needs to be very accurate. When performing the first
calculation in binary, K is truncated (e.g. 11 / 5 would give 2). The second
calculation would also have the same problem, and therefore the value B2
would be very innaccurate.
When performing division in binary, it is easy to produce a remainder. This
could be done in the first calculation when finding K. However, if I were to
do this, how could I perform the second binary division when the divisor (K)
itself consists of a quotient *and* a remainder?
There is probably a straightforward, established way of doing this, but I
have been unable to work out how.
My solution so far has been to do this: multiply the value taken from the
ADC (A) by a large number. That is, the numerator is much larger than the
denominator and, due to this, errors due to truncation in the quotient are
extremely small in percentage terms and the final error is acceptable. I've
just simply shifted the 16 bit ADC conversion value by 8 bits to the right,
effectively producing a 24-bit value. However, I find this method to be
somewhat crude (although it works) and I'd like to do things 'properly'.
However, if anyone thinks this method is probably the best way then I'll
stick to it.
Any advice on the matter would be very gratefully appreciated.
Best regards, Trev
www.resonance.fsnet.co.uk
More information about the Synth-diy
mailing list