Math HELP

buntay

Senior Member
Hello friends,
I need some math help, so let me set the stage. On my diesel truck I have a fuel rail pressure transducer for the trucks computer. There is a spot to add another one, now I have found an OEM transducer so everything stays safe. What I want to do is add this transducer so I can monitor what the ECM should be approximately seeing. So here is the info I can find on the transducer. It is 0-5 volts and linear. Below are what the pressures should be at the given voltage.
I need help with the formula that gets me closest to the following table using and ADC line and READADC command.
____________________
0 psi = .5v
5801 psi = 1.39v
10153 psi =2.06v
14504 psi = 2.72v
20305 psi = 3.61v
26107psi = 4.5v
_______________________
Any Help would be greatly appreciated
Thanks,
Buntay
 

goom

Senior Member
The relationship between pressure and voltage is nearly linear. The following formula is a good approximation (26 psi or 0.25% maximum error):
psi = 6530*Volts-3273
 

Goeytex

Senior Member
A bit of rounding but should be very close.

Code:
Symbol ADVAL = W0
Symbol PSI = W1 


Do
     ReadADC10 C.1, ADVAL
     PSI = ADVAL * 32 - 3273
   
    If PSI > 29463 then
       PSI = 0                  '// Overflow - READAD10 was less 102 (.5V)   
   End If
Loop
 

buntay

Senior Member
Thanks goom :) so now my question would be, if READADC gives me a value of 0v=0 and 5v=255 how do I make the formula work. If I take 30,000 PSI / 255 increments I get 117.64 PSI per increment which IS an acceptable variance per increment, how do I do the formula based on the 0-255 and taking into consideration that 0 PSI on the transducer will still output .5v which will give me a base READADC value of 25 (5v /255=.019 or .02v per inc and .02 * 25=0.5v) and still keep my pressure to volt linearity.

Thanks for your help :)
 

buntay

Senior Member
Thanks Goeytex, Thats what I was looking for. I will plug that in in the next week or so and borrow a ECM Scanner and compare :)
 

westaust55

Moderator
If I might suggest a slight change (fine tuning) to reduce the error.
May be better if the fuel rail pressure is "normally" relatively constant in the region around say 18,000 to 25,000 psi - but ultimately depends upon the fuel delivery control strategy as different system makes use different philosophies.

Code:
Symbol ADVAL = W0
Symbol PSI      = W1 


DO
     ReadADC10 C.1, ADVAL
     PSI = ADVAL * 32 - [COLOR="#FF0000"]3301[/COLOR]
   
    If PSI > [COLOR="#FF0000"]32768[/COLOR] then
       PSI = 0                  '// Overflow - READAD10 was less 102 (.5V)   
   End If
Loop
 

buntay

Senior Member
Hello again,
So I made some tweaks to the code provided by Goeytex and westaust55 (thank you :) ) to keep it on course throughout the given table but now my tweaks wont pass syntax. Can someone tell me why? I plan on using a 20x2 and it is failing at symbol DIFF.

Thanks in advance for any assistance :)

Code:
Symbol ADVAL = W0
Symbol PSI = W1 
Symbol DIFF =W2

DIFF = 3475

Do
     ReadADC10 C.1, ADVAL

If ADVAL < 290 then DIFF = 3475: goto Cal
If ADVAL > 290 and < 431 then DIFF = 3605: goto Cal
If ADVAL > 431 and < 754 then DIFF = 3795: goto Cal
If ADVAL > 754 then DIFF = 3905: goto Cal




Cal:
     PSI = ADVAL * 32 - DIFF
   
    If PSI > 29463 then
       PSI = 0                  '// Overflow - READAD10 was less 102 (.5V)   
   End If
Loop
 

Goeytex

Senior Member
You cannot have multiple statements after IF without end if. Try this instead ... and it eliminates all of those horrible "gotos". We don't want to have any Djkstra worshipers passing out.

Code:
Symbol ADVAL = W0
Symbol PSI = W1 
Symbol DIFF =W2

DIFF = 3475

Do
   ReadADC10 C.1, ADVAL

   Select Case ADVal
     Case < 290 : DIFF = 3475
     Case 291 to 430 : DIFF = 3605
     Case 431 to 754 : DIFF = 3795
     Case > 754 : DIFF = 3905     
   End Select

   PSI = ADVAL * 32 - DIFF
   
     If PSI > 29463 then
       PSI = 0  ;// Overflow
     End if
Loop
 

AllyCat

Senior Member
Hi,

now my tweaks wont pass syntax.
It's always worth stating what synax error YOU get and trying to understand what it means.

The syntax error I get for your code in a 20X2 (it's also worth including a #PICAXE 20X2 command at the top of the file) is "Expected a label not the variable DIFF". The problem here is that there are two different formats for the IF command:

The first format is IF <condition> THEN GOTO <label> but the "GOTO" is "optional" (i.e. implied) which IMHO is arguably not a good idea. That is what the Editor/Compiler thinks you are trying to do (but you don't have a label called DIFF for it to go to).

The other format is IF <condition> THEN <newline> do something <newline> do more if you wish <newline> ENDIF (or ELSEIF). That is what you are trying to do but you haven't included a <newline>, or its colon ( : ) equivalent, nor the ENDIF/ELSEIF.

When you fix that, you'll probably get a syntax error in the next line, because the syntax is IF <condition> AND <condition> THEN ... and your second condition is not complete.

Cheers, Alan.

PS: C.1 does appear to have ADC capability (it's called ADC9).
 
Last edited:
Top