Bit Logic Operations
Contacts, Coils & Edge Detection
The heart of PLC programming. Bit logic instructions handle every Boolean operation — from simple contacts and coils to flip-flops and edge detection. Master these and you can build any automation logic.
What Are Bit Logic Operations?
Bit logic operations are the most fundamental instructions in PLC programming. They work with Boolean signals (TRUE/FALSE, 1/0) — reading input states, combining conditions with AND/OR logic, and controlling outputs. In LAD, these appear as contacts and coils on rungs. In FBD, they appear as AND/OR/NOT gate boxes.
Every PLC program uses bit logic instructions extensively. A motor start/stop circuit, an alarm condition, a valve interlock — they all begin with contacts reading sensor states and end with coils driving actuators.
Contacts — Reading Input States
Contacts read the Boolean state of a tag and pass it along the logic chain
Normally Open Contact
—| |—What It Does
Reads a Boolean tag (BOOL). If the tag is TRUE (1), the contact closes and passes power (RLO = TRUE) to the next element. If the tag is FALSE (0), the contact is open and blocks power flow. This is the most used instruction in LAD programming.
When to Use It
Every time you need to check if a condition is TRUE: is a button pressed? Is a sensor active? Is a flag set? Place a normally open contact and assign your tag to it.
Pro Tips
The name 'Normally Open' comes from relay logic — the contact is open (not passing current) in its normal/rest state. It closes when energized.
Multiple NO contacts in series create AND logic. Multiple NO contacts in parallel branches create OR logic.
In FBD, the equivalent is simply wiring a BOOL variable to an AND/OR box input — no explicit contact symbol needed.
Normally Closed Contact
—|/|—What It Does
The inverse of a normally open contact. If the tag is FALSE (0), the contact is closed and passes power. If the tag is TRUE (1), the contact opens and blocks power. It acts as a NOT operation on the tag value.
When to Use It
When you need to check that a condition is NOT true: emergency stop not pressed, no fault active, limit switch not reached. Very common for safety interlocks and alarm conditions.
Pro Tips
Use NC contacts for emergency stops and safety circuits — they fail safe. If the wire breaks, the NC contact opens and stops the machine.
In FBD, the equivalent is a negated input (small circle on the input pin of an AND/OR box).
Don't confuse the NC contact instruction with a physically NC push-button. They are independent concepts.
Invert RLO
—|NOT|—What It Does
Inverts (negates) the current Result of Logic Operation (RLO). If the logic chain up to this point evaluates to TRUE, NOT makes it FALSE, and vice versa. It operates on the accumulated logic result, not on a specific tag.
When to Use It
When you need to invert a complex logic expression rather than a single tag. Instead of rewriting the entire condition with inverted contacts, place NOT at the end to flip the result.
Pro Tips
NOT inverts the entire RLO at that point in the chain — it's different from an NC contact which inverts only one tag.
In FBD, use the NOT box or negate the output of a logic gate.
Use sparingly — overuse of NOT makes logic hard to read. Often, restructuring the logic is clearer.
Coils — Controlling Outputs
Coils write the result of the logic chain to an output tag
Assignment
—( )—What It Does
Writes the current RLO (Result of Logic Operation) to a Boolean tag. If the logic chain is TRUE, the tag becomes TRUE. If FALSE, the tag becomes FALSE. This is the standard output coil — it directly reflects the input logic every scan cycle.
When to Use It
For any output that should directly follow its input conditions. A pilot light that's ON when a motor runs, a valve that opens when conditions are met. The output tracks the input — when conditions go FALSE, the output goes FALSE too.
Pro Tips
The assignment coil is 'non-retentive' — it writes every scan. If the logic goes FALSE, the output immediately goes FALSE.
A tag should only be assigned in ONE network. Multiple assignments to the same tag cause the last one to win, leading to unpredictable behavior.
In FBD, the assignment is simply connecting the output of a logic gate to a BOOL tag.
Negate Assignment
—(/)—What It Does
Writes the inverted RLO to a Boolean tag. If the logic chain is TRUE, the tag becomes FALSE. If the logic chain is FALSE, the tag becomes TRUE. It combines Assignment + NOT in one instruction.
When to Use It
When an output should be active in the opposite condition. For example, a 'system OK' lamp that turns OFF when a fault is detected. Instead of inverting the entire logic chain, use the negated coil.
Pro Tips
Equivalent to placing a NOT before a regular assignment coil, but more compact.
Use with caution — negated coils can be confusing to read. Sometimes it's clearer to restructure the logic.
In FBD, this is a negated output connection.
Reset Output
—(R)—What It Does
When the RLO is TRUE, the tag is set to FALSE (0). When the RLO is FALSE, the tag is unchanged (retains its current value). This is a one-directional operation — it can only turn things OFF, never ON.
When to Use It
In Set/Reset circuits: one network Sets the output (turns ON), another Resets it (turns OFF). Use Reset for stop conditions, fault clearing, and alarm acknowledgment. The Reset typically has priority in safety logic.
Pro Tips
Reset only acts when its RLO is TRUE. When RLO is FALSE, the output stays unchanged — it does NOT set it to TRUE.
In a S/R pair, the instruction that appears LAST in the program has priority (if both conditions are TRUE simultaneously).
Reset is retentive — after a Reset, the output stays FALSE until explicitly Set again.
Set Output
—(S)—What It Does
When the RLO is TRUE, the tag is set to TRUE (1). When the RLO is FALSE, the tag is unchanged (retains its current value). This is a one-directional operation — it can only turn things ON, never OFF.
When to Use It
In Set/Reset circuits: use Set for start conditions, latch signals, and first-run flags. Once Set, the output remains TRUE until explicitly Reset — making it 'self-latching' without needing a seal-in contact.
Pro Tips
Set only acts when its RLO is TRUE. When RLO is FALSE, the output stays unchanged — it does NOT reset it.
Classic motor control: Network 1 = Start button → Set Motor. Network 2 = Stop button OR Fault → Reset Motor.
Be careful with retentive tags in safety circuits — after a power cycle, Set outputs may retain their last state depending on the DB settings.
Bit Field Operations
Set or reset a range of bits in a single operation
SET_BF — Set Bit Field
What It Does
Sets a contiguous group of bits to TRUE starting from a specified address. You define the starting bit and the number of bits to set. When the RLO is TRUE, all specified bits are set to 1.
When to Use It
When you need to activate multiple related outputs simultaneously — for example, setting all bits of a status word, initializing a group of flags, or activating a bank of outputs at once.
Pro Tips
Useful for batch operations instead of writing individual Set instructions for each bit.
The number of bits parameter determines how many consecutive bits are affected.
Like Set, this only acts when RLO is TRUE — bits are unchanged when RLO is FALSE.
RESET_BF — Reset Bit Field
What It Does
Resets a contiguous group of bits to FALSE starting from a specified address. You define the starting bit and the number of bits to reset. When the RLO is TRUE, all specified bits are cleared to 0.
When to Use It
When you need to clear multiple flags or outputs at once — for example, clearing all alarm bits in a status word, resetting a group of outputs during shutdown, or initializing a data area.
Pro Tips
The counterpart of SET_BF — use them together for group-level Set/Reset operations.
Particularly useful for clearing alarm words or status registers in one operation.
Like Reset, this only acts when RLO is TRUE — bits are unchanged when RLO is FALSE.
Flip-Flops — Latching Circuits
Bistable elements that remember their state until explicitly changed
SR — Set/Reset Flip-Flop
What It Does
A bistable flip-flop with Set priority. It has two inputs: S (Set) and R (Reset), and one output Q. When S=TRUE, Q becomes TRUE. When R=TRUE, Q becomes FALSE. When both S and R are TRUE simultaneously, Q is TRUE (Set dominates).
When to Use It
For latching circuits where the Set condition should have priority. In an SR flip-flop, if both start and stop are pressed at the same time, the output stays ON. Use this when 'start priority' is acceptable.
Pro Tips
SR = Set priority. If S=1 and R=1 → Q=1. Use when starting is more important than stopping.
In safety-critical applications, prefer RS (Reset priority) — it's safer if both conditions trigger simultaneously.
The flip-flop is a single box in both LAD and FBD with S, R inputs and Q output.
RS — Reset/Set Flip-Flop
What It Does
A bistable flip-flop with Reset priority. It has two inputs: R (Reset) and S (Set), and one output Q. When S=TRUE, Q becomes TRUE. When R=TRUE, Q becomes FALSE. When both R and S are TRUE simultaneously, Q is FALSE (Reset dominates).
When to Use It
For latching circuits where safety is paramount. The Reset (stop) condition has priority — if both start and stop are active, the output is OFF. This is the standard choice for motor control and safety interlocks.
Pro Tips
RS = Reset priority. If S=1 and R=1 → Q=0. The safer choice for most industrial applications.
Classic motor control pattern: S = Start_Button AND NOT Fault, R = Stop_Button OR Emergency_Stop OR Fault.
The output Q is retentive within the scan cycle — it holds its value until the flip-flop is evaluated again.
Edge Detection — Detecting Signal Changes
Detect when a signal transitions from FALSE→TRUE or TRUE→FALSE
Scan Operand for Positive Edge
—|P|—What It Does
Detects a rising edge (FALSE→TRUE transition) on a specific operand. The instruction compares the current value with the value from the previous scan. If the value changed from 0 to 1, the RLO is TRUE for exactly one scan cycle. Requires an edge memory bit (M-bit) to store the previous state.
When to Use It
When you need a one-shot pulse from a sustained signal: count button presses, trigger a single action on a level change, increment a counter on each activation. Without edge detection, a held button would trigger every scan cycle.
Pro Tips
You MUST assign a unique edge memory bit (M-bit) — do NOT reuse the same M-bit for multiple edge detections, or they will interfere.
The output is TRUE for exactly one PLC scan cycle (typically 1-50ms). If you need a longer pulse, use a timer.
In LAD, this appears as a contact with 'P' marking. The M-bit tag is shown above/below the contact.
Scan Operand for Negative Edge
—|N|—What It Does
Detects a falling edge (TRUE→FALSE transition) on a specific operand. The instruction compares the current value with the value from the previous scan. If the value changed from 1 to 0, the RLO is TRUE for exactly one scan cycle. Requires an edge memory bit.
When to Use It
When you need to react to a signal turning OFF: detect when a button is released, trigger on sensor deactivation, or capture the moment a process step completes.
Pro Tips
Same rules as positive edge — each negative edge detection needs its own unique M-bit.
Useful for 'button release' actions: start a timer when a button is released, not when pressed.
In a shutdown sequence, use negative edges to detect when each step completes (output goes from ON to OFF).
Set Operand on Positive Edge
—(P)—What It Does
Sets (writes TRUE to) a specified operand for one scan cycle when a positive edge (FALSE→TRUE) is detected on the RLO. Combines edge detection and output assignment in one instruction.
When to Use It
When you want to set a flag or output for exactly one scan on a rising edge, without needing a separate edge detection contact followed by a coil.
Pro Tips
This is a coil-type instruction — it goes at the end of a rung, not in the middle.
Requires an edge memory bit just like the contact version.
The operand is TRUE for one scan only, then automatically returns to FALSE.
Set Operand on Negative Edge
—(N)—What It Does
Sets (writes TRUE to) a specified operand for one scan cycle when a negative edge (TRUE→FALSE) is detected on the RLO. Combines falling edge detection and output assignment in one instruction.
When to Use It
When you want to set a flag or output for exactly one scan on a falling edge. Useful for triggering post-deactivation actions.
Pro Tips
Coil-type instruction — place at the end of a rung.
Requires its own unique edge memory bit.
Often used for 'cleanup' actions that should happen once when a process stops.
P_TRIG — Scan RLO for Positive Edge
What It Does
Detects a rising edge on the RLO (Result of Logic Operation) rather than on a specific operand. When the combined logic result transitions from FALSE to TRUE, the output is TRUE for one scan cycle. The edge memory is stored within the instruction instance.
When to Use It
When you want to detect a rising edge on a complex logic combination, not just a single tag. For example: detect when (Sensor1 AND Sensor2 AND NOT Fault) first becomes TRUE.
Pro Tips
P_TRIG operates on the accumulated RLO — it detects the edge of the entire logic chain before it.
The edge memory is built into the instruction — no separate M-bit needed.
In FBD, P_TRIG is a box with CLK input and Q output.
N_TRIG — Scan RLO for Negative Edge
What It Does
Detects a falling edge on the RLO. When the combined logic result transitions from TRUE to FALSE, the output is TRUE for one scan cycle. The edge memory is stored within the instruction instance.
When to Use It
When you want to detect when a complex condition stops being true. For example: detect the moment (Auto_Mode AND All_Clear) goes from TRUE to FALSE.
Pro Tips
N_TRIG is the falling-edge counterpart of P_TRIG.
No separate M-bit needed — the edge memory is internal.
Useful for detecting the end of a combined condition rather than a single signal.
R_TRIG — Detect Positive Signal Edge
What It Does
An IEC 61131-3 compliant rising edge detector function block. It has a CLK input and a Q output. When CLK transitions from FALSE to TRUE, Q is TRUE for one scan cycle. The edge memory is stored in the instance data of the FB.
When to Use It
When you want IEC-standard edge detection with its own instance data. R_TRIG is a function block — each instance maintains its own edge memory automatically. Preferred in structured, reusable code.
Pro Tips
R_TRIG is an FB — it needs instance data (either its own DB or as a multi-instance in a parent FB). This makes it self-contained and reusable.
Available since V1.0 on S7-1200/1500. This is the IEC 61131-3 standard way of edge detection.
In SCL: myRTRIG(CLK := mySignal); IF myRTRIG.Q THEN ... END_IF;
F_TRIG — Detect Negative Signal Edge
What It Does
An IEC 61131-3 compliant falling edge detector function block. It has a CLK input and a Q output. When CLK transitions from TRUE to FALSE, Q is TRUE for one scan cycle. The edge memory is stored in the instance data of the FB.
When to Use It
When you want IEC-standard falling edge detection with its own instance data. F_TRIG is the falling-edge counterpart of R_TRIG.
Pro Tips
F_TRIG is an FB with its own instance — like R_TRIG, it's self-contained and IEC 61131-3 compliant.
In SCL: myFTRIG(CLK := mySignal); IF myFTRIG.Q THEN ... END_IF;
Prefer R_TRIG/F_TRIG over |P|/|N| contacts when writing reusable library code, as they don't require external M-bits.
Quick Reference — All 20 Bit Logic Instructions
| # | Instruction | LAD Symbol | Shortcut | Description |
|---|---|---|---|---|
| 1 | Normally Open Contact | —| |— | F9 | Passes power when tag is TRUE |
| 2 | Normally Closed Contact | —|/|— | F10 | Passes power when tag is FALSE |
| 3 | Invert RLO | —|NOT|— | — | Inverts the Result of Logic Operation |
| 4 | Assignment | —( )— | Shift + F7 | Writes RLO to output tag |
| 5 | Negate Assignment | —(/)— | — | Writes inverted RLO to output tag |
| 6 | Reset Output | —(R)— | — | Sets tag to FALSE when RLO is TRUE |
| 7 | Set Output | —(S)— | — | Sets tag to TRUE when RLO is TRUE |
| 8 | SET_BF — Set Bit Field | — | — | Sets a range of bits to TRUE |
| 9 | RESET_BF — Reset Bit Field | — | — | Resets a range of bits to FALSE |
| 10 | SR — Set/Reset Flip-Flop | — | — | Flip-flop with Set priority (S=1,R=1 → Q=1) |
| 11 | RS — Reset/Set Flip-Flop | — | — | Flip-flop with Reset priority (S=1,R=1 → Q=0) |
| 12 | Scan Operand for Positive Edge | —|P|— | — | Detects rising edge on an operand |
| 13 | Scan Operand for Negative Edge | —|N|— | — | Detects falling edge on an operand |
| 14 | Set Operand on Positive Edge | —(P)— | — | Sets operand for 1 scan on rising edge |
| 15 | Set Operand on Negative Edge | —(N)— | — | Sets operand for 1 scan on falling edge |
| 16 | P_TRIG — Scan RLO for Positive Edge | — | — | Detects rising edge on the RLO |
| 17 | N_TRIG — Scan RLO for Negative Edge | — | — | Detects falling edge on the RLO |
| 18 | R_TRIG — Detect Positive Signal Edge | — | — | IEC rising edge detector (FB) |
| 19 | F_TRIG — Detect Negative Signal Edge | — | — | IEC falling edge detector (FB) |
Frequently Asked Questions
What is the difference between Set/Reset coils and SR/RS flip-flops?
Set (S) and Reset (R) coils are individual instructions placed in separate networks — you control priority by which network comes last. SR/RS flip-flops are single boxes with both inputs — the priority is built-in (SR = Set priority, RS = Reset priority). Flip-flops are more compact and make the priority explicit.
Which edge detection should I use: |P|/|N|, (P)/(N), P_TRIG/N_TRIG, or R_TRIG/F_TRIG?
|P|/|N| contacts detect edges on a specific tag and need an external M-bit. (P)/(N) coils combine edge detection with output assignment. P_TRIG/N_TRIG detect edges on the RLO (combined logic). R_TRIG/F_TRIG are IEC-standard FBs with built-in memory. For reusable library code, prefer R_TRIG/F_TRIG. For simple inline logic, |P|/|N| contacts are fine.
Why does my Set/Reset circuit behave unexpectedly?
The most common cause is both Set and Reset conditions being TRUE simultaneously. In that case, the last instruction in the program wins. If your Reset network is before your Set network, the output will be Set. Solution: use an RS flip-flop (Reset priority) for safety-critical circuits, or ensure your conditions are mutually exclusive.
Can edge detection work on analog values or only BOOL?
Edge detection instructions (|P|, |N|, R_TRIG, F_TRIG) work only on Boolean signals. For analog values, you need to create a comparison (e.g., value > threshold) that produces a BOOL result, then apply edge detection to that BOOL.