adccommunitymod (AutomationDirect) asked a question.

CLICK logic newbie seeking counter implementation hints

Created Date: November 29,2016

Created By: DanSut

**** This post has been imported from our legacy forum. Information in this post may be outdated and links contained in the post may no longer work.****

Hi all, first post here I generally code for *nix servers but have done a reasonable bit of Twido PLC ladder logic maintenance and refactoring using TwidoSuite but given the Twido has been EOL'd and my requirements of it are very minimal I'm giving the CLICK a try. Concepts have been broadly transferable for me be but available instructions are quite different. My first question here is really for those that are more familiar with using the CLICK instructions to help find the most efficient/elegant of achieving my goal: I have a DC input that I increment at counter on both rising and falling edge with the requirement that when the input is high the counter is odd (LSBit 1) and when is low it is even (LSBit 0). { "data-align ": "center ", "data-linktype ": "2 ", "data-size ": "custom ", "height ": "117 ", "width ": "493 ", "data-attachmentid ":103622} I'm using the above logic that does just what I want to do but it wasn't my first choice and is slightly more painful to copy/paste/adjust for other input/counter pairs. I was hoping for something like: { "data-align ": "center ", "data-linktype ": "2 ", "data-size ": "custom ", "height ": "117 ", "width ": "493 ", "data-attachmentid ":103621} but it doesn't look like that is possible :( unless I am missing something :confused: Grateful for all comments, ideas, or alternative ways of achieving this. Cheers /dan


  • adccommunitymod (AutomationDirect)

    Created Date: November 29,2016

    Created by: DanSut

    Hi all, first post here

    I generally code for *nix servers but have done a reasonable bit of Twido PLC ladder logic maintenance and refactoring using TwidoSuite but given the Twido has been EOL'd and my requirements of it are very minimal I'm giving the CLICK a try. Concepts have been broadly transferable for me be but available instructions are quite different.

    My first question here is really for those that are more familiar with using the CLICK instructions to help find the most efficient/elegant of achieving my goal:

    I have a DC input that I increment at counter on both rising and falling edge with the requirement that when the input is high the counter is odd (LSBit 1) and when is low it is even (LSBit 0). { "data-align ": "center ", "data-linktype ": "2 ", "data-size ": "custom ", "height ": "117 ", "width ": "493 ", "data-attachmentid ":103622}

    I'm using the above logic that does just what I want to do but it wasn't my first choice and is slightly more painful to copy/paste/adjust for other input/counter pairs. I was hoping for something like: { "data-align ": "center ", "data-linktype ": "2 ", "data-size ": "custom ", "height ": "117 ", "width ": "493 ", "data-attachmentid ":103621}

    but it doesn't look like that is possible :( unless I am missing something :confused:

    Grateful for all comments, ideas, or alternative ways of achieving this.

    Cheers

    /dan

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: November 30,2016

    Created by: kewakl

    Cannot cast X101 to Single.

    You may be able to use masking/shifting/hex, but as you said earlier "more painful to copy/paste/adjust for other input/counter pairs. "

  • adccommunitymod (AutomationDirect)

    Created Date: November 30,2016

    Created by: kewakl

    RETRY

    PACK all Inputs into a HEX WORD

    |

    ---------------------------------------------------------------------+ Copy Pack

    | C1 C15

    | DH101

    +-----------------------------

    Mask BIT C1 into DH201

    |(.)Hex

    ---------------------------------------------------------------------+ Math DH201

    | DH101 AND 1h

    +-----------------------------

    Do the original math (with odd/even compensation

    C1 -Rising edge |(.)Hex

    ----]^ ( (DH1 + DH201) MOD 2h)

    | +-----------------------------

    | Convert the HEX value back to DS Numeric

    C1 | |

    ----]v

    Copy all your inputs into 16-bit HEX WORDS, then you can do MASKING, shifting and other wonderful mathing on the bits - once masked

    The registers that I selected are ARBITRARY. I used bits so that I could test the maths without physical / electrical input wiring.

    Then copy the 16-bit hex words back to 16-bit DS Numerics.

    The 1h and the 2h are simply 1 and 2, the editor WILL put the 'h ' in the (HEX)math instruction.

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: November 30,2016

    Created by: DanSut

    Thanks kewakl,

    Your solution might not be any simpler for the single case but it has given me some ideas when I have many inputs I want to deal with like this. Maybe a FOR could actually come in useful... the next thought would be where can I actually can you use the pointer addressing that the manual talks about? it certainly doesn't seem to work in MATH.

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: November 30,2016

    Created by: kewakl

    Maybe a FOR could actually come in useful... the next thought would bewhere can I actually can you use the pointer addressing that the manual talks about? it certainly doesn't seem to work in MATH.

    When using the For instruction, YOU MUST MAINTAIN THE LOOP COUNT!

    pointers ONLY work in COPY Single.

    I have a project posted on this forum that uses pointers to move datablocks around the click address space.

    I use FOR LOOP/ pointers like the BELOW example to implement recipes in plc, as I am not fond of maintaining recipes (sheets) in HMIs.

    look here

    Basic operation:

    . SRC origin

    . DST origin

    . Element offset

    Of course, Ds10 - DS12 can be populated in any other way. Just ensure that you either code some range checking of FIX YOUR Ranges.

    This code will copy 50 words from DS1000 to DS2000

    You may devise a more creative loop tracking method, but this has worked for me.

    Source Origin

    SC2 |

    ---] ^

    +-------------

    TRIGGER |

    ---]^

    |

    +-------------

    track loop count |

    ---------------------------+ MATH DS101

    | DS101 + 1

    +-------------

    calc SRC offset |

    ---------------------------+ MATH DS102

    | DS101 + DS10

    +-------------

    calc DST offset |

    ---------------------------+ MATH DS103

    | DS101 + DS11

    +-------------

    copy data from SRC to DST|

    ---------------------------+ Copy Single

    | DS DS

    +-------------

    |

    ---------------------------+ Next

    +-------------

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: November 30,2016

    Created by: DanSut

    Thanks again kewakl, some good hints there that I'm sure will save me some experimentation.

    Especially the fact that Help topic CL195 states: only Single COPY instruction supports Pointer Addressing!

    aside: seriously, why was it so difficult to get the link to CL195 and have it not indexed by Google?

    Good example too - this sort of thing makes the CLICK a better product all around :D

    Expand Post