Airspeed from MPX5500DP differential pressure sensor using a PIC16F88


Closed Thread
Results 1 to 27 of 27

Hybrid View

  1. #1
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    If you have an op-amp in a non-inverting configuration, you have two resistors: one (call it R1) from the op-amp output to the inverting input, and another resistor (call it R2) from the inverting input to GND (usually). The gain will be 1+ (R1/R2). If you tie the end of R2 that normally would go to GND to a voltage instead, the output will be shifted. The gain from that point will be (R1/R2).

    For example: If you have an input that goes from 5 to 6 volts, and you need to change it to one that goes from 0 to 5 volts, you need a gain of 5 (1 volt change going in, to 5 volts change at the output). You could choose R1= 4K and R2= 1K. The gain would be 1+ (4K/1K) = 5.
    Now you need to shift it "down" to the 0 - 5 V range. The gain to the inverting input will be 4 (4K/1K), so you need to apply 5V/4 = 1.25V ABOVE 5V = 6.25V to the end of R2.

    Remember that if you use a voltage divider to provide this 6.25V, the thevenin resistance of the divider will be added to R2's value. The best way around this is to connect R2 to the output of a unity-gain op-amp, and drive THAT op amp with a divider from a voltage reference. And one final thing - if you don't have a negative voltage source for the (-) power pin of the op-amp, you will need a rail-to-rail output type in order for the output to get to near zero volts.
    Charles Linquist

  2. #2
    Join Date
    Oct 2010
    Location
    Northern Colorado
    Posts
    19


    Did you find this post helpful? Yes | No

    Default

    Thanks for the Help.

    So, I got the op amp all set up to keep the voltage under five volts. I can't believe I let that slip my mind when I was setting this up.

    Now, for coding, to get the analog output of the sensor to a use-able number in the pic. I understand that the pic has to have the AD conversion turned on.

    So, I want to hook up the analog voltage input on to pin RA7 on a 16f88. Would this be the correct code to do that

    'Set up AD conversion
    TRISA = %10000000 'sets RA7 as input and the rest as outputs
    ADCON1.7 = 1 'Right justify for 10-bit results
    Pause 500 'Wait .5 seconds for warm up
    But then, I'm stumped on getting the digital value from that pin to a value to plug into the equations for velocity.

    I'm sorry I'm so slow at this. I'll end up in the lab at 6AM tomorrow working on this so I want to make so I have as much information as possible to get as much done as I can.

    -Marcus

  3. #3
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    You can take a look at this and the data sheet to help you figure it out.
    Basics for reading an ADC with a 0 to 5 volt input and the chip running on 5 volts.
    Change as needed.
    Code:
    <font color="#000000">    <font color="#008000"><b><i>'16F88 10 BIT ADC TEST  FOR CHANNEL 0
        </i></b></font><font color="#FF0000"><b>DEFINE </b></font><font color="#0000FF"><b>OSC </b></font><font color="#800000"><b>4           
        </b></font><font color="#0000FF"><b>OSCCON </b></font>= <font color="#800000"><b>%01100000
        </b></font>@ <font color="#0000FF"><b>__config _CONFIG1</b></font>, <font color="#0000FF"><b>_INTRC_IO </b></font>&amp; <font color="#0000FF"><b>_WDT_OFF </b></font>&amp; <font color="#0000FF"><b>_LVP_OFF </b></font>&amp; <font color="#0000FF"><b>_MCLR_OFF </b></font>&amp;<font color="#0000FF"><b>_CP_OFF
        ANSEL </b></font>= <font color="#800000"><b>%00000001
        </b></font><font color="#0000FF"><b>TRISA </b></font>= <font color="#800000"><b>%11111111
        </b></font><font color="#0000FF"><b>CHAN0  </b></font><font color="#FF0000"><b>VAR WORD   </b></font><font color="#008000"><b><i>'VAR TO HOLD ADC0 READING
        
        </i></b></font><font color="#0000FF"><b>START</b></font>:
        <font color="#FF0000"><b>HIGH </b></font><font color="#0000FF"><b>PORTB</b></font>.<font color="#800000"><b>3    </b></font><font color="#008000"><b><i>'HEART BEAT LED
        </i></b></font><font color="#FF0000"><b>PAUSE </b></font><font color="#800000"><b>250
        </b></font><font color="#FF0000"><b>LOW </b></font><font color="#0000FF"><b>PORTB</b></font>.<font color="#800000"><b>3
        </b></font><font color="#FF0000"><b>PAUSE </b></font><font color="#800000"><b>250
        </b></font><font color="#008000"><b><i>'BELOW WILL SHOW WHAT THE ADRESH AND ADRESL REGISTER HOLDS
        </i></b></font><font color="#FF0000"><b>SEROUT2 </b></font><font color="#0000FF"><b>PORTB</b></font>.<font color="#800000"><b>2</b></font>, <font color="#800000"><b>16780</b></font>, [<b><i>&quot;ADRESH &quot;</i></b>,<font color="#FF0000"><b>DEC </b></font><font color="#0000FF"><b>ADRESH</b></font>,<b><i>&quot; ADRESL &quot;</i></b>,<font color="#FF0000"><b>DEC </b></font><font color="#0000FF"><b>ADRESL</b></font>,<font color="#800000"><b>$a</b></font>,<font color="#800000"><b>$d</b></font>]
        <font color="#FF0000"><b>PAUSE </b></font><font color="#800000"><b>50
        </b></font><font color="#008000"><b><i>'BELOW SHOWS THE 10 BIT READING OF ADC0 IN VAR CHAN0
        </i></b></font><font color="#FF0000"><b>SEROUT2 </b></font><font color="#0000FF"><b>PORTB</b></font>.<font color="#800000"><b>2</b></font>, <font color="#800000"><b>16780</b></font>, [<b><i>&quot;CHAN0 &quot;</i></b>,<font color="#FF0000"><b>DEC </b></font><font color="#0000FF"><b>CHAN0</b></font>,<font color="#800000"><b>$a</b></font>,<font color="#800000"><b>$d</b></font>]
        <font color="#FF0000"><b>PAUSE </b></font><font color="#800000"><b>250
        </b></font><font color="#FF0000"><b>GOSUB </b></font><font color="#0000FF"><b>ADC_0      </b></font><font color="#008000"><b><i>'STARTS THE READING OF ADC CHANNEL 0
        </i></b></font><font color="#FF0000"><b>GOTO </b></font><font color="#0000FF"><b>START
        
        ADC_0</b></font>:       <font color="#008000"><b><i>'READ AN0
        </i></b></font><font color="#0000FF"><b>ADCON1 </b></font>= <font color="#800000"><b>%10000000      </b></font><font color="#008000"><b><i>'SET FOR 10 BIT
        </i></b></font><font color="#0000FF"><b>ADCON0 </b></font>= <font color="#800000"><b>%00000001      </b></font><font color="#008000"><b><i>'TURNS ADC ON
        </i></b></font><font color="#FF0000"><b>GOSUB   </b></font><font color="#0000FF"><b>READ_AD
        CHAN0</b></font>.<font color="#0000FF"><b>HighByte </b></font>= <font color="#0000FF"><b>ADRESH  </b></font><font color="#008000"><b><i>'PLACES THE HIGH AND LOW BYTE
        </i></b></font><font color="#0000FF"><b>CHAN0</b></font>.<font color="#0000FF"><b>LowByte  </b></font>= <font color="#0000FF"><b>ADRESL   </b></font><font color="#008000"><b><i>'INTO VAR CHAN0
        </i></b></font><font color="#FF0000"><b>RETURN
        
        </b></font><font color="#0000FF"><b>READ_AD</b></font>:   <font color="#008000"><b><i>'DOES THE ADC CONVERSION
        </i></b></font><font color="#FF0000"><b>PAUSE   </b></font><font color="#800000"><b>50
        </b></font><font color="#0000FF"><b>ADCON0</b></font>.<font color="#800000"><b>2 </b></font>= <font color="#800000"><b>1
        </b></font><font color="#FF0000"><b>WHILE </b></font><font color="#0000FF"><b>ADCON0</b></font>.<font color="#800000"><b>2 </b></font>= <font color="#800000"><b>1</b></font>:<font color="#FF0000"><b>WEND
        RETURN  
                        
        
    </b></font>
    Dave
    Always wear safety glasses while programming.

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Charles,
    Would you consider writing an article for the wiki covering different ways of using op amps?
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    I guess I could in the next week or two.
    Charles Linquist

  6. #6
    Join Date
    Oct 2010
    Location
    Northern Colorado
    Posts
    19


    Did you find this post helpful? Yes | No

    Default

    Thanks for the help you guys. I'll look through the code and try to decipher what exactly its doing and make sure I have it set up for my application.

    Is the serout2 command just sending the data to the lcd? Rather than using an LCDOUT command?

    Got to the lab early this morning, got my LCD up and running. Went to reconfigure my op amp and find out its grounding something across the +-15V pins. No idea what is going on because last time I used the circuit it was working perfectly. Oh well, good thing I've got another 4 op amps on the way!

  7. #7
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    I waa displaying the data on a terminal with SEROUT2.
    Dave
    Always wear safety glasses while programming.

Members who have read this thread : 0

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts