Aliasing tags in Schneider Twido PLC ladder logic

SamyFiny

Member
Join Date
Nov 2020
Location
Joplin Missouri
Posts
4
Hello Every one,
This question came around in my place of work (MOAWP).
It appears very simple on the surface, but I could not get right when I tried.
The question is to provide some sort of aliasing (similar to RSLogix 5000) in the Twido PLC using only the ladder logic available in the programming interface.
In more details, we would have two bits say A and B for example. A program is developed so that these two bits are identical at all times.
So when bit A changes from any states to any states, then Bit B will track it. At the same time when bit B changes then bit, A should track it as well. In addition, all changes must occur in the same CPU scan (this latter condition could be relaxed if it becomes a problem)
I have tried the obvious:
|
|-----------| A |------------------------------------( B )
|
|
|
|-----------| B | ------------------------------------( A )
|
|
but this gives a problem when bit A is false, and bit B turns true (externally). You can see that B becomes also false (first rung) as seen from the ladder above, this is because A is false. Then bit B being false will turn off bit A (which was false, to begin with). On the next scan, bit A turns off bit B again. This situation continues endlessly. In the end, we did not achieve the desired result.
Any help will be appreciated
Thanks everyone.
 
Last edited:
...
I have tried the obvious:
|
|-----------| A |------------------------------------( B )
|
|
|
|-----------| B | ------------------------------------( A )
|
|
but this gives a problem when bit A is false, and bit B turns true (externally). You can see that B becomes also false (first rung) as seen from the ladder above, this is because A is false. Then bit B being false will turn off bit A (which was false, to begin with). On the next scan, bit A turns off B.
In the end, we did not achieve the desired result.
Any help will be appreciated
Thanks everyone.


Welcome to the forum.


I don't think the quoted part in blue is necessary, because B was already 0 so it does not have wait until the next scan to become 0.


The trick will be to detect a change in either bit in to decide when the other should be changed, and then use a Set/Reset (or Latch/Unlatch, in A-B-speak) or equivalent.


What happens when both bits change state on the same scan should not be a problem because, assuming both were the same on the previous scan, then both will be the same.


Finally, how to initialize these bits is going to be the most interesting part.
 
Last edited:
Brute force; there is probably a cleaner way; there is also a way to do this without Set/Reset.



Code:
### Detect externally-changed A or externally-changed 
### B (not shown) since last scan

      A     ABlast      Achanged
