Hi Ed,
The sensor nominally outputs 0.5V at 0 psi. With 5V as the reference the 10bit ADC will return a value of 102 (102.4 ideally) for a 0.5V input.
Becaues we are taking 40 readings and then dividing that by 10 we go from 10bit reslution to 12bit (4 times oversampling) so our 102.4 now becomes 102.4*40/10=409 which is where the 409 in the code comes from.
At full scale (7psi, 0.07psi whatever is is) the sensor nominally outputs 4.5V. With 5V as the reference the 10bit ADC will return a value of 921 (921.6 ideally) for a 4.5V input.
Because we are taking 40 readings and then dividing that by 10 we go from 10bit resoultion to 12bit (4 times oversampling) so our 921.6 now becaomes 921.6*40/10=3686.
So now we have a value ranging from 409 to 3686 for our 0 to 7 (or 0.07) psi. The first thing we need to do is remove the offset. Easy enough, just subtract 409 to get a value ranging from 0 to 3277 for our 0 to 7 (or 0.07psi).
The final step is to get that strange value into something reassembling the actual pressure and that's where the 547 numbler comes in.
The */ operator has be covered numerous times on the forum. It's like multiplying by units of 1/256. So 3277 * (1/256*547) = 7002.
So now we have a value ranging from 0 to 7002 for a pressure of 0 to 7 (or 0.07 or whatever) psi and all we need to do is to put a decimal point between the correct digitis when displaying the value.
For 0 to 7psi:
HSEROUT["Pressure: ", DEC ADResult/1000, ".", DEC2 ADResult//1000, "psi", 13]
For 0 to 0.07psi:
HSEROUT["Pressure: 0.0", DEC ADResult, "psi", 13]
Obviously, if your sensor outputs values other than the nominal (which of course is likely) the numbers needs to be tweaked to calibrate the readings.
/Henrik.
Bookmarks