Reverse Decode - is there a better way to do this.

TConnolly

Lifetime Supporting Member
Join Date
Apr 2005
Location
Salt Lake City
Posts
6,152
I have a DINT tag named ToolSelect (ControlLogix) in which only one bit will ever be set at a time. Each bit corresponds to a location in a tool holder. The set bit is the tool that is currently selected.

To determine the number of the bit which is set (for display on HMI as the tool number) I am using the following equation.

ToolNumber = LN(ToolSelect)/LN(2)

or

CPT ToolNumber LN(ToolSelect)/.69314718

Quick and simple. It also flies right over the head of Bubba on the maintenance staff.

I've tried to come up with an easier to understand method that can be programmed in one or two rungs.

I know I could do a repetitive divide by 2 and count the number of iterations, but Bubba doesn't get loops either.

Short of just commenting the rung and telling Bubba that is just how it is, does anyone have any ideas.
 
I'd stick with what you have. Just comment the snot out of it. In the greater scheme of things this will always work assuming only one bit is set. As long as you comment what it is and why its there no one will get too worked up about it.

Keith
 
Well..... I'd comment it, and hope that Bubba will just accept that it works...

Or, you can try using the FBC (File Bit Comparison) instruction.. that might work.
 
XPY works building a DCD equivalant. Log and LN are the inverse functions of XPY. How do you use it for creating an ENC equivalent?
 
The FBC instruction would do it. I seriously thought about using it when I originally worte the routine. I didnt use it because of the extra tags it would require. I think FBC would confuse Bubba even more - the set up of the instruction is more complex. At least with the log computation I can show Bubba it works on a calculator.
 
I am not familiar with ControlLogix but I am presuming a DINT is a double integer. Why can't you declare an array or structure of bits for your tool holder and then refer to the bits as required in the program ? DINT variables should be used to store DINTs.
 
Aaahh, strongly datatyped Mr Goldsworthy!
I agree, but I'm now waiting to hear all the reasons why Alaric shouldn't do it this way.

Ken
 
The tool position is modified by a mathematical operation. A simple math operation also returns a number for the position. Its easier to do math on DINTs than BOOL arrays.

The program is object oriented. Thus the tool holder/changer is a single object tag defined by a UDT containing all information pertintent to the control of it. Becuase its a UDT a BOOL array vs DINT does not affect memory size.

Addressing single bits in a DINT is the same as addressing bits in a bool array and creates no difficulty.
DINTTAG.1
BOOLARRAY.1
 

Similar Topics

Hi all, I'm having trouble solving a problem I've been working on for several months, and thought you might like a stab at it. The machine runs...
Replies
22
Views
946
I have a SX2 plc and i'm getting 0-10v analog signal,but i need 10bar analog output in 0v can someone explain how its done
Replies
2
Views
543
I'm trying to add on to a safety circuit and trying to make sure this is fail-safe. My safety scanner needs some muting when things aren't running...
Replies
8
Views
819
Hi, I have issue with acs800 starting the motor in reverse for like 5-6 seconds with a max speed of around -220 rpm before it goes to the...
Replies
10
Views
2,000
I am looking at a 1305 drive connected to a PLC5 via RIO. The drive is working and I was able to get a functional HIM working on the drive as...
Replies
3
Views
1,849
Back
Top Bottom