Vai al contenuto

How to make a counter using IEC61131 programming

Home Forum Programmazione IEC 61131 (LogicLab) How to make a counter using IEC61131 programming

Stai visualizzando 2 post - dal 1 a 2 (di 2 totali)
  • Autore
    Post
  • #35222
    Sergio Bertana
    Amministratore del forum

    A customer has a simple question that i consider interesting to post in the forum.

    How can I make a counter up while button is true using the IEC61131 programming languages ?
    The C language program is:

    counter=0;
    while (button == true)
    {
      counter=counter+1;
    }

    #37265
    Sergio Bertana
    Amministratore del forum

    The IEC61131 norm, supports 5 different programming languages, so you can choose the best of them to solve the problem.

    In LD (Ladder Diagram) you can use the ADD block and the program would be like in the picture. As you see the LD program has two different rungs, in the first, the program acts exactly as in the C program. If the LI0 is active the counter is increased at every program loop. In the second the counter count the times the LI1 becomes active.

    In ST (Structured Text) you can write a program in a very similar way than the C language. So the program would be like in the picture.

    Attached the print and the source code of a LogicLab project that manages the counter, you can test it directly on the PLC simulator.

Stai visualizzando 2 post - dal 1 a 2 (di 2 totali)
  • Devi essere connesso per rispondere a questo topic.