PLC Programming languages as part of IEC 61131-3 standard
Let’s take a moment to celebrate the 30th anniversary of the International Electrotechnical Commission (IEC) 61131-3 standard. Part three of this standard describes five programming languages for Programmable Logic Controllers (PLC)s including:
- Ladder Diagram (LD)
- Function Block Diagram (FBD)
- Structured text (ST)
- Instruction List (IL)
- Sequential Function Chart (SFC)
Each PLC manufacturer is free to develop tools using a single language or multiple languages targeting their niche market and user base. Crouzet has chosen to use FBD and SFC. The resulting IEC 61131-3 subset is well integrated in Crouzet Soft application. It’s a streamlined interface where the cleverly designed FBD and SFC blocks support each other.
Introduction to the Crouzet implementation of a Sequential Function Chart (SFC)
The article is an education piece describing a programmer’s first SFC application. The goal is to learn the SFC by developing a state-based binary counter that counts from 0 to 7. This SFC based program shown in Figure 1 reflects lessons learned in your digital logic class. The program is complex enough that we can discover some of the SFC nuances. It also features a style that you may find useful for future SFC programming. Please take a moment to view the counter simulation by watching the 13 second video.
Figure 1: Sequential Function Chart (SFC) implementation of a binary counter.
Video 1: Operation of the SFC based binary counter in the Crouzet-Soft simulator.
State logic for a SFC based binary counter
The code of Figure 1 is an 8-state state machine. Each state is embodied as a SFC step block such that one, and only one, state may be active at any given time. We can visualize this as a token ring where each SFC step block holds the token for one cycle before passing it on to the next. In this example, the step time is determined by a Pulse Per Second (PPS) signal. We start with S0 holding the token. one second later the token is passed to S1, and so on until it arrives at S7. On the next PPS, S7 completes the ring by passing the token back to S0.
Tech Tip: Look closely at the SFC step block in Figure 1. Notice the square within a square signifying the “resettable initial step” block. This block binds all other blocks by acting as a puppeteer to all other SFC blocks. Upon a system reset, the initial token materializes in the critical resettable initial step block. This block may also capture / remove the token(s) from all other blocks upon subsequent resets. This action can be difficult to visualize as the invisible wires connect all blocks to the principle resettable initial step block.
To better understand the operation of a SFC step block, consider the situation presented in Figure 2. In this picture we see that the token is held by state #4. We could say that the token is held in the little box within the larger symbol box. The presence of this token activates the S4 signal.
Just beneath the little box is a little gate symbol blocking the token’s path down the wire. It is controlled by the machinery to the left. The already active S4 signal is logically ANDed with the PPS signal. On the next PPS, the gate will be opened allowing the token to “fall” down to the S5 state. This process is repeated for all states with S7 returning to S0.
Figure 2: Crouzet debugging window with the system halted at state 4.
Tech Tip: The PPS signal represents the smallest pulse width possible for a PLC. Using the self-resetting Time On timer (TON) we generate pulse with a width of one PLC program scan. This narrow pulse is essential to the operation of this counter as it prevents everything from happening all at once. Stated another way, the counter breaks if the PPS is replaced by a constant on signal. While not a precise analogy, it’s like forgetting to add the break statement to a C programming case structure – the token is in free-fall while the enable signal is on.
Output logic for an 8 to 3 encoder
As previously mentioned, one and only one state may be active at any given time. The state with the “token in a little box” is active state. The machinery on the left is used to advance the token. We can now talk about the machinery on the right. In other words, things to the left of the SFC step block form the “state-next” machinery. The state “registers’ are encapsulated in the SFC blocks. Finally, the things to the right form the output logic.
Recall that our objective was to construct a binary counter: 000, 001, … 111, 000, … repeating. This requires an 8 to 3 encoder which is implemented using a trio of 4-input OR gates. The resulting outputs are labeled B0, B1, and B2 corresponding to the 1, 2, and 4 places. The final piece is a binary to decimal converter which drives the display.
Programming style
No programming discussion is complete without talking about style. In Figure 1 we see a mixture of Crouzet’s Wiring and Text modes. In some instances, the connection between block is formed with a wire. In other instances, the connection is formed using named (text) nodes such as PPS. The programmer is free to choose the method that results in a clean easy to read program.
Reall that the Figure 1 program is focused on the SFC. Consequently, it’s important to draw lines to focus attention on the state machine. The result is a compact easy to follow program with a state machine core that flows down the center of the page.
Contrast this with the output logic. There are over 12 wires represented on the right-hand side of the page. Using “Text” mode provides a non-cluttered representation. Use of Wiring mode would have resulted in a difficult to follow mess of overlapping wires.
Finally, you may have noticed a “Yes” block on the left next to the TON. This is unique Crouzet node replication block. Internally, it acts as a wire directly jumpering the input to the output. However, it does break a node into two with unique names. In this example, it allowed “Wiring Mode” on the left side and “Text” mode on the right. This was done to clearly show the feedback (self-resetting) line for the TON. This simple “Yes” allowed a clutter free was to show the PPS signal connection to the state-next machinery.
Conclusion
You are encouraged to reproduce this program in your PLC. It provides a right-sized introduction to state-based control within the Crouzet PLC. The exercise will also familiarize you with the tools and the importance of style.
This program does not require physical hardware. Consequently, this may be a good way to take the Crouzet software and simulator on a test run. As an educator, this programming exercise would be a good homework or in-class exercise.
Your comments and suggestions are welcomed. Also, you are encouraged to provide a screen shot of your PLC program.
Best Wishes,
APDahlen
About the Author
Aaron Dahlen, LCDR USCG (Ret.), serves as an application engineer at DigiKey. He has a unique electronics and automation foundation built over a 27-year military career as a technician and engineer which was further enhanced by 12 years of teaching (interwoven). With an MSEE degree from Minnesota State University, Mankato, Dahlen has taught in an ABET accredited EE program, served as the program coordinator for an EET program, and taught component-level repair to military electronics technicians. Dahlen has returned to his Northern Minnesota home and thoroughly enjoys researching and writing articles such as this.