Programming in Sequential Function Chart (SFC)
Creating programming block in the SFC implementation language
- 1. Select a folder in the Solution Explorer in the PLC project.
- 2. In the context menu select the command Add > POU...
- The Add POU dialog opens.
- 3. Enter a name and select the implementation language Sequential Function Chart (SFC).
- 4. Click Open.
- TwinCAT adds the programming block to the PLC project tree and opens it in the editor.
Adding step-transitions
- 1. Select the transition after the Init step.
- The transition is shown in red.
- 2. In the SFC menu or the context menu select the command Insert step-transition after.
- TwinCAT adds step Step0 and transition Trans0.
- 3. Select the transition Trans0 and in the SFC menu or the context menu select the command Insert step transition.
- TwinCAT adds transition Trans1 and step Step1 before Trans0.
Alternatively, you can move the elements Step and Transition from the Toolbox view into the diagram with drag and drop.
See also:
- TC3 User Interface documentation: Command Insert step-transition after
- TC3 User Interface documentation: Command Insert step transition
Add entry action
- 1. Select Step0.
- 2. In the SFC menu or the context menu select the command Add entry action.
- By default, a prompt appears for specifying the duplication mode for the step actions. This is used to specify whether the reference information is copied to the existing step action objects or whether the objects should be "embedded" when the step is copied in the future. If embedding is selected, new step action objects are created when the step is copied. The duplication mode is defined in the step property Duplicate or Copy. As long as this property is disabled, the copied steps call the same actions as the current step.
- 3. For this example, retain the Copy reference default setting and confirm with OK.
- The Add entry action dialog opens.
- 4. Enter "Step0_entry" as name and select the implementation language "Structured Text (ST)". Click Add.
- TwinCAT adds the action Step0_entry under the function block in the PLC project tree and opens the action in the editor. In the entry action Step0_entry you can now program instructions, which are to be executed once when the step Step0 is enabled.
- 5. Close the editor for Step0_entry.
- The step Step0 is now marked with an E in the lower left corner. Double-clicking the E to open the editor.
- The entry action Step0_entry now appears in the step properties under Entry action. Here you can also select another action, if required.
- 6. Select Step0. Press [Ctrl] + [C] to copy the step.
- The added copy of the step contains the same entry action that was added above. In other words, the new step calls the same action.
SFC editor options In the TwinCAT options for the SFC editor category you can specify whether the prompt for specifying the duplication mode should always appear when a step action is added, or you can specify duplication mode as standard. |
See also:
- Reference Programming: SFC Element Properties
- TC3 User Interface documentation: Command Add entry action
- TC3 User Interface documentation: Dialog Options - SFC editor
Add exit action
- 1. Select Step0.
- 2. In the SFC menu or the context menu select the command Add exit action.
- By default, a prompt appears for specifying the duplication mode for the step actions. Please refer to the notes in sections “Adding an input option” and “SFC element properties”.
- The Add exit action dialog opens.
- 3. Enter "Step0_exit" as name and select the implementation language "Structured Text (ST)". Click Add.
- TwinCAT adds the action Step0_exit under the function block in the PLC project tree and opens the action in the editor. In the exit action Step0_exit you can now program instructions, which are to be executed once before the step Step0 is disabled.
- 4. Close the editor for Step0_exit.
- The step Step0 is now marked with an X in the lower right corner. Double-clicking the E to open the editor.
- You can define the exit action in the step properties under exit action. Here you can also select another action, if required.
See also:
- TC3 User Interface documentation: Command Add exit action
Add Action
- 1. Double-click on Step0.
- By default, a prompt appears for specifying the duplication mode for the step actions. Please refer to the notes in sections “Adding an input option” and “SFC element properties”. The Add Action dialog opens.
- 2. Enter "Step0_active" as name and select the implementation language "Structured Text (ST)". Click Add.
- TwinCAT adds the action Step0_active under the function block in the PLC project tree and opens the action in the editor. In the step action Step0_active you can now program instructions, which are to be executed as long as the step is active.
- 3. Close the editor for Step0_active.
- Step0 is now marked with a black triangle in the upper right corner.
You can define the action in the properties of the step under Step actions. Here you can also select another action.
Adding an alternative branch
- 1. Select Step1.
- 2. In the SFC menu or the context menu select the command Insert branch right.
- TwinCAT adds the step Step2 to the right of Step1. The steps are as linked as parallel branch with a double line.
- 3. Select one of the two double lines.
- The double line is shown in red.
- 4. Select the command Alternativ in the context menu or the SFC menu.
- TwinCAT converts the branch to an alternative branch. The double line changes to a single line.
An alternative branch can be converted to a parallel branch with the Parallel command.
See also:
- TC3 User Interface documentation: Command Insert branch right
- TC3 User Interface documentation: Command Alternative
Adding a jump
- 1. Select Step2.
- 2. In the SFC menu select the command Insert jump after.
- TwinCAT adds the Step jump after step Step2.
- 3. Click on the jump destination Step of the jump.
- You can now enter the jump destination manually or select it via the Input Assistant . Select Step0.
See also:
- TC3 User Interface documentation: Command Insert jump after
Adding macro
- 1. Select Step1.
- 2. In the SFC menu or the context menu select the command Insert macro after.
- TwinCAT adds the macro Macro0 after the step Step1.
- 3. Double-click on the element Macro0.
- The macro opens in the implementation part of the editor. The header shows the name Macro0.
- 4. In the SFC menu or the context menu select the command Insert step transition.
- TwinCAT inserts a step transition combination.
- 5. In the SFC menu or the context menu select the command Exit macro.
- The implementation part shows the main diagram again.
See also:
- TC3 User Interface documentation: Command Insert macro after
- TC3 User Interface documentation: Command Insert step transition
- TC3 User Interface documentation: Command Exit macro
Adding an association
- 1. Select Step2.
- 2. In the SFC menu or the context menu select the command Insert action association.
- TwinCAT adds an association to right next to the step Step2.
- 3. Click in the left field of the association to select the qualifier.
- You can enter the qualifier manually or select it via the Input Assistant . Select “P”.
- 4. Click in the right field of the association to select the action.
- You can enter the action manually or select it via the Input Assistant .
See also:
- TC3 User Interface documentation: Command Insert action association
Analyzing expressions with AnalyzeExpression
The AnalyzeExpression function block from the Tc2_System library allows the analysis of expressions. It can be used in the SFC diagram, for example, to examine the result of the SFCError flag, which is used to monitor timeouts in the flow chart.
See also:
- Documentation Tc2_System: AnalyzeExpression
- Reference Programming: SFC Flags