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.
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
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
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
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?
Re: Help with look up table
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
Re: Help with look up table
Subtract 255 from all the values and you can use bytes in the lookup table and add 255 after the lookup.