Real Power Algorithm using ladder on MicroLogix

davephilpot

Member
Join Date
Oct 2005
Location
Calgary, Alberta
Posts
6
Hi all, I have come into a problem. One of the products that we are using is the MicroLogix processor from Rockwell. We have a customer that now requires a Power Function, ie. x to the power of y, with real numbers for both x and y.

In the other processors, ie. controllogix, slc, there is an available compute function for this. In the MicroLogix, there is not and you have basic math functions only, +, -, *, /, Log and a few others.

Has anyone ever implemented something like this in Ladder using basic math only, or have any ideas how to go about it.

Any help would be appreciated.

Thanks.
 
You may have a real problem. The MicroLogix platform doesn't support the XPY (X to the Power of Y) function. If both X and X are changing variables you will probably have to upgrade to a SLC or RSLogix 5000 platform.

If only the X value changes and the function itself is well behaved you may be able to use Excel or another math program to develop a 2nd or third order polynomial that gives the desired result with four function math. Look at this thread:

http://www.plctalk.net/qanda/showthread.php?t=16474&page=2&pp=15&highlight=regression

Then you can calculate the result with four function math.
 
Another workaround may be to do the math in the HMI, if one exists. I've done this with PanelMates and Panelviews to get trig functions that are cumbersome or unavailable in a low end PLC.
 
What is the maximum exponent y? If it is known and small, a for-next loop will do the trick.

Which ML processor are you using? That will also dictate what solution can be recommended.
 
Does the ML1500 support indirect addressing? You could do an X p Y via indirect if you were in a pinch.
 
This is a program I banged out really quick that should work on an ML1200.

I haven't tested it.

It is suitable for only non-negative integer exponents.
 
Alaric said:
This is a program I banged out really quick that should work on an ML1200.

I haven't tested it.

It is suitable for only non-negative integer exponents.

So what do you do when Y is not a positive whole number? A true power function will support any number represented with a float data type. Example: 2.83^-1.75
 
Last edited:
jstolaruk said:
So what do you do when Y is not a positive whole number?

You create a more complex subroutine.

The sample was intended to show just one way the most common case might be handled.
 
Buy a better PLC!

For a single use I would have the customer buy a better PLC with a X^Y function. For my products I would use a library or write it myself.

jstolaruk said:
So what do you do when Y is not a positive whole number? A true power function will support any number represented with a float data type. Example: 2.83^-1.75

So, Alaric, what do you do?
DSPs and most micro controllers do not have a X^Y function. I know the TI DSP and PowerPC I used don't have a X^Y function so....
How do they do it? HOW DOES A CONTROL LOGIX DO IT?

A S7 would do well since this wouldn't be too hard to write in STL. I bet someone has done that already.
 
A ControlLogix has an x^y function and also supports the x**y notation in structured text. If I had to construct one from scratch I would do it in ST.

Now you've got me to thinking Peter (which is what I suspect was your intent all along 🍺 ) about how to implement a full fledged EXP instruction. I'll have to give it some thought and get back.

Naturally for negative integer exponents, X^Y where Y is negative you would calculate 1/(X^|Y|).

I'll have to give it some thought on how to do rational exponents.


edit:
OK, I checked and the ML supports the SQR (square root) instruction.
So I should be able to use the rule where
X^Y * X^Z = X^(Y+Z) for calculating rational exponents.

So 3^2.5 becomes 3^2 * 3^0.5 with the fractional part being calculated using the square root function. Manipulating the fractional part of the exponent can get really hairy in ladder, which is the only language the ML supports. Hopefully the original poster doesn't need rational exponents. If he does, it may be worth it to upgrade to a compact-logix.
 
Last edited:
First, I would want to know why a X^Y function is required.
If so what is the accuracy required?
Are the exponents only integers?

Negative exponents are easy. First do the calculations as if the exponent is positive and then dived the result into 1.

Breaking down the exponent into integer and fractional calculations is probably a good idea. Raising X to an integer number is easy. The fractional part will always result in a number less than X and therefore should be too big.
 
If only the ML had an LN function...

Well, why not give it one?

Obviously only a very sad person with way too much time on their hands would want to do this, so here goes.

Years ago, I was on the mailing list for the Hewlett Packard Journal, and they published the algorithms used in the HP35 calculators. The attached program calculates ln(x) using a rough interpretation of the HP35 algorithm. The constants in the program are the ones used by HP, which are chosen for quick operation with a BCD processor, so no doubt a better set could be found. I have tested the program on a 5/02 processor, so I would guess it would run on an ML1000 OK. The input number N7:0 and result N7:1 are scaled by 10000, and the program works for values of x between 0.1 and 0.9999 (i.e. 1000 and 9999 in N7 registers). If you need a value of x outside this, use a stored value of ln(10) and scale your number by a factor of ten accordingly. Start the calculation by toggling B3:0/0 on.

Don't use this for anything serious. The algorithm is not checked for singularities or monotonicity. I had one of the early HP35's when they first came out, and it did actually have a singularity in the ln() function. I forget which way round it was, but if you put in 2, and 'round tripped' the ln and exp function, you got back 2.02. Any other number worked fine.

Yeh I know the program's got no comments and stuff, but it's Friday, so now I'm going to the pub
 

Similar Topics

Hi, how do I convert 2x Integer registers to a Real? The two integers are from Modbus registers that contain a floating point value, I need to...
Replies
2
Views
98
I am working on a project using a NB screen and NX1P2 PLC. I am having a really hard time getting a real number to properly translate through to...
Replies
3
Views
121
I am trying to copy an array of real numbers into a UDT with a real data type element. I have attached a snip below showing my COP instruction...
Replies
4
Views
203
Hi Iam using monitouch hmi(V9 soft) with omron plc cj2m (CX programmer). In this I want to read a data from hmi to plc. The data was like...
Replies
0
Views
94
Hi all. Me again still learning Rockwell. So I'll be polling an INT data array from a Modbus SE power meter with a L82 (with a Modbus ProSoft in...
Replies
56
Views
1,382
Back
Top Bottom