Exponential calculations on MicroLogix 1200

D

Thread Starter

Daryl K

I'm doing a low-budget upgrade of a high-power, vacuum furnace. The project is pretty straightforward and simple, and as a result I specified a MicroLogix 1200 processor, which is plenty for the control needed (or so I thought).

After the project began, the need for a high vacuum gauge became critical. If you've ever worked with high-vac gauges (i.e. < 10^5 Torr) most feedback on a volts-per-decade scale. Meaning, to properly scale the value in the PLC the formula is 10^(volts-10). Bingo, the MicroLogix family does not have the XPY function.

The only solution I could come up with was converting by log, which necessitated a lookup table (since there is no LOG instruction either), but generating the lookup to three decimal places creates 1,000 entries, and exceeds user data table memory size.

Has anyone encountered a similar problem with "simulating" an X^Y instruction and found a more creative way to solve the problem using only basic math (ADD, SUB, MUL, DIV)? Beyond this, two PID loops and a menu-entry system are all I need, so it seems a waste to move to a higher-power (and more expensive) PLC just because of the lack of a single complex math instruction.

Many thanks in advance for any info.
 
C
I turned to my trusty text books and refound the series expansions for exponentials. Would this work?

a^x = 1 + x*LNa + ((x*LNa)^2)/2! + ((x*LNa)^3)/3! + ...

where "LN" is LOGe or natural log and "a" in your case is 10 so LNa will be 2.302585. Of course, something like (x*LNa)^3 would have to be implemented as (x*LNa)*(x*LNa)*(x*LNa) or x*x*x*12.208072. It won't be pretty without a compute block, but still doable in ladder.

Good Luck,

Chip
 
T

Thomas Hergenhahn

<clip>
> After the project began, the need for a high vacuum gauge became critical. If you've ever worked with high-vac gauges (i.e. < 10^5 Torr) most feedback on a volts-per-decade scale. Meaning, to properly scale the value in the PLC the formula is 10^(volts-10). Bingo, the MicroLogix family does not have the XPY function.
>
> The only solution I could come up with was
>converting by log, which necessitated a lookup
>table (since there is no LOG instruction
>either), but generating the lookup to three
>decimal places creates 1,000 entries, and
>exceeds user data table memory size. <

You could use less entries and interpolate between entries. Use log base 2 instead of base ten. You can than shift your values until they fit into range 1 to 2 and just add or subtract number of shifts from the found log value.

> Has anyone encountered a similar problem with >"simulating" an X^Y instruction and found a
>more creative way to solve the problem using
>only basic math (ADD, SUB, MUL, DIV)? <

You can calculate e to the power of x using the taylor sequence:
x +1/2x^2 +1/3x^3+ 1/4 x^4... (or so).

To make this calculation easy, find out how much accuracy you need. Then, if you e.g. need up to 1/10 x^10, calculate in revers order:

(((1/10*x +1/9)*x)+1/8)*x)....

You can further prestore the n/x factors.
 
At the risk of sounding obtuse why not set up a subroutine and pass it the values you want including the power. Then use a MUL instruction inside the subroutine and jump to the top of the routine based on the power (-1). If the power is an INT then it's really easy. Call the routine periodically to cut down scan time.

Your routine would look something like this:

Exp and Mantissa are pre-loaded before calling the subroutine.
-------------------
MyExp = 1
Result = 1

Label_1:
if Exp < = then Result = -1 Return (Error)

if Exp = 0 Then
Result = 1
Return
End If


Result = Result * Mantissa

MyExp = MyExp + 1
If MyExp <= Exp then Goto Label_1
-------------------
Hope this helps,

Good Luck,

(8{)} :) .)

[email protected]
 
Responding to Daryl K's original query... here is a reiteration program using only te aritmetic functions.

A^x = e^(xlna) = e^B. Letting B = xlnA, a constant, then,

e^B = [1+ sum (n = 1 to n) B^n / n! ]

But a simpler series to implement is,

e^B = [ 1 + sum (n = 1 to n ) B^n / C(n) ]

where C(n) = n(n-1)! But, C(n) = n times preceding or, C(n-1) term, thereby eliminating the factorial calculation.

Regards,
Phil Corso, PE {Boca Raton, FL, USA}
[[email protected]] ([email protected])
 
D

Daryl Krzewinski

I am WAY overdue responding (due to being buried alive in projects), and don't know if anybody will even see this so much later, but I just wanted to thank all who responded.

After some experimentation I found that the Taylor Series expansion worked best. Since I am so short of memory in the MicroLogix, it's small size was also attractive.

The pseudo code equivalent of the final sequence looks like this:

a. Do
b. n = n + 1
c. x_power = x_power * x
d. coeff = coeff * ln10 / n
e. result = result + coeff * x_power
f. Loop until n equals desired Taylor degree

Since the 1200 does not support the ln instruction either, I created a floating point lookup table and manually entered the 10 calculated values of ln10 (1 to 1e-09) I would need.

After developing the algorithm and doing some tests, I found that the optimal number of passes through the loop was about 10, where accuracy was within 0.0001%. The rate of return fell off sharply after more than 10 passes, with accuracy improving at an almost immeasurable percentage. Below 8 passes accuracy dropped off above 1%, which was not acceptable for my application (your mileage may vary).

Sorry for the long response, and I hope somebody that can use and gain from this data finds this.

Thanks!

Daryl
 
Top