Speed Sensor Anyone???


Results 1 to 20 of 20

Threaded View

  1. #2
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default Re: Speed Sensor Anyone???

    This one is from http://www.steveonweb.com/node/378 using the MPX5050 differential sensor. (This is air speed. Not sure if you are looking for air or water speed

    Code:
    '****************************************************************
    '*  Name    : airspeed.BAS                                      *
    '*  Author  : Steve Turner                                      *
    '*          : www.steveonweb.com    [email protected]  *
    '*  Notice  : Use as you like                                   *
    '*  Date    : 6/06/02                                           *
    '*  Version : 1.4                                               *
    '*  Notes   : An airspeed Project Created for an unmanned       *
    '*          : Aerial Vehicle. Uses a Motorola MPX5050           *
    '*          : differential pressure sensor connected to RA1     *
    '*          : good to 270 Mph using an op-amp for a sensor      *
    '*          : gain of 5                                  *
    '*          :    PIC16F877 
    '****************************************************************
    ' PicBasic Pro program
    '
    ' Connect analog input to channel-1 (RA1)
    
    'Setup LCD
    'This setup will tell PBP a 2-line LCD is connected in 4-bit mode 
    'with the data bus on the top 4
    'bits of PORTB, Register Select on PORTB.1, and Enable on PORTB.0.
    DEFINE LCD_DREG PORTB 'Set LCD Data port
    DEFINE LCD_DBIT 4  'Set starting Data bit
    DEFINE LCD_RSREG PORTB 'Set LCD Register Select port
    DEFINE LCD_RSBIT 1 'Set LCD Register Select bit
    DEFINE LCD_EREG PORTB 'Set LCD Enable port
    DEFINE LCD_EBIT 0 'Set LCD Enable bit
    
    symbol cr = 13          ' Carrige Return
    symbol lf = 10          ' Line Feed
    sout        var portd.7
    
    temp1       var word
    Pressure    var word    ' in pascals
    Airspeedmet var word    ' Airspeed meters / sec
    Airspeed    var word    ' Airspeed in MPH
    OutVolt     var word    ' Output voltage of sensor in .1 mv
    ADvalue     var word
    counter     var byte
    NewADvalue  var word
    
    ' Sets up the port for AD conversion
        TRISA = 111111      ' Set PORTA to all input
        ADCON1 = 000100     ' Set PORTA analog and RIGHT justify result
                            ' RA1 is AD in, Vdd is V+ ref, Vss is V- ref (GND)
        ADCON0 = 001011    ' Configure and turn on A/D Module 'Fosc RC
        Pause 500           ' Wait .5 second for it to warm up
    
    loop1:
    'Resets temp variables for a fresh start
    counter = 1
    NewADvalue = 0
    
    'This loop adds 64 AD conversion values together, and then divides 
    'by 16 to get a 12 bit value from a 10 bit input
    
    for counter = 1 to 50 'no more than 64, then it can overflow
    
        ADCON0.2 = 1        ' Start Conversion
    
    notdone: Pause 5
        If ADCON0.2 = 1 Then notdone    ' Wait for low on bit-2 of ADCON0, conversion finished
    
    'Load Value into word variable ADvalue
        ADvalue.highbyte = ADRESH    ' Move HIGH byte of result to ADvalue
        ADvalue.lowbyte = ADRESL    ' Move LOW byte of result to ADvalue
    
    NewADvalue = NewADvalue + ADvalue 'just keep adding them 
    next
    
    ADvalue = NewADvalue / 50 'will produce 12bit from a 10bit AD converter
    
    'calculate the values
    
        gosub calcVoltage
        gosub calcPressure
        gosub calcairspeed
        
    'display the results on an LCD
        LCDOUT $FE,1,"AD ",dec4 ADvalue," Volt ",dec5 OutVolt
        LCDOUT $FE,$C0,"Pres ",dec5 pressure," Asp ", dec3 airspeed
        pause 5
        SEROUT2 sout,396,["ADvalue = ",dec4 ADvalue,"  OutVolt = ",dec5 OutVolt,"  Pressure = ",dec5 pressure, "  Airspeed = ", dec3 airspeed,10,13]
    
    goto loop1
    end
    
    'Subroutines
    
    'gives millivolt*10
    calcVoltage:
        'OutVolt = ADvalue * resolution
        OutVolt = ADvalue */ 2500 ' = ADvalue * 2500 / 256
        OutVolt = OutVolt + 260    'Correcting for Sensor Being a little off    
        return
    
    calcPressure:
    if outvolt < 2000 then goto zero
    'Vout = VS x (0.018 x P +0.04) gives with VS = 5volt
    'P=(Vout - 0.2)/0.09
    'p = ((Vout0.1mv - 2000) * 10) / 9
        pressure = (OutVolt - 2000) * 10
        pressure = div32 9 'In pascals
        return
    
    zero:
        Pressure = 0
        gosub calcairspeed
    
    calcairspeed:
    'airspeed = square root of {(2*pressure) / 1.225} ' pressure in Pascals
    '/ 1.225 = *.8163 '53499/65536 = .8163
    temp1 = (2*pressure) ** 53499
    airspeedmet = sqr temp1 'takes the square root of temp1
    'meters per second * 2.237 = miles per hour
    airspeed = airspeedmet * 224
    airspeed = airspeed/100
        return
    Last edited by ScaleRobotics; - 1st May 2012 at 15:42.
    http://www.scalerobotics.com

Members who have read this thread : 0

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

Posting Permissions

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