Sign in to follow this  
Followers 0
Colin Carpenter

Look Up Table

5 posts in this topic

I wonder if any of the experts on here could point me to a tasty function that I know nothing about ...... I have a Q2AS PLC that is reading the probe units from a NIR fat sensor into an analogue input. No problem there and it's working fine, but I have to analyse the measured probe units and convert them into engineering units, in this case Fat %. I have created fat samples of varying amounts and have put the probe in and noted the probe units for each of the samples, allowing a graph to be drawn of how the Fat% varies with amount of probe units. Again, no problem and the graph gives a nice smooth curve, but when asking Excel to work out the relationship between the two variables, it can't find a sensible equation that links the two, so I've programmed the PLC to read the probe units and do lots of code along the lines of : IF <Probe Units> Greater than <Constant A> AND <Probe Units> Less than <Constant B> THEN <Fat%> = <Determined Value from Graph> It's fine and it works OK but needs 40 comparisons to work out the Fat% from 0 to 40% at 1% intervals. If I want to increse the resolution to 0.5% then I would have to double the number of comparisons etc. I've seen arrays are possible in the Q, and wonder if anyone has used a neat software solution to minimise the code so that, given a probe unit value, the system can pick a value out of the array if the probe unit value is greater than a second array value and less than a third array value? Hope that's clear ......

Share this post


Link to post
Share on other sites
If i understand correctly, you've got a graph (not linear) with a certain amount of (xn = probe units, yn = % fat) points. For a given x, you need to find the y? You can make a table with 2 columns (40 rows, or more depending on your division): - first column = x1,x2... xn = probe units (let's say these points go into D0 - D39) - second column = y1, y2,... yn = % fat (let's say these points go into D50-D89) For a certain x, you need to find y. You can do this with a simple loop. - search the position of the x in the xn column: with a FOR NEXT loop, you look up the x in D0-D39, starting with D0z0 (first row) and working your way through the rows until you find the value - when you get a match, get the corresponding y in the yn column: D50z0 If your x is between two xn values, you can save both x and y values between which the x is and interpolate. Let's say your x is between row 14 and 15, you save x and y from row 14 and x and y from row 15 and interpolate. That are different search methods for faster searching but for a column with a small amount of rows, that shouldn't be an issue. In the QnU, Mitsubishi has introduced the great SCL instruction for this type of thing. But that doesn't help in your case. Edited by Mitsu

Share this post


Link to post
Share on other sites
Agree with Mitsu, In addition; yes arrays are possible in the QnAS series. If you use labels, you define arrays of any given type. If you don't use labels, simply set the starting point and use x amount of registers.

Share this post


Link to post
Share on other sites
Ah ... a FOR NEXT loop ... have never tried that before, will look it up and have a go. Thanks for that !!

Share this post


Link to post
Share on other sites
Too bad you don't have a newer processor. The SCL function that is available on the iQ processors would be perfect! Could you use indexing? Set up an array of Fat% values corresponding to 1-40%. Then take your probe input, do some math/comparisons to round it to the nearest percent, then shove that value into an index register. For example: D0 is probe % in tenths of a percent (i.e. 10 = 1.0%) D2 is Fat% in tenths of a percent D101-D140 is 40-value lookup table of Fat% values Code: LD SM400 / D0 K10 D10 ------Divide probe percent by 10, place in D10 LD>= D11 K5 ------Is remainder (in D11) greater or equal to 5? + D10 K1 D10 ------If so, increment D10 (round up). If not, do nothing. LD SM400 MOV D10 Z0 ------Move divided value into index register MOV D100Z0 D2 ------Fetch Fat% from lookup array

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0