Math operations and help please

ramasule

Member
I have a formula which is y = 27.003(x)EXPONENT-1.1001

x are values from 2.5v to .5v on the adc channel

I am looking for help on how to convert this into a usuable pixace operation.

Thank you for your time,

Derek L
 

BeanieBots

Moderator
Well, I dare say it's possible to implement a basic quadratic or maybe higher order polynomial in integer maths to get mathematically within the basic resolution of the ADC and hence justifiable calculation resolution. However, it's too late in the day for me to think along those lines so here's another idea.
http://www.micromegacorp.com/picaxe.html
It also offers 12-bit resolution on the ADC as well.

Maybe some kind sole will work out the factors for a simple polynomial for you!

Addition:-
You're only using a limited ADC range. At 8-bit, you're only going to see 102 different values. That would suggest a simple lookup table.
 
Last edited:

ylp88

Senior Member
Just to clarify, is the equation you need:

y = 27.003 (x) e^(-1.1001), where e is the Natural Logarithm Base

or

y = 27.003 (x)^(-1.1001)

The former is easier since it is essentially all constants which end up being very close to, y = (27.003)(x)(0.3328) =~ 9(x). The latter can quite closely be approximated by, y = (27)(1/x) = 27/(x).

Any of these what you are wanting?

ylp88
 

westaust55

Moderator
Maths

Untested, but a possible solution this:

Code:
READADC b0   ; get value in the range 0 to 255  where actual will be roughly in rage 23 to 129
b1 = b0 * 21 / 470
b1 = 30 – b1 * 47 / b0
 
Last edited:

dusko

New Member
I have the same range finder. This is what I did: I entered the numbers from the manual into Excel and played with trendlines, trying to find a simple one, giving relatively small error. I ended up with a very simple formula:

distance (cm) = 5662/bits

where "bits" is the original reading from ADC10 (not converted into mV). I think I remember finding 5662 by using Solver in Excel and minimizing the sum of errors. The average error (the difference between this simple formula and 27.003X^-1.1) was ~3.6%. I've also tested my formula with a measuring tape, placing obstacles at different distances and the results were very good.
 

BeanieBots

Moderator
Like Dusko, I too have found that sensor to be more than adequate when used LINEAR. There is little point in trying to get a better response as other factors such as surface texture and temperature will have a more significant effect. If REALLY required, you could test the value and use a slightly steeper straight line at closer ranges.
 

ylp88

Senior Member
Perhaps:
Code:
READADC b0
w1 = b0 * 2
w1 = 2700 / w1
With the result in w1 in centimetres?

0.5V input to ADC - ~25 on READADC
25 * 2 = 50
2700 / 102 = 54cm (~57cm ideal)

1.0V input to ADC - ~51 on READADC
51 * 2 = 102
2700 / 102 = 26cm (~27cm ideal)

2.5V input to ADC - ~127 on READADC
127 * 2 = 254
2700 / 254 = 11cm (~13cm ideal)

ylp88
 
Last edited:

Jeremy Leach

Senior Member
Hi, I'd definitely go for a lookup. I've developed a picaxe code 'module' to interpolate from a graph represented by points stored in a table. I've been meaning to put it into the code snippets section. What picaxe are you using and have you got a fair bit of code space ?

EDIT: I've added my 'GraphLookup' code module into the Code Snippets folder. It's currently showing an example for ArcTan, but in theory I think you could use it for your purposes, although I haven't tried ! It might help you though, unless there is a direct maths solutions that's more obvious. Converting the module to be used on other picaxes shouldn't be a problem.
 
Last edited:
Top