Jump to content

pulse and sub routine

Recommended Posts


i got a subroutine call when MB 0 is on. In this subroutine i want to catch a falling edge of MB1.

if i set MB 0 then i set MB1. Then i reset MB 0

the subroutine isn't call anymore. I now reset MB1.

When i set MB0 again i call the subroutine and then the falling edge is "activate". Is this a normal behaviour?

i first thought that the rise and fall edge where decided at the start of the scan cycle? but it seems it is net dependent !

It's maybe an rfc something rule but i am not aware enough of those rules. I just wnat a confirmation it's a normal thing and not a bug...


Link to comment
Share on other sites


For the transition, [N] or [P], O/S keep previous state and current state of MI or other bit.

If there is change in state between previous and current scans, O/S activate [N] or [P] contact for 1 scan.

Mean of scan in this case is not a System scan, but two sequential entryes into subroutine.

So you have to take care about this.


Link to comment
Share on other sites

It is generally understood no matter whose platform you use that the transitions are based off WHEN in the program that bit of memory gets written resulting in a change of state.

It is not (should not be) be directly related to the "housekeeping" portion of the scan.

However, if you are reading physical Inputs, then those are updated only during the "housekeeping" portion of the scan.

Unless of course you use an immediate IO read to sample the hardware IO before the "housekeeping".

Since MB bits are internal, there is no housekeeping necessary for them, therefore the end of the scan is irrelevant.

In addition, if you have conditionally executed subroutines in a PLC (which should normally be avoided for a host of reasons) your code may completely miss transitions that came and went because the transitional instruction you are using will base that off of the evaluation of that instruction the previous time it was exectued.

On the flip side, you could have the same bit (MB) of memory trigger positive and negative transitions multiple times in one single scan.

Link to comment
Share on other sites

After actually playing around a bit, it appears that the transistions in Visilogic do not function anything like I thought they did either.

As Alex hints at, it appears that the memory bits associated with change of state are sampled on each and every subroutine, including the main subroutine.

This means that if you call the same subroutine twice or more within one total PLC scan, any transitional within will only be evaluated true the first time through.

However, that transition will still be detected by the calling subroutine and subsequent other subroutine calls within the global scan.

If you then have combinations of SET and RESET on those bits outside the subroutine calls, depending on order and placement you can create anamolous and unpredictable behavior.

In some cases, even disregarding subroutines, I saw evidence of transitionals being affect by changes being made to the bits within that same scan. In other instances it was not tied to the scan.

For example, I put two identical --|n|--[iNC+]-- networks in consecutive networks incrementing unique integers. Both would count.

However if I put a reset coil of the bit with the referenced N transition above between these two identical networks, the second of them would stop counting. It did this even though there was no difference in the change of state. Therefore just having overwritten the same state to said memory area the transition was lost. Which means it was updated immediately with the reset coil and not the subroutine.

I was also able to create situations where it recogized transitions within routines, but did not recognize those transition in the main subroutine.

Can we please get a concise and detailed description of exactly how and when the transitional contacts are updated and evaluated?

Based on the observed behavior, the description in the help file is actually incorrect/incomplete.

  • Upvote 1
Link to comment
Share on other sites

Hi Damian,

How transition contact works?

Behind the transition "contact", in fact there are 3 more internal bit registers - one for P contact, one for N contact and one for "buffer". That's why the number of transition contacts is limited.

When the scan comes to specific transition contact (P or N), it compares the value of the linked to this contact bit (let's say MB0) with the value of the buffer.


1. bit = 0 & buffer = 0 -> P = 0 and N = 0 no transition detected

2. bit = 1 & buffer = 0 -> P = 1 and N = 0

3. bit = 0 & buffer = 1 -> P = 0 and N = 1

4. bit = 1 & buffer = 1 -> P = 0 and N = 0 no transition detected

After updating P & N contacts, controller copy the value of the bit to the buffer and con tinue the scan.

As result - if in previous scan we had case 2 and P = 1; in the current scan we will have case 4 and P contact will be reset back to 1.

This way transition contact by definition are active only one scan.

Important note: proceeding the transition contact in the way described above is when the scan is comming to this specific contact in the application. If, for ecample specific subroutine is not scanned for some time and the transition contact is inside, it will be activated only when the subroutine is scanned again.

I hope this makes sense. Let me know if you need any additional info.

  • Upvote 2
Link to comment
Share on other sites

  • 11 years later...

Admin, please delete my previous post, so no one gets confused. I summarized everything here.

I spent in sum probably 4-5h on this P/N edge topic testing it on PLC breaking my head over it.

How it works:
Lets say we have P-edge contact in certain string of the code.
- Every P-contact acts as separate block with its own buffer and additional bit for P edge. 
- Every time that program scan comes to the -lPl- input its buffer bit state is compared to the current state of the observed MB.
- If buffer state is 0 and new MB state is 1, then -lPl-input state is SET (conducts) immediately on that scan and buffer is updated with new MB stateMB state is written only in buffer of this observed -lPl- input not in all -lPl- inputs for this MB if there is more of them in the code!
- On the next scan cycle, if MB state hasn´t changed (stayed 1), -lPl- input will compare it´s buffer state (which is now 1) to MB state which is still 1 so no change detected. That means the state of -lPl- input will be non conductive -> -lPl- input not triggered.

Since every -lPl- input acts as separate block with its own buffer this will be the behavior of the next program (Lets observe single scan of the program):
Program scan start: 
- String 1:  MB1 state 0
- String 2: MB1 output coil was SET in the code - MB1 state transitions from 0 to 1
- String 3:  -lPl-  P edge input of MB1 is scanned, triggered and will conduct because there was a P transition detected
- String 4: MB1 output coil was RESET - MB1 state transitions from 1 to 0
- String 5: -lPl-   P edge input of MB1 is scanned but not triggered  since the buffer state of this certain -lPl-  input is 0  and when compared to the observed MB state which is 0 as well there was no change.

Each  -lPl- input of the same MB acts as a separate unit! So when one -lPl-  input gets triggered, the buffer and the state changes only for that -lPl- input. The rest are still waiting to be scanned and compared their buffer value to the actual MB value.

With this in mind it´s easier to predict what happens with -lPl- inputs in subroutines, because they work in the same way.

Important thing to note when you test the FW with "Watch option" (sunglasses icon) ! 
If you click on the MB input and force SET it through Visilogic SW the system will act as you SET the MB at the beginning of the scan not in the middle of the code where this MB actually sits. That means -lPl- edge inputs will act in a different sequence. 

Example of code:
-l P l-  -lSET2l-                   If edge MB1 is detected SET MB2
-l     l-                                        Input MB1
-l Pl -  -lRESET2l-             If P edge MB1 is detected RESET MB2
If you turn on Watch, click on MB1 input and force SET it the program will act as you would SET this MB at the beginning of the scan and the result of MB2 will be RESET.

The proper way of doing it while testing: 
-l P l-  -lSET2l-                     If edge MB1 is detected SET MB2
-l      l-  -( SET )-                     Input MB3 that SETS output coil of MB1 
-l P l-  -lRESET2l-               If P edge MB1 is detected RESET MB2
If you turn on Watch, click on MB3 input and force SET it, the Output coil of MB1 will be properly SET during program scan in string 2.  The result of MB2 will be SET!

So when you have P/N edge inputs in the code,  avoid directly force SETting the corelated inputs through Watch function in Visilogic SW. Rather Use another test bit which will trigger the output coil of the MB which have P/N edge input contacts in the code.

Hope this helps to someone.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...