Bizarre Scanning Probs!

Davey Wombat

Member
Join Date
Dec 2004
Location
London, Ontario
Posts
5
I have always assumed that I was correct in thinking that the output image table is scanned and updated after the user code.
However, in a recent experiment I think I have proved myself wrong (or more likely I've overlooked something :))
Have a look:


x Out1 Out0
--[ ]----[oneshot]----[ ]----(L)
|
| Out1
|--(U)

x Out0 Out1
--[ ]----[oneshot]----[ ]----(L)
|
1st scan | Out0
---------[ ]--------------|--(U)




What I'm trying to do is toggle between Out0 and Out1 whenever bit "x" is true.

My way of thinking (wrong):
1 - Upon the first scan, Out1 is set and Out0 is reset -- this works.
2 - When bit "x" goes true, Out0 will latch and Out1 will unlatch.
3 - This is where I think the problem resides: Since Out0 has not yet been updated (at the end of the program scan), the second section of code should not execute. Correct?
4 - I have a sneaking suspicion that it does however because Out0 never becomes set!

There is obviously a major flaw in my thinking here so I would greatly appreciate it if someone could bring this to light!

Thanks!
 
Actually, your Out0 is updated immedieatly. This is just a bit in the image table. The physical output will be updated at the end of the scan.

In your case your second rung will execute and your physical output will not change state.

My understanding of the image table is that it is internal bits that update the ins and outs between scans.
 
Last edited:
Rick Densing said:
... The physical output will be updated at the end of the scan. ...

For many PLC's, yes. Ditto for physical inputs.

Unfortunately, you'll be pulling your hair out when you come across a plc that doesn't do that, until you realize it, give your self a dope slap and wish you could you do the same to the design / marketing person(s) that decided not to have the plc do I/O to/from an image table between scans.
 
Well here's how i fixed it (just for curiosity):


x Out0
----[ ]-----|EQU |---------(L)
|N7:0 | |
|1 | | Out1
|---(U)

x Out1
----[ ]-----|EQU |---------(L)
|N7:0 | |
|0 | | Out0
1st scan |---(U)
---------[ ]------------|

Out0
----[ ]-----------------|MOV |
|0 |
|N7:0 |
Out1
----[ ]-----------------|MOV |
|1 |
|N7:0 |




That'll get me up and running for now but it seems really clunky to me for what it's for. Anyone have any suggestions for a little more finesse? ;)
 
How about


x bit
---[ ]-----[oneshot]-------------( )

bit OUT0 OUT0
---[ ]-----[/]---+---------------( )
|
bit OUT0 |
---[/]-----[ ]---+

OUT0 OUT1
---[/]---------------------------( )


 
For most PLC that I worked with you can do an update of the physical I/O any time for example AB SLC500. You would use the IOM instruction which stands for Imediate Output with mask. When this instruction is executed then the outputs of the slot address specified in the instruction will be updated using the mask.
 
Thank you Bernie. That works very well.
I do have one question on how it is possible though.
Are all conditions for a given output computed before the final state of the output is determined? Rungs are scanned left to right top to bottom so upon the second scan through the code after 'x' has gone high (and 'bit' will now be low), how is there anything to seal in Out0?
I'm reading through my post here and I can't seem to get my thoughts across the way i want but hopefully you understand what i'm saying!
 
On scans when 'bit' is not true - and this would be most of them - the bottom parallel branch in the second rung controls and sends the current state of OUT0 to the coil OUT0 thus latching itself. Only on the occasional single scan when 'bit' is true does OUT0 flip to the opposite state as controlled by the upper parallel branch.

[Edit] To directly answer your question, yes all the conditions for an output are determined before the output state is set. So for the pass when 'bit' is true - the upper branch evaluates to the oppositie of the current state of OUT 0 and the lower branch evaluates as 'false' since 'bit is not on. Since this is an OR branching, if either branch is 'true' then the output will be 'true'. On the next scan - when 'bit' is off - the upper branch will evaluate as 'false' and the lower branch will evaluate to the same as the current state of OUT0 which is sent to OUT0 preserving its state ('latching' it) while 'bit' is off.
 
