Manometer project continued.


Closed Thread
Results 1 to 13 of 13

Hybrid View

  1. #1
    Join Date
    Apr 2011
    Location
    NSW, Australia
    Posts
    39

    Default Manometer project continued.

    OK, I have the math to a point where it is calculating somewhere near the number I want.

    I have connected the hardware. A MPXV4006 pressure sensor which is connected to a MCP3201 ADC which in turn goes via SPI to a 18F14K50 PIC.

    Attached is the setup.

    Code:
    ' Variables
    SCK     VAR PORTB.6 'Clock pin
    CS     VAR PORTC.1 'Chip Select Active low
    SDI     VAR PORTB.4 'Data In pin
     
     COUNTS var word
     lbit var COUNTS.byte0
     hbit var COUNTS.byte1
    '-------------------------------------------------------------------------------
    Define LOADER_USED 1
    INCLUDE "MODEDEFS.BAS"
    DEFINE OSC 12
    DEFINE SHIFT_PAUSEUS 10  'gives a 50KHZ clock pulse                                                       
    TRISB.4 =1               ' set PortB 4 as an input
    TRISB.6 =0               ' set PortB 6 as an output         
     
    TRISC =%00000000                        
    knots var long
    knotsRem var long
    HIGH CS
    START:
     
    LOW CS 
    PAUSEUS 50 'delay after CS goes low for conversion to start. Probably not needed
    SHIFTIN SDI,SCK,2,[counts\14]  ' using mode 2 for SPI
    high cs 
     
    'knots = ((SQR(counts*100))*1563)/10000
    'knotsRem = (SQR(counts*100)*1563)//10000
    'serout2  portb.7,396,[ #Knots,".",dec3 knotsRem,"  ",#counts,",","   Knots",13,10]
    serout2  portb.7,396,[ #lbit,"   ",#hbit,13] ' Just send out ADC value to start
    GOTO START:
    END
    I can see the data coming in on the scope. If I move the plunger of the syringe, I get the data changing, but always get a Zero when I send it out to the serial port.

    I havent used the shiftin command before. It looks right so I'm not sure where I am going wrong.

    Any help would be appreciated.

    TIA
    aajgss
    Attached Images Attached Images  

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,115


    Did you find this post helpful? Yes | No

    Default Re: Manometer project continued.

    If your data to see on terminal is in the counts variable, you have this line commented out.

    Ioannis

  3. #3
    Join Date
    Apr 2011
    Location
    NSW, Australia
    Posts
    39


    Did you find this post helpful? Yes | No

    Default Re: Manometer project continued.

    Thanks Ioannis,

    I changed it to counts, Unfortunatly no difference, but at least if it was working I wouldn't have seen it anyway. Thanks for the tip.

    I also Added

    ANSELH.2 = 0

    This then worked, however I must say when I read the datasheet for the 18F14K22 I interpret it that it should be digital so it wouldnt be necessary to add this statement so I am a bit confused. Maybe another 40 or 50 reads and it might sink in!!!

    regards
    aajgss

  4. #4
    Join Date
    Apr 2011
    Location
    NSW, Australia
    Posts
    39


    Did you find this post helpful? Yes | No

    Default Re: Manometer project continued.

    I now have everything working and calculating air speed

    I used "DEC1" to only print out to one decimal point.

    Running the program gave some strange results. On occasion the count would increase, but the Knots value woud reduce.

    By printing out all of the remainder, I could see what was going on.
    eg for 2577 counts, the value would be 110.7 and for 2579 counts the value would be 110.1. The problem being in the true value

    2577 counts is 110.457 and 110.501. The "DEC1" would give the digit either the 1 or 7 and not the 4 or the 5 as I expected (read hoped)

    How can I get the first digit?

    thanks
    aajgss

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


    Did you find this post helpful? Yes | No

    Default Re: Manometer project continued.

    What does your code look like now?
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Apr 2011
    Location
    NSW, Australia
    Posts
    39


    Did you find this post helpful? Yes | No

    Default Re: Manometer project continued.

    Hi Dave,

    Code is attached. Thanks for looking

    Code:
    Define LOADER_USED 1
    INCLUDE "MODEDEFS.BAS"
    DEFINE OSC 12
    DEFINE SHIFT_PAUSEUS 10                                                       
    TRISB.4 =1               ' set PortB 4 as an input
    TRISB.6 =0               ' set PortB 6 as an output         
    ANSELH.2 =0
    DEFINE ADC_BITS 8
    DEFINE ADC_CLOCK 3
    DEFINE ADC_SAMPLEUS 50
    ANSEL =%10000000      ' Enable ADC channel-AN2
    ANSELH =%0000                         
    OSCCON=%01100000                       
    TRISA =%00001111                        ' Set ports A3-A2-A1-A0 as inputs
                           
    TRISC =%01001000                        
    knots var long
    knotsRem var long
    zero var word
    zeroSw var portc.6
    i var byte
    avg var word
    HIGH CS
    START:
    for i = 1 to 10 
    LOW CS 
    PAUSEUS 150 'delay after CS goes low for conversion to start. Probably not needed
    SHIFTIN SDI,SCK,2,[counts\14]  ' using mode 2 for SPI
    high cs 
    avg = counts + avg
    next
    counts = avg/10
    avg=0
    if zeroSw then  zero = counts                               'Get value at zero pressure
    if zeroSw then high portc.2
    counts = counts -zero  'set zero point 
    if counts >65000 then counts= 0                           'in case of underflow
    knots = (((SQR(counts*10000))*65500)/301)/10000
    knotsRem = ((SQR(counts*10000)*65500)/301)//10000
    serout2  portb.7,396,[ #Knots,".",Dec1 knotsRem," Knots   ",#counts,"   ",#zero,10,13]
    GOTO START:
    END
    Thanks
    aajgss

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