Find most significant bit.

Ron's point, which he stated, was explicitly to have another priority i.e. above using a "better" algorithm.
I would rather use Ron's method than the log method. Log functions are very compute intensive especially of the PLC doesn't have floating point processor. Using two log functions is a crime. There are faster methods than Ron's method.
 
I maybe be missing something, but wouldn't a Seq INT and a multistate indicator (assuming FT) be easier and the maintenance guys don't even have to get the laptop out.
 
As some others already mentioned, use an INT for the states.

Never run a Sequence as fixed values,
'Step1'
'Step2'
'Step3'

Make open step so your sequence starts at for example:
Step10
Step20
Step30
 
I don't care what the lesser bits are doing they have to be made for the most significant to make.

Are ALL the lesser bits always on? That is, is your sequence value always 1,3,7,15,31....

If so, then adding 1 makes it 2,4,8,16,32.... A single bit is set that is the 2^step number not met.

While doing the Log(x)/Log(2) trick will work, a more "efficient" method would be to use the following code (all tags are DInts. StepBitwise is your bit-set sequence word):

CLR StepNo.
ADD (StepBitwise, 1, StepBit_SingleBit)
AND (Step_SingleBit , #32:aaaa_aaaa , Temp) NEQ ( Temp, 0) ADD (StepNo, 1, StepNo);
AND (Step_SingleBit , #32:cccc_cccc , Temp) NEQ ( Temp, 0) ADD (StepNo, 2, StepNo);
AND (Step_SingleBit , #32:0f0f_0f0f , Temp) NEQ ( Temp, 0) ADD (StepNo, 4, StepNo);
AND (Step_SingleBit , #32:ff00_ff00 , Temp) NEQ ( Temp, 0) ADD (StepNo, 8, StepNo);
AND (Step_SingleBit , #32:ffff_0000 , Temp) NEQ ( Temp, 0) ADD (StepNo, 16, StepNo);

At this point, StepNo contains the value ( 1 , 2, 3, 4, 5 ...) of the step that is waiting for its bit to be set. To get the number of the step that is complete, subtract 1.

Keep in mind that this technique only works if StepBit_SingleBit has one and only one bit set. Your description of how you code your sequencer makes that likely, but if process changes have caused you to skip, say, step 3, and thus the 3 bit is never set, this will not work.

I agree that Ron's method is probably better, more bullet proof. But this code should make Peter at least a smidge happier. Some of us don't forget his tips and twiddles.
 
Last edited:
Binary search, this should be among the fastest, assuming bit tests are cheap. Six rungs and fifteen instructions: one MOV; one XIC; four OTEs; four OTUs.


I don't know why the [MOV 0 N7:1] is necessary; Rungs 0001-0005 should assign 0 or 1 to all five relevant bits (N7:1/0 through N7:1/4).


xxx.png
 
UGH !! Sequencers using bit logic ! Nooooooooo !!

Lose power, lose bits ! Noooooooo !!

One rule I have, if the processor restarts for any reason, nothing is lost. Of course we can detect a re-start, and deal with it accordingly, but we must NEVER forget where we left ofF !!
 
There are other more elegant ways, but if the goal is to give a KISS to Bubba, even the longest armed knuckle dragger should be able to understand Rons' method.

Bubba.
+1

This is the only way I would do it, I often "gear" 3 or more step_Sequence together, so step_1 needs to be at a specific step before step_2 can get from from step 4 to 5 and ...........

To keep me on top of things I have a bit for each step in each sequence, telling me where i am at.

Step_Setup.png
 
+1

This is the only way I would do it, I often "gear" 3 or more step_Sequence together, so step_1 needs to be at a specific step before step_2 can get from from step 4 to 5 and ...........

To keep me on top of things I have a bit for each step in each sequence, telling me where i am at.

Liked the indicator bit 🍻
 
Brute Force ST - Throw this in an AOI

Location:=0;

for Index:=31 to 0 by -1 do;
if DINT_to_Search.[Index] then
Location:=Index;
exit;
end_if;
end_for;

All looks good until the realisation that a DINT has only 31 data bits, numbered 0 to 30. Bit 31 is the SIGN bit of a DINT data-type.

So it makes a big difference depending on how the 32-bit memory space is used. Is it a DINT data-type, or is it just a collection of 32 bits parcelled up in a "structured" DINT where not all bits have an actual numerical value....

Goalposts have to be planted firmly in the ground from the outset, and documented !
 

Similar Topics

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
69
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
62
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
455
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
899
I've got TIA portal v18, KTP1200 HMI. I want to add a slider bar (if that's the correct name for it) to an HMI screen. Baslcally, like a...
Replies
8
Views
981
Back
Top Bottom