-+---] [------]/[---+-----( )-----
 |                  |
 |    A     ABlast  |
 +---]/[------] [---+

(same for B/ABlast/Bchanged goes here)

### React to external changes in A or external changes in B (not shown)
  
  Achanged             A         B
----] [----------+----] [-------]S[---+---
                 |                    |
                 |     A         B    |
                 +----]/[-------]R[---+
 
(Same for Bchanged/.../A goes here)

### Save final state for both; use A, nothing needed for B
    A      ABlast
---] [------( )------
There is still a lot to think about e.g.

  • what if I/O is asynchronous? (probably buffer inputs and outputs)
  • what about initialization?
 
Last edited:
there is also a way to do this without Set/Reset.


Heh, I have a thing about flip-flops. Also, XOR and AND instructions for discrete bits would make it cleaner.


Update: fixed typo, changed last [XIC/NO A] in second flip-flop to be [XIC/NO B]

PXL_20201125_040454983.jpg
 
Last edited:
Drbitboy, I think you’re taking the bone again. I was going to make some fenn treasure type post about flip flops but I left it alone, for now. Remember, it’s almost finals season.
 
Brute force; there is probably a cleaner way; there is also a way to do this without Set/Reset.



Code:
### Detect externally-changed A or externally-changed 
### B (not shown) since last scan

      A     ABlast      Achanged
-+---] [------]/[---+-----( )-----
 |                  |
 |    A     ABlast  |
 +---]/[------] [---+

(same for B/ABlast/Bchanged goes here)

### React to external changes in A or external changes in B (not shown)
  
  Achanged             A         B
----] [----------+----] [-------]S[---+---
                 |                    |
                 |     A         B    |
                 +----]/[-------]R[---+
 
(Same for Bchanged/.../A goes here)

### Save final state for both; use A, nothing needed for B
    A      ABlast
---] [------( )------
There is still a lot to think about e.g.

  • what if I/O is asynchronous? (probably buffer inputs and outputs)
  • what about initialization?


There is only 256 bits on M-area on twido.


Depending how many bits you need to "alias" on program side this will efficially use all bits.
Also if there is plenty of bits, I would go to words and packed bits to/from word.
Couple rungs whit DINT-memorys would have 32 bits and only 6words used.
Still you can copy also bits to M-are from MW or MD and vice versa.

Or changing old twido to newer would make things also easier?


Is added IO cards TWD* or TM2* marked?
 
Last edited:
[It's become "I can code that algorithm in N instructions," with N to be minimized. And I'm the only one playing :oops:. So yes, it's a very tasty bone.]


To go less brute force, the algorithm could leave or change just one of the bits, e.g.



Code:
### Detect change in A

        A   ABlast    Achanged
---+---] [---]/[---+----( )---
   |               |
   |    A   ABlast |
   +---]/[---] [---+

### Assign B based on AChanged, so A can be made same as B later
### - If A changed,
###   - then ensure B is same as A;
### - Else A did not change,
###   - So ensure B does not change,
###     

 
     Achanged   A          B
---+---] [-----] [---+----( )---
   |                 |
   | Achanged   B    |
   +---]/[-----] [---+
and then finish with


Code:
     B          A
----] [----+---( )---+---
           |         |
           | ABlast  |
           +---( )---+
 
Implementation and testing of that last algorithm are complete: the invariant was maintained i.e. there were no mismatches (C5:4/ACC) between A and B after applying the algorithm (cf. the image below) after 11,600+ changes to A and/or B to-date; a snapshot after the first 1400+ changes is shown in the image below.
Invariant: ensure discrete bits A and B have the same value at the end of every scan
=> If only A changes from last scan, then assign A's value to B
=> If only B changes from last scan, then assign B's value to A
Changes to A and/or B are synthetic, use Latch/Unlatch at the top of the scan before the algorithm, and are driven by bits in MicroLogix 1100 16-bit free-running clock (S:4); changes occur at 7-8Hz.


The attached .ZIP contains the image and the program: .RSS/MicroLogix 1100/RSLogixLite; .PDF.


If the OP is doing this for a homework assignment, then my intent is not that they simply copy this work, but rather try to understand and improve on it. The algorithm is basically a pair of rungs that are each similar to a flip-flop.


Nine contacts (XIO/XIC instructions) and four coils (OTEs) is, I think, the minimum needed to implement the required behavior using this approach. I would not be surprised to see another approach might cut the number of instructions by a third or more; almost certainly doing this in INTs and bit-wise INT instructions (XOR etc.) would use fewer instructions (6? instead of 13).


ab_match_running.png
 
It takes eight (8) inscructions to change 32 bits with Dint-wods.
Same principle can be used also to individual bits, but then you need set and reset coils, so inscruntions are 16 for one bit only.

bits_copy_test.png
 
It takes eight (8) inscructions to change 32 bits with Dint-words.


I incorrectly thought it was 6, but we can name that tune in seven (7) notes:



  1. XOR A BitsLastly Achanged
  2. AND A Achanged AAchanged
  3. XOR B Achanged XORBAchanged
  4. AND B XORBAchanged BNotAchanged
  5. OR AAChanged BNotAchanged B
  6. MOV B A
  7. MOV B Bitslastly
Steps 2-5 implement ((A AND Achanged) OR (~Achanged AND B))
 

Similar Topics

Hello Every one, This question came around in my place of work (MOAWP). It appears very simple on the surface, but I could not get right when I...
Replies
1
Views
1,885
Traditionally I create buffer routines to read all inputs into a new tag, and conversely, the output buffers to the actual output tags. However I...
Replies
4
Views
2,556
Hi all, I currently have a rejection conveyor belt with 4 lanes and with 1 paddle per lane to sort the quality of a particular agricultural...
Replies
7
Views
1,601
I'm a big fan of aliasing I/O channels to P&ID device names, but with all the new built-in I/O features, how are the cool kids aliasing? The...
Replies
8
Views
3,574
I really wish RA would allow elements of User Defined Data Types to alias other Tags. Does anyone know of a better work around than assigning...
Replies
1
Views
1,598
Back
Top Bottom