Airspeed from MPX5500DP differential pressure sensor using a PIC16F88


Closed Thread
Results 1 to 27 of 27

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    So, after working it over a little, this is what I've got.

    'Using PIC16F88
    'Identify and set the internal oscillator clock speed (required for the PIC16F88)

    'Using configuration bits of the following
    'Oscillator: INTRC-OSC2 as RA6
    'Watchdog Timer: ON
    'Power Up Timer: ON
    'Code Protect: Off
    'RA5/MCLR pin function select: RA5 (to use this pin as extra I/O instead of MCLR)

    DEFINE OSC8
    OSCCON.4=1
    OSCCON.5=1
    OSCCON.6=1

    'Turn on and configure AN4 (A/D convertor on pin 3)

    ANSEL.4=1 : TRISA.4=1 'sets up the A/D conerter on RA4/AN4 (pin3) and sets it to an input
    ADCON1.4=1 'have 10 bits be right justified
    DEFINE ADC_BITS 10 'AN4 is a 10-bit AD conversion
    DEFINE ADC_CLOCK 3 'Sets clock to internal oscillator
    DEFINE ADC_SAMPLEUS 10 'Pause for sampling, I don't actual use this anywhere in the program

    'Initialize I/O pins
    TRISB=0 'Set PORT B pins to all outputs
    TRISA=%00010000 'Set PORT A pins to output except for RA4/AN4(pin 3), it will be set as an input

    'Declare variables

    ad_word Var Word 'Word from the A/D converter (10 bits padded with 6 0's)
    P Var Word 'P is the calculated pressure variable from the reading of the pressure sensor
    V Var Word 'V is the calculated airspeed from the pressure value
    X Var Word 'X is a variable taking place of the calculation 2*9/1.2
    maxp Con 60 'Max pressure reading of 60 Pa, random max pressure that can be changed

    'main loop

    main:
    ADCIN 4, ad_word 'read value from voltage input on AN4, pin 3 and then store as ad_word

    Pauseus 100 'check sampling time for that of the sensor and the pic to see if this value is correct

    P = maxp * ad_word / 1023 'equation to calculate pressure using the variables and constants defined earlier
    'Also contains 10 bit results
    'Hopefully will output whole value without truncation, if it does find value to multiple by
    X = 2 * P / 1.2

    V = SQR X 'calculating velocity with the sqaure root of 2 times pressure (p) divide by density (1.2)

    LCDOUT $FE, 1, "V"

    Pause 100 'unsure of the pause and if this will show the dynamic change in airspeed

    Goto main

    End
    But, now I am getting an error. I believe it is with one of my eqautions but I am unsure why. The error I am getting is....

    Executing: "C:\pbp\PBPW.EXE" -ampasmwin -oq -z -p16F88 "airsp.bas"
    PICBASIC PRO(TM) Compiler 2.50b, (c) 1998, 2008 microEngineering Labs, Inc.
    All Rights Reserved.

    U:\WINDTUNNEL\AIRSPEED PROJECT\AIRSP.BAS ERROR Line 46: Syntax error.Halting build on first failure as requested.
    BUILD FAILED: Wed Nov 10 12:28:39 2010
    Any help?

    Thanks!!

    -Marcus

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


    Did you find this post helpful? Yes | No

    Default

    Or, here is this to make it easier to read.

    Code:
     'Using PIC16F88
    'Identify and set the internal oscillator clock speed (required for the PIC16F88)
    
    'Using configuration bits of the following
    'Oscillator: INTRC-OSC2 as RA6
    'Watchdog Timer: ON
    'Power Up Timer: ON
    'Code Protect: Off
    'RA5/MCLR pin function select: RA5 (to use this pin as extra I/O instead of MCLR)
    
    DEFINE OSC8
    OSCCON.4=1
    OSCCON.5=1
    OSCCON.6=1
    
    'Turn on and configure AN4 (A/D convertor on pin 3)
    
    ANSEL.4=1 : TRISA.4=1			'sets up the A/D conerter on RA4/AN4 (pin3) and sets it to an input
    ADCON1.4=1				'have 10 bits be right justified
    DEFINE ADC_BITS 10				'AN4 is a 10-bit AD conversion
    DEFINE ADC_CLOCK 3				'Sets clock to internal oscillator
    DEFINE ADC_SAMPLEUS 10			'Pause for sampling, I don't actual use this anywhere in the program
    
    'Initialize I/O pins
    TRISB=0						'Set PORT B pins to all outputs
    TRISA=%00010000					'Set PORT A pins to output except for RA4/AN4(pin 3), it will be set as an input
    
    'Declare variables
    
    ad_word		                Var		Word		'Word from the A/D converter (10 bits padded with 6 0's)
    P			Var		Word		'P is the calculated pressure variable from the reading of the pressure sensor
    V			Var		Word		'V is the calculated airspeed from the pressure value
    X			Var		Word		'X is a variable taking place of the calculation 2*9/1.2 
    maxp		                Con		60		'Max pressure reading of 60 Pa, random max pressure that can be changed
    
    'main loop
    
    main:
    	ADCIN 4, ad_word                     'read value from voltage input on AN4, pin 3 and then store as ad_word
    
    	Pauseus	100		'check sampling time for that of the sensor and the pic to see if this value is correct
    
    	P = maxp * ad_word / 1023	'equation to calculate pressure using the variables and constants defined earlier
    				'Also contains 10 bit results
    								                                                'Hopefully will output whole value without truncation, if it does find value to multiple by
    	X = 2 * P / 1.2
    
    	V = SQR X					'calculating velocity with the sqaure root of 2 times pressure (p) divide by density (1.2)
    
    	LCDOUT $FE, 1, "V"
    
    	Pause 100					'unsure of the pause and if this will show the dynamic change in airspeed
    
    Goto main
    
    End

  3. #3
    Join Date
    Feb 2010
    Location
    USA, New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default

    Hello Marcus,

    I suspect your error is here as we only get integer math:
    Code:
    	X = 2 * P / 1.2
    Try this instead:
    Code:
    	X = 20 * P / 12
    Best Regards,
    Paul
    The way to avoid mistakes is to gain experience. The way to gain experience is to make mistakes.

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


    Did you find this post helpful? Yes | No

    Default

    Thanks, Paul!

    I'll give that a try when I am in lab tomorrow morning. I also got my op amps today so hopefully I can get my pitot and up running tomorrow!

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


    Did you find this post helpful? Yes | No

    Default

    Paul, that fixed the problem. Thanks again.

    Hopefully this all works as planned now!

  6. #6
    Join Date
    Feb 2010
    Location
    USA, New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default

    Hello Marcus,

    No problem, that was an easy one. Dave (and you) did the hard part of the work. I'm glad you have it working!

    Best Regards,
    Paul
    The way to avoid mistakes is to gain experience. The way to gain experience is to make mistakes.

  7. #7
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    I am glad your code works. But in case you will need one decimal place precision in your calculation, then you can re-work your formula in this way:

    Code:
    Vu  var byte ' unit
    Vd var byte  ' decimal
    
    P = 6000 * ad_word / 614
    V = SQR(P)
    Vu = V DIG 1
    Vd = V DIG 0
    
    LCDOUT $FE, 1, Vu,".",Vd
    Cheers

    Al.
    Last edited by aratti; - 11th November 2010 at 14:59.
    All progress began with an idea

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


    Did you find this post helpful? Yes | No

    Default

    Fellas,

    I am having a problem with my LCD display that I can't seem to figure out what the deal is. I have a 16 x 2 LCD that has a Hitachi 44780 driver. I am having problems with the value it is reading being displayed in a useable number.

    Sitting at "idle" the LCD outputs 00008, which is fine. But then when the values increase it gets up to 00010 and then roles back around to 00001 and can do that for several cycles up and down. What is it doing? It should be outputting a velocity in relation to the pressure.

    My basic LCDOUT command is as follows

    Code:
    LCDOUT $FE, 1,"Begin Program"
    
    Pause 2000
    
    'main loop
    main:
    	ADCIN 4, ad_word				'read value from voltage input on AN4 (pin 3) and then store as ad_word
    
    	Pauseus	200						'check sampling time for that of the sensor and the pic to see if this value is correct
    
    	P = maxp * ad_word / 1023	'equation to calculate pressure using the variables and constants defined earlier
    									'Also contains 10 bit results
    									'Hopefully will output whole value without truncation, if it does find value to multiple by
    	Pauseus 200
    
    	X = 20 * P / 12
    
    	Pauseus 200
    
    	V = SQR X					'calculating velocity with the sqaure root of 2 times pressure (p) divide by density (1.2)
    
    	Pauseus 200
    
    	LCDOUT $FE, 1
    
    	LCDOUT $FE, $80 + 4, dec5 V			'Output Velocity to LCD, should be in m/s
    
    	Pauseus 200				
    
    Goto main
    
    End
    Any thoughts?

    You are all great and I am so thankful for all the help you guys are giving me!

    -Marcus

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