Skip to main content

Programming in the Ladder Diagram (LD)

Creating a POU in the Ladder Diagram (LD) implementation language

  1. In the device tree, select the application.

  2. Click the Project → Add Object → POU command.

    The Add POU dialog opens.

  3. Specify a name and select the Ladder Logic Diagram (LD) implementation language.

    Click the Add button.

    CODESYS adds the POU to the device tree and opens it in the editor. An empty network is inserted in the implementation part. The empty network is bounded on the left by a vertical line, which represents a bus bar. The ToolBox view is also opened automatically, where the suitable elements, operators, and function blocks are available for LD programming.

Adding a contact and a function block (TON)

Requirement: A POU with the implementation language LD is opened in the editor and an empty network is inserted.

  1. In the ToolBox view, click the Ladder Elements category.

  2. Click the Contact element, drag it into your network and drop it at the insertion position Start here.

    The contact is added on the left in the network directly at the vertical line.

  3. Click ??? and enter the identifier of a Boolean variable. The Input Assistant is also available for this.

  4. In the ToolBox view, click the Function Blocks category and drag the TON function block to an insertion position on the connecting line to the right of the inserted contact.

    CODESYS inserts the TON box to the right of the contact. The contact is connected with the input IN of the TON function block.

  5. Specify a time constant at the PT input (example: T#3s).

    If the variable of your contact becomes TRUE, then the IN input of the TON function block also becomes TRUE. For example, with a on-delay time of T#3s the TON function block forwards the value TRUE to the Q output.

For more information, see the following: Contact

Inserting a closed branch

Requirement: A POU with the implementation language LD is opened in the editor and an empty network is inserted.

  1. Click inside the empty network and click FBD/LD/IL → Insert Contact.

  2. Select the connecting line to the left of the contact and click FBD/LD/IL → Set Branch Start Point.

    The start point on the connecting line is indicated by a red rectangle. CODESYS indicates all possible end points of the branch with a blue rectangle.

  3. Click a blue rectangle in order to set the end point of your closed branch.

    CODESYS inserts the branch between the start and end points. The program flow will run through both branches until the end point.

    If you insert the branch at a box instead of at a contact, then the box will only be called if none of the other branches is TRUE.

For more information, see the following: Closed Branch