Programming in the CFC Editor

In the CFC editor, you can wire POUs to each other and create well-structured block diagrams.

The editor supports you in the following ways:

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 box output of the Box element to the box input of the Output element.

    ⇒ The cursor symbol changes when it reaches the box input.

  4. Release the left mouse button.

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

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.

    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 in the context menu. 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 program PrgFirst 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.

    ⇒ 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.

  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 POU in the editor. The type, name, and POU pins are displayed accordingly.

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

    ⇒ Example:

    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 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.

  3. Click in the source connection marks.

    ⇒ You can edit the name.

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

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

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.

  2. Position two Box elements on the line.

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

  3. Click CFC ‣ Routing ‣ Route All Connections .

    ⇒ The collision is resolved.

  4. Change the connecting lines gradually.

    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.

  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.

    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.

    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. Unlock the connection by clicking Unlock Connection or by clicking the lock symbol.

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

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

Hint

Connections in a group are not auto-routed.

Reducing the display of a POU

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

  1. Select a POU whose pins are partially disconnected.

    ⇒ Example: fb_DoIt_1

    The POU needs space for all of the pins.

  2. Click CFC ‣ Pins ‣ Remove Unused Pins .

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

See also