question for math wizards


Closed Thread
Results 1 to 23 of 23
  1. #1
    Join Date
    Apr 2011
    Location
    NSW, Australia
    Posts
    39

    Default question for math wizards

    I am using a pressure sensor that gives me .2V to 4.8V from 0 to 6 KPA

    I want to convert that firstly into mm H20 and then mm H2O to Knots. The first bit is easy. The equation for the mm H2O to knots is 7.7538*(mmH2O ^ .5).

    That where I am having the trouble with no FP Math

    All ideas welcome

    aajgss

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: question for math wizards

    SQR(mmH2O)*(504/65)

    SQR(mmH2O)*(1543/199)

    SQR(mmH2O)*(2551/329)

    SQR(mmH2O)*(31116/4013)

    Hint: Use MiscEl

    Careful with the math overflow
    Last edited by mister_e; - 30th May 2011 at 08:30.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  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

    Awesome stuff Steve

    Thanks for your help

    aajgss

    ps not sure what you mean by MiscE?

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


    Did you find this post helpful? Yes | No

    Default Re: question for math wizards

    Give this a try...
    MiscEL
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default Re: question for math wizards

    Got It!

    Thought it was a ! and not an l - old eyes no glasses. Often get told I need them - maybe I do


    Thanks
    aajgss

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


    Did you find this post helpful? Yes | No

    Default Re: question for math wizards

    Quote Originally Posted by aajgss View Post
    Got It!

    Thought it was a ! and not an l - old eyes no glasses. Often get told I need them - maybe I do


    Thanks
    aajgss
    I know what you mean... without mine I walk into walls .. try stairs with a new pair of bifocals
    Dave
    Always wear safety glasses while programming.

  7. #7
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: question for math wizards

    I'm sure in the same boat... without mine I can't even say if it's an elephant ... or a supermarket
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  8. #8
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: question for math wizards

    Quote Originally Posted by aajgss View Post
    Got It!

    Thought it was a ! and not an l - old eyes no glasses. Often get told I need them - maybe I do


    Thanks
    aajgss
    You mean you tried to read that text and type it ? !!!

    Thank Jobs / Gates / Linus for copy/paste !
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

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


    Did you find this post helpful? Yes | No

    Default Re: question for math wizards

    Ok,

    Lets forget I said the first bits easy!!!

    Instead of converting to mmH2O and then converting that to Knots, I decided to go straight from ADC counts to Knots.

    So the equation comes out to be (SQR(ADC Counts))* ( 484/79).

    Excel comes up with the correct answer. for 1 ADC count the result comes out at 6.1266 knots. Doing the same calculation in a PIC the result is 6 knots. It appears that the result is the integer part only.

    The numbers I am trying to get is in the table

    mmH2O ________Knots
    15_____________ 30
    26.5 ___________40
    41.5 ___________50
    60 _____________60
    81.5 ___________70
    106.5 __________80
    134.5 __________90
    166.5 _________100
    201 ___________110
    239.5 _________120


    How do I calculate the correct value and still heed Steves advice to be careful of Math Overflow?


    Thanks
    aajgss
    Last edited by aajgss; - 3rd June 2011 at 15:55.

  10. #10
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: question for math wizards

    Hello aajgss,
    What level of resolution are wanting to display, I mean how many decimal places ?
    You could multiply up by 10, 100, 1000 and display using DEC modifier and "." .
    I didn't notice which PIC you are using but 18Fs can use long variables which if I am not mistaken are 32 bit vars.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

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


    Did you find this post helpful? Yes | No

    Default Re: question for math wizards

    Hi Archangel

    Resolution I would like is to 1 decimal place. The project I am working on is an electronic manometer to check calibration of the Air Speed Indicator for gliders.
    The limits are critical at 30 knots. The ASI must be within +/- 1.5 knots at 30 knots.

    I am using an 18F14K50. I did try a LONG variable and multiplied the counts by 10000, but still got the same results. I looked like I was getting a 16 bit math overflow. Most likely cause was me not knowing what I am doing. Is it just a case of using a LONG identifier or is there something else I need to do. There is an option in MCS to use PBPL. Is PBPL another part of PBP, a different program all together or some type of addin? I find the documentation for this kind of simple info a bit difficult to locate.


    Thanks
    aajgss

  12. #12
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,611


    Did you find this post helpful? Yes | No

    Default Re: question for math wizards

    Hi,

    Your answer is here :
    Excel comes up with the correct answer. for 1 ADC count the result comes out at 6.1266 knots
    you have to use a signal amplifier to get more ADC counts for the same outputted voltage ...

    A logarithmic amplifier could be a nice idea to get a linear ADC input voltage Vs Speed.

    I remember some really good work had been done here for Vu-meters ... ( a greek project ... )

    CA3089 or NE 604 could be some interesting keywords to try ...

    have fun

    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 " !!!
    *****************************************

  13. #13
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,588


    Did you find this post helpful? Yes | No

    Default Re: question for math wizards

    Quote Originally Posted by aajgss View Post
    ...I am using an 18F14K50. I did try a LONG variable and multiplied the counts by 10000, but still got the same results. I looked like I was getting a 16 bit math overflow. Most likely cause was me not knowing what I am doing. Is it just a case of using a LONG identifier or is there something else I need to do. There is an option in MCS to use PBPL. Is PBPL another part of PBP, a different program all together or some type of addin? I find the documentation for this kind of simple info a bit difficult to locate.
    ...

    I see it at least in section 3 (pages 17 and on), and in section 4 on Variables (page 23) and Division (page 37). It could be in other places; no fast way to use SEARCH in a book besides the table of contents (no index that I can see).

    (I really need to reread the manual, they've added important information in there)
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

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


    Did you find this post helpful? Yes | No

    Default Re: question for math wizards

    Archangel

    Thanks for the info. I think that may be the way to go. A 12 or 14 bit ADC may give me enough resolution.

    Robert,
    You hit the nail on the head. Exactly what I was meaning.

    From the Manual
    "PBP is the DOS version of the compiler. PBPW is the Windows version
    of the compiler and can take advantage of all the PC’s memory. PBPL is
    the long version of the compiler and can use 32-bit variables, as well as
    all of the PC’s memory under Windows. PBPL can only be used with the
    PIC18 devices.",

    But when I use a LONG variable and get the same answer as not using it I am stuck between "Did I do it right" or " Do I have the right version. Do I have PBPL" Where does it say "The version you are using is PBPL or PBP? As far as I know I am using PicBasic Pro. The executable that MCS or MPASM runs is PBP.EXE

    Remember, I am only new at this and finding this type of info that others take as commonplace is not so straight forward for a beginner like me. I also do a lot of searching this and other forums/ websites, but again I feel that I am expected to know this as its "simple stuff".

    Please note, I am not trying to offend or anything like that, just trying to highlight some of the frustrations I have with finding / understanding the "simple stuff"

    Regards
    aajgss

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


    Did you find this post helpful? Yes | No

    Default Re: question for math wizards

    Sorry Acetronics, I did mean to address you, instead I put Archangel

    aajgss

  16. #16
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,588


    Did you find this post helpful? Yes | No

    Default Re: question for math wizards

    Quote Originally Posted by aajgss View Post
    ...But when I use a LONG variable and get the same answer as not using it I am stuck between "Did I do it right" or " Do I have the right version. Do I have PBPL" Where does it say "The version you are using is PBPL or PBP? As far as I know I am using PicBasic Pro. The executable that MCS or MPASM runs is PBP.EXE

    Remember, I am only new at this and finding this type of info that others take as commonplace is not so straight forward for a beginner like me. I also do a lot of searching this and other forums/ websites, but again I feel that I am expected to know this as its "simple stuff".

    Please note, I am not trying to offend or anything like that, just trying to highlight some of the frustrations I have with finding / understanding the "simple stuff"

    Regards
    aajgss

    Can you give us more details on exactly what tools (software/hardware) you use?

    I have yet to use long division either. Off the top of my head, I recall a setting in
    MeLabs programmer to state what compiler/options to use.

    EDIT: Correction, in MicroCode Studio.

    - View.
    - Compile & Program options

    There is a toggle to Use PBPL. (I have MicroCode Studio Plus version, can't comment for sure on basic version)

    I would start by enabling that if I were to use PBPL on a PIC 18F device.

    The first thing I would do is a simple test program connected to a LCD.
    That way I would make sure to learn how to use the syntax properly
    before integrating it into a larger program.
    Last edited by Demon; - 5th June 2011 at 20:10.

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

  18. #18
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,611


    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 " !!!
    *****************************************

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

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

  21. #21
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,588


    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

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

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

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