# How to program a formula

3 replies to this topic

### #1 Kwagga

Kwagga

New Member

• Members
• 5 posts

Posted 08 July 2011 - 05:36 AM

Hi guys,

I'm building a little test unit that will interface with our refrigeration equipment and it will carry out certain tests.

I need to be able to program the following 2 formulas and simply display the answer on the LCD of the XD12.

The X value will actually be from a 0-10V input connected to a pressure transducer. The answer (Y-value) will be displayed.

Y=0.0000002X^3 - 0.000253X^2 + 0.167X - 44.46
The only X values that will go into this formula are between 29.5 and 492.5 as these I'll manipulate from the 0-10V input.

Y=0.0000042X^2 + 0.038X - 13.05
The only X values that will go into this formula are between 976.2 and 2766.6 as these will be manipulated values from the 0-10V input.

If it helps, these 2 formulas are close fit graphs to a pressure/temperature table for R404a refrigerant.

If it's impossible to program these formulas, how would I go about entering a pressure temperature chart from 7.6kPa to 2766.6kPA, and have the PLC read a corresponding temperature from the table, and be able to take a linear average for values between the table values.

### #2 Jesus Miranda

Jesus Miranda

Forum Savant

• Authorized Member
• 125 posts

Posted 14 July 2011 - 04:53 PM

Hello.

There is no way that you can load this formula into the Millenium 3.

The Millenium 3 doesn't have any floating point arithmetic. All the numbers processed by the controller are 16-bit integers. The value for these numbers can range between -32768 and 32767.

You can somehow manage values with a decimal point by using a Display block (e.g. 1205 displayed with 2 decimal places is shown on the screen as 12.05).

The only thing that you can do in this case is to use a lookup table (use block Y=F(x)).

Could you please clarify what do you mean by "be able to take a linear average for values between the table values".

What exactly do you want to do?

### #3 Kwagga

Kwagga

New Member

• Members
• 5 posts

Posted 06 October 2011 - 05:58 AM

I hope my attachment attached properly.

I actually got it right in my program.
M04 and M05 labelled LPPT and HPPT are the macros where I actually do this.

It takes a 0-10V input from a pressure transducer and converts is to an actual pressure reading in kPa.
Then I have 2 formulas like the one I presented that converts that pressure to a temperature for R404A refrigerant.
The formula presents the relationship between the 2.
So with pressure as my input to the macro, my output is temperaute according to formula.

### #4 Kwagga

Kwagga

New Member

• Members
• 5 posts

Posted 06 October 2011 - 06:12 AM

QUOTE(Jesus Miranda @ Jul 15 2011, 12:53 AM)
Could you please clarify what do you mean by "be able to take a linear average for values between the table values".

What I mean here was only applicable to a look-up table...

If I create a lookup table like the following...
Input 1 = Output 15
Input 5 = Output 75
Input 10 = Output 200

Looking at a table like that we can see that the relationship between the input growth and output growth is not linear.
So what happens if I Input 3? That's not a value in the table. So how is it's output calculated?
3 is pretty much halfway between 1 and 5. Will the output be a number halfway between 15 and 75?

#### 0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users