displaying pressure sensor readings below 0 on LCD

justplanejim

New member
My project involves reading a 5v pressure sensor signal via readadc and outputting an ASCII number along with text to an AXE133Y LCD display module. It is eventually going to be a boost pressure display for my car.

My problem is when the pressure drops below 0psi, I can't figure out how to get my numbers to count backwards from 0. Because the Picaxe adc converts the input to a digit between 0 and 255, when ever the number drops below 0, it goes to 255. Is there an easy way to fix this?
 

Attachments

Hello, could you check if the value changes to 254 at a pressure of -1 psi? I usually work with the 18B20 temperature probe, and since the PICAXE only works with positive values for me, my probe would return 128 for a temperature of -1 degree. Do you think there might be something similar?
 
Hi,

You may need to only add a line b1 = -b1 immediately after label lob: Alternatively, it might be written as b1 = 256 - b1 , or for more detailed calculations look for the "Twos Complement" number system.

Cheers. Alan. (sent from my phone).
 
Hi Jim
It would probably be best to find some technical data
on the sensors you intend to use.

here's an example to run in the PICAXE Editor simulation (Line numbers represent the adc value)
for a Bosch 3bar map sensor 0 -5v. looking at the data sheet
with a 0.4v reading we would have -14 psi we can calculate an adc reading of 20
and @ 4.65v should have a reading of 29 psi so the adc reading would be about 237 with a 5.00 vref(supply).
our step value for psi is -14 to 29 is 43
our step value for adc is 20 to 237 is 217 (to zer0 our adc value we subtract 20)

so our adc formula to convert to psi becomes
b1 = b0 -20 * 43 /217 -14 in this case should work fine we can multiply up to 255 without overflow,

using a high word can be advantageous when dealing with bigger numbers
and sometimes our division can be more accurate which may be helpful for your other sensors.
to work out our high word value 43 / 217 x 65536 +1 = 12987
b0 = b0 -20 **12987 -14

Rich (BB code):
SYMBOL sign= b10

boost:
 'readadc a.1, b0
for b0 = 1 to 255 'Display adc values for simulation

DisplayV:
w20 = b0*196+50/100
bintoascii w20,b11,b12,b13
sertxd(b11,".",b12,b13,"v  ") ' 02 resolution 

DisplayPSI:
  if b0 <20   then lob ' comment line out to view out of range values
 'let b1= b0-20**12987-14 ' highword example 
 let b1=b0-20*43/217-14   ' 
sign=" ":if b1>240 then :b1=-b1 :sign="-" :endif
 
sertxd ("Boost: ",sign, #b1, " PSI   ")   sertxd(13,10)
  hib:'within range (adc 20 to 237)(0.4: to 4.65)(-14 psi to 29)
  goto btn
 
  lob:'out of range
   sertxd ("Boost: "," !!", " PSI   "  )   sertxd(13,10)
   goto btn

 btn:next b0
 

Attachments

  • boschmapsensor.JPG
    boschmapsensor.JPG
    99.2 KB · Views: 3
Back
Top