Shop OBEX P1 Docs P2 Docs Learn Events
Interfacing a Pressure Transducer to a Protoboard — Parallax Forums

Interfacing a Pressure Transducer to a Protoboard

tae2010tae2010 Posts: 38
edited 2010-06-26 04:59 in Accessories
Hi there,

Ive been using a USB Protoboard for the past few weeks and Ive wanted to interface an MSI 0-100psi pressure transducer that I have. I know it runs on 5 volts, and I plan to use an external regulated power supply to drive it, but I wanted to know how I can interface the board to the signal pin ( the sensor outputs 0.5-4.5 volts). Also I want the board to be able to convert the read voltages into·pressure values·and display·the data·in the propterminal on regular intervals.

The long term goal of this project is to control when a solenoid valve turns on and off based on the pressure reading.

It seems like a simple thing to do, but if someone can point me in the right direction as far as wiring and code is concerned, it would help a lot.

Thanks
«1

Comments

  • LeonLeon Posts: 7,620
    edited 2010-05-06 23:01
    Use an ADC with a voltage divider. You will then need to scale the ADC readings to get the actual pressure.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Leon Heller
    Amateur radio callsign: G1HSM
  • computer guycomputer guy Posts: 1,113
    edited 2010-05-06 23:50
    Like Leon said.

    Red wire to +5V
    Black to GND
    Green to an ADC with a voltage divider.

    The hardest thing will be to calibrate the ADC, maybe have an analoge pressure sensor connected as a reference whilst u adjust the ADC.
    The coding should be easy.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "powered by Propeller" domed stickers $1.50 - Find them here
    Check out my Design and Technology project for my Higher School Certificate www.ecosureblog.net

    The Sarah Myatt Fund - Help Sarah and Her Family Fight Quadriplegia HERE
  • tae2010tae2010 Posts: 38
    edited 2010-05-07 03:29
    Thanks for the replies. Im not very familiar with ADC's, what model of ADC do you recommend then for the specs I have or is there one built into the board?

    Post Edited (tae2010) : 5/7/2010 3:44:28 AM GMT
  • LeonLeon Posts: 7,620
    edited 2010-05-07 07:43
    You might be able to wire the parts for the simple sigma-delta circuit (see Object Exchange) onto your board but I'd use the ADC chip and software that you will also find there.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Leon Heller
    Amateur radio callsign: G1HSM
  • computer guycomputer guy Posts: 1,113
    edited 2010-05-07 11:53
    Parallax sells the 4 and 8 channel versions of the MCP3208. The 8 channel version can be found here www.parallax.com/StoreSearchResults/tabid/768/txtSearch/MCP3208/List/0/SortField/4/ProductID/573/Default.aspx

    The code for interfacing it can be found here obex.parallax.com/objects/180/

    I can't help you with connecting it up as I haven't used it before however DACs are pretty easy to connect.
    Usualy just:

    VDD to 5V
    VSS to GND
    Ref to a pot between 0v and 5v
    Ch1 to the green wire from your sensor
    Dout, Din, Clk and Cs all go to prop pins via a resister.

    Please confirm this with someone else before conecting it though.

    I hope this makes things clearer for you. smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "powered by Propeller" domed stickers $1.50 - Find them here
    Check out my Design and Technology project for my Higher School Certificate www.ecosureblog.net

    The Sarah Myatt Fund - Help Sarah and Her Family Fight Quadriplegia HERE
  • LeonLeon Posts: 7,620
    edited 2010-05-07 12:21
    It will work at 3.3V The VREF input should be connected to +3.3V. An external reference could be used, but isn't really necessary in this application.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Leon Heller
    Amateur radio callsign: G1HSM

    Post Edited (Leon) : 5/7/2010 12:26:30 PM GMT
  • tae2010tae2010 Posts: 38
    edited 2010-05-08 01:28
    So could I use a 10k ohm potentiometer as my voltage divider, where one end of the pot hooks to Vss, one to the ADC (Vin +), and the other to the green line of my sensor?

    Based on my understanding, Vdd would hook into Vref and Vcc. /CS, CLK and D0 would all hook into pins on the board, and Vin - & GND would hook into Vss. (I'll probably end up using the 3202 since I dont need many analog inputs)

    But then what will Din hook into?

    Just trying to verify if Ive got this so I dont mess up my sensor.

    Thanks.

    Post Edited (tae2010) : 5/8/2010 2:17:02 AM GMT
  • LeonLeon Posts: 7,620
    edited 2010-05-08 16:29
    Just use a couple of 1% resistors for the voltage divider. You will know exactly what division ratio you are getting, which isn't the case with a pot.

    Post a schematic of how you propose to wire it up, it'll be easier to check it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Leon Heller
    Amateur radio callsign: G1HSM
  • tae2010tae2010 Posts: 38
    edited 2010-05-08 21:38
    Heres the diagram I was thinking it would look like. Im not sure about the D1 pin, and the POT. Based on a tutorial I found for wiring an ADC from Parallax they used a POT instead of a voltage divider. Since I didnt really need so many inputs as with the 3204 and 3208, I went with the 3202.

    pressure%20sensor%20diagram.png
  • LeonLeon Posts: 7,620
    edited 2010-05-08 21:55
    I don't understand why you want to use a pot, you know the input voltage range. You need decoupling for the ADC supply pins.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Leon Heller
    Amateur radio callsign: G1HSM

    Post Edited (Leon) : 5/8/2010 10:01:38 PM GMT
  • tae2010tae2010 Posts: 38
    edited 2010-05-08 23:33
    Well I was thinking that a Pot could replace a voltage divider; its practically the same thing if you compare the two schematics. What do you mean by 'decoupling for the ADC supply pins'? If I did use resistors instead of the Pot, 1k ohm would be fine right?

    Also does my wiring diagram look fine?

    pressure%20sensor%20diagram2.png

    Post Edited (tae2010) : 5/8/2010 11:47:51 PM GMT
  • LeonLeon Posts: 7,620
    edited 2010-05-09 11:16
    You need a 100 nF capacitor across the supply and ground pins.

    Use resistors; they are much more stable, easier to mount and cheaper.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Leon Heller
    Amateur radio callsign: G1HSM
  • tae2010tae2010 Posts: 38
    edited 2010-05-09 21:28
    Just for my understanding, whats that capacitor for? Supply as in Vcc right?

    Thanks for helping me out.
  • LeonLeon Posts: 7,620
    edited 2010-05-09 22:06
    It's called a decoupling or bypass capacitor, one should be used with all ICs. It goes between the Vcc and ground pins. Momentary high currents are required when the chip is operating, which are supplied by the capacitor, and prevented from affecting other parts of the circuit. It's a good idea to use an additional 10 uF capacitor as well, with analogue circuits like ADCs, to keep noise levels down. It'll work without them, but the readings might be very noisy. I often use a pot to check an ADC and the software, before I connect the actual sensor. It makes testing easier.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Leon Heller
    Amateur radio callsign: G1HSM

    Post Edited (Leon) : 5/9/2010 10:13:27 PM GMT
  • tae2010tae2010 Posts: 38
    edited 2010-05-09 23:54
    So the 10 uF capacitor would hook in series with the 100nF cap?
  • LeonLeon Posts: 7,620
    edited 2010-05-10 03:41
    No! In parallel.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Leon Heller
    Amateur radio callsign: G1HSM
  • tae2010tae2010 Posts: 38
    edited 2010-05-10 05:52
    Oh Ok, Thanks for the help. I'll be sure to post after finals, if this works out.
  • tae2010tae2010 Posts: 38
    edited 2010-05-28 05:27
    Well I managed to build the circuit, and I worked out the code for the 3202, but nothing is happening. Here is the latest setup Ive got. Im using a 1k ohm pot to vary the analog input to test the system. I'll include my code and my schematic if anyone can take a look to help me out. I dont have a clue why it wont work, its compiling, and it looks good to me.

    http://lh3.ggpht.com/_JitqFAafVeQ/S_9VDWG-IoI/AAAAAAAAAGk/-JhztlgSt1c/ADC Circuit.png

    And the code:
    
    OBJ
     ' LCD     : "LCDRoutines4" 'for the LCD methods
       PST     : "Parallax Serial Terminal"
       Debug   : "SimpleDebug"
                                                         
    CON                                                                   
      _CLKMODE=XTAL1+ PLL2X         'The system clock spec
      _XINFREQ = 5_000_000          
       chipDin =07    'to pin  5     
       chipClk =04    'to pin  7   
       chipSel =01    'to pin  1    
       chipDout=06    'to pin  6
       BitsRead=12
    
       Baud =  115200
       'relaypwr = 02
       'ledpwr = 05
       
    VAR
      long stack2[noparse][[/noparse]25]
      word PotReading               
      word DataRead
    
      byte  rxString[noparse][[/noparse]50]  'Holds [noparse][[/noparse]50] incoming serial bytes
      Long  Temp
    
    DAT       ''Line up all the expected Strings
    
     binaryvalue byte  "8-bit binary value: ", 0 
    
    PUB Main
    
    Go
                                                                 
    PUB Go
      'cognew(Cog_LCD, @stack2)        
      DIRA[noparse][[/noparse]chipDin]~~     '19 data set up to the chip   
      DIRA[noparse][[/noparse]chipClk]~~     '20 oscillates to read in data from internals                     
      DIRA[noparse][[/noparse]chipSel]~~     '21 osc once to set up 3202                                     
      DIRA[noparse][[/noparse]chipDout]~     '22 data from the chip to the Propeller                               
      repeat        
        DataRead:=0             'Clear out old data
        waitcnt(1000+cnt)       'Wait for things to settle down, but not needed
        outa[noparse][[/noparse]chipSel]~~         'Chip select has to be high to start off                        
        outa[noparse][[/noparse]chipSel]~          'Go low to start process
                                       
        outa[noparse][[/noparse]chipClk]~          'Clock needs to be low to lead data     
        outa[noparse][[/noparse]chipDin]~~         'must start with Din low to set up 3202                   
        outa[noparse][[/noparse]chipClk]~~         'Clock high to read data in
                                       
        outa[noparse][[/noparse]chipClk]~          'Low to load      
        outa[noparse][[/noparse]chipDin]~~         'High single mode                  
        outa[noparse][[/noparse]chipClk]~~         'High to read
                                               
        outa[noparse][[/noparse]chipClk]~          'Low to load               
        outa[noparse][[/noparse]chipDin]~          'Odd = channel 0          
        outa[noparse][[/noparse]chipClk]~~         'High to read
                                        
        outa[noparse][[/noparse]chipClk]~          'Low to load       
        outa[noparse][[/noparse]chipDin]~~         'msbf high = MSB first                
        outa[noparse][[/noparse]chipClk]~~         'High to read
        
        outa[noparse][[/noparse]chipDin]~          'making line low for rest of cycle
        
        outa[noparse][[/noparse]chipClk]~          'Low to load 
                                'Read the null bit, we dont need to store it
        outa[noparse][[/noparse]chipClk]~~         'High to read
       
        repeat BitsRead          'Reads the data into DataRead in 12 steps
          outa[noparse][[/noparse]chipClk]~         'Low to load 
          DataRead:=DataRead+ina[noparse][[/noparse]chipDout]  'Xfer the data from pin chipDout                           
          outa[noparse][[/noparse]chipClk]~~        'High to read  
          DataRead <<= 1         'Move data by shifting left 1 bit. Ready for next bit
            
        outa[noparse][[/noparse]chipSel]~~          'Put chip to sleep, low power
          DataRead >>= 1         'Shift data right 1 bit to cancel last "bad" shift
          PotReading:=DataRead   'Finished data read for display
    
        Printstr(string( "8-bit binary value: " )   )
        pst.bin(PotReading,8)
    
    PUB PrintStr(str1)
    pst.str(str1)
    
    



    (Edit: for some reason the image wont appear, so I included the link of it)

    Post Edited (tae2010) : 5/28/2010 5:44:01 AM GMT
  • Paul Sr.Paul Sr. Posts: 435
    edited 2010-06-05 21:33
    How has your project progressed? I am interested as I have a couple of soil moisture sensors that would require almost the same setup!
  • tae2010tae2010 Posts: 38
    edited 2010-06-06 06:20
    Sorry Paul, I havent made any progress on this yet. I got stuck with the code that I uploaded, and the testing of that code didnt get me anywhere. Im going to try it again with some different code and see if I make progress that way. If anyone has suggestions to this code that I uploaded, I welcome them.

    I'll keep you posted on any updates. At the moment, since I cant get the ADC and the code to work, Im working on the user interface part of the project.
  • tae2010tae2010 Posts: 38
    edited 2010-06-14 17:58
    Can anyone help me on this? I still cant get the code to work, but the setup is the one we talked about in this thread. I dont have the slightest idea why it wont work, Im not even getting any transmission over the USB to the computer.
  • ElectricAyeElectricAye Posts: 4,561
    edited 2010-06-15 04:25
    tae2010 said...


    And the code:
    
    OBJ
     ' LCD     : "LCDRoutines4" 'for the LCD methods
       PST     : "Parallax Serial Terminal"
       Debug   : "SimpleDebug"
                                                         
    
    
    



    In your Object block, should "Parallax Serial Terminal" be "Parallax_Serial_Terminal" or some other name that has no spaces? Maybe I'm wrong but I didn't think SPIN is very fond of spaces.
  • hover1hover1 Posts: 1,929
    edited 2010-06-15 12:20
    PST : "Parallax Serial Terminal" is valid, spaces are OK.

    But you never start the PST. You need to include:

    PST.Start(Baud)
    

    or
    

    PST.Start(115_200)
    

    Jim
  • ElectricAyeElectricAye Posts: 4,561
    edited 2010-06-15 13:24
    hover1 said...
    PST : "Parallax Serial Terminal" is valid, spaces are OK.

    ....

    Tar-nation! I didn't know that. Thanks for correcting me! blush.gif
  • tae2010tae2010 Posts: 38
    edited 2010-06-20 01:56
    Well I got it to work at last and it outputs data to the serial terminal. Also Ive got a potentiometer hooked up to the 3202 to calibrate it, and that seems to be working. And its even outputting the binary like its supposed to! Also got the chip to output a decimal value of the voltage measured, but Ive got issues with how its calculating, so instead of it outputting a 5 volt measurement, its really outputting 2.0 as the highest. I followed a tutorial of how to calibrate on a stamp, but the code isnt the same, so its possible that Im coding this part wrong.

    The major problem Im experiencing is that the decimal keeps including a -1 in the numbers to the right of the decimal place. Also the voltage isnt as high as its supposed to be. Im using a 1k ohm pot to change values, so is that why my voltage read is so low?

    Heres the code, perhaps someone can tell me what Im doing wrong? As I always say, Two sets of eyes are always better than one.

    
    Pub CalcVolts
    
    v := 5*adcRead / 4095
    r := 5*adcRead //4095
    v2 := 100*r /4095
    v3 : 10*r //4095
    v3 : 10*v3 /4095
    
    If (v3 >=5)
       v2:=v2 +1
    If (v2 >= 100)
       v:= v+1
       v2:= 0
    
    Return
    
    
    



    All those variables are setup as Longs, except adcRead, which is setup as a word.

    Thanks everyone for helping!

    Post Edited (tae2010) : 6/20/2010 2:55:10 AM GMT
  • HarpritHarprit Posts: 539
    edited 2010-06-21 13:38
    So what did it take to get it working
    What were you doing wrong
    I'm interesting because you were using my code and I want to make sure there was no mistake in it.

    Harprit
  • tae2010tae2010 Posts: 38
    edited 2010-06-22 03:04
    I added the serial start code to get the serial to receive data via the 3202 rather than outputting to an LCD screen. And from there I set it up to output as a binary number or a Decimal number.

    Only reason it wasnt working before, is I forgot to start the serial connection. Its working now, Im just not sure if its working correctly. The max output voltage the Propeller is outputting is only 2volts, and Im supplying a 5V supply to the pot that is changing the analog input. The maximum the Propeller puts out should be around 2.5v. So I dont know what Im doing wrong in my setup or if Im missing a key bit of info from the 3202 spec sheet.
  • HarpritHarprit Posts: 539
    edited 2010-06-22 14:46
    Post your ckt diagram and complete listing and I will take a look
    Harprit
  • tae2010tae2010 Posts: 38
    edited 2010-06-23 05:17
    pressure%20sensor%20diagram01.png

    OBJ
     ' LCD     : "LCDRoutines4" 'for the LCD methods
       PST     : "Parallax Serial Terminal"
                                                         
    CON                                                                   
      _CLKMODE=XTAL1+ PLL2X         'The system clock spec
      _XINFREQ = 5_000_000          
       chipDin =10    'to pin  5     
       chipClk =12    'to pin  7   
       chipSel =13    'to pin  1    
       chipDout=14    'to pin  6
       BitsRead=12
    
       Baud =  115200
       relaypwr = 02
       ledpwr = 05  
       
    VAR
      long stack2[noparse][[/noparse]25]
      word adcRead               
      word DataRead
    
      byte  rxString[noparse][[/noparse]50]  'Holds [noparse][[/noparse]50] incoming serial bytes
      Long  Temp
    
      Long v, r,v2,v3,v4
    
    
    DAT       ''Line up all the expected Strings
    
            pin02 byte "PIN02", 0
            pin23 byte "PIN23", 0
            stop  byte "stop", 0
            exit  byte "exit", 0
            on    byte "ON", 0
            off   byte "OFF", 0
            WrongData byte "Don't Hand Me that Garbage", 0
            high byte "High", 0
            low byte "Low", 0
                                                            
    PUB Go
    
     pst.StartRxTx(31,30,0,Baud)
     
      'cognew(Cog_LCD, @stack2)        
      DIRA[noparse][[/noparse]chipDin]~~     '10 data set up to the chip   
      DIRA[noparse][[/noparse]chipClk]~~     '12 oscillates to read in data from internals                     
      DIRA[noparse][[/noparse]chipSel]~~     '13 osc once to set up 3202                                     
      DIRA[noparse][[/noparse]chipDout]~     '14 data from the chip to the Propeller                               
      repeat        
        DataRead:=0             'Clear out old data
        waitcnt(1000+cnt)       'Wait for things to settle down, but not needed
        outa[noparse][[/noparse]chipSel]~~         'Chip select has to be high to start off                        
        outa[noparse][[/noparse]chipSel]~          'Go low to start process
                                       
        outa[noparse][[/noparse]chipClk]~          'Clock needs to be low to lead data     
        outa[noparse][[/noparse]chipDin]~~         'must start with Din low to set up 3202                   
        outa[noparse][[/noparse]chipClk]~~         'Clock low to read data in
                                       
        outa[noparse][[/noparse]chipClk]~          'Low to load      
        outa[noparse][[/noparse]chipDin]~~         'High single mode                  
        outa[noparse][[/noparse]chipClk]~~         'High to read
                                               
        outa[noparse][[/noparse]chipClk]~          'Low to load               
        outa[noparse][[/noparse]chipDin]~          'Odd = channel 0          
        outa[noparse][[/noparse]chipClk]~~         'High to read
                                        
        outa[noparse][[/noparse]chipClk]~          'Low to load       
        outa[noparse][[/noparse]chipDin]~~         'msbf high = MSB first                
        outa[noparse][[/noparse]chipClk]~~         'High to read
        
        outa[noparse][[/noparse]chipDin]~          'making line low for rest of cycle
        
        outa[noparse][[/noparse]chipClk]~          'Low to load 
                                'Read the null bit, we dont need to store it
        outa[noparse][[/noparse]chipClk]~~         'High to read
       
        repeat BitsRead          'Reads the data into DataRead in 12 steps
        
          outa[noparse][[/noparse]chipClk]~         'Low to load 
          DataRead:=DataRead+ina[noparse][[/noparse]chipDout]  'Xfer the data from pin chipDout                           
          outa[noparse][[/noparse]chipClk]~~        'High to read  
          DataRead <<= 1         'Move data by shifting left 1 bit. Ready for next bit
            
        outa[noparse][[/noparse]chipSel]~~          'Put chip to sleep, low power
          DataRead >>= 1         'Shift data right 1 bit to cancel last "bad" shift
          adcRead:=DataRead   'Finished data read for display
    
          
        'pst.str(string( "12-bit binary value: " )   )
        'pst.Bin(adcRead,12)
        'pst.str(string(pst#NL))
    
        'pst.str(string( "Decimal Equivilant: "))
        'pst.Dec(adcRead)
        'pst.str(string(pst#NL))
    
        CalcVolts
        
        pst.str(string( "Voltage Equivilant: "))
        pst.Dec(v)
        pst.str(string("."))
        pst.Dec(v2)
        pst.Dec(v3)
        pst.Dec(v4)
        pst.str(string(pst#NL))
        
        waitcnt(clkfreq/2 + cnt)
        '0 to 4095 for 12bit
    
    PUB CalcVolts
    
    v := 5 * adcRead / 4095
    r := 5 * adcRead // 4095
    v2 := 100 * r / 4095
    v3 := 100 * r // 4095 
    v4 := 10 * v3 / 4095 
     IF (v4 >= 5)
         v2 := v2 + 1 
     IF (v2 >= 100)  
         v := v + 1 
         v2 := 0 
    
    RETURN
    
    



    Thanks for taking the time to take a look at whats wrong. That last bit of code I used one of the tutorials supplied with the Digital (ADC) package that you can buy. Except that tutorial was for the Stamp, so I had to change the code to get it to work on the Propeller.
  • HarpritHarprit Posts: 539
    edited 2010-06-23 08:42
    Send me your mailing address so I can send you what I found out.
    Its easier for me to send you my hand written stuff that way.
    I will make up your ckt and get you a solution/notes of some sort.
    This seems manageable. Might take a day or two.
    Then you can post it all for all to see.

    H
Sign In or Register to comment.