Advance Logic comparaison / Multiple Bit Scan Check

mitureg

Member
Join Date
May 2013
Location
Canada
Posts
199
Hi everyone, I hope you are well.

This is for a fire alarm HMI. The client wants a popup that traces a single fire detection device in a SINGLE ZONE on a map, or a ZONE SELECTION PAGE if there is multiple active device in one or multiple zone. I have this logic problem where I want to trigger a choice of 2 HMI pages depending on input conditions (single or multiple fire alarm).

We have 60 fire detection device covering 36 different zones.


-Page 1: IF the number of memory bits %M, for example between %M100 and %M200 returning a "1" is more than 1 (aka.: several bits AT THE SAME TIME)

-Page 2: if the number of memory bits %M, between %M100 and %M200 is EQUAL to 1.


Much appreciated,
Alex
 
Well, without knowing what your instruction set has to offer, you could do something like this:
Here, X is an integer containing all the bits you wish to examine...
(for some reason, the editor won't show indents below...)


TestThis = X
If (X > 0) Then
While (TestThis) And (Nbits < 2)
Nbits = Nbits + 1
TestThis = TestThis And (TestThis - 1)
EndWhile
If (Nbits > 1) Then
Page 1
Else
Page 2
End If
EndIf


or more succinctly,

Nbits = 0
TestThis = X
If (X > 0) Then
TestThis = TestThis And (TestThis - 1)
If (TestThis > 0) Then
Page 1
Else
Page 2
End If
EndIf

Based on (http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogObvious
 
Last edited:
(for some reason, the editor won't show indents below...)
The site editor automatically removes leading spaces, unless you "Go Advanced" and use the "Ladder" tags (which preserves your text exactly as entered).
 
Thank you for your answers. So using Nbits or registers would be the solution. Anybody familiar with these functions in TwidoSuite from Sneider?

Regards.
Alex
 
Have you got anything on this one Lancie?
There have been many discussions of ways to count bits, such as using "bit hack" methods, or just settting up a loop that loops for the number of bits, and counts each time it finds a "1" or ON bit. See the old threads listed below. Unfortunately, none are written for a Schneider Twido, but you should be able to adopt one of the methods. I know you can use labels in TwidoSuite, and then use jumps to loop back 100 times to that label until all bits in your range %M100 to %M200 have been examined and the 1's counted.

http://www.plctalk.net/qanda/showthread.php?t=77291&highlight=count+bits

http://www.plctalk.net/qanda/showthread.php?t=80010&highlight=count+bits

http://www.plctalk.net/qanda/showthread.php?t=82375&highlight=count+bits

http://www.plctalk.net/qanda/showthread.php?t=35894
 
Last edited:
Hi Lancie, thank you for the multiple references to other posts. I see there is many solution to this problem.

The easiest solution to design and implement I think would be to use a counter that counts the number of bits in an ARRAY, then I would have comparative input conditions on 2 other rungs (if value = 1; flag page 1, if value = or > 2; flag page 2).

In TwidoSuite, from the documentation, I see that %C1.V correspond to the value of the counter 1.

My idea was to increment "1" to the current counter value whenever the condition is reached on any of the 60 fire alarm device that I want to scan for bite=1.

The value %C1.V is suppose to be read/write, however I do not find any way to have it work with incrementation e.g.: %C1.V := C1.V+1.

Would you have any ideas Lancie?
I've been working on this thing all day and still nothing comes out. This would be so easy with a BITSUM function like they use in Siemens systems or an ADD or MOV function block using an INDEX in Logix.

Much appreciated,
Alex

CaptureTwidoCounter.jpg
 
The value %C1.V is suppose to be read/write, however I do not find any way to have it work with incrementation e.g.: %C1.V := C1.V+1.
No, a Counter Value in the Twido cannot be written to by the program (only by the Counter function itself). If you want to use a counter, you will have to trigger it in the normal way to make it count.

But you do not really need a counter, simply an ADD instruction that adds 1 to a memory word (such as %MW1 or similar). Then you must figure out a way to loop through the add instruction for 100 times, each time increasing the bit number by 1 (using indexed addressing). The problem is tht I have found no way to use indexed addressing on bits in TwidoSuite. It does allow indexed addressing for words, but not bits. Maybe it is possible to move your 100 bits (%M100 to %M200) to word addresses using Bit Strings, then count the 1 bits in each of these new words. Right now I don't see a good way to step through the 100 bits in order to count them (other than writing 100 rungs, each for one of your 100 bits to be counted).

There is one way to do it (without indexed addressing) using a bit-shift register. FIrst COPY the 100 bits to a temporary location, then shift these 100 bits through a bit-shift register, one bit every 0.01 seconds, each time looking at the shift-register Destination value and if = 1, ADD 1 to %MW1. At the end, %MW1 will contain the number of bits in the range that are 1. Then you can use that information to determine which Page to go to.
 
Last edited:
Would you have any ideas Lancie?
Here is a method (but the details may be wrong) using 7 cascaded bit-shift registers. (They each only shift 16 bits, and you have 100 bits to examine, so it requires 6 x 16 = 96, + 4 bits from the 7th SBR instruction). I tried to move %M100 to %M200 to SBR0:15 to SBR6:4, but I am not sure if I have the syntax correct (see the last Rung 17). Maybe this will give you a starting point anyway.
 
Last edited:
Now I realize that the 7 cascaded shift registers must be in reverse order from 6 to 0, because first we move the last bit out of SBR6 and count it, then do the bit-shift, leaving SBR6.0 empty (to be filled with SBR5.15). Here is that change.
 
Last edited:
Thank you for the research in TwidoSuite Lancie. I gave a measure of 100 device %m100 to %m200 to be succinct in my initial post explanation like I usually do.

It's rather 60 devices and the memory bits are distributed in 2 adjacent series with a gap in between: %m131 to %m179 and another short series around %m200. I do not have the program with me right now, it is now the weekend and my laptop is at my workplace. I now realise I should have brought it. That's what I'll do next weekend.

Thank you for the SBR idea. This is a very elaborate idea, I can't believe there's isn't any simpler logic to achieve what I want. Too bad the Index Addressing function is not available for memory bits.

I think you figured out there isn't any ways to handle the internal memory bits to do much. Most of everything is Twido must be handled with memory WORDS from what I understand.

Much appreciated,
Keep me updated if you have more ideas.

Alex
 
Last edited:
Hi Lancie, I am trying to understand your SBR program and its quite hard for me to wrap my head around. Would there be a visual way to explain it to me?

Many of my colleagues told me about a visual logic representation software named Grafcet. That's how they get students started with logic, control and ladder programming in french schools nowadays I think.

Would you like to give a try to represent your SBR program for the Fire Alarm?

If yes, here's a link that describes what it does:
http://www.plcdev.com/introduction_grafcets

I am still looking for a good source to download it.

Much appreciated,
Alex
 
Last edited:
HI tried to move %M100 to %M200 to SBR0:15 to SBR6:4, but I am not sure if I have the syntax correct (see the last Rung 17).
I have never touched a Twido, but I did have a quick through the manual. I don't see %SBRi as a valid operand for a load instruction. See my attachment. They list BLK.x in OP2 (the 'from' register), but not OP1 (the 'to' register). Let's hope that's NOT the case.

I thought of a possible different approach. mitureg doesn't really need to know how many bits are on, just that there is 'more than one' on. If the bits are mapped into words, we know that if this word is equal to zero, no alarms are on. If we set a latch when the word changes from zero to some non-zero value, then that latch tells us an alarm was triggered. Let's call this latch 'only one alarm'.

When the 'only one alarm' latch is on, we can then check for the value of this word to change, every scan. If it does, then we know that a second alarm was tripped, and set another latch. This is our 'more than one alarm' latch. After that, we don't care about additional alarms. We know there are at least two.

Therefore, when the 'only one alarm' latch is ON, and the 'more than one alarm' latch is OFF, only one alarm is present. When the 'more than one alarm' latch is on, there are at least two alarms.

These latches would both get reset when the word returns to zero.

One problem with this method would be if the first two alarms happened to both get triggered on the exact same scan. Unlikely, but still possible.

🍻

-Eric

twido.jpg
 
Eric Nelson said:
When the 'only one alarm' latch is on, we can then check for the value of this word to change, every scan. If it does, then we know that a second alarm was tripped, and set another latch. This is our 'more than one alarm' latch. After that, we don't care about additional alarms. We know there are at least two.

Therefore, when the 'only one alarm' latch is ON, and the 'more than one alarm' latch is OFF, only one alarm is present. When the 'more than one alarm' latch is on, there are at least two alarms.


Thank you Eric, very well summed up. This is exactly what I need.

Cheers!
 

Similar Topics

I'm a bit stuck again... See the redacted picture. At the moment, pressing F7 saves the "live" laser measurement into the boxes indicated by the...
Replies
9
Views
1,075
I have 2 TIA Wincc projects. One project is in TIA V17 Wincc Professional and other project is in TIA V15 Wincc Advance. How can I copy the Wincc...
Replies
1
Views
1,247
Is it possible to convert the project in Wincc Professional to Wincc advance?
Replies
6
Views
1,798
I have a tia v17 project in laptop. I prepared a PC to be used as HMI. In Tıa projecy there is wincc advance. How can I transfer this wincc...
Replies
1
Views
1,364
Does anyone know where I can order a T9110 SIS processor from? Seems like the availability of them online is scarce.
Replies
4
Views
1,896
Back
Top Bottom