🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
NEWSLIVESearch All Content
đŸ’ŧ Servicesâ„šī¸ Aboutâœ‰ī¸ ContactView Pricing Plansfrom $10

PLC Ladder Logic and Industrial Automation

Robotics & MechatronicsHardware and AutomationđŸŸĸ Free Lesson

PLC Ladder Logic and Industrial Automation

What You'll Learn

  • 1Compute the PLC scan cycle and explain what its length costs in reaction time
  • 2Build a fail-safe start and stop seal-in with an on-delay timer and counter
  • 3Scale raw analog counts into engineering units with the standard linear map
  • 4Evaluate positional and incremental PID output and derive a minimum safety distance

A production cell lives or dies by its scan cycle: inputs are sampled, rungs evaluated, and outputs written once per scan, so scan length sets the reaction time of the machine. Ladder logic looks like a wiring diagram, but the arithmetic is short: add the phases, reason about one scan of delay, and scale what the analog input reports. This lesson works the scan budget, a latched start circuit with a timer, and the PID and safety-distance calculations commissioning engineers perform.

Theory and Foundations

The controller copies field inputs into the image table, solves the program, transfers the image table to the outputs, then runs housekeeping such as diagnostics and communications.

The latched-start rung is the commonest in industry: a momentary start energizes a coil that its own contact holds, with a normally closed stop in series so a broken wire stops the machine.

Timers are scanned, not continuous: an on-delay asserts only after its accumulated value passes the preset while the rung stays true.

Analog channels arrive as integer counts, converted with the same linear map before any control logic sees them.

Discrete PID evaluates once per sample time, so the integral is a sum scaled by and the derivative a difference divided by .

The equivalent incremental form changes only the actuator, which makes clamp handling straightforward.

Safety distances are derived, not tuned: reaction time times approach speed, plus an offset for the detection plane. The standard form for a detection device such as a light curtain is

with for detection capability of 40 mm or better, the system response in seconds, the detection plane height in millimetres, and the minimum distance from the hazard.

Key Formulas

Worked Examples

Ladder elementFunctionStation useCommon pitfall
Examine if closed and openbit tests in a rungpermissions and interlocksmixing no and nc field wiring
Seal-in branchlatches a coilstart and stopstop not wired normally closed
On-delay timer TONdelays assertionpump after startpreset counted in scan steps
Retentive timer and counteraccumulates while falsecycle and reject countsmissing reset rung
Compare and moveanalog setpointsrecipe changesscaling factors in wrong units
PID function blockclosed loop controltemperature, pressure, speedsample time mismatched to scan
Safety relay contactsdual channel tripe-stop and guard monitoringdefeating the diagnostic test

Real-World Examples

  • IEC 61131-3 languages - One station mixes ladder for interlocks, function block diagram for drives, and structured text for recipes, all compiled to one scan.
  • Programmable controllers - A 500 I/O rack scans in 5 to 10 ms, and PROFINET remote IO adds 1 to 4 ms of network latency on top.
  • Safety functions - A dual channel emergency stop to ISO 13849-1 PL d uses redundant contacts, cross monitoring, and a safety relay whose de-energize time joins in the stop calculation.
  • Sequencing - Fill, clamp, weld, and release stations are step sequences of seal-ins and timers, with counters tracking tool life and diverting rejects.

â„šī¸Add the scan to every timing budget

A 6 ms scan adds up to 6 ms of reaction delay before any sensor or actuator delay, so the response time in the minimum distance formula must include it.

The Seal-In and Timer as Structured Text

The seal-in is the rung every technician can debug live, and writing it in structured text shows that it is one boolean expression retained between scans. Pair it with an on-delay timer whose accumulated value advances only while the rung stays true and the start sequence becomes deterministic: releasing the start button changes nothing, opening the stop clears the latch on the next scan, and the pump asserts one preset after the conveyor has run continuously for that long. Wire the stop normally closed so a broken conductor stops the machine.

