RSLogix 500 Program Problem

Archie

Member
Join Date
May 2002
Location
Orangeburg, SC
Posts
1,944
I was working on a message rotator in a SLC 5/04 when I came into a problem that seemed like it would be very easy, but turned out to be quite tricky in ladder.

I have a word (B3:0) that will have a single bit active and I need to find which corresponding bit number is active and store it in N7:0. For example

If B3:0 = 0000000000000001 , then N7:0 should be 0
If B3:0 = 0000000000000010 , then N7:0 should be 1
If B3:0 = 1000000000000000 , then N7:0 should be 15

A simple LOG base 2 would solve it easily, but I could only find a LN and LOG base 10 in the instruction set. I am thinking there is a very simple solution that evades me.




...... OK, just as I finished typing this I came up with the answer, but I would still be interested in seeing how others solve it.
 
Last edited:
Archie said:
...... OK, just as I finished typing this I came up with the answer, but I would still be interested in seeing how others solve it.

Share Archie...

The only way I am coming up with is stupid... and long, if B3:0 = X then MOV to N7, that would work but its way to long...

I have tried a double divide but could not get that to work then I tried bit wise but also no luck

but I have not given up...

Tim, I have never used the FBC in Logix so I will have to give that a try, but it does not look easy to set up...when I have a little more time (busy taken screen shots :D )
 
My first couple tries were long, complicated and even faulted the processor with math errors. I had to think way back to advanced math and logarithms. There is a reason the LOG instruction only gives you base 10. Base 10 Log can be used to derive any other bases.

Here is the basic equation:

2^x=value of word

Let's say bit 3 is set giving us a value of 8.

2^x=8

A base 2 log of the value 8=3 (the bit number that was set)

Using base 10 log you can get a base 2 with this equation:

Log(Word Value)/Log(2)

So back to our word value of 8

Log(8)/Log(2)=3

Enough theory, here is the simple answer:

CPT, LOG(B3:0)|Log(2)
Store the result in N7:0

So it is solved with one Compute instruction.
 
Archie said:
Enough theory, here is the simple answer:

CPT, LOG(B3:0)|Log(2)
Store the result in N7:0

So it is solved with one Compute instruction.

Oooh. Dude, that just might be more efficient than the FBC. I wonder how the execution times comapre?
 
geniusintraining said:
Tim, I have never used the FBC in Logix so I will have to give that a try, but it does not look easy to set up...when I have a little more time (busy taken screen shots :D )
It doesn't look easy !?! I can setup the FBC much quicker than you can take a few screen shots(y)
 
what is wrong with you guys? Can't you use the search function?

Archie said:
I was working on a message rotator in a SLC 5/04 when I came into a problem that seemed like it would be very easy, but turned out to be quite tricky in ladder.

I have a word (B3:0) that will have a single bit active and I need to find which corresponding bit number is active and store it in N7:0. For example

If B3:0 = 0000000000000001 , then N7:0 should be 0
If B3:0 = 0000000000000010 , then N7:0 should be 1
If B3:0 = 1000000000000000 , then N7:0 should be 15
Tricky my a$$. What is wrong with 16 rungs?
XIC B3:0/0 MOV 0 N7:0
XIC B3:0/1 MOV 1 N7:0
XIC B3:0/2 MOV 2 N7:0
ETC
Bubba can understand this and it will be faster than all the floating point multiplies and divides it takes to execute a log function.

A simple LOG base 2 would solve it easily, but I could only find a LN and LOG base 10 in the instruction set. I am thinking there is a very simple solution that evades me.
It should have evaded a little harder. Archie, OkiePC and Bernie, go to the corner and study how a log function is computed. A report is due on Monday.

TW, is right FBC instruction is the way to go if bubba can handle it.

This has been discussed before many times.
http://www.plctalk.net/qanda/showthread.php?t=20432&highlight=FBC
LD AR2 recently had a thread on the same topic for S7s.

There is also a thread where Alaric came up with the same solution as Archie over 2 years ago.
http://www.plctalk.net/qanda/showthread.php?t=20381&highlight=FBC
 
Peter Nachtwey said:
Tricky my a$$. What is wrong with 16 rungs?
XIC B3:0/0 MOV 0 N7:0
XIC B3:0/1 MOV 1 N7:0
XIC B3:0/2 MOV 2 N7:0
ETC
Bubba can understand this and it will be faster than all the floating point multiplies and divides it takes to execute a log function.
Read below...

GiT said:
The only way I am coming up with is stupid... and long, if B3:0 = X then MOV to N7, that would work but its way to long...


Peter Nachtwey said:
TW, is right FBC instruction is the way to go if bubba can handle it.
Bubba's reading up on it :)


------------------------------------

Tim, I will send you the screen shots of the ifix progam on Tuesday
 
Peter Nachtwey said:
... Archie, OkiePC and Bernie, go to the corner and study how a log function is computed. A report is due on Monday.

LOL

Peter Nachtwey said:
TW, is right FBC instruction is the way to go if bubba can handle it.

Platform dependable solution, easy for Opie or Bubba to figure out from RSLogix help. Won't work in AD for example but...

Peter Nachtwey said:
There is also a thread where Alaric came up with the same solution as Archie over 2 years ago.
http://www.plctalk.net/qanda/showthread.php?t=20381&highlight=FBC

The floating divide then integer conversion may be a more portable solution worth a good fresh debate. Archie explained how he arrived at the same function that Alaric used.

And I gave up calculating A/B execution times back in the 5/40 days...Bernie or one of the other guys may still have the resources...
 
Peter Nachtwey said:
Tricky my a$$. What is wrong with 16 rungs?
XIC B3:0/0 MOV 0 N7:0
XIC B3:0/1 MOV 1 N7:0
XIC B3:0/2 MOV 2 N7:0
ETC
Bubba can understand this and it will be faster than all the floating point multiplies and divides it takes to execute a log function.
I'm kind of torn as to whether Bubba would understand 16 rungs or 1 rung with a good comment..... "Find which bit number in B3:0 is true"

Peter Nachtwey said:
There is also a thread where Alaric came up with the same solution as Archie over 2 years ago.
http://www.plctalk.net/qanda/showthread.php?t=20381&highlight=FBC
That would have been the thread I would have liked to have found earlier, but just couldn't get the search terms right.
 
Archie said:
That would have been the thread I would have liked to have found earlier, but just couldn't get the search terms right.
You can see above that I just used FBC.

Platform dependable solution, easy for Opie or Bubba to figure out from RSLogix help. Won't work in AD for example but...
You didn't read my thread about what to do if a FBC instruction isn't available did you? If you look at the date I wrote that reply after waiting two days for someone to find the right solution. Even when I gave a big hint.
 

Similar Topics

Hi I have a machine which has recipes in the plc ,using indirect addressing, we have a screen where we enter the recipes and then save the recipe...
Replies
23
Views
4,128
Hi guys I have a machine that works fine, but today we had an issue where the operator speeds the line up to 20cpm the feeder but didnt adjust...
Replies
11
Views
3,153
Is there a way to do a mass copy of comments and tag names from one program to another? They are 100% identical, one goes online (uploaded from...
Replies
1
Views
3,129
I was trying to modify a program online the other day using RSLogix 500 . The PLC is a SLC5/05. I was online with the PLC, and could change...
Replies
2
Views
5,474
I had an idea to improve some of my standard programs, and make them easier to modify/expand in the future. Is there a way to address the current...
Replies
9
Views
3,665
Back
Top Bottom