Shop OBEX P1 Docs P2 Docs Learn Events
Analog to digital and scaling help with underwater ROV pressure sensor — Parallax Forums

Analog to digital and scaling help with underwater ROV pressure sensor

AndrewParsonsAndrewParsons Posts: 13
edited 2012-07-09 22:50 in BASIC Stamp
Team,

I wold like to thank everyone here for thier help in the past towards my underwater ROV project. I have begun to work on the sensors. In paticular I have started work in the pressure sensor (manufaturing part number # P51-100-A-B-I36-4.5V-000-000). With help from the Analog to digital stamp in class book I have been able to get a 8bit adc reading 0.5~4.5V from the sensor and converting it to digital.

Now I would like to convert the code below to run with a Basic Stamp 2sx and 10bit ADC converter. Next I am looking to add more code to scale the readings to the 1024 resoulution the 10bit ADC puts out and read out in PSI and feet below sealevel.

Here are the knowns
- The sensor is a absoulute pressure sensor so 0psi = 0.5 volts
- The sensor is at about 1.00 volts at sealevel 14.5psi (1bar) (actual)
- The sensor is at 4.5 volts at 150 psi (10.34bar) (not tested but is promised off spec sheet)
- 100M (below sealevel) = 9.8 bar (142psi)
- 142psi = 328ft (below sealevel)
- 1ft = 0.4329psi
- 1psi = 2.31 ft

I am not great at math by any means nor am I good at programming (but i am learning). Using the above information how would one scale the sensor using BASIC to have it read the PSI and feet as i decend. Thanks.

'
[ Title ]
' Basic Analog and Digital - 150 psi absoulute pressure sensor
' {$STAMP BS2} ' will be changed to sx ver of course
' {$PBASIC 2.5}

'
[ Declarations ]
adcBits VAR Byte
v VAR Byte
r VAR Byte
v2 VAR Byte
v3 VAR Byte

'
[ Initialization ]
CS PIN 0
CLK PIN 1
DataOutput PIN 2
DEBUG CLS 'Start display.

'
[ Main Routine ]
DO
GOSUB ADC_Data
GOSUB Calc_Volts
GOSUB Display
LOOP

'
[ Subroutines ]
ADC_Data:
LOW CLK
LOW CS
PULSOUT CLK, 210 ' using a Basic Stamp 2sx do i need to chance the 210?
SHIFTIN DataOutput,CLK,MSBPOST,[adcBits\8] ' To convert to 10 bit do I change the
'8 to a 10 and that is it?
HIGH CS
RETURN

Calc_Volts:
v = 5 * adcBits / 255 ' by 1024 now?
r = 5 * adcBits // 255 ' by 1024 now?
v2 = 100 * R / 255 'by 1024 now?
RETURN

Display:
DEBUG HOME
DEBUG "8-bit binary value: ", BIN8 adcBits
DEBUG CR, CR, "Decimal value: ", DEC3 adcBits
DEBUG CR, CR, "DVM Reading: "
DEBUG DEC1 v, ".", DEC2 v2, " Volts"
RETURN


Thanks in advance

Comments

  • AndrewParsonsAndrewParsons Posts: 13
    edited 2012-07-09 13:04
    Bump, any help would be much appricated.
  • stamptrolstamptrol Posts: 1,731
    edited 2012-07-09 13:52
    There's fundamentally nothing different in using an 8-bit or 10-bit converter. But, its not likely the exact same instruction will work with both chips. See the Data Sheet. Also, you won't hurt anything by not getting it right the first time you try.

    Your variables may have to go to Word values to accomodate the larger results returned from the a/d.

    Anything to do with timing (PULSOUT, SERIN/SEROUT, FREQOUT) will change as noted in the Helpfile for the various commands.

    Cheers,
  • NWCCTVNWCCTV Posts: 3,629
    edited 2012-07-09 17:16
    There is a formula for converting BS2 to BS2sx. It has been a while since I have used this, but I will try to locate it and post it when I find it.

    Edit: I found it. I think this is what you are referring to. This may not be what you are looking for as far as the math goes, but it should get you started. This was actually for using a Piezo speaker. It is the CON value that makes the change for specific chips.

    ' {$STAMP BS2sx}
    ' {$PBASIC 2.5}

    #SELECT $STAMP 'PULSOUT/PULSIN Scaling - conditional compilation
    #CASE BS2, BS2E, BS2PE
    PScale CON $0100
    #CASE BS2P, BS2PX, BS2SX
    PScale CON $0280
    #ENDSELECT
    #SELECT $STAMP 'FREQOUT Duration Scaling
    #CASE BS2
    FODScale CON $0100
    #CASE BS2P, BS2PX, BS2SX
    FODScale CON $03C6
    #ENDSELECT
    #SELECT $STAMP 'FREQOUT Freq Scaling
    #CASE BS2
    FOFScale CON $0100
    #CASE BS2P, BS2PX,BS2SX
    FOFScale CON $0044
    #ENDSELECT
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2012-07-09 22:50
    Andrew,

    We would have to know more about the 10 bit converter you are using. There is a lot of variation in how they work. You asked:
    [FONT=courier new][SIZE=1]PULSOUT CLK, 210 ' using a Basic Stamp 2sx do i need to chance the 210?
    SHIFTIN DataOutput,CLK,MSBPOST,[adcBits\8] ' To convert to 10 bit do I change the 
    '8 to a 10 and that is it?[/SIZE][/FONT]
    
    The variable adcBits will certainly have to be a WORD instead of a byte in order to hold the 10 bits. The initial pulseout may or may not be needed--That is the sort of thing that depends on the exact converter you are using. I don't see anything in your program that would be affected by difference in timing between the BS2 and the BS2sx.

    Scale factors to convert from adcBits to pressure or depth units too will depend on the reference and scale factor of the ADC. There are a couple of math tricks that can help with the math. For example, If your ADC covers a range of 500mV to 4500mV for a pressure range of 0 to 150psi, then the conversion multiplier is 1500/4000 = 0.375 in units of 0.1 psi. The Stamp can compute that by using the ** operator.
    psi10 = mV ** 24576 ' where 24576 = 0.375 * (2^16)
Sign In or Register to comment.