Recent from talks
Nothing was collected or created yet.
Ladder logic
View on WikipediaThis article needs additional citations for verification. (May 2012) |
Ladder logic was originally a written method to document the design and construction of relay racks as used in manufacturing and process control.[1] Each device in the relay rack would be represented by a symbol on the ladder diagram with connections between those devices shown. In addition, other items external to the relay rack such as pumps, heaters, and so forth would also be shown on the ladder diagram.
Ladder logic has evolved into a programming language that represents a program by a graphical diagram based on the circuit diagrams of relay logic hardware. Ladder logic is used to develop software for programmable logic controllers (PLCs) used in industrial control applications. The name is based on the observation that programs in this language resemble ladders, with two vertical rails and a series of horizontal rungs between them. Ladder diagrams were once the only way to record programmable controller programs, but today, other forms are standardized in IEC 61131-3. For example, instead of the graphical ladder logic form, there is a language called Structured text, which is similar to C, within the IEC 61131-3 standard.
Overview
[edit]
Ladder logic is widely used to program PLCs, where sequential control of a process or manufacturing operation is required. Ladder logic is useful for simple but critical control systems or for reworking old hardwired relay circuits. As programmable logic controllers became more sophisticated it has also been used in very complex automation systems. Often the ladder logic program is used in conjunction with a human–machine interface (HMI) program operating on a computer workstation.
The motivation for representing sequential control logic in a ladder diagram was to allow factory engineers and technicians to develop software without additional training to learn a language such as FORTRAN or other general-purpose computer language. Development and maintenance were simplified because of the resemblance to familiar relay hardware systems.[2] Implementations of ladder logic may have characteristics, such as sequential execution and support for control flow features, that make the analogy to hardware somewhat inaccurate.
Ladder logic can be thought of as a rule-based language rather than a procedural language. A "rung" in the ladder represents a rule. When implemented with relays and other electro-mechanical devices, the various rules execute simultaneously and immediately. When implemented in a programmable logic controller, the rules are typically executed sequentially by software in a continuous loop, or "scan". By executing the loop fast enough, typically many times per second, the effect of simultaneous and immediate execution is achieved. Proper use of programmable controllers requires an understanding of the limitations of the execution order of rungs.
Syntax and examples
[edit]The language itself can be seen as a set of connections between logical checkers (contacts) and actuators (coils). When a path exists from the left side of the rung to the output through asserted (true or "closed") contacts, the rung is considered true, and the output coil storage bit is set to 1 or (true). If no such path exists, the output is false (0), and the "coil" by analogy to electromechanical relays is considered "de-energized". This analogy between logical propositions and relay contact status was established by Claude Shannon.
Ladder logic has contacts that make or break circuits to control coils. Each coil or contact corresponds to the status of a single bit in the programmable controller's memory. Unlike electromechanical relays, a ladder program can refer any number of times to the status of a single bit, equivalent to a relay with an indefinitely large number of contacts.
So-called "contacts" may refer to physical ("hard") inputs to the programmable controller from physical devices such as pushbuttons and limit switches via an integrated or external input module, or may represent the status of internal storage bits which may be generated elsewhere in the program.
Each rung of ladder language typically has one coil at the far right. Some manufacturers may allow more than one output coil on a rung.
- Rung input
- Checkers (contacts)
—[ ]—Normally open contact, closed whenever its corresponding coil or an input which controls it is energized. (Open contact at rest.)—[\]—Normally closed ("not") contact, closed whenever its corresponding coil or an input which controls it is not energized. (Closed contact at rest.)
- Rung output
- Actuators (coils)
—( )—Normally inactive coil, energized whenever its rung is closed. (Inactive at rest.)—(\)—Normally active ("not") coil, energized whenever its rung is open. (Active at rest.)
The "coil" (output of a rung) may represent a physical output which operates some device connected to the programmable controller, or may represent an internal storage bit for use elsewhere in the program.
A way to recall these is to imagine the checkers (contacts) as a push button input, and the actuators (coils) as a light bulb output. The presence of a slash within the checkers or actuators would indicate the default state of the device at rest.
Logical AND
[edit]-----[ ]-------------[ ]------------------( ) Key switch 1 Key switch 2 Door motor |
The above realizes the function: Door motor = Key switch 1 AND Key switch 2
This circuit shows two key switches that security guards might use to activate an electric motor on a bank vault door. When the normally open contacts of both switches close, electricity is able to flow to the motor which opens the door.
Logical AND with NOT
[edit]------[ ]--------------[\]----------------( ) Close door Obstruction Door motor |
The above realizes the function: Door motor = Close door AND NOT Obstruction.
This circuit shows a push button that closes a door and an obstruction detector that senses if something is in the way of the closing door. When the normally open push button contact closes and the normally closed (NC) obstruction detector is closed (no obstruction detected), electricity is able to flow to the motor which closes the door.
Logical OR
[edit] --+-------[ ]------------+-----------------( )
| Exterior unlock | Unlock
| |
+-------[ ]------------+
Interior unlock
|
The above realizes the function: Unlock = Interior unlock OR Exterior unlock
This circuit shows the two things that can trigger a car's power door locks. The remote receiver is always powered. The unlock solenoid gets power when either set of contacts is closed.
Industrial STOP/START
[edit]In common industrial latching start/stop logic, we have a "Start" button to turn on a motor contactor, and a "Stop" button to turn off the contactor.
When the "Start" button is pushed the input goes true, via the "Stop" button NC contact. When the "Run" input becomes true the seal-in "Run" NO contact in parallel with the "Start" NO contact will close maintaining the input logic true (latched or sealed-in). After the circuit is latched the "Stop" button may be pushed causing its NC contact to open and consequently the input to go false. The "Run" NO contact then opens and the circuit logic returns to its inactive state.
--+----[ ]--+----[\]----( )
| Start | Stop Run
| |
+----[ ]--+
Run
-------[ ]--------------( )
Run Motor
|
The above realizes the function: Run = (Start OR Run) AND (NOT Stop)
This latch configuration is a common idiom in ladder logic. It may also be referred to as seal-in logic. The key to understanding the latch is in recognizing that the "Start" switch is a momentary switch (once the user releases the button, the switch is open again). As soon as the "Run" solenoid engages, it closes the "Run" NO contact, which latches the solenoid on. The "Start" switch opening up then has no effect.
- Note: In this example, "Run" represents the status of a bit in the PLC, while "Motor" represents the actual output to the real-world relay that closes the motor's real-world circuit.
For safety reasons, an emergency stop ("ES") may be hardwired in series with the "Start" switch, and the relay logic should reflect this.
--[\]----[\]----+--[ ]--+---------( )
ES Stop | Start | Run
| |
+--[ ]--+
Run
-------[ ]--------------( )
Run Motor
The above realizes the function: Run = (NOT ES) AND (NOT Stop) AND (Start OR Run) |
Complex logic
[edit]Here is an example of what two rungs in a ladder logic program might look like. In real-world applications, there may be hundreds or thousands of rungs.
Typically, complex ladder logic is "read" left to right and top to bottom. As each of the lines (or rungs) are evaluated the output coil of a rung may feed into the next stage of the ladder as an input. In a complex system there will be many "rungs" on a ladder, which are numbered in order of evaluation:
This represents a slightly more complex system for rung 2. After the first line has been evaluated, the output coil "A/C" is fed into rung 2, which is then evaluated and the output coil "Cooling" could be fed into an output device "Compressor" or into rung 3 on the ladder. This system allows very complex logic designs to be broken down and evaluated.
Additional functionality
[edit]Additional functionality can be added to a ladder logic implementation by the PLC manufacturer as a special block. When the special block is powered, it executes code on predetermined arguments. These arguments may be displayed within the special block.
+-------+
-----[ ]--------------------+ A +----
Remote unlock +-------+
Remote counter
+-------+
-----[ ]--------------------+ B +----
Interior unlock +-------+
Interior counter
+--------+
--------------------+ A + B +-----------
| into C |
+--------+
Adder
|
In this example, the system will count the number of times that the interior and remote unlock buttons are pressed. This information will be stored in memory locations A and B. Memory location C will hold the total number of times that the door has been unlocked electronically.
PLCs have many types of special blocks. They include timers, arithmetic operators and comparisons, table lookups, text processing, PID control, and filtering functions. More powerful PLCs can operate on a group of internal memory locations and execute an operation on a range of addresses, for example, to simulate a physical sequential drum controller or a finite-state machine. In some cases, users can define their own special blocks, which effectively are subroutines or macros. The large library of special blocks along with high-speed execution has allowed use of PLCs to implement very complex automation systems.
Limitations and successor languages
[edit]Ladder notation is best suited to control problems where only binary variables are required and where interlocking and sequencing of binary is the primary control problem. Like all parallel programming languages, the sequential order of operations may be undefined or obscure; logic race conditions are possible which may produce unexpected results. Complex rungs are best broken into several simpler steps to avoid this problem. Some manufacturers avoid this problem by explicitly and completely defining the execution order of a rung, however, programmers may still have problems fully grasping the resulting complex semantics.
Analog quantities and arithmetical operations are clumsy to express in ladder logic and each manufacturer has different ways of extending the notation for these problems. There is usually limited support for arrays and loops, often resulting in duplication of code to express cases that in other languages would call for use of indexed variables.
As microprocessors have become more powerful, notations such as sequential function charts and function block diagrams can replace ladder logic for some limited applications. Some newer PLCs may have all or part of the programming carried out in a dialect that resembles BASIC, C, or other programming language with bindings appropriate for a real-time application environment.
Popularity
[edit]In 2019, IEEE Spectrum ranked ladder logic as number 50 out of 52 in a list of popular programming languages.[3]
See also
[edit]References
[edit]- ^ "The Basics of Ladder Logic".
Ladder logic uses switch or relay contacts to implement Boolean expressions. In years past, ladder logic was made possible with discrete relays and was sometimes termed relay logic.
- ^ Edward W. Kamen Industrial Controls and Manufacturing, (Academic Press, 1999) ISBN 0123948509, Chapter 8 Ladder Logic Diagrams and PLC Implementations
- ^ "Interactive: The Top Programming Languages". IEEE Spectrum. Archived from the original on 2019-09-18.
Further reading
[edit]- Walker, Mark John (2012-09-08). The Programmable Logic Controller: its prehistory, emergence and application (PDF) (PhD thesis). Department of Communication and Systems Faculty of Mathematics, Computing and Technology: The Open University. Archived (PDF) from the original on 2018-06-20. Retrieved 2018-06-20.
External links
[edit]- "Chapter 6: ladder logic" by Tony R. Kuphaldt
Ladder logic
View on GrokipediaOverview and History
Definition and Purpose
Ladder logic, also known as ladder diagram (LD), is a rule-based graphical programming language standardized under IEC 61131-3 for programming programmable logic controllers (PLCs).[6] This standard specifies the syntax, semantics, and graphical representation of LD as one of five programming languages for industrial automation systems, enabling consistent implementation across PLC vendors.[7] The primary purpose of ladder logic is to control machinery and processes in manufacturing environments by digitally simulating the behavior of electrical relay logic circuits.[8] It facilitates the design of control sequences for applications such as motor drives, conveyor systems, and safety interlocks, allowing engineers to automate operations that were traditionally handled by hardwired relays.[1] Key characteristics of ladder logic include its visual representation through diagrams consisting of vertical rails and horizontal rungs, with symbols for inputs (e.g., switches) and outputs (e.g., solenoids) connected by logical operators like AND, OR, and NOT. Programs are executed in a continuous scan cycle, comprising an input scan to read field device statuses, a logic solve phase to evaluate the rungs sequentially from top to bottom and left to right, and an output update to reflect the results to actuators.[9] The name "ladder logic" derives from its resemblance to the ladder-like diagrams used in relay-based control systems, where power rails and cross-connections mimic electrical schematics.[8] Its roots lie in the relay logic diagrams of early industrial control systems.[10]Historical Development
Ladder logic originated in the early 20th century as a graphical method for documenting and designing hardwired relay-based control systems in manufacturing environments. These relay ladder diagrams visually represented the interconnections of electromechanical relays, switches, and other components in control panels, mimicking the structure of electrical schematics to facilitate troubleshooting and maintenance. This approach became standard in industrial automation for its intuitive resemblance to physical wiring, allowing electricians familiar with relay circuits to interpret complex logic without needing specialized programming knowledge. A pivotal milestone occurred in 1968 when Richard Morley, working through Bedford Associates, invented the first programmable logic controller (PLC) in response to a request from General Motors (GM) to replace bulky relay racks with a more flexible, reprogrammable system for automotive assembly lines. The PLC was designed to emulate relay logic digitally, using ladder logic as its primary programming method to ensure familiarity for maintenance personnel accustomed to relay diagrams. The prototype Modicon 084 PLC, programmed exclusively in ladder logic, was demonstrated and installed at GM's Hydra-Matic division in 1969, marking the first industrial deployment and significantly reducing wiring complexity while enabling easier modifications to control sequences.[11][12][13] During the 1970s, ladder logic expanded rapidly within the automotive and process industries as PLC adoption grew beyond GM. Modicon's systems, commercialized from the late 1960s, set the template for ladder-based programming, while competitors like Allen-Bradley introduced their Bulletin 1774 PLC in 1970—the first to explicitly use the term "programmable logic controller"—standardizing ladder-like interfaces that mirrored relay schematics for broad accessibility. This era saw PLCs proliferate in manufacturing, displacing thousands of relays per installation and boosting efficiency in sectors like assembly and chemical processing.[4][14] The 1980s and 1990s brought formalization to ladder logic through the shift to software-based implementations, driven by microprocessor advancements that minimized reliance on physical relays and enabled more compact, cost-effective PLC hardware. Graphical editors emerged, allowing users to draw ladder diagrams directly on computers rather than hand-wiring or using punch cards, which streamlined development and debugging in complex systems. This evolution culminated in the 1993 publication of the IEC 61131-3 standard, which officially codified Ladder Diagram (LD) as one of five standardized PLC programming languages, ensuring interoperability and promoting ladder logic's enduring role in industrial control.[15][16]Basic Structure and Syntax
Diagram Components
Ladder logic diagrams are graphical representations that emulate the structure of relay-based control circuits, utilizing specific visual elements to denote inputs, outputs, and logic flow. The fundamental structure includes two vertical power rails: the left rail symbolizes the incoming power source, typically always energized, while the right rail represents the common return path, completing the circuit. These rails form the vertical boundaries of the diagram, with power conceptualized as flowing horizontally from left to right across the diagram. Horizontal lines, known as rungs, connect the power rails and serve as individual logic networks or control lines, each encapsulating a complete Boolean expression or sequential operation. Multiple rungs stack vertically to form the full program, allowing for complex control strategies while maintaining a clear, hierarchical visual layout. Rungs are the primary building blocks for organizing logic, ensuring that each operates independently yet contributes to the overall system behavior. Inputs to the logic are represented by contact symbols, which control the continuity of power flow based on the state of physical devices such as sensors or switches. A normally open (NO) contact, depicted as two parallel vertical lines (|--|), remains open in its default state and closes to allow power flow when the associated input condition is true (e.g., a sensor detecting presence). Conversely, a normally closed (NC) contact, shown as two parallel lines with a diagonal slash (|--|/|), is closed by default and opens to interrupt flow when the input is true. These symbols directly map to real-world switching behavior, facilitating intuitive programming for electrical engineers. Outputs are symbolized by coil icons, which activate connected devices like motors, solenoids, or indicator lights when power reaches them. The standard coil, illustrated as a pair of parentheses (--( )--), energizes its associated output upon receiving power flow, setting the corresponding bit to true. Variations include set (S) and reset (R) coils for latching outputs, denoted as --(S)-- and --(R)--, which maintain state until explicitly changed. These elements ensure that outputs reflect the cumulative logic from preceding contacts on the rung. Addressing schemes assign unique identifiers to diagram elements, linking them to physical I/O modules or internal memory. In many programmable logic controller (PLC) systems, such as those from Rockwell Automation, inputs are referenced using notations like I:0/0, where "I" indicates input, "0" the slot or module number, and "/0" the specific bit within that module. Outputs follow a similar format, e.g., O:0/1 for output slot 0, bit 1. This structured addressing enables precise mapping between diagram symbols and hardware points, supporting scalable system design.[17] Power flow rules dictate how the diagram is interpreted: logic evaluates strictly from left to right along each rung, propagating an energized state only if all necessary contacts are closed, and rungs are scanned sequentially from top to bottom during program execution. An energized path from the left rail through valid contacts to a coil will activate that output, mimicking electrical current in a relay circuit. This directional evaluation ensures predictable behavior and aligns with the graphical analogy of power distribution.[18] Standard diagram conventions draw from established symbology to promote consistency across implementations. The ANSI/ISA-5.2 standard specifies symbols for binary logic elements, including relay contacts and coils, originally developed for process operations and interlock systems. While this provides a foundational set—such as basic NO and NC contacts—vendor-specific notations may introduce extensions, like abbreviated addressing or additional graphical modifiers, to accommodate proprietary hardware features. The following table summarizes core symbols as defined in related international standards:| Symbol Type | Graphical Representation | Description |
|---|---|---|
| Normally Open Contact | -- | |
| Normally Closed Contact | --/ | |
| Standard Coil | --( )-- | Energizes output when power reaches it. |
| Power Rail (Left) | | (vertical line) | Represents incoming power source. |
| Power Rail (Right) | | (vertical line) | Represents return path. |
| Rung | Horizontal line | Logic path connecting rails. |
Rung Logic and Execution
In ladder logic, each rung represents an independent Boolean equation that evaluates the logical conditions between input contacts and output coils, with multiple rungs collectively forming the overall program ladder executed by a programmable logic controller (PLC).[20] This structure mimics relay logic circuits, where the left power rail connects to input conditions, and the right rail leads to output actions, ensuring modular and sequential processing.[21] The execution model of ladder logic operates within a continuous cyclic scan performed by the PLC, typically lasting 1 to 100 milliseconds depending on program complexity and hardware.[20] During each scan cycle, the PLC first reads the status of all physical inputs and stores them in an input image table; it then evaluates the ladder logic rungs sequentially to solve the Boolean equations using bitwise operations on memory bits; finally, it updates the physical outputs from the output image table and performs diagnostic housekeeping.[20] This model, defined in the IEC 61131-3 standard, ensures deterministic and repeatable control in industrial environments by isolating input reading from output writing to prevent mid-scan disruptions. Boolean evaluation within a rung follows electrical circuit principles: contacts in series implement AND logic, requiring all conditions to be true for current to flow through; parallel branches implement OR logic, where any true condition allows flow; and normally closed (NC) contacts provide negation by inverting the signal.[21] Rungs are processed from left to right, simulating current flow from the power rail to the output coil, which energizes only if the cumulative logic evaluates to true.[20] The scan proceeds in a top-to-bottom direction across rungs and left-to-right within each rung, enforcing a linear execution order without inherent feedback loops in basic implementations to maintain predictability.[21] This unidirectional flow aligns with the IEC 61131-3 execution semantics for ladder diagrams, prioritizing simplicity and avoiding race conditions in standard operation. Basic error handling in ladder logic execution addresses fault conditions such as missing or invalid I/O modules, which trigger diagnostic flags in the PLC's status registers during the housekeeping phase of the scan cycle.[20] Additionally, watchdog timers monitor for scan time overruns, halting the PLC and entering a safe stop mode if the cycle exceeds a predefined threshold, as specified in IEC 61131-3 task configurations to prevent system instability.Programming Examples
Simple Logic Circuits
Ladder logic implements basic Boolean operations through the arrangement of contacts and coils on rungs, mimicking electrical relay circuits to evaluate logical conditions. These simple circuits form the foundation for more complex control programs, using normally open (NO) and normally closed (NC) contacts to represent input states.[3][22]Logical AND
The logical AND operation in ladder logic requires all input conditions to be true for the output to energize, achieved by placing NO contacts in series on a rung. For example, two switches must both be closed to energize a light, simulating a basic security system where multiple conditions must align.[3][22] A textual representation of the rung for a two-input AND is:|--[A]--[B]--(LAMP)--
|--[A]--[B]--(LAMP)--
| Input A | Input B | Output |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
Logical OR
The logical OR operation allows the output to energize if any input condition is true, implemented by connecting NO contacts in parallel branches on a rung. For instance, multiple sensors can activate a motor if at least one detects an object, such as in a simple conveyor system trigger.[3][22] A textual representation of the rung for a two-input OR is:|--[A]--+--(MOTOR)--
| |
|--[B]--+
|--[A]--+--(MOTOR)--
| |
|--[B]--+
| Input A | Input B | Output |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
AND with NOT
Combining AND with negation uses an NC contact in series with NO contacts, where the negated input must be false for the overall condition to be true. For example, an alarm activates if a pressure sensor indicates excess pressure (NO contact closed) while a safety interlock is disengaged (NC contact closed when off).[23][24] A textual representation of the rung for this AND with NOT is:|--[PRESSURE]--[/INTERLOCK]--(ALARM)--
|--[PRESSURE]--[/INTERLOCK]--(ALARM)--
| Input PRESSURE | Input INTERLOCK | Output |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
Industrial Control Circuits
Industrial control circuits in ladder logic are designed to manage machinery operations safely and reliably, often incorporating latching mechanisms to maintain states and interlocks to prevent hazardous conditions. A fundamental example is the STOP/START circuit, which uses latching relay logic to control devices like motors. In this circuit, a momentary normally open (NO) start button initiates operation by energizing a run coil, while a maintained normally closed (NC) stop button de-energizes it. The latching is achieved through a seal-in contact parallel to the start button, ensuring the circuit remains powered after the start button is released. For instance, with input assignments such as X1 for start (NO) and X2 for stop (NC), the output Y1 (run coil) energizes when X1 is pressed, passing power through X2 and the seal-in contact of Y1 itself.[25][26] This pattern extends to motor control circuits, particularly forward/reverse operations with interlocks to avoid simultaneous activation that could damage equipment. In a typical forward/reverse setup, separate rungs control forward (Y1) and reverse (Y2) contactors, each including an NC interlock contact from the opposite direction's output to block conflicting signals. Overload protection is integrated via NC contacts from thermal overload relays, which open to de-energize the circuit if current exceeds safe limits. Using I/O like X1 (forward start, NO), X2 (reverse start, NO), X3 (stop, NC), X4 (overload, NC), the forward rung might feature: X3 in series with X1, paralleled by Y1's NO seal-in, followed by X4 and the NC interlock from Y2, outputting to Y1. Similarly, the reverse rung mirrors this with X2, Y2 seal-in, X4, and NC from Y1. When running forward (Y1 energized), the reverse rung's interlock opens, preventing activation until stop is pressed and Y1 de-energizes. In a faulted state, such as overload (X4 open), both outputs de-energize, stopping the motor.[26][27] To visually indicate an overload trip, a dedicated rung can drive an output light when the overload contact opens. For example, in a CLICK PLC, with the overload input assigned to X4 (normally closed, opens on trip) and the tripped light output to Y3, the rung uses a normally closed contact [/X4] in series with the output coil (Y3). This energizes the light precisely when X4 opens due to the overload condition.[28][29] Rung Example for Overload Trip Indicator (Text Representation):|----[/X4 (NC)]---------------------------(Y3 OL Tripped Light)----|
|----[/X4 (NC)]---------------------------(Y3 OL Tripped Light)----|
--|/X2|--+--|X1|--(Y1)
|
+--|Y1|--
--|/X2|--+--|X1|--(Y1)
|
+--|Y1|--
--|/X3|--+--|X1|--|/X4|--|/Y2|--(Y1)
|
+--|Y1|--------------------
--|/X3|--+--|X1|--|/X4|--|/Y2|--(Y1)
|
+--|Y1|--------------------
Advanced Functionality
Timers, Counters, and Instructions
Ladder logic extends beyond basic Boolean operations through specialized instructions for handling time-based delays and event counting, primarily implemented as function blocks placed on rungs. These instructions simulate electromechanical timers and counters while providing programmable parameters for precise control in industrial processes. Timers and counters are essential for sequencing operations, such as delaying motor starts or tracking production counts, and are standardized in frameworks like IEC 61131-3 for interoperability across PLC vendors.[32][33] Timers in ladder logic include on-delay (TON), off-delay (TOF), and retentive on-delay (RTO) types, each configured with a preset time (PT) value, such as T#5s for 5 seconds, and an accumulated or elapsed time (ET or ACC) value that tracks progress. The TON function block activates its output (Q or DN) after the input (IN) condition remains true for the full PT duration, resetting ET to zero if the input drops before completion; this non-retentive behavior suits applications requiring fresh starts on interruptions.[34] For example, a TON timer with PT set to T#10s can delay the start of a conveyor belt after a start button is pressed, ensuring safe initialization by holding the motor output false until the delay elapses.[35] The TOF block, conversely, keeps the output true immediately upon input activation but delays deactivation for PT after the input goes false, ideal for extending signal durations like alarm acknowledgments.[36] RTO timers accumulate time across power cycles or interruptions without resetting ACC unless explicitly commanded, making them suitable for totalizing run times in intermittent processes.[37] Counters operate similarly as function blocks, with up-counter (CTU), down-counter (CTD), and reset inputs managing preset values (PV), such as 10 for counting parts, and current values (CV or ACC). The CTU increments CV by one on each rising edge of the count input (CU) until CV reaches or exceeds PV, at which point the done output (Q or DN) sets true; overflow occurs if CV exceeds the maximum integer limit (e.g., 32767 for 16-bit), typically wrapping around or halting depending on the PLC implementation.[38] A CTD decrements CV on rising edges of the count-down input (CD) from PV down to zero or below, setting Q true when CV ≤ 0, with underflow preventing further decrement below zero in standard configurations. The reset input (R), often part of the block, sets CV to zero and clears Q when energized, ensuring counters restart for new cycles.[39][33] In a batch processing scenario, a CTU with PV=10 can count 10 filled containers before activating an alarm output, resetting via R after acknowledgment to prepare for the next batch.[40] Beyond timers and counters, ladder logic incorporates data manipulation instructions like compare (EQU, NEQ), move (MOV), and basic arithmetic (ADD, SUB), treated as function blocks with inputs for operands and outputs for results or status. The EQU instruction evaluates if two values are equal, outputting true if they match, while NEQ outputs true for inequality, both supporting types like integers for conditional branching.[33] MOV transfers a source value to a destination without altering the source, useful for copying sensor data to registers. ADD sums two or more inputs (e.g., ADD(IN1:=5, IN2:=3, OUT=>8)), and SUB subtracts them (e.g., SUB(IN1:=10, IN2:=4, OUT=>6)), handling integer or real numbers with overflow flags in some systems.[41] These instructions execute as function blocks on ladder rungs, evaluated left-to-right during PLC scans, with an enable input (EN) that activates the block when true and an enable output (ENO) mirroring EN for chaining; done bits (DN or Q) indicate completion, such as a timer expiring or counter reaching PV, while fault bits signal errors like division by zero in math operations. For instance, a pump warm-up sequence might use a TON with PT=T#30s enabled by a start signal, setting DN to energize the pump motor only after the delay, preventing cold starts.[42] Rung conditions preceding the block determine EN, and outputs feed subsequent logic, maintaining the sequential flow akin to relay evaluation.[43]| Instruction Type | Key Parameters | Typical Behavior |
|---|---|---|
| TON (On-Delay) | IN (BOOL), PT (TIME), Q (BOOL), ET (TIME) | Delays output activation by PT; resets on input false.[34] |
| TOF (Off-Delay) | IN (BOOL), PT (TIME), Q (BOOL), ET (TIME) | Delays output deactivation by PT after input false.[36] |
| RTO (Retentive) | IN (BOOL), PT (TIME), DN (BOOL), ACC (TIME) | Accumulates time retentively; requires reset to clear.[37] |
| CTU (Up Counter) | CU (BOOL edge), R (BOOL), PV (INT), Q (BOOL), CV (INT) | Increments CV to PV; Q true at limit.[38] |
| CTD (Down Counter) | CD (BOOL edge), R (BOOL), PV (INT), Q (BOOL), CV (INT) | Decrements CV from PV to 0; Q true at zero.[39] |
| EQU/NEQ (Compare) | IN1/IN2 (e.g., INT), OUT (BOOL) | OUT true if equal (EQU) or not equal (NEQ).[33] |
| MOV (Move) | IN (e.g., INT), OUT (e.g., INT) | Copies IN to OUT.[44] |
| ADD/SUB (Math) | IN1/IN2 (e.g., INT), OUT (INT) | Sums/subtracts inputs to OUT.[41] |
