Technical Article

Deep Dive into PLC Sequential Function Chart (SFC) Programming

August 31, 2023 by Shawn Dietrich

Sequential function charts (SFCs) are a great tool when processes require sequence control, but things can get complicated fast. Here are some ways to create better SFC programs and applications.

The graphical programming language called sequential function chart, or SFC, is standardized by IEC 61131-3. The chart reads from top to bottom, and blocks are used to represent steps, transitions, and functions. This style of programming is similar to function block diagrams and has some of the same pitfalls that generate complexity and decrease programming efficiency.

 

Sequential function chart (SFC) programming example layout.

Figure 1. Sequential function chart (SFC) programming example layout. Image used courtesy of Schneider Electric

 

First Things First: Lay Out the Groundwork

Just like any programming language, spending time doing the groundwork, laying out and structuring the code, will save you time in the long run. SFC programs are great for applications that use sequences. A versatile solution, SFCs are perfect for automated assembly lines or automation that relies on actuator positions, servo positions, or any boolean sensor to advance to the next step. Start by reviewing the overall process and then break the process into smaller sequences. When a pick-and-place station lifts the part from the feeder escapement, the sequence might include picking and placing it and then applying another sequence to the escapement. 

By breaking up the process it lays out the SFC program by default. Also, try to use the SFC to trigger other processes or outputs. However, avoid doing calculations or processing within the SFC, instead, use handshakes or function blocks to kick off other processes.


Figure 2. An example of a step in an SFC diagram.

Figure 2. An example of a step in an SFC diagram.

 

Looks Are Everything

Using a similar approach to FBD programming, you want to make sure blocks and transitions are spaced out as much as possible and use comments when necessary. With SFC, you can add parallel branches, but exercise caution with this practice. If you add too many branches, the diagram can become cluttered and hard to read. 

Essentially, best practice dictates working to make the diagram look neat and tidy. If wires are in the way, they are likely to be hidden, so reference arrows should be used. Make sure step actions don’t overlap with transitions or other steps.

Figure 3. Improperly spaced text and layout (intentionally exaggerated for effect).

Figure 3. Improperly spaced text and layout (intentionally exaggerated for effect).

 

One Step Forward, One Step Back

Sequences rely on being able to step forward when required and hold when not required. The same is true when the sequence needs to take a step backward. For example, if there was a very long pneumatic cylinder that took a long time to travel from a retracted to an extended position, the sequence would need to wait for that cylinder to reach the extended position via the extended sensor. Most SFC programs will have an input on the transition that tells the controller when it is okay to move to the next step. 

This input can be programmed in a couple of ways:

  1. Each transition can have a different set of conditions which allow the sequence to transition to the next step. This requires a custom set of conditions which will need to be adjusted for every step, but it is very clear what causes the transition, and each step can have different conditions.
  2. Create a logic rung outside of the SFC that sets a single bit used on every transition. Typically I like to use an all-sensors OK bit or monitor a fault word. If any fault is pending I know that the sequence needs to wait. By using a single bit for every step, you reduce the complexity of the SFC program and remove processing to another subroutine. 

 

Handshakes, A Great Way to Introduce Yourself

Similar to how FBD relies on handshakes to interface with other subroutines or processes, handshakes are a great way to reduce SFC complexity. Avoid long strings of conditions on steps or setting outputs directly within the SFC itself. Set handshakes and drive conditions within other subroutines. I like to use UDTs for devices like cameras and robots and often add handshakes such as “start,” and “started” in the UDT.  That way, everything I need to communicate and control the device is in one tag. 

 

Figure 4. Parallel SFC branching.

Figure 4. Parallel SFC branching.

 

Figure 5. Settings to establish step properties.

Figure 5. Settings to establish step properties.

 

Applications

If we refer back to our pick-and-place station example we would need to create a SFC for the three pneumatic cylinders and another SFC for the escapement. Each cylinder, gripper raise/lower, shuttle extend/retract, and gripper open/close, would all have faults if the sensors are not in the correct position with respect to their expected state. 

After that, it is highly recommended one monitor the fault word. If there was any fault pending it is best to prevent the step forward in the SFC. To accommodate a step delay, some IDEs offer timers built into the SFC step. With Rockwell Automation’s Studio 5000, each step has parameters that can be set including a step timer.  When a part is present and the escapement is in the pick position, start the pick-and-place SFC. 

Each step of the SFC would set a different expected state for the cylinders, these expected bits are our handshakes. As the expected state changes a fault would be pending until the cylinder reaches its position, then the sequence would step forward.

 

Spend Less Time, Get Better Results with SFC

Writing the sequence this way allows the programmer to spend less time programming sequences and more time writing communication code or integrating the machine. When reviewing the sequence it's easier to understand what should happen in the next step and what has already happened from previous steps.