question for math wizards


Closed Thread
Results 1 to 23 of 23

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default Re: question for math wizards

    Thanks Robert,

    I am using PBP V2.6 with a PicKit 2 programmer and a low pin count USB board and 18F14K50.

    I have had some success by enabling PBPL in MCS.

    The values I am after and the values I get are really close. Probably close enough for this particular project.

    mmH2O _______Knots ________Pic Output to serial port
    15_____________ 30______________ 30.09
    26.5 ___________40_______________39.56
    41.5 ___________50_______________50.16
    60 _____________60______________60.19
    81.5 ___________70______________69.61
    106.5 __________80______________80.2
    134.5 __________90______________89.72
    166.5 _________100______________99.75
    201 ___________110_____________109.79
    239.5 _________120_____________119.8


    To get these values I used


    Code:
     
    knots var long
    knotsRem var long
    counts var long
    pause 100
    MAINLOOP
    for counts = 0 to 10000 
    knots = ((SQR(counts*100))*1563)/10000
    knotsRem = (SQR(counts*100)*1563)//10000
    serout2 portb.7,396,[ #Knots,".",dec3 knotsRem," ",#counts,","," Knots",13,10]
    'pause 10
    next
    Goto Mainloop
    But there are a few "oddities" I dont know how to deal with.One thing I did see was a printout like this. 1st coulmn is Knots and the second
    the counts corresponding to that value.the question I have is why so many values the same, and then it jumps by about .5 knots. As I said, not critical in this instance, but may be in a future project and if I can get it sorted now all the better.

    143.708 8404, Knots
    143.708 8405, Knots
    143.708 8406, Knots
    143.708 8407, Knots
    143.708 8408, Knots
    143.271 8409, Knots
    143.271 8410, Knots
    143.271 8411, Knots
    143.271 8412, Knots
    143.271 8413, Knots
    143.271 8414, Knots
    143.271 8415, Knots

    I am guessing its the integer math thing again, just after some clarification


    Acetronics,
    Yes, its not me its Excel !!

    I did recalculate it in Excel by using the "ROUND" function, but his rounds up or down. I would expect that integer math always rounds down. I am guessing correctly?
    Thanks
    aajgss

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Default Re: question for math wizards

    Quote Originally Posted by aajgss View Post
    Acetronics,

    Yes, its not me its Excel !!
    Are you really sure your Math is good ???

    I'm not ...

    for counts = 0 to 10000
    knots = ((SQR(counts*100))*1563)/10000
    knotsRem = (SQR(counts*100)*1563)//10000
    1) due to your ADC ... "Counts" granularity is 1/1024 or 1/4096 ( let's dream ) ... just a detail ... but important.

    2) knots = ((SQR(counts*100))*1563)/10000 = SQR ( counts ) * 1563 / 1000 ... YESSS, no need to multiply "Counts", as granularity will remain the same ... !!!

    3) you can't use the remainder trick ... as it is a SQUARE function ... remember SQR ( A ) + SQR ( B ) != SQR ( A+B )

    Ok, I don't have the easy solution at the time ... but' Im on the way !!!

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default Re: question for math wizards

    Hi Acetronics,

    Here is some brief details of what I did and why I did it.

    ADC CountsADC VoltsmmH2OKnots10.00030.0411.5620.00060.0812.2130.00090.1222.71

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


    Did you find this post helpful? Yes | No

    Default Re: question for math wizards

    Hi Acetronics,

    Here is some brief details of what I did and why I did it.
    Code:
    ADC Counts              ADC Volts           mmH2O         Knots
    
    1                       0.0003              0.041         1.56 
    
    2                       0.0006              0.081         2.21 
    
    3                       0.0009              0.122         2.71
    
    
    
    now using
    
    knots = ((SQR(counts))*1563)
    
    and looking at the integer value that I would expect would be returned
    
    ADC Counts     ADC Volts     mmH2O      SQR(counts)       Integer valuegives me     Knots
    1             0.0003        0.041         1                       1                  1.56
    
    2             0.0006        0.081         1.414                   1                  1.56
    
    3             0.0009        0.122         1.73                    1                  1.56
    
    
    
    now using
    
    knots = ((SQR(counts*100))*1563)/10000
    
    
    
    ADC Counts     ADC Volts     mmH2O      SQR(counts*100)       Integer valuegives me     Knots
    
    1              0.0003        0.041             10                    10               1.56
    2              0.0006        0.081             14.14                 14               2.188
    3              0.0009        0.122             17.32                 17               2.657
    So I guess what I am saying is that it was the only way I could see of getting close to the resolution I needed.

    As for the remainder, that is the .56 at 1 count, .188 at 2 counts etc.

    Anyway, that was my train of thought. I am sure there must be a simpler way, i'm just not able to see it. Well I'm off to find that section of the forum for ideas to improve PBP "Floating Point Math"

    regards
    aajgss

  5. #5
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,172


    Did you find this post helpful? Yes | No

    Default Re: question for math wizards

    Yup, I tried three counts in Open Office Calc using 2 versions of the formula and got identical results:

    ((SQRT(cell))*1563)/1000
    ((SQRT(cell*100))*1563)/10000

    Code:
    1  1.563
    2  2.210
    3  2.707
    Are those above the expected results?


    Or are these?

    Code:
    1  1.560
    2  2.188
    3  2.657
    Last edited by Demon; - 7th June 2011 at 05:47. Reason: 'cause I can't write formulas out of Calc properly in my posts yet

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


    Did you find this post helpful? Yes | No

    Default Re: question for math wizards

    Hi Robert,

    I think the difference comes from the multiply by 100. This gives the result of for example 3 counts 17 and not 1.732.
    But as I said one decimal place is close enough for me.

    aajgss

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


    Did you find this post helpful? Yes | No

    Default Re: question for math wizards

    Thanks to all for you help to this stage.

    Now I'm off to create a new thread for the next bit. I have the hardware setup and producing data, just a bit of trouble reading it.

    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