Logic for scaling more than two coordinates required

hajdeen82

Member
Join Date
Jul 2008
Location
BANGALORE
Posts
6
Hi

I want to generate a code for a scaling of x,y table,like what we do in analog input scaling of PLC's. Normally for analog inputs we have two co-ordinates. But in my case it is like this

X Y
0 0
325 340
360 360
From this data for each value of X given as input, the corresponding y value should be the output.

Could anyone help please
 
Well, technically that isn't scaling because it isn't linear. What you have would be more of a computed value. You'll need to figure out what the curve would be, then program that in to a compute command. To calculate the curve equation accurately, you're going to need more points.

Or just put in one big massive array and do a lookup...
 
hi
in my case i can write a logic if my co-ordinates are only 2 using y=mx+c i.e
X Y
0 0
325 340

The output will be corresponding to the input of X,but i'm looking for some logic where i can insert the 3rd co-ordinate as well
 
No help from me

I have seen this done with scales. They call it a 3 point cal. I don't know how to do it but I would like to find out.
 
If it is linear between the 3 points (I.E. linear between 0,0 - 325,340 and linear between 325,340 - 360,360) or you aren't too concerned about accuracy, you can just check if the input is over 325. If is is NOT then use y = mx where m=(340/325). If it is greater then use y = ((x-325)*20)/35 + 340.

For increased accuracy (more of a curve) just use more points. Here is how it is done in C:

int i = 1;
float PVSpan, InputSpan;

// Readings is an array of known inputs
// Gallons is an array of known outputs
// Input is the actual input reading

while((Input > Readings) && (Readings != 0)) i ++;

if(Input == Readings)
return Gallons + Offset;

else
{
PVSpan = Gallons - Gallons[i-1];
InputSpan = Readings - Readings[i-1];
if(InputSpan > 0)
return MulDivF((Input - Readings[i-1]), PVSpan, InputSpan) + Gallons[i-1] + Offset;
else
return Gallons[i-1] + Offset;
}

Hopefully that helps. FYI, MulDiv(a, b, c) is (a*b)/c. MulDivF is the same but uses floating point math.

Regards,
Dan
 
You are going to need more points, but you can get the equation for any data set using Excel charts.

Enter your data in two columns, highlight them, and insert a chart. Use an X-Y type chart. After you have the chart showing in the spreadsheet click on the data and select "Add Trendline". Check the options for show equation on chart, and show R-squared value (this indicates how close your equation matches the data 1 = perfect). I usually use a polynomial, but you can pick whatever seems to best suit your data. Click OK and voila - your equation shows on the chart. For polynomial you can keep increasing the order until you get a good fit. I also format the numbers to get enough decimal places for accuracy.
 
Last edited:
After you have the polynomial don't use exponents when programming the polynomial. Expand out the polynomiall using the form

Ax3 + Bx2 + Cx + D = (Ax +B)x +C)x + D

Exponential operations take quite a bit longer to execute than successive multiplies.
 
Hey guys, I think you missed the point. I think I did at first

Scilab code

A=[1,0,0;1,325,325^2;1,360,360^2];
B=[0;340;360];
x=inv(A'*A)*A'*y

// Verify A*x=B
A*x


-->x
x =

- 9.719D-15 // close to 0
1.4747253
- 0.0013187

-->A*x
ans =

- 9.719D-15 // Close to 0
340.
360.

What I think hajdeen82 wants to do is generate the code so that given 3 points he can find the coefficients of an equation.

I would assume the equation would have the same form as what Alaric posted. So how does one calculate A B and C in ladder?
 
Alaric said:
Ax3 + Bx2 + Cx + D = (Ax +B)x +C)x + D

šŸ™ƒ
I see I messed up the the superscript codes in my previous equation. It should read this way:

Ax3 + Bx2 + Cx + D = (Ax +B)x +C)x + D



edit:
Here is a snip of code from a control logix add on instruction I wrote to linearize the input from an S type thermocouple transmitter. The transmitter does not do the linearizing. I use four different polynomials depending on the input value, in this case the 4-20mA input was previously scaled to the mV range of the TC.
Code:
[/size]
IF X < 1.874 Then 
Y := (((((((((((((((((2.797863 * X) - 23.41819) * X) + 82.30279) * X) - 159.0859) * X) + 188.8214) * X ) - 152.2486 ) * X) + 102.2374 ) * X) - 80.05041 ) * X) + 184.9495 ) * X);
ElsIf X < 10.4 Then 
	Y := (((((((((((((((((8.211273E-009 * X) - 1.44738E-007 ) * X) + 2.183475E-005) * X) - 0.001291638) * X) + 0.03187964) * X) - 0.4163258) * X) + 3.145946) * X) - 15.34713) * X) + 146.6299) * X) + 12.91507;
ElsIf X < 17.536 Then
	Y := (((((((((0.0002081619 * X) - 0.01441694) * X) + 0.4719687) * X) - 8.536869) * X) + 162.1573) * X) - 80.87801;
Else
Y := (((((((0.6247205 * X) - 42.65694) * X) + 1092.658) * X) - 12358.92) * X) + 53338.75; 
End_IF;
 
Last edited:
There are only three points ( knowns ) so the equation can have only three unknowns.

The equation I provided above will generate coefficients for 'over determined' systems. That is one where there are more points or knowns than coefficients or unknowns.

This still doesn't answer the OPs question about doing it in ladder.
 
Peter Nachtwey said:
What I think hajdeen82 wants to do is generate the code so that given 3 points he can find the coefficients of an equation.

The problem is that hajdeen82 hasn't piped back in here to let us know what he really wants/needs.

My thought was that it is a simple two step scaling.

Below a certain value, follow one slope and above it follow another. My German friends call this a Knee-curve.

It would be nice to know what the process and hardware involved is so a better answer can be given.
 

Similar Topics

I have a couple of 4-20 mA signals coming in and I need to scale them using ladder logic. One signal will be used to show wicket gate opening...
Replies
5
Views
6,894
I got my PanelView Plus 7 working with a Micrologix 1500. How would I connect my laptop to the PanelView to view the ladder logic while operating...
Replies
6
Views
77
Hello, I am trying to replicate a piece of logic on the PLC5 onto an SEL RTAC. I am using ladder on SEL and FBD. I am having issue on the ladder...
Replies
13
Views
221
Hello again..trying something on an existing poorly written program and just wanted to double check something system is an A-B MicroLogix 1200 In...
Replies
5
Views
169
Good morning fellow sea captains and wizards, I am being asked to do the above and obtain 4 values from each slave, I know about the MRX and MWX...
Replies
32
Views
781
Back
Top Bottom