+ Post New Thread
Results 1 to 7 of 7
  1. #1
    Newbie level 4
    Points: 38, Level: 1

    Join Date
    Mar 2017
    Location
    Viginia
    Posts
    6
    Helped
    0 / 0
    Points
    38
    Level
    1

    Storage of values to be looked up

    I am working with the results of the A to D and I need to convert the voltage value to airspeed. I have the equations but most require floating point or some form of exponential math. I don't think the pic can do that. So my next option is to merely do a look up based on whatever value I read. At this point I am in over my head with the pic. I am using a Pic877a, not locked into it at this point. I am also using the PBP3 compiler and Pic basic. Any guidance would be wonderful.
    The input is from a Motorola MPX series transducer. I am reading from 20 knots up to about 160. The voltage range is 0 up to about 1.20. I have vref set at 1.25.
    Brian

    •   Alt20th March 2017, 17:52

      advertising

        
       

  2. #2
    Super Moderator
    Points: 68,072, Level: 63
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    11,134
    Helped
    3675 / 3675
    Points
    68,072
    Level
    63

    Re: Storage of values to be looked up

    Floating point math uses lots of memory but a 16F877A can do it and it has an ADC on-board as well. Please post the formula and I'll see if it will fit.

    Look up tables are easy in a PIC, especially if there are less than about 254 entries per table because of the neat way you can use a variable to 'jump ahead' from the table start to an entry further along. If you use a PIC18F series processor they have instructions dedicated to accessing look up tables so it's even easier.

    another Brian.
    PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.
    It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.



  3. #3
    Newbie level 4
    Points: 38, Level: 1

    Join Date
    Mar 2017
    Location
    Viginia
    Posts
    6
    Helped
    0 / 0
    Points
    38
    Level
    1

    Re: Storage of values to be looked up

    y = 0.0304x2 - 0.0994x + 166.22 From the excel work I have done,
    X = KNOTS
    Y = BINARY VALUE from about 145 to 960
    The binary value is the result from the 10 bit conversion. The knots are values that I have pre calculated from the Motorola data sheet (MPX5010 Differential transducer)and some actual testing using a pressure input and measured against a prime standard. The knots are actually calculated from an equation dealing with PSi I can provide that as well if you are interested,
    With respect to the limit of 254 , there are pre-calculated values from 10 knots up to 160 knots in 1 knot increments. I am targeting the one knot increment display. The math would preclude the "lookup " function.
    Thanks so much
    The other other Brian



    •   Alt21st March 2017, 13:02

      advertising

        
       

  4. #4
    Super Moderator
    Points: 24,476, Level: 38
    andre_teprom's Avatar
    Join Date
    Nov 2006
    Location
    Portugal
    Posts
    7,350
    Helped
    917 / 917
    Points
    24,476
    Level
    38
    Blog Entries
    5

    Re: Storage of values to be looked up

    You don't need necessarily to use float point notation. You could try to scale the whole equation to turn all values to an integer form, as follows:

    Code:
    y = ( 1/10,000 ) * ( 304*x^2 - 994*x + 1,662,200 )
    And in order to save a lot of calculations due to the division opperation, you could even try approximate the factor to a power of two:

    Code:
    y = ( 1/8,192 ) * ( 249 *x^2 - 914*x + 1,361,674)
    Replacing division by right shift opperation:

    Code:
    y = ( 249 *x^2 - 914*x + 1,361,674) >> 13
    Considering that the above calculation would exceed the LONG magnitude, you could split the function within 2 manageable parts:

    Code:
    y = ( ( 249 *x^2 - 914*x) >> 13 ) + 166
    In shorts, you have to make several attempts to fit the above calculation in your 8-bit microcontroller, perhaps succeeded, but pehaps leading you to the conclusion that it should be done just with float numbers, but you have to experiment in practice.
    --------------------------------------------------------------------------------------------------
    Part of the world that you live in, You are the part that you're giving ( Renaissance )



  5. #5
    Newbie level 4
    Points: 38, Level: 1

    Join Date
    Mar 2017
    Location
    Viginia
    Posts
    6
    Helped
    0 / 0
    Points
    38
    Level
    1

    Re: Storage of values to be looked up

    I ran the first code in my spreadsheet and it works well. However I do not understand the pic well enough to actually translate this into actual pic basic. I am sorry, I am learning just really slow!



  6. #6
    Super Moderator
    Points: 68,072, Level: 63
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    11,134
    Helped
    3675 / 3675
    Points
    68,072
    Level
    63

    Re: Storage of values to be looked up

    Don't forget if you are using the PICs ADC, the values it produces are from 0 to 1023 so the formula needs adapting accordingly.

    I'm pretty sure that formula will fit inside a 16F877A quite nicely and leave room to drive an LCD or LED display or serial interface. I program in C though, I've never used PBP3. I do have a copy of Oshonsoft's PIC BASIC but I find the language quite tedious to use.

    Brian.
    PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.
    It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.



    •   Alt21st March 2017, 18:24

      advertising

        
       

  7. #7
    Newbie level 4
    Points: 38, Level: 1

    Join Date
    Mar 2017
    Location
    Viginia
    Posts
    6
    Helped
    0 / 0
    Points
    38
    Level
    1

    Re: Storage of values to be looked up

    I am working on coming up to speed on the HI TEC C compiler so let me see what you have. I went with the basic because the tool was already here. I don't really have any loyalty to it.
    Brian

    With respect to the value range of the A2D , it will be fine for what I am doing. Right now I go from about 134 to 945



--[[ ]]--