How to write a for loop in ladder?

eric.lin
2018-09-12
2018-09-14
  • eric.lin - 2018-09-12

    Hi,
    I want to add a for loop using ladder language,
    but I can not find a 'for' in the toolbox
    I am not familiar with ladder language in codesys,
    can someone give me a help ?
    Thanks

     
  • johnlee - 2018-09-13

    hi eric.lin,

    unlikely codesys do not have For function in Ladder Diagram. If you want to use there is available for structured text.

    Thank you
    John Lee

     
  • ndzied1 - 2018-09-13

    Te best part of CoDeSys is that you can use the language that is best for a specific task. If everything else is in ladder and you just need one FOR loop, you can create an action in structured text and call it from the ladder.

     
  • r.evbatyrov - 2018-09-13

    Hi Eric,

    even if there is no built-in support for loops in LD, you can construct it with several simple operators.
    1. Initialize a cycle index with MOVE operator.
    2. In the next network(s) do your loop logic. Provide a label for the first network in the loop body. Say, MY_LABEL
    3. Increment a cycle index (or decrement if you're creating a count down index) with assignment like i + 1 ------ i
    4. Do a cycle condition check with GE (or LE for count down) operator which supplies a JUMP element to MY_LABEL.

    Regards,
    Roman

    eric.lin hat geschrieben:
    Hi,
    I want to add a for loop using ladder language,
    but I can not find a 'for' in the toolbox
    Thanks

     
  • eric.lin - 2018-09-14

    Ok, I've done my for loop using other basic LD operators
    Thanks for all the suggestions

     

Log in to post a comment.