ADC10 Calculation

neiltechspec

Senior Member
Having a bit of trouble getting my head around the calculation need for a Oil Pressure Gauge.

The sensor gives a linear o/p from 0 to 100 PSI.
0 psi = 0.5v
50 psi = 2.5v
100 psi = 4.5v

Normally I would use -

Supply Voltage 5v

adcconfig 0
readadc10 w0

Then it would be easy to convert the value w0 to read PSI.

But because 0 psi is not 0v I am somewhat flummoxed at the moment.

Any help appreciated.

Neil
 

goom

Senior Member
The equation for the line defining the response is:
psi = 25 x ADC -12.5
To accommodate integer maths:
psi = 50*ADC-25/2
 

hippy

Technical Support
Staff member
Notice that the value read isn't a voltage but a value of 0-255 (READADC) or 0-1023 (READADC10), and that needs to be converted to a voltage. For READADC10 ...

psi = ( Vadc - 0.5 ) * 25

psi = ( ( Nadc * 5 / 1023 ) - 0.5 ) * 25

psi = ( ( Nadc * 10 / 1023 ) - 1 ) * 25 / 2

Limiting psi to only positive values ...

Code:
Symbol Nadc = w0
Symbol psu  = w1

ReadAdc10 ADC_PIN, Nadc
psi = Nadc * 10 / 1023 Min 1 - 1 * 25 / 2
 

marks

Senior Member
Hi neiltechspec,
at 0 psi our readadc10 value is 0.5v/5v x 1023steps = 102.3
so at 100 psi our value becomes 920.7
so we get w0=w0 - 102.3 / 8.184

a neat trick to convert our adc10 value to 1000 steps is ** 64064

so we can now use w0=w0**64064-100/8

if our supply voltage isn't exactly 5.0v just tweak the high word **
 

neiltechspec

Senior Member
Temporarily substituted a 5K pot for the sensor.


ReadAdc10 ADC_PIN, w0
w0 = w0 * 10 / 1023 Min 1 - 1 * 25 / 2, didn't seem to work quite right, only gave 4 values throughout the range

w0=w0**64064-100/8, works a treat

Neil.
 

hippy

Technical Support
Staff member
w0 = w0 * 10 / 1023 Min 1 - 1 * 25 / 2, didn't seem to work quite right, only gave 4 values throughout the range
You could be right. It only determines integer voltage which is probably why there are so few steps.
 
Top