PROGRAM ConveyorStart
VAR
    Start    : BOOL;   (* momentary, normally open  *)
    Stop     : BOOL;   (* wired normally closed     *)
    Run      : BOOL;   (* seal-in coil              *)
    LubTimer : TON;
    Pump     : BOOL;
END_VAR

Run := (Start OR Run) AND NOT Stop;

LubTimer(IN := Run, PT := T#3S);
Pump := LubTimer.Q;
END_PROGRAM

Scan, Scaling, and PID in One Check

Three short functions cover most of what a commissioning engineer verifies on the first day: the scan length sets the reaction floor, the linear map turns raw counts into engineering units, and the positional PID output can be compared against the incremental form to prove that two implementations agree. When they disagree the sample time is usually written where milliseconds were expected for seconds, or the integral sum was accumulated without its scaling factor. Run the three checks together and a download that lengthened the scan shows up immediately.

python
def scan_ms(t_in, t_prog, t_out, t_overhead):
    return t_in + t_prog + t_out + t_overhead

def scale(raw, raw_min, raw_max, eu_min, eu_max):
    return (raw - raw_min) / (raw_max - raw_min) * (eu_max - eu_min) + eu_min

def pid_positional(kp, ki, kd, ts, e, e_prev, i_sum):
    return kp * e + ki * ts * i_sum + kd * (e - e_prev) / ts

scan = scan_ms(1.2, 3.5, 1.0, 0.3)
temp = scale(3000, 0, 4000, 0, 250)
out = pid_positional(2.0, 0.5, 0.1, 0.1, 10, 12, 60)
print(round(scan, 1), round(temp, 1), round(out, 1))   # 6.0 187.5 21.0

Common Mistakes

Wiring the stop as a normally open contact

Fix: A cut wire then looks like a released stop and the machine runs on; wire it normally closed so failure de-energizes the coil.

Ignoring scan time in timer accuracy

Fix: Timers evaluate once per scan, so a 3.000 s preset can assert one scan late; add the scan to the reaction budget.

Scaling raw counts without checking the range

Fix: Scale over the whole span, not one count: 0 to 4000 counts on 0 to 250 degrees C is 0.0625 per count.

Key Takeaways

  • Scan time is input plus program plus output plus overhead: 1.2 plus 3.5 plus 1.0 plus 0.3 equals 6.0 ms.
  • The seal-in holds a coil after a momentary start while a normally closed stop stays in series for fail-safe behavior.
  • Analog scaling is a linear map: 3000 of 4000 counts on a 0 to 250 range reads 187.5 degrees C at 0.0625 per count.
  • Positional and incremental PID agree exactly: 21.0 percent output and a minus 6.5 percent step.

Frequently Asked Questions

Why is ladder logic still dominant?

Because it mirrors the contact wiring it replaces, scans transparently, and lets a technician debug a live rung without a compiler.

What happens when a program is downloaded while the machine runs?

An online edit compiles into a shadow buffer and switches between scans; a full download stops the processor briefly. Both need a defined process state, so production downloads happen behind a lockout.

Does a PLC replace a safety relay?

Yes, to PL d or higher, but only with dual channel inputs, diagnostic coverage, and certified logic; a plain scan with single channel contacts is not one.

Interview Questions

Q1: A light curtain with 14 mm detection sits at 900 mm height and 20 ms system response. What is the minimum distance?

C = 1200 minus 0.4 x 900 = 840 mm, and S = 1600 x 0.020 plus 840 = 872 mm from the hazard.

Q2: Why must a stop button be normally closed?

So the circuit fails de-energized: a broken wire behaves exactly like a pressed stop and removes torque from the drive.

CW

ChatWhole Learn Editorial Team

Written by experienced data scientists, software engineers, and educators. All content is reviewed by industry professionals to ensure accuracy and relevance.

Last reviewed: 2026-10-16

—
☆☆☆☆☆
0 ratings

Rate & Feedback

Need Expert Robotics & Mechatronics Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement