Home
Prox / RFID
Verichips
Ladder Logic
[interfacing] †
Tube Joints
Key Code From Photo
SolveSpace (3d CAD)
SketchFlat (2d CAD)
Photographs
Miscellany
Resume / Consulting
Contact Me

LDmicro Forum - analog scaling

(you are viewing a thread; or go back to list of threads)

analog scaling (by AleX)
hi Jonathan,
I ask if there is a possibility, how i can made an scaling dual signal, I know the limits of the 10bit but for the sensor I would like use "lm19 +/-3°C" I think will plus ok for my job.
+130°C=303mV
0=1863.9mV
-55=2485mV
Thank you
AleX
Wed Dec 2 2009, 02:43:28
(no subject) (by Jonathan Westhues)
Let's assume a 5 V reference. This means that a code of 1023 corresponds to 5 V, and a code of 0 corresponds to 0 V. The datasheet gives our equation

V = (-11.79 mV/deg)*T + (1.8528 V)

relating the sensor's output voltage to the temperature. This agrees closely, though not exactly, with the points that you give above. The error occurs because the sensor is nonlinear. If we cared, then we could model the nonlinearity; but it's a relatively small effect (~one degree), so we probably don't.

If x is our ADC code, then V = x*(5000 mV)/(1023 codes) = x*4.8876. I'll stop writing the units, and assume that we're working in degrees C, mV, or ADC codes. We substitute to get

x*4.8876 = -11.79*T + 1852.8
T = (x*4.8876 - 1852.8)/(-11.79)
T = 157.15 - x*0.4146

We can't code that equation directly, because we have only integer math. So we might, for example, approximate that as

T = 157 - (x*17)/41

By approximating 157.15 as 157, we introduce 0.15 degrees error. By approximating 0.4146 as 17/41, we introduce about 0.02% error, or about 0.03 degrees error over our 130 - (-55) = 185 degree range. Both of these are negligible compared to the accuracy of the sensor of itself.

The maximum possible code of 1023 results in a multiplication with the result 17*1023 = 17391. This is less than the most positive 16-bit signed integer, 32767, so nothing overflows. (If we chose a different approximation--for example, 165/398, then the result 165*1023 would overflow and generate a bad result.)

Make sure to do the multiplication first, and then the division. This makes best of use the precision in our integer math. If you reversed the order, computing (x/41)*17, then you would have quantized by an extra factor of 41 (since the result of the division is quantized to the nearest integer), effectively throwing away log2(41) ~ 5 bits, half the ADC resolution.

And note that division in LDmicro--as in C and most languages--truncates instead of rounding. So really, we should write

T = 157 - (x*17 + 20)/41

where 20 is approximately 41/2, since round(x) = floor(x + 0.5).
Wed Dec 2 2009, 03:33:50
thank you (by AleX)
thank you very much!
AleX
Wed Dec 2 2009, 07:31:37
Post a reply to this comment:
Your Name:
Your Email:
Subject:
(no HTML tags; use plain text, and hit Enter for a line break)
Attached file (if you want, 5 MB max):