Last edited:
Flip Flops. Let me count the ways....

Congratulations:

You have correctly solved the 1 button - 2 output problem.

Anyone have any suggestions for a little more finesse?

If you search on the phrase "flip flop" you will find many other solutions. Here are a few of the better ones:


The One-Shot:

PB PB-ONS
-----| |-----|ONS|-------------( )

PB-ONS Out1 Out1
--+-----| |------|/|-----+-----( )
| |
| PB-ONS Out1 |
+-----|/|------| |-----+



The Exclusive OR:

PB WAS WAS
-----| |--------| |-----+--------( )
|
PB Out1 |
-----|/|--------| |-----+


PB WAS Out1
-----| |--------|/|-----+--------( )
|
PB Out1 |
-----|/|--------| |-----+



The Counter:

PB +---- CTU ---+
----| |---------| COUNTER |
| Preset: 2 |
+------------+

+----- EQU ---+ Out1
------| COUNTER.ACC |----------( )
| 1 |
+-------------+

+----- GRT ---+ COUNTER
------| COUNTER.ACC |---------[RES]
| 1 |
+-------------+



The Hardwired Relay Solution: (works in PLCs too)


PB R2 R3 R1
---| |----|/|---+---|/|----( )--
|
R1 |
---| |----------+


PB R1 R4 R2
---|/|----| |---+---|/|----( )--
|
R2 |
---| |----------+


PB R2 R3
---| |----| |-----------( )--


PB R1 R4
---|/|----|/|-----------( )--


R1 Out1
---| |------------------( )--



The single Rung:

PB CHECK Out1 Out1
---| |---+---|/|-----|/|---+---(L)
| |
| | CHECK
| +---( )
|
| CHECK Out1 Out1
+---|/|-----| |---+---(U)
| |
| | CHECK
| +---( )
|
| CHECK
+---------------------( )




The Misused Oneshot:

PB B3/0 Out1 B3/1 Out1
|----] [-----[OSR]----+---]/[-----[OSR]-----(L)----|
| | |
| | Out1 B3/1 Out1 |
| +---] [-----[OSR]-----(U)----|


Note that the same address, B3/1, is used in two different oneshots


Since Out0 is always in the exact opposite state as Out1, we can just add:

Out1 Out0
------|/|-------------------( )


to any of the above solutions to get the control that you have.



The next challenge, of course, is to have the following pattern with each push of the button:

OFF
OUT1
OFF
OUT0
(repeat)

The easiest solution to modify, of course, is the Counter. Can you do it with one of the bit-wise ones?
 
Last edited:
Re: Flip Flops. Let me count the ways....

You likes to you burn time thinking of logical problems.Is good Activity.
You write one book, Allen Nelson?

For me is news is down.

Allen Nelson said:
Congratulations:

You have correctly solved the 1 button - 2 output problem.

If you search on the phrase "flip flop" you will find many other solutions. Here are a few of the better ones:



Explain better, the instruction GRT? You not use EQU=1 and EQU=2, or possible.

The Counter:

PB +---- CTU ---+
----| |---------| COUNTER |
| Preset: 2 |
+------------+

+----- EQU ---+ Out1
------| COUNTER.ACC |----------( )
| 1 |
+-------------+

+----- GRT ---+ COUNTER
------| COUNTER.ACC |---------[RES]
| 1 |
+-------------+




It old hire, now exist Flip-Flop Relay (hardware) coil + mecanic came.
The Hardwired Relay Solution: (works in PLCs too)


PB R2 R3 R1
---| |----|/|---+---|/|----( )--
|
R1 |
---| |----------+


PB R1 R4 R2
---|/|----| |---+---|/|----( )--
|
R2 |
---| |----------+


PB R2 R3
---| |----| |-----------( )--


PB R1 R4
---|/|----|/|-----------( )--


R1 Out1
---| |------------------( )--



The Misused Oneshot:

PB B3/0 Out1 B3/1 Out1
|----] [-----[OSR]----+---]/[-----[OSR]-----(L)----|
| | |
| | Out1 B3/1 Out1 |
| +---] [-----[OSR]-----(U)----|


Note that the same address, B3/1, is used in two different oneshots


Since Out0 is always in the exact opposite state as Out1, we can just add:

Out1 Out0
------|/|-------------------( )


Position is important??!?!?! After or before

to any of the above solutions to get the control that you have.



The next challenge, of course, is to have the following pattern with each push of the button:

OFF
OUT1
OFF
OUT0
(repeat)

The easiest solution to modify, of course, is the Counter. Can you do it with one of the bit-wise ones?
 
The Collection.

I am just showing examples of other solutions to the same problem.

Every time I come across a new way of doing something, even if it's something that I already know how to do, I file it away in my "Bag of Tricks".

The bag is getting pretty big now. But I don't intend on publishing it. It's MY bag.

Each of these solutions have been posted at least once on this forum someplace, usually several times. This problem comes up a lot. All I've done is collected them in one place.

For each of these solutions, there are variations, such as you point out on the Counter solution.

Each solution has behind it a philosophy of not just the solution, but HOW TO ARRIVE AT THE SOLUTION.

The One-shot method is perhaps the most common method used. One thing that makes the problem hard for newbies is that the PB is on for more than one scan. The one-shot solves that issue, and then uses simple XOR logic to do the rest.

The XOR method is the direct result of a Karnaugh map of the problem. Knowing how this logic is derived allows you to solve many similar state problems.

The Counter method comes in a close second (and maybe even beats) the One-Shot for most popular. It's certainly the easiest to understand, and most flexible, allowing you to add states with little extra code.
It is also the most wasteful in terms of memory.

Of course you can buy a modern flip-flop relay. Again, it's not the solution, but the process of determining the solution that makes this one important. The key here is that the contacts don't necessarily get set on the same/next scan as when the coil is energized. Principles used in the development here may be useful when communicating between PLCS, where updates

The Single Rung is actually a representation of a flow-chart. It's also an interesting example of how to make double-coiling work FOR you. It is also very similar to the code that Wombat posted at the beginning of this thread.

The misused one-shot is just plain silly. Actually, careful analysis will reveal that it is almost exactly the same as the Single Rung. When you understand this rung, you understand one-shots better.
 
Last edited:
To follow up on Allen's discussion, here's a little exploration I did some time ago.

There are several ways to program the flip-flop function. The following is a list of some of the permutations along with the Boolean equation for each one. In each example, T represents the trigger which is assumed to be a one-shot, and Q represents the output. T' and Q' represent NC contacts.

For PLCs without a one-shot instruction, here's how to make one. PB represents the input point that is to generate the one-shot. INT is an internal coil. T is the one-shot.

PB INT T
--| |----|/|-----------( )-


PB INT
--| |------------------( )-



Here's a common implementation. It's easy to remember.

Example 1.


T Q Q
--| |-----|/|--+-------( )-
|
T Q |
--|/|-----| |--+


The equivalent Boolean equation is:

Q = (T * Q') + (T' * Q)

where Q' = NOT(Q) and T' = NOT(T)

If you evaluate the equation when T = 0 and T = 1, you see why T needs to be a one-shot.
Q Q
If T = 0, then Q = (0 * Q') + (1 * Q) or Q = Q. --| |-------( )-

This means that Q will retain its state. If ON, it will stay ON. If OFF, it will stay OFF.

Q Q
If T = 1, then Q = (1 * Q') + (0 * Q) or Q = Q'. --|/|-------( )-

This means that if T were to remain ON, then Q would alternate between ON and OFF every program scan.

---------------------------------------------------
Reverse the order of elements in the second parallel branch.

Example 2.

T Q Q
--| |-----|/|--+-------( )-
|
Q T |
--| |-----|/|--+


The Boolean is:

Q = (T * Q') + (Q * T')

It's pretty obvious that Examples 1 and 2 are identical, but look what happens in the next pair of examples.

--------------------------------------------------------
This is another common implememtation. It's as easy to remember as the first.

Example 3.

T T Q
--| |--+--|/|--+-------( )-
| |
Q | Q |
--| |--+--|/|--+


The Boolean is:

Q = (T + Q) * (T' * Q')

Which equates to:

Q = (T * T') + (T * Q') + (Q * T') + (Q * Q')

But (T * T') = 0 and (Q * Q') =0 so we are left with:

Q = (T * Q') + (Q * T') which is the same as both of the earlier results.

---------------------------------------------------------
Now look at what might appear to be equivalent to Example 3.

Example 4.

T T Q
--| |--+--|/|--+-------( )-
| |
Q | Q |
--|/|--+--| |--+


The Boolean is:

Q = (T + Q') * (T' * Q)

Which equates to:

Q = (T * T') + (T * Q) + (Q' * T') + (Q' * Q)

Q = (T * Q) + (Q' * T')

Not only is this different from the earlier versions, but evaluate it when T =0, which is the normal state of the one-shot and you see it alternates between ON and OFF every program scan.

Q = (0 * Q) + (Q' * 1) or Q = Q'

---------------------------------------------------------
Here's another common implementation.

Example 5.

T Q Q
--| |--+--|/|--+-------( )-
| |
Q | T |
--| |--+--|/|--+


The Boolean is:

Q = (T + Q) * (Q' * T')

Which equates to:

Q = (T * Q') + (T * T') + (Q' * Q') + (Q * T') or

Q = (T * Q') + (Q * T') which is the same as examples 1 through 3.

---------------------------------------------------------
Watch what happens when you leave out the vertical shunt between the NO and NC contacts.

Example 6.

T Q Q
--| |-----|/|--+-------( )-
|
Q T |
--| |-----|/|--+


The Boolean is:

Q = (T * Q') + (Q * T')

Which is the same as examples 1 through 3 and 5. The vertical shunt makes no difference. Notice that this is identical to example 2.

----------------------------------------------------------
Let's try leaving out the vertical shunt from Example 3.

Example 7.

T T Q
--| |-----|/|--+-------( )-
|
Q Q |
--| |-----|/|--+


The Boolean is:

Q = (T * T') + (Q * Q') or Q = 0 (Always OFF).

The same thing happens if you leave the vertical shunt out of Example 4.

-------------------------------------------------------------
Let's try adding a vertical shunt to Example 1.

Example 8.

T Q Q
--| |--+--|/|--+-------( )-
| |
T | Q |
--|/|--+--| |--+


The Boolean is:

Q = (T + T') * (Q + Q')

but (T + T') = 1 and (Q + Q') = 1, so Q = 1 (Always ON).

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

 

Similar Topics

I was tasked with resolving some latency issues on a DH+ network. There were 16 SLC504's and 4 PV550's on a single segment, all were working...
Replies
2
Views
2,032
Someone I know has a com problem with some equipments. They are connected in a token ring pathern. PC, PLCs and devices are sharing this RS485...
Replies
10
Views
3,266
Hello, I am using Unity pro V15. I have Quantum CPU 671 and Ethernet NOE 77101 configured. I have configured IO scanning on NOE. I have attached...
Replies
5
Views
179
Hi I am in the process of making an OT lab for training and to test incident response, an i keep hearing NOT to scan network because some...
Replies
3
Views
902
Looking for some application advice with barcode scanners and Compactlogix PLC and a Panelview Plus. I assume Ethernet/IP is the way to go here...
Replies
1
Views
1,663
Back
Top Bottom