PDA

View Full Version : Help with scaling math..



ardhuru
- 15th May 2017, 08:59
Hi guys,

I have a home made capacitive sensor I intend to use to measure the depth of water with.

Seems to work fine, but here is the issue.

I am *not* interested in the absolute value of the capaity in terms of uF or nF etc.

The test sensor is a foot long; when it is completely out of the water reservoir, I get a value of 10. This would be the capacity created by the cable, connector etc.

When its fully immersed, the value is 60.

Now, I need to output the reading on a scale of 1 to 100, as a percent. So, 10 would correspond to 1 (or 0?), and 60 to 100.

Therefore, is calculating the percent as simple as (Actual_Reading-Reading_Min)*100/(Reading_Max-Reading_Min)?

I plotted the actual readings taken at 0%, 25%, 50%, 75% and 100%, and the expected computed values, and there is a slight discrepency.

X axis is the inches of the probe under water, and y axis is the reading.

Is there a better way of scaling, as against the formula I've used, for a better fit?

8406

HenrikOlsson
- 15th May 2017, 10:24
How about: Percentage = (ActualValue - 10) * 2 ?

pedja089
- 15th May 2017, 10:41
Hank, your formula gives blue line, If I understand correctly, he want red.
You can try to get more precision formula of red curve in excel. Look what is best approximation, and which you can implement in code. I'll start with polynomial equation, because it easiest to implement.

HenrikOlsson
- 15th May 2017, 19:09
Right. I don't know if the chart showed the actual values of the measurment or the values output by the formula used.
In either case I don't quite understand the X-axis scale of that chart, I would've expected it to end at 100% not 120%.

If it's the values of the actual measurments it seems to "just" be a dual slope line so it shouldn't be too hard to apply to decide if you're below or above the "knee" and act accordingly. If there's more curve to it than that a lookup table should do it and since it's not really that many values (only 50) there's really no need to do any interpolation between points.

I'd like more data before trying to come up with a solution though. Like a table with the raw value, as seen by the PIC, for every 10% from 0-100.

/Henrik. Not Hank :-)

amgen
- 15th May 2017, 23:41
your chart with equation.... how to remove first image???

8408