First the ADC needs to be converted into KPA for yourformuls to work.
You will need to have the ADC setup with a 3.0 volt reference.
Using the old formula of
y = mx-b
y = output 'Volts
m = slope
x = input units
b = offset
You are wanting to read form 0 to 30 amps.
You are wanting to read form 0 to 3.92kpa.
Output is 0.6 to 3 volts.
Start off by look at the output in volts. You have a 2.4 volt span. Giving a span of 3.92 / 2.4 = 1.633
m = 1.633
The offset. Starting at 0.6 volts. 0.6 volts = 0 kpa. The offset is 0.6 * 1.633 = 0.98
b = 0.98
Plug all this into the formula and lets say the input is 3.0 volts.(full scale)
y = (1.633 * 3) - 0.98
y = 3.92
Now convert this to an 10 bit PIC resolution.
10 bits ADC = 0 to 1023, 1024 steps.
At 3.0 volts one volt of input will will read 341.
Spanning 2.4 volts or 818 steps (2.4 * 341).
New value for m. 3.92 / 818 = 0.00479
m = 0.00479
The new offset starting at 205, (0.6 * 341).
205 * 0.00479 = 0.98
b = 0.98
y = (ADC * 0.00479) - 0.98
ADC = 1023
y = 3.92kpa
ADC is from the sensor.
Now for some code.
Code:' m = 0.00479 ' b = 0.98 ' y = (ADC * 0.00479) - 0.98 ' ADC = 1023 ' y = 3.92kpa M CON 479 'm = 0.00479 * 10,000 B CON 98 'b = 0.98 * 100 ADC VAR WORD 'INPUT FROM SENSOR Y VAR WORD 'KPA Z VAR WORD 'DUMMY VAR Z1 VAR WORD 'DUMMY VAR 'V = SQRT((2 * (Y/1000)) / 1.225) V VAR WORD 'METERS/SECOND D CON 122 'AIR DENSITY START: ADC = 1023 'FULL SCALE HARD CODED, NO SENSOR Z = ADC * M Z1 = DIV32 1000 Y = Z1 - B Z = (2 * Y * 10000) Z1 = DIV32 1000 V = SQR(Z1 / D *100) LCDOUT $FE,1,"KPA= ",DEC Y/100,".",DEC Y//100 LCDOUT $FE,$C0,"M/S= ",DEC V PAUSE 250 GOTO START





Bookmarks