Manometer project continued.


Closed Thread
Results 1 to 13 of 13

Hybrid View

  1. #1
    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

  2. #2
    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

  3. #3
    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.

  4. #4
    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

  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.

    Try DEC2 then try DEC3 to see what the command does.
    Then take a look at DIG
    4.17.7. DIG

    DIG returns the value of a decimal digit. Simply tell it the digit number (0 - 4 with 0 being the rightmost digit) you would like the value of, and voila.

    B0 = 123 ' Set B0 to 123
    B1 = B0 DIG 1 ' Sets B1 to 2 (digit 1 of 123)
    Add a DIG statement to your code to "pull" the DIGit you want.
    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.

    Thanks Dave,

    I looked at both as you suggested. These are the results

    Number 40.8914

    DEC2 returns the value 1
    DEC4 RETURNS
    Number 50.143

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


    Did you find this post helpful? Yes | No

    Default Re: Manometer project continued.

    Hit the end button before finished.

    Results
    Code:
    DEC 1
    47.6 Knots   686   
    46.8 Knots   9598   
    46.7 Knots   8727  
    46.2 Knots   9162  
    47.6 Knots   686   
    46.4 Knots   8074   
    46.2 Knots   9162   
    46.7 Knots   8727   
    46.2 Knots   9162   
    46.8 Knots   9598   
    DEC 2
    46.28 Knots   5028   
    46.69 Knots   3069  
    46.28 Knots   5028   
    46.81 Knots   5681   
    46.93 Knots   893   
    46.39 Knots   7639   
    46.62 Knots   9162  
    46.16 Knots   6116   
    46.81 Knots   5681   
    46.04 Knots   7204  
    DIG 1
    43.1 Knots   3910   
    42.4 Knots   6946   
    43.7 Knots   3475   
    43.8 Knots   6086   
    44.3 Knots   438  
    43.6 Knots   4563   
    43.5 Knots   5651  
    43.5 Knots   5651   
    43.8 Knots   6086  
    43.8 Knots   6086   
    DIG 2
    49.0 Knots   7016  
    49.5 Knots   8539   
    49.0 Knots   5058   
    49.9 Knots   8975
    50.4 Knots   498   
    50.4 Knots   498   
    49.0 Knots   5058   
    49.4 Knots   7451   
    49.6 Knots   4622   
    49.0 Knots   5058
    The value before Knots is what is the result of whether I have used DEC 1or 2 and DIG 1 or 2. The value fi=ollowing is the knotsRem variable.

    The DEC1 and 2 seem to make sense, although not displaying the first digit but the DIG 1 and 2 look to return the 2nd digit for DIG1 and 3rd digit for DIG2

    Before I was confused - now I'm way past that!!
    Looking at the manual there doesn't seem to be anywhere that left justifies a number.

    Thanks
    aajgss
    Last edited by aajgss; - 20th June 2011 at 23:05.

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