Implementing Latches in SCL
Kenneth Jensen
Automation, Integration, & Controls Engineer / Electrical Engineer / Power Coordinator / Drive Engineer
Introduction
Latches are a fundamental concept in PLC programming, used to maintain a state or hold an output until a certain condition is met. In this article, I'll explain what latches are, why they're used, and how to implement them using Structured Control Language (SCL). We'll also explore practical applications of latches in automation, create latch-based control sequences, and cover debugging and testing latch functions.
What Are Latches and Why Are They Used in PLC Programming?
Latches are great for capturing instantaneous changes that occur. They latch in another bit and that can be used while the machine is "in that state," using reset to tell the machine that it is no longer in that state. As you will see, IF Statements are a common way to create latch logic. Examples include:
Types of latches commonly used in PLC programming:
Implementing Set/Reset Latches Using SCL
Basic Set/Reset (SR) Latch Example
Here's an example of how to implement a basic SR latch in SCL. It's important to note that in IF, ELSEIF, ELSE structures, the first argument takes priority. This means that for permissives or safety devices, you want the safety to fail conservatively, so it can't be overwritten.
FUNCTION_BLOCK FB_SRLatch
BEGIN
IF R THEN //R is a bit set for Reset
Q := FALSE; // Reset latch
ELSIF S THEN //S is a bit set for Set
Q := TRUE; // Set latch
END_IF;
END_FUNCTION_BLOCK
Practical Applications of Latches in Automation
Latches are widely used in automation for various purposes, such as:
- Machine Start/Stop Control: Maintaining the state of a machine until a stop condition is met.
- Alarm Systems: Holding an alarm state until acknowledged by an operator.
- Process Control: Ensuring a process continues running until a specific condition is met.
Creating Latch-Based Control Sequences
Example: Machine Start/Stop Control with Permissive Logic
Let's enhance our machine start/stop control example by adding permissive logic to ensure safety:
领英推荐
FUNCTION_BLOCK FB_MachineControl
BEGIN
// Use the latch for machine control with permissive logic
IF Permissive THEN
FB_SRLatch( //Calling SRLatch Function Block and setting what S, R & Q are
S := Start,
R := Stop,
Q => MachineOn);
ELSE
MachineOn := FALSE; // Ensure the machine is off if permissive is not met
END_IF;
END_FUNCTION_BLOCK
In this example, the machine will only start if the permissive condition is true. This ensures that safety requirements are met before the machine can operate.
Handling Permissive and Safety Logic
To ensure safety and proper operation, I place all the start permissive logic in its own section, and the run permissive in its own section. The outcomes of this logic are used to allow equipment to start or run. Run permissive logic should always shut down the equipment if any condition is not met. Typical permissives include:
- Position: Ensuring components are in the correct position.
- Equipment Safety: Confirming safety devices are active.
- Other Conditions: Any other conditions specific to the process.
Debugging and Testing Latch Functions
Debugging latches involves checking the inputs and ensuring that the latch behaves as expected. Here are some tips:
- Monitor Inputs and Outputs: Use your PLC software to monitor the inputs and outputs of the latch function block.
- Check Logic Flow: Ensure that the conditions for setting and resetting the latch are correctly implemented.
- Simulate Scenarios: Simulate different scenarios to test the latch behavior under various conditions.
Example: Testing the SR Latch with Permissive Logic
In your PLC software, create a test program to simulate the inputs and observe the latch behavior:
ORGANIZATION_BLOCK MainOB
VAR
TestLatch : FB_SRLatch; // Instance of SR latch
StartTest : BOOL := FALSE; // Simulated start input
StopTest : BOOL := FALSE; // Simulated stop input
PermissiveTest : BOOL := TRUE; // Simulated permissive input
LatchOutput : BOOL; // Output from the latch
END_VAR
BEGIN
// Call the SR latch function block with permissive logic
IF PermissiveTest THEN
TestLatch(
S := StartTest, // Simulated start input
R := StopTest, // Simulated stop input
Q => LatchOutput // Output from the latch
);
ELSE
LatchOutput := FALSE; // Ensure the output is off if permissive is not met
END_IF;
// Add additional logic to simulate start/stop
IF TestSW = FALSE THEN
StartTest := TRUE;
END_IF;
IF TestSW = TRUE THEN
StopTest := TRUE;
END_IF;
END_ORGANIZATION_BLOCK
By simulating the start, stop, and permissive inputs, you can observe and verify the behavior of the SR latch with permissive logic, ensuring it functions as expected.
Final Thoughts
Latches are powerful tools in PLC programming, enabling you to maintain states and control processes effectively. By understanding and implementing latches using SCL, you can enhance your automation projects and improve process reliability.
Stay tuned for the next article in my series, where I'll dive into more advanced SCL programming techniques!
About the Author: Ken Jensen brings over 20 years of experience in electrical, automation, & controls engineering across diverse industries like nuclear, steel, and glass. He is a highly skilled problem-solver with expertise in electrical systems, PLCs, SCADA, and Industry 4.0 technologies. He is adept at leading projects, driving innovation, and fostering collaboration.