Help with look up table


Closed Thread
Results 1 to 8 of 8

Hybrid View

  1. #1
    Join Date
    May 2004
    Location
    brighton
    Posts
    149

    Default Help with look up table

    Hello All

    i have a big problem on my hands which i ned some help with.
    i have got the following data which comes from a sensor and i need to calibrate this to Bar.
    the sensor outputs period in uS and the corresponding pressure i need to equal this to are below

    PERIOD PRESSURE IN BAR
    324.7
    327.8
    0.25
    330.8 0.5
    335.1 0.75
    338.2 1
    341.6 1.2
    346 1.4
    350.5 1.6
    354.5 1.8
    359.3 2.0
    363.7 2.2
    369.7 2.4
    374.1 2.6
    379 2.8
    386.4 3.0



    my question is what is the best way to approach this .
    should ido it with lots of if then statements of have you guys got a better way i can do this


    Code:
        if period <=  325 then 
        pressure = 0
        endif
        if period >  325 and period < 328 then 
        pressure = 0.25
        endif
         if period >  328 and period < 330 then 
        pressure = 0.5
        endif
        if period >  330 and period < 33 then 
        pressure = 0.25
        endif
    Best Regards
    Isaac

  2. #2
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default Re: Help with look up table

    Isaac, you can tray with the regression coefficient.

    Pulse VAR word
    Pressure VAR word
    Dummy VAR word
    Slope con 476
    Inter con 15

    Dummy = Pulse x Slope

    Pressure = Div32 10000

    Pressure = Pressure - Inter

    This will give you a 10% drift but it could be acceptable.

    Cheers

    Al.
    All progress began with an idea

  3. #3
    Join Date
    May 2004
    Location
    brighton
    Posts
    149


    Did you find this post helpful? Yes | No

    Default Re: Help with look up table

    Thanks for you help
    i am work on this at the moment
    but not sure its going to work out right

    would test tomorrow

    regards
    Isaac


    datax var word
    pressure var word
    goto main
    Get_Pressure:

    if (datax <= 325) then pressure =0
    if (datax <= 328) and (datax > 325) then pressure = 25
    if (datax <= 331) and (datax > 328) then pressure = 50
    if (datax <= 336) and (datax > 331) then pressure = 75
    if (datax <= 339) and (datax > 336) then pressure = 100
    if (datax <= 342) and (datax > 339) then pressure = 120
    if (datax <= 346) and (datax > 342) then pressure = 140
    if (datax <= 351) and (datax > 346) then pressure = 160
    if (datax <= 355) and (datax > 351) then pressure = 180
    if (datax <= 360) and (datax > 355) then pressure = 200
    if (datax <= 364) and (datax > 360) then pressure = 220
    if (datax <= 370) and (datax > 364) then pressure = 240
    if (datax <= 375) and (datax > 370) then pressure = 260
    if (datax <= 379) and (datax > 375) then pressure = 280
    if (datax <= 387) and (datax > 379) then pressure = 300
    if (datax < 323) or (datax > 389) then pressure = 999
    return

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: Help with look up table

    Not sure if it's better, but the title was about a LOOKUP table ...

    Code:
    Idx      VAR BYTE
    
    Get_Pressure:
        LOOKDOWN2 datax,<=[322,325,328,331,336,339,342,346,351,355,360,364,370,375,379,389,65535],Idx
        LOOKUP2       Idx,[999,  0, 25, 50, 75,100,120,140,160,180,200,220,240,260,280,300,  999],pressure
    RETURN
    Last edited by Darrel Taylor; - 11th April 2012 at 02:14.
    DT

  5. #5
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: Help with look up table

    Isaac, I think I would do it this way, eliminating the AND in each of the statements by using a CASE statement. I also notice there is no compare for the value of 389. Is this intentional?

    select case datax
    case is < 323
    pressure = 999
    case is < 326
    pressure = 0
    case is < 329
    pressure = 25
    case is < 332
    pressure = 50
    case is < 337
    pressure = 75
    case is < 340
    pressure = 100
    case is < 343
    pressure = 120
    case is < 347
    pressure = 140
    case is < 352
    pressure = 160
    case is < 356
    pressure = 180
    case is < 361
    pressure = 200
    case is < 365
    pressure = 220
    case is < 371
    pressure = 240
    case is < 376
    pressure = 260
    case is < 380
    pressure = 280
    case is < 388
    pressure = 300
    case is > 389
    pressure = 999
    end select
    Dave Purola,
    N8NTA
    EN82fn

  6. #6
    Join Date
    Apr 2007
    Location
    Pennsylvania, USA
    Posts
    158


    Did you find this post helpful? Yes | No

    Default Re: Help with look up table

    For what it's worth, in my experiences, using IF THEN commands compile to a smaller file size than using the CASE command. That said, I would use a lookup table as Darrel provided an example.

    What sensor are you using?
    Shawn

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