PLC Finite State Machine Control Using a Sequence Cam Block

Return to the Industrial Control and Automation Index

Safety: The setup shown in Figures 1 and 2 is for demonstration purposes only. It is a 24 VDC system driven by a bench power supply (not shown). Proper installation practices must be followed for high power 3-phase systems. Also, proper control and monitoring is necessary to protect the system from malfunction and to inform the operator of fault conditions. As a starting point please keyword search UL 508A.

The cam sequencer is a common Programmable Logic Controller (PLC) function. This sequencer is beneficial as complex operations can be described in tabular form. Perhaps the best use of this table is the maintenance of the Finite State Machine’s (FSM) state variable. This solves a challenging problem especially if you were attempting to use ladder logic programming.

In this article, we will explore the cam function as implemented in the Crouzet Millenium Slim PLC. This is one of the smallest PLC offered by DigiKey. As will be shown, it is easy to implement a moderately complex state machine in the PLC. For advanced Crouzet programming, you are encouraged to use Sequential Function Charts (SFC). In either case, it’s good practice to use the method that yields the most readable code. This ensures that the program can be understood by others. This is especially important for quick machine restoration.

The test setup is shown in Figures 1 and 2. Here we see a model 88983902 Millenium Slim PLC installed on the PLC trainer. A selector switch is used to activate the PLC with a pushbutton to begin a cycle and another to abort the process. The primary output and focus of this cam-controlled sequence is a large three-phase motor starter.

The setup is unremarkable with the controls connected as per the Crouzet datasheet. The motor starter is connected as described in a previous interposing relay article. Please note that additional wire and programming considerations are required for a safe installation of a high power 3-phase system.

The alarm is unconventional in that we are using a speaker with series connected 220 Ω series resistor. The tone is generated by a 400 Hz 50% duty cycle PWM signal. While this may or may not be good practice in the field, it provides an excellent learning opportunity to understand the operation and capabilities of a PLC and its Pulse Width Modulated (PWM) output.

Figure 1: Picture of the Crouzet Millenium Slim PLC installed next to two interposing relays.

Figure 2: The Crouzet PLC in installed on the PLC trainer with pushbutton control as well as a large 3-phase reversing motor contactor.

Safety: Additional programming steps are necessary to control and monitor a three-phase reversing motor starter. Topics such as auxiliary contacts and interlocks are beyond the scope of this article.

FSM demonstration using a 7-step cycle

The purpose of this setup is to demonstrate the operation of a table-based FSM. For this exercise, let’s define a machine cycle as:

  1. Idle waiting for a button press
  2. Signal a system start via three short alarm blasts
  3. Forward for 5 seconds
  4. Wait for 3 seconds
  5. Signal a system start via three short alarm blasts
  6. Reverse for 5 seconds
  7. Return to idle

A cycle is initiated when the selector switch is in the on position and the cycle start pushbutton is pressed. The state diagram for this sequence is shown in Figure 3. This visual is a restatement of the 6-step list. Each bubble contains the state name as well as the desired outputs which will soon be described. If you are interested here is an article describing how the diagram was constructed using \LaTeX. It’s worth mentioning that this tech forum supports \LaTeX. The best use is for presentation of math equations.

Figure 3: State Sequence for the Finite State Machine encoded into the Crouzet CAM function

Code description

Now that we have an understanding of the machine cycle, we can move on to the code implementation. Figure 4 presents the Function Block Diagram (FBD) implementation. The code for the 6-state machine cycle is presented on the left. The code for the three-alarm is to the right. Observe that we have implemented two state machines both of which are based on the cam function. In this article we will focus exclusively on the machine cycle FSM. You can download the file attached to the end of this article to explore the alarm section.

To understand the FBD code, we need to first understand the operation of the cam. This is a good time to read this sidebar about the mechanical ratcheting cam. That article will help you form a metal model with a direct analogy to the Crouzet function block.

Figure 4: Crouzet Function Block Diagram implementation of machine cycle featuring the cam block.

The cam function operates as a look up table. The block has eight outputs. For any given state we are free to choose the logic level of the output. Figure 5 presents the table “programming.” The six states are represented by the rows. The outputs are represented by the column. For any given state we select either a one or a zero. Note that the numbers (only 7 used) are the same as those represented in Figure 3 state machine.

At this point we can return to the Figure 4 FBD and see how the machine operates:

  • The S1 signal is routed to the output O1 to drive the forward motor coil
  • The S2 signal is the reverse coil drive is sent to output O2.
  • The S3 signal is sent to a rising edge trigger (R_TRIG) block which is then used to start the three-alarm cycle.
  • Signals S4 and S5 are used to activate Time On (TON) timers for the appropriate delay.
  • Signal S6 is sent to PLC output O4 to drive the front panel lamp.
  • Signal S7 is used to enable or disable the Cycle Start pushbutton (Input I3)

The signals were chosen to simplify the FBD signal routing. The cam signal assignments were chosen for clarity and to minimize the number of line crossings. Perhaps it would have been better to use the “Text” mode as was done for the teal-colored Reset signal.

Figure 5: The cam function operates as a look up table with state as row and individual outputs on the columns.

Pulsed signals to advance the FSM

The mechanically ratcheting cam encapsulates one of the real challenges of using the software cam block. Specifically, the coil must be deactivated in order to catch the ratchet tooth in preparation for the next state advance. In the software application, this means that the “Forward” input of the cam block is edge sensitive.

Observe that the cam block is driven by a 4-input OR gate. Technically, it’s driven by five unique outputs when we include the 2-input OR gate that collect the output of the 3- and 5-second TON timers. These five signals are all used to advance the cam:

  1. In state 0: cam S7 is active. A pulse will be produced when the cycle pushbutton (I3) is pressed. If the selector switch (I1) is on the pulse will advance the cam to position 2.

  2. In state 1: cam S7 light turn on the panel lamp (Q4). It also starts the 3-alarm mechanism. When the three-alarm cam system is complete its S3 output will be sent back advancing the primary cam to state 2.

  3. In state 2; cam S7 output keeps the panel lamp turned on. It also activates the 5 second TON timer via output S5. When the TON is complete it sends a pulse back to the primary cam advancing it to state 3.

  4. States 3 to 5 repeat the process for signaling and then reversing the motor.

Here is a short video showing the system in action:

Conclusion

The cam block provides an easy way to encode simple state machines. Here the term simple implies consecutive states - a circle - as shown in Figure 3. For more complexity in a Crouzet application, we should use the SFC language.

If you encounter issues with the cam block, be sure to verify that you are relaxing the input. Use of pulsed signal generators such as the R_TRIG and self-resetting timers are beneficial.

Best Wishes,

APDahlen

CAM_Example.pcs (50.2 KB)

Return to the Industrial Control and Automation Index

1 Like