More tidbits. What does this do?

not that you would like to torture people... :)

don't have PLC at this moment so I wrote a small program
in TP to check it out. i's definitelly some sort of pattern
it looks like fractal (when put on graph, it looks like
some sort of koch's snowflake).

the even numbers return sequence like this:
1,2,1,4,1,2,1,8,1,2,1,4,1,2,1,16,
1,2,1,4,1,2,1,8,1,2,1,4,1,2,1,32,
1,2,1,4,1,2,1,8,1,2,1,4,1,2,1,16,
1,2,1,4,1,2,1,8,1,2,1,4,1,2,1,64,
1,2,1,4,1,2,1,8,1,2,1,4,1,2,1,16,
1,2,1,4,1,2,1,8,1,2,1,4,1,2,1,32,
1,2,1,4,1,2,1,8,1,2,1,4,1,2,1,16,
1,2,1,4,1,2,1,8,1,2,1,4,1,2,1,128,
1,2,1,4,1,2,1,8,1,2,1,4,1,2,1,16,
1,2,1,4,1,2,1,8,1,2,1,4,1,2,1,32,
1,2,1,4,1,2,1,8,1,2,1,4,1,2,1,16,
1,2,1,4,1,2,1,8,1,2,1,4,1,2,1,64,
1,2,1,4,1,2,1,8,1,2,1,4,1,2,1,16,
1,2,1,4,1,2,1,8,1,2,1,4,1,2,1,32,
1,2,1,4,1,2,1,8,1,2,1,4,1,2,1,16,
1,2,1,4,1,2,1,8,1,2,1,4,1,2,1,256,
1,2,1,4,1,2,1,8,1,2,1,4,1,2,1,16,
1,2,1,4,1,2,1,8,1,2,1,4,1,2,1,32,
....
 
Last edited:
Torture?

I don't think of learning something as being torture. It is more of a useful puzzle. I am shocked that no one has really figured out what the two instructions in my first post really do.

Think of this as a set of bits, not numbers. Display as bits. What does it do?

I actually use this technique in C more than in PLC programs. This can be handy when prioritizing things like writing messages to a display or using MSG blocks to communicate to a motion controller etc.

Code:
     while ( bits )
     {
        bit = bits & -bits;    // & is the 'and' operator
        bits = bits & ~bit;    // The ~ is a 'not' operator
        usefulfunction(bit);   // call function with bit
     }
 
The first non-0 bit!

I got it!

It returns the first non-0 bit in the sequence!

0000 0000 - 0101 1010 = 1110100110

1110100110 (&) 0101 1010 = 0000 0010

Hey, that IS a useful tidbit! I knew something like that existed someplace :) And as a prioritization routine, it's brilliant. I've spent waaaay too many hours figuring out how to prioritize messages and fault screens, and this makes me one happy camper! Thanks!

Also, Peter, thank you for motivating me to use figure out how to use the base function on my calculator

TM
 
Message Priority

The way we have it here is by writing the message number to an integer file given the alarm condition, and it is prioritized by overwriting the previous rung, so the lower the rung in the file the higher the priority. I would love to hear about other methods.....
 
You got it!

Code:
SUB 0 N7:0 N7:1
AND N7:0 N7:1 N7:1
XOR N7:0 N7:1 N7:0


The code above assumes N7:0 contains a set of bits represent things that must be prioritized. This code finds the least significant ( highest priority ) bit and copies it into N7:1 where it can be acted on. The XOR instruction removes the LSB from the set of priority bits. This will work with registers of any length and is fast and safe. However, it is not obvious as we can see. You need to document this trick if you use it because we can see the average technician will not understand just by looking at it.

Good going panic mode for having the curiosity and Tim for seeing the pattern.
 
Peter Nachtwey said:
Assume there is a set of 16 bits in N7:0. What is the result in N7:1

SUB 0 N7:0 N7:1
AND N7:0 N7:1 N7:1

Salvation! The years a colleague showed to this code to me. I can understand and know that it functions.
But not it totality, I do not get to repeat, that conflict binary taste.

Other verification new value, possible compare or XOR operation and
value > 0, enable code below

The code verification BIT
[LADDER}
Other code: k=constant V22=Variable verification

MOVE V1 02 => load D1=02
MOVE V10 128 => load D10=128
MUL V1 K2 V1 => Scans D1= 2,4,8,16,32... right to left
DIV V10 K2 V10 => Scans D10 =128,64,32,16... left to right

AND V1 V22 V33 => Get the BIT
ADD V33 K100 V33 => Add offset + BIT
JMP V33 => Subroutine ACK the BIT , or CALL
[/LADDER}
 

Similar Topics

I didn't want to hijack the thread so I started this one. It isn't strictly related to PLC but the techniques could be useful in PLCs too...
Replies
3
Views
5,994
How does one find the least significant bit WITHOUT: 1 checking for a bit being set in each bit position. 2 looping. 3 using lookup tables. 4...
Replies
19
Views
5,814
Hello, i need to use P_Intlk and feed the Status interlock OK bit to a P_DOut block. However, there's 17 interlocks for this output. How can I...
Replies
1
Views
109
Hi everyone, recently i worked with a cmore panel and have the question that how can clear alarm list whit remote form,right now only can with...
Replies
0
Views
111
Hello, friends, I am trying to upgrade a system that uses an Onrom incremental encoder (E6B2-CWZ6C) connected to a Danfoss VFD (FC360), but now...
Replies
4
Views
275
Back
Top Bottom