RSLogix Log2 Alternative

kekrahulik

Member
Join Date
Apr 2009
Location
Lancaster,pa
Posts
397
I’m locked in a hotel room trying to do a month’s worth of programming in a few days (called in as the last minute janitor for a mess) and I need a little time saving help with RSLogix5000 programming.
I have programmed each bit of a DINT to represent a state (DINT.0 = State 0, DINT.1 = State 1). One and only one bit is ever true at a time, so the DINT value can only be 1, 2, 4, 8, 16, 32, 64....
I would like to quickly determine the bit position within the DINT and store it as an integer. Ie if the DINT = 32, my integer result would be 5.
A quick way would be to take the Base2 Log of the DINT, but I only see Base10 Log in RSLogix5000. It seems that I should be able to use an FBC to do this, but I need to break the DINT bits out to an array first.
Any ***y solutions out there?
 
The fast way to program it: DintTag = LN(StateTag)/0.6931472


However log functions are CPU intensive. What you want it the SLC 500 equivalent of the DCD instruction. Check Rockwell's website for a downloadable AOI.
 
Or a FOR NEXT loop or a recursive (GASP - gotta watch that stack) SUB (Shift right and count until the value is 0).

Good Luck,

(8{)} :) .)
(Yosi)
 
I like the AOI approach. I don't mind writing the code - just hate to have something that ugly.

Another one of those simple answers that I should have come up with myself - love this forum.

Thanks!
 
In case anyone was wondering how DintTag = LN(StateTag)/0.6931472 was derived:

To find log base 2 of X you use LN(X)/LN(2)

X is variable but LN(2) is a constant equal to .6931472. The floating point computation will be very very close to a whole integer so type casting the answer to a DINT completes the conversion.
 
performance

I know it's an old thread, but I found it useful.
I tested both "brute force" and Log2 methods. Brute force works two times faster.
 

Similar Topics

Hi Everyone, I am not proficient in RSLogix 500 so I have a question regarding the evaluation of N7:0 data as an input. So as I understand in...
Replies
1
Views
81
Hi folks, in the alarm manager of Rslogix 5000, the tag-based alarm has been created. But when I tried to change the condition, it was found the...
Replies
2
Views
151
I have a little bit of experience with Allen-Bradley. I have a Micrologix 1500 (RSLogix 500) and a PanelView Plus 7 (FactoryTalk View Studio ME)...
Replies
3
Views
161
I am completely stuck on building a ladder program that requires a start button to be pressed 3 times to turn on motor 1. Then motor 2 starts...
Replies
20
Views
572
Back
Top Bottom