Skip to main content

Programming in the CFC Editor

Note

You commit to the implementation language when creating the POU. Afterwards, it is not possible to switch between the Continuous Function Chart (CFC) and Continuous Function Chart (CFC) - page-oriented implementation languages.

Inserting elements and wiring with connecting lines

  1. Drag a Box element and an Output element into the editor.

  2. Click the output of the Box element.

    The output is marked with a red box.

  3. Drag a connecting line from the output pin of the Box element to the input pin of the Output element.

    The cursor symbol changes when it reaches the input pin.

  4. Release the left mouse button.

    The output pin of the box is wired to the input pin of the output.

    _cds_img_prg_simple.png

You can also hold down the Ctrl key, select each pin, and then right-click Connected Selected Pins.

Calling of instances

  1. Create a new project using the standard template and specify the name First for example.

    The project First.project is created.

  2. Extend the application with the function block FB_DoIt in the ST implementation language with inputs and outputs.

    Example:

    FUNCTION_BLOCK FB_DoIt
    VAR_INPUT
        iAlfa : INT;
        iBravo: INT;
        sCharlie : STRING := 'Charlie';
        xItem : BOOL;
    END_VAR
    VAR_OUTPUT
        iResult : INT;
        sResult : STRING;
        xResult : BOOL;
    END_VAR
    VAR
    END_VAR
    iResult := iAlfa + iBravo;
    
    IF xItem = TRUE THEN
        xResult := TRUE;
    END_IF
  3. Select the application and click Add Object → POU. Select the Continuous Function Chart (CFC) implementation language and the type Program. Specify the name PrgFirst for example.

    Click OK to confirm the dialog.

    The PrgFirst program is created and it opens in the editor. It is still empty.

  4. Instantiate function blocks and declare variables.

    PROGRAM PrgFirst
    VAR
        iCounter: INT;
        fbDoIt_1 : FB_DoIt;
        fbDoIt_2 : FB_DoIt;
        iOut : INT;
        sOut: STRING;
        xOut: BOOL;
    END_VAR
  5. Drag a Box element from the Toolbox view into the editor.

  6. Click the ??? field and type in ADD as the box name.

    The box type is ADD. The box acts as an adder.

  7. Click line 3 in the declaration editor.

    The declaration line of iCounter is selected.

  8. Click in the selection and drag the selected variable into the implementation. Focus there on an input of the ADD box.

    An input has been created, declared, and connected to the box.

  9. Click again in the selection and drag the variable to the output of the ADD box.

    An output has been created, declared, and connected to the box.

  10. Drag an Input element from the Toolbox view to the implementation. Click its ??? field and type in 1.

  11. Connect the 1 input to an input of the ADD box.

    A network is programmed. At runtime, the network counts the bus cycles and stores the result in iCounter.

    cfc_img_first_network_add.png
  12. Click line 5 in the declaration editor.

    The line is selected.

  13. Click in the selection and drag the selected instance into the implementation.

    The instance appears as a box in the editor. The type, name, and box pins are displayed accordingly.

    cfc_img_first_network_doit.png
  14. Drag the fbDoIt_2 instance to the editor. Interconnect the instances to each other and to inputs and outputs.

    Example:

    cfc_img_first_network_add_doit1_doit2.png

    A program in ST with the same functionality might look like this:

    PROGRAM PrgFirstInSt
    VAR
        iCounter: INT;
    
        fbDoIt_1 : FB_DoIt;
        fbDoIt_2 : FB_DoIt;
    
        iOut : INT;
        sOut: STRING;
        xOut: BOOL;
    END_VAR
    iCounter := iCounter + 1;
    fbDoIt_1(iAlfa := 16, iBravo := 32, sCharlie := 'First', xItem := TRUE, iDelta := 2, iResult => fbDoIt_2.iAlfa, xResult => fbDoIt_2.xItem);
    fbDoIt_2(iBravo := fbDoIt_1.iResult, sCharlie := 'Second', iDelta := 2, iResult => iOut , sResult=> sOut, xResult => xOut);

Creating connection marks

Requirement: A CFC POU has connected elements.

  1. Select a connecting line between two elements.

    The connecting line is displayed as selected. The ends of the connecting line are marked with cfc_icon_selected_input.png red boxes.

  2. Click CFC → Connection Mark.

    The connection is separated into a Connection Mark – Source and a Connection Mark – Sink. The name of the mark is generated automatically.

    cfc_img_prg_simple_with_connection_mark.png
  3. Click in the source connection marks.

    You can edit the name.

  4. Specify the name SimpleMark for the source connection mark.

    The source connection mark and sink connection mark have the same name.

    cfc_img_prg_simple_with_named_connection_mark.png

Resolving collisions and fixing connecting lines by means of control points

The following example shows how to use the Route All Connections command with control points.

  1. Position the Input and Output elements. Connect the elements.

    cfc_img_prg_simple2_control_point.png
  2. Position two Box elements on the line.

    The connecting line and the boxes are marked red because of the collision.

    cfc_img_prg_simple2_red_linie.png
  3. Click CFC → Routing → Route All Connections.

    The collision is resolved.

    cfc_img_prg_simple2_routed_line.png
  4. Change the connecting lines gradually.

    cfc_img_prg_simple2_manual_routed_line.png

    The connecting line has been changed manually and is now blocked for auto-routing. This is shown by a lock symbol at the end of the connection.

    _cds_img_prg_simple2_locked_routed_line.png
  5. Select the connecting line and click CFC → Routing → Create Control Point.

    A control point is created on the connecting line. The connecting line is fixed to the control point.

    cfc_img_prg_simple2_locked_routed_line_with_control.png

    You can also drag a control point from the Toolbox view to a line.

  6. Change the connecting line as seen in the following example.

    cfc_img_prg_simple2_changed_line_with_control.png

    Use the control point for changing the connecting line according to your needs. You can set any number of control points.

  7. In the context menu, click CFC → Routing → Remove Control Point to remove the control point.

  8. Click Unlock Connection or click the lock symbol to unlock the connection.

  9. Select the connecting line and click Route All Connections.

    The connecting line is routed automatically as seen in Step 3.

    _cds_img_prg_simple2_locked_routed_line.png

Important

Connections in a group are not auto-routed.

Reducing the display of a box

Requirement: A CFC POU is open. In the editor, its boxes with all declared pins are displayed.

  1. Select a box whose pins are partially disconnected.

    Example: fb_DoIt_1

    cfc_img_box_with_unconnected_pins.png

    The box needs space for all of the pins.

  2. Click CFC → Pins → Remove Unused Pins.

    Now the box needs less space and is displayed only with the functionally relevant pins.

    cfc_img_box_without_unconnected_pins.png