Find exponential value in micrologix

BachPhi

Member
Join Date
Dec 2007
Location
Los Alamos
Posts
640
Given y = 2^x . Find x when y is known. IF x is not a whole number, reject it ( move -1 to result).

1. Given CPT, XPY, LOG available

2. Can you do it with less? like XPY or LOG is not avail. ML1000 do not have these instructions

I currently have a long routine to do it, but I would love to see other solutions. TIA.
 
Last edited:
Well, we know the formula is gonna be X = (log y/log 2). Log 2 we can do ourselves and change to 0.301029996. Now, the only times this is going to be a whole number, are multiplications of 8. 8, 16, 32, 64, 128, 256, etc. Try it. Map out the formula in Excel and look. 8, 16, 64, 128, 256, etc. It makes sense - your denominator is only going to evenly divide a numerator that is a multiple of 8 since 8 is the first time it divides evenly. Is a modulo function available? You could just divide your Y by 8 and see if the remainder is 0.

Edit: Just realized it goes by 8^1, 8^2, 8^3 etc and not multiples of 8. That changes things a bit. You could test if you continue to divide by 8 that it eventually reaches 1.

Edit 2: Jesus, why cant I math today? it's 8*2, 8*2*2, 8*2*2*2 etc so in reality, you'd have to divide by 2 until it reached 8, and make 8 itself an exception.

There's probably a trick with binary you could use that I haven't thought of, since that's how binary math works past the 3rd bit in the word. You could check above the 3rd LSB to see if only 1 bit is set as mentioned below me
 
Last edited:
I tried it by setting a single bit using indirect but the ML1000 doesn't support indirect. Too bad.

It works fine in a ML1100 for integers and long.

Edit - never mind - misread the OP question
 
Last edited:
ML1000 only supports integer - so y = 0 to 32767 (positive range)

If y is positive then ...

In 15 rungs examine the bits of y starting from the lowest. In each rung, if bit is set then increment a 'count' and set an 'index' value starting at 0 for the first rung, increasing by 1 in each rung.

After this ...

If the 'count' is greater than 1 then invalid (x is non integer) - set result to -1.

If 'count' is 1 then x = index.

If the 'count' is zero then Y was zero.

This is just an expansion of Peter's note.

You could also just use 15 rungs each comparing y to the result of 2^x where x is an integer (0 - 14)
 
Last edited:
For a limited range of values, you could use the floating point representation bits of the exponent (8 bits) to get the log2 of your value.

load floating point value
shift left 1
shift right 24
subtract 127
get the log2 as integer value
 
Mov -1 x
equ y 1 mov 1 x
equ y 2 mov 2 x
equ y 4 mov 3 x
equ y 8 mov 4 x
equ y 16 mov 5 x
equ y 32 mov 6 x
equ y 64 mov 7 x
equ y 128 mov 8 x
equ y 256 mov 9 x
equ y 512 mov 10 x
equ y 1024 mov 11 x
equ y 2048 mov 12 x
equ y 4096 mov 13 x
equ y 8192 mov 14 x
equ y 16384 mov 15 x
 
@proof: I like your brute force approach, but what if y = 3, 12, 15, etc...? Actually x = 0 when y =1, x = 1 when y = 2, x =3 when y =8
 
Last edited:

Similar Topics

Hi , Where i can find Mitsubishi PLC Card end of line & replacement model details. i am looking for Q02CPU replacement model. Please advice. thanks
Replies
2
Views
126
I have tested every screen and no single screen individually has this fault pop up, but when I compile and send to the PanelView it comes up. If I...
Replies
4
Views
177
Hi, One of my customers has an old fabric tensile testing machine. The IC # AD7501KN of its controller has malfunctioned. This IC is related to...
Replies
1
Views
81
Hello everyone, I am a student and would like to take the next step and learn FactoryTalk (Batch preferably) and how to create HMIs etc. Would...
Replies
4
Views
494
Hi, Have a look at this picture... How can I find out the memory address of this tag? It was created by adding it to DB "Data_block_1", but I...
Replies
6
Views
1,064
Back
Top Bottom