Control Engineering Online Update for March 10, 2006

By Control Engineering Staff March 10, 2006
March 10, 2006
Highlights Sponsored by Phoenix Contact
PLC programming tools have evolved greatly over the last 20 years. However, a great majority of PLC implementations have not. The reason: management is constantly faced with the dilemma that only certain technicians know how the program was written and are therefore the only individuals qualified to troubleshoot and/or modify it. Grafcet, also known as sequential function chart programming (SCF), offers an IEC 61131-1-compliant approach.

CLIPLINE Complete from Phoenix Contact
Four connection technologies work together via our patented dual bridge system, which accepts the same push-in jumpers and accessories. Screw clamp, spring-cage, auto-spring and insulation displacement connectors provide the right connection technology for any application. Visit for more information on this innovative technology.

Structured PLC Programming using Grafcet

Structured programming methodologies for PLCs have been present for decades and can even be implemented on legacy controllers. Most of these methodologies incorporate a graphical flowchart of the control sequence, which translates directly into controller logic. These flowcharts can be read, written and modified by non-programmers with the assurance that what has been conveyed graphically will be implemented verbatim in logic. Direct benefits to controller owners include:

• Shorter logic development cycle
• Accelerated testing and commissioning tasks
• Reduction of downtime due to enhanced diagnostics
• Easier offline simulation and factory acceptance testing

One of these programming methodologies is known as Grafcet—a graphical programming methodology founded in 1977 and further defined in IEC 60848 and IEC 61131-3 as sequential function chart programming (SFC). The term is a French acronym: Graphe Fonctionnel de Commande Etape-Transition, which means Functional Graph of a Step-Transition Command. Figure 1 below shows the base elements of a simple Grafcet.

The sequence begins at Step 0 where Action #1 is performed. The sequence then waits until Condition #1 is met before advancing to Step 1 where Action #2 is performed. The sequence stays on Step 1 until Condition #2 is met at which point it advances to Step 2. Once on Step 2, Action #3 is performed for one program scan and then the sequence returns to Step 0 where the cycle repeats.

There are two popular implementations of this structure in PLCs. Bit-based, or latch/unlatch style, and file-based or memory-table style.

Also sponsored by Moxa

Visit to learn about Moxa’s 2-8 port Plug-N-Play Embedded Computers for Manufacturing Automation, Power/Utility, Transportation, POS/ATM, Environmental Monitoring, and more. Features: Linux and Windows support, Robust Fanless Design, LCM Display and keypad for HMI, Dual 10/100 Mbps Ethernet, and Intel Xscale processor. Call to learn more 888-MOXA-USA.

Bit-based Grafcet

The simplest implementation of the Grafcet flowchart can be done with basic latch-unlatch ladder logic. In this implementation, a subroutine is assigned to each Grafcet. Step transition logic is resolved at the top of the subroutine and step output or action logic is resolved immediately following.

To ensure that at least one program scan occurs between each step, both a transition word and a step word are employed for each Grafcet. Bits in the step word initiate actions whereas bits in the transition word initiate step transition. In this way, a step with no conditions will still insure that actions have a chance to execute. Figure 2 illustrates the required logic.

Resolving the transitional logic is a direct translation from the Grafcet. For our example from Figure 1, the transitional logic in Figure 3 could be used:

Typical step action logic to resolve the Grafcet from Figure 1 might appear as shown in Figure 4.

Advantages of this style of programming are:
• Easy to understand by electricians
• Can be implemented on virtually any PLC
• Rung/network number can directly relate to step number
• Forcing a step simply requires setting the step bit
• Conditions to pass step can be easily seen on one rung/network of logic
• Parallel branch execution is possible within same Grafcet
• Relatively low programming overhead required

Disadvantages include:
• Sequencing modifications require ladder-logic changes
• The larger the Grafcet, the more logic that is required
• Automatic step manipulation and recovery can be challenging

File-based Grafcet

Similar to the canned drum sequencer instructions found in many PLC controllers, file-based Grafcet attempts to implement this with standard logic while permitting flexibility not available in these instructions. Input and output conditions are stored in preset files. A step counter is used as an index into these files.

As a minimum, the following data words will be required:

STEP_COUNTER – holds the step number
INPUT_WORD – mapped to all required inputs
OUTPUT_WORD – activates required outputs
INPUT_XOR_RESULT – holds result of the input XOR

The following data files will also be required:

#INPUT_MASKS – holds required inputs for each step
#INPUT_STATES – holds required states for each input
#OUTPUT_PRESETS – holds required outputs for each step

Once the format is in place, step presets for virtually any aspect of an automatic sequence can be defined. Logic is minimal to incorporate other features. To implement our example from Figure 1, the mapping shown in Figure 5 could be used. The Grafcet could then be modified to match Figure 6.

Mapping inputs

Sequence input mapping would appear as shown in Figure 7:

Grafcet presets

The status of the real inputs is compared against the conditions, which are expected to pass step (presets). For this article, both an input file (mask bits) and a state file (is the input ON or OFF) are used. By turning on a bit in the Mask file, the sequence is being told that the user expects to look at that input on that step in order to pass step. By setting the associated state bit in the State file, it is indicated that the user expects to see that input turn ON in order to pass step. Similarly, by setting a bit in the Output file, it is indicated that the associated output condition should be activated on that step. Absence of a set bit for an output on a step will force the output off on that step.

Table 1 shows the presets required to implement the Grafcet defined in Figure 6:

Bit #: 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Word 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
Word 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0
Word 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1
Word 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1
Word 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
Word 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0
Word 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1
Word 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Word 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
Word 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1
Word 2 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
Word 3 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Table 1

Step evaluation

The logic required to evaluate real inputs against the preset files and to advance a step if they are met is key to the File-based Grafcet architecture. Figure 8 demonstrates how this is implemented on a PLC:

Passing step

Once the XOR result evaluates to zero, the Grafcet can then pass step by incrementing the step counter as shown in Figure 9.

Setting outputs

Setting the output word from the preset stored for the current step is shown in Figure 10.

Real outputs are then set by the images of the output word as shown in Figure 11.

Advantages of File-based Grafcet are:

• One set of logic executes all steps
• Preset files can be used for any aspect of a sequence including:

• Step changes can be made directly in the data table
• Steps can be advanced and repeated with ease
• Once the stepping logic is proven, it will work for any number of steps
• Can be implemented on any PLC that supports indirect addressing, AND, OR and XOR functions
• Real I/O changes are easily accommodated in the mapping logic
• Diagnostic and preset conditions are easily visualized

Disadvantages include:
• Requires more overhead than Bit-based Grafcet
• Electricians may require additional training to understand the indirect addressing model

Why Grafcet?

Through utilization of IEC 61131-1 compliant software and techniques such as Grafcet, programs can be written which will be easier to troubleshoot, maintain and re-deploy for different applications. The Grafcet techniques demonstrated in this article have been implemented on a wide assortment of PLCs including those from Rockwell Automation, Siemens, Omron, Modicon, Idec, Mitsubishi and Westinghouse. The Grafcet chart is easy to understand and can be interpreted and even revised by non-programmers ensuring that the machine cycle will function as anticipated by all stakeholders the first time.

Online resources

Grafcet home page:

IEC 60848 Standard:

Petri Nets:

SFC defined in IEC 1131-1:

By Mike Voll, controls manager, Manufacturing/Industrial, Stantec Consulting Ltd.