View Full Version : Help with look up table
isaac
- 10th April 2012, 21:07
:._sour: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
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
aratti
- 10th April 2012, 22:37
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.
isaac
- 11th April 2012, 00:24
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
Darrel Taylor
- 11th April 2012, 02:07
Not sure if it's better, but the title was about a LOOKUP table ... :)
Idx VAR BYTE
Get_Pressure:
LOOKDOWN2 datax,<=[322,325,328,331,336,339,342,346,351,355,360,364,37 0,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
Dave
- 11th April 2012, 11:48
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
spcw1234
- 11th April 2012, 13:41
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?
isaac
- 11th April 2012, 18:32
Thanks all for your advise
the at 389 the pressure is 3.3Bar but if its more than 3 bar i raise an alarm
my results are divided by 100 before its displayed.
Darrel the Lookup table works fine .
Shawn FYI ..........its a Vibrating Wire Sensor :)
Respect To You Guys
Isaac
Art
- 13th April 2012, 00:13
Subtract 255 from all the values and you can use bytes in the lookup table and add 255 after the lookup.
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.