Most PLC programming tutorials hand you a syntax reference and tell you to start typing. That approach skips the one thing that actually determines whether your logic works: understanding how a PLC executes code in the first place. A PLC is not a general-purpose computer, and writing code as if it were one leads to logic errors that are genuinely difficult to trace.
This tutorial builds the mental foundation before you open any software. You will learn what the scan cycle is, why it changes how you think about every line of logic you write, and how physical signals connect to program variables through I/O mapping. From there, you will get a practical overview of the four IEC 61131-3 programming languages, the international standard that governs PLC programming across platforms and vendors. You will also see how the most common beginner mistakes all trace back to one misunderstood concept, and how that same concept becomes your most reliable troubleshooting tool. By the end, you will carry a clear mental model into your first programming session, rather than a list of commands you do not yet know how to use.
A PLC Is Not a Computer, It Is a Scan Engine
If you have written code before, your first instinct when approaching PLC programming will work against you. That instinct needs to be replaced before you write a single rung of logic.
A general-purpose computer runs code sequentially: a function is called, executes its instructions top to bottom, returns a value, and stops. The processor then waits for the next event or call. A PLC does not work this way at all. It runs a continuous, repeating loop called the scan cycle, and that loop never stops as long as the PLC is powered and in run mode.
The Three Phases of Every Scan
Every scan cycle executes three phases in fixed order:
- Input image table refresh. The PLC reads every physical input (switches, sensors, pushbuttons) and copies their states into a block of memory called the input image table. Your program does not read live field inputs. It reads this memory snapshot.
- Logic execution. The PLC evaluates every rung, function block, or statement in your program using the values frozen in the input image table. Output values are written to a second memory block, the output image table, not directly to physical hardware.
- Output image table update. Once logic execution is complete, the PLC pushes the output image table values to the physical output terminals, energizing or de-energizing real-world devices.
Then the cycle starts over. Immediately. Continuously.
How This Differs from a PC
On a PC, code runs when triggered and stops when finished. Nothing re-evaluates unless called again. A PLC re-evaluates every line of logic on every scan, regardless of whether any input has changed. A sensor that has been on for ten minutes still gets read and re-evaluated thousands of times per minute. The machine state is not remembered by the program flow; it is re-computed from current inputs on every pass.
What Scan Time Means in Practice
A full scan cycle on a typical industrial PLC completes in 1 to 20 milliseconds. That number is not just a performance metric; it directly constrains your design. Any event shorter than one scan time can be missed entirely. Time-sensitive sequences, pulse detection, and high-speed counting all require dedicated hardware or instructions that operate outside normal scan execution. If you design a timing sequence assuming your logic responds instantaneously to an input, you are assuming something the scan cycle does not guarantee.
Why Software Engineers Break This Immediately
Engineers coming from software development naturally write logic meant to execute once and exit. A startup sequence coded as a linear block of conditionals seems correct on paper, but in a PLC every condition in that block is re-evaluated on the next scan, often with unintended results. State does not advance because you wrote the steps in order; it advances only because you explicitly designed the program to track and manage transitions across repeated scans.
The required mental shift is this: stop thinking about code that runs and finishes. Start thinking about logic that is continuously re-evaluated against a frozen snapshot of your machine’s state, dozens of times per second, forever.
Everything else in PLC programming builds on that model.
What the Scan Cycle Actually Changes About How You Write Logic
Knowing the scan cycle exists is the first step. Knowing how it forces you to rethink every line you write is what actually makes your logic reliable.
Variable state persistence is the first shift. In a general-purpose function, local variables initialize fresh on every call. PLC variables do not. A BOOL tag that was TRUE at the end of scan 47 is still TRUE at the start of scan 48, unless something explicitly clears it. This is intentional: it is how latches, motor run bits, and mode flags work correctly across hundreds of scans. The problem comes when a beginner expects a variable to reset on its own. It will not. Every tag you use carries its last known state forward until your logic overwrites it.

The instantaneous update assumption is where beginners hit their first hard failure. A common mistake: rung 5 sets an output coil, and rung 8 reads that coil as a condition, assuming it is already live. In many platforms, the output image table is not pushed to the physical output until the end of the scan. The physical device has not responded yet. Any logic that assumes the real-world effect exists mid-scan is building on a false premise. This produces intermittent failures, because behavior can vary with scan load, platform, and timing, making root cause analysis genuinely difficult.
Edge detection is where the scan model creates a specific, non-obvious constraint. Suppose you want to trigger an action exactly once when a pushbutton goes from FALSE to TRUE. A naive approach: check if the bit is TRUE on the current rung. But that bit will be TRUE for every scan while the button is held, so the action fires repeatedly, not once. You cannot reliably compare “current value” to “previous value” across two rungs of ladder code. PLCs solve this with dedicated edge-detection instructions: R_TRIG for rising edge and F_TRIG for falling edge, defined in IEC 61131-3. These instructions internally store the previous scan’s state and fire their output for exactly one scan on the transition. Use them whenever you need a one-shot response to a state change.
Coil conflict is a ladder logic specific trap. If two separate rungs both drive the same output coil, the PLC does not throw an error. It executes both rungs in scan order and the last write wins. Rung 3 might energize the coil; rung 20 might de-energize it. The physical output reflects rung 20’s result every scan, regardless of rung 3. Multiple coils on the same address are almost always a logic design error, and they are easy to create accidentally in large programs.
The failure case that ties all of this together: a classic start/stop motor circuit that passes simulation without a problem but drops the motor run output unpredictably on hardware. The cause is almost always a seal-in rung that reads the output image before the scan completes, combined with a coil conflict introduced during a later edit. Simulation environments often execute rungs with idealized timing that hides the issue. Real hardware, with real scan jitter and I/O update delays, exposes it immediately. Tracing this back requires understanding exactly which scan phase each rung reads from and writes to, which is precisely why the mental model has to come before the code.
I/O Mapping: How Physical Reality Connects to Your Code
The scan cycle behaviors covered above all depend on one underlying mechanism you haven’t seen yet: how physical signals actually reach your code, and how your code’s decisions reach physical devices.
The answer is that they never communicate directly.
The Input Image Table
At the very start of each scan, the PLC reads every physical input channel and copies those states into a dedicated memory region called the input image table. For the entire duration of logic execution, your program reads exclusively from that memory snapshot. It never queries the field device directly.
This matters more than it sounds. If a pushbutton changes state while your logic is running, that change does not exist yet, from your program’s perspective. It will appear in the input image table at the start of the next scan. This is the one-scan delay, and it is not a flaw; it is intentional. It guarantees that every variable your logic reads stays consistent throughout a single scan, preventing mid-scan state corruption.
During commissioning, this is the most common source of false fault assumptions. An input appears to be ignored, a technician assumes a wiring problem, and the actual cause is a signal that toggled and resolved within a single scan window. Understanding the input image table eliminates that diagnostic dead end immediately.
The Output Image Table
Your program does not write directly to physical outputs either. During logic execution, output values are written to a separate memory region called the output image table, which acts as a staging area. Only after logic execution completes does the PLC push the output image table values to the physical output channels.
The direct consequence: setting an output coil in rung 5 does not energize the physical terminal until the end of that scan. If your design assumes the field device responds before the scan completes, that assumption is wrong, and it will produce failures that are difficult to reproduce consistently.
I/O Addressing: Physical Addresses and Symbolic Tags
Every physical I/O channel has a hardware address that maps to its slot, module, and channel position. You can reference that address directly in code, though most industrial PLC programming practice assigns a symbolic tag name to each hardware address instead. Your logic then references the tag, not the raw address.
Memory-mapped I/O addressing is the underlying mechanism that makes this work. The tag is an alias; the PLC resolves it to the correct image table location at compile time. The reason conventions favor explicit tag-to-address mapping is maintainability: when hardware changes, you update the mapping in one place rather than hunting through hundreds of rungs for a raw address.
Safety and Sequencing Implications
PLCs execute safety-critical programs across industrial sectors where failures can cause catastrophic physical harm, including chemical refineries, nuclear facilities, and railway signaling systems. In those contexts, logic that assumes a physical output is live the moment a coil is set is a design defect.
The correct pattern is to use feedback confirmation. After setting an output, read a separate feedback input on the next scan to verify the device actually responded. Never assume the output image table and the physical world are synchronized within the same scan.
The Four IEC 61131-3 PLC Programming Languages Explained

With I/O mapping established, the next layer is language. Once you understand that your program reads a snapshot and writes to a staging area, you need to choose how to express that logic. That is exactly the problem IEC 61131-3 solves.
IEC 61131-3 is the international standard that defines a unified software model for PLC programming. It specifies four primary languages, plus the common elements that support all of them: elementary and user-defined data types, variables with explicit scope rules, Program Organization Units (POUs such as Programs, Function Blocks, and Functions), and configuration structures that map execution to hardware resources. These elements apply across platforms, which means the concepts you learn here transfer when you switch hardware.
Ladder Diagram (LD)
Ladder Diagram is the oldest of the four languages and deliberately resembles relay control schematics. Contacts on the left represent conditions; coils on the right represent outputs. Electricians and technicians can trace the logic visually without opening a programming manual, which makes it the standard choice for discrete on/off control, safety relay replacement, and any logic that maintenance personnel need to verify in the field. Its visual model maps directly to the physical panel wiring it replaced, so the mental translation between drawing and code stays short. LD is not the best fit when logic becomes deeply nested or mathematically complex.
Structured Text (ST)
Structured Text is a high-level, Pascal-like textual language. It handles mathematical calculations, string processing, and complex conditional logic far more cleanly than LD. Engineers from a software background tend to find it immediately readable. The critical warning here is that ST’s sequential appearance is misleading. The entire ST block re-executes every scan, top to bottom, as a single unit. There is no “waiting,” no event loop, and no sequential flow that persists between scans. Writing ST as if it were a Python script that runs once is the most common mistake engineers with a software background make when first doing industrial PLC programming. Scan-cycle awareness matters more in ST than in any other language precisely because the syntax hides the cyclic execution model.
Function Block Diagram (FBD)
Function Block Diagram is a graphical language organized around signal flow rather than relay logic. Data enters function blocks on the left, is processed internally, and exits on the right. Those outputs connect as inputs to the next block downstream. This structure maps cleanly onto how the scan cycle handles data: outputs computed during one scan feed into the next evaluation. FBD is the natural language for continuous control loops, PID blocks, and analog signal processing, where chains of mathematical operations need to be visually traceable from sensor input to final control element.
Sequential Function Chart (SFC)
Sequential Function Chart is the state-machine language of IEC 61131-3. A program written in SFC consists of steps, transitions, and the actions associated with each step. Only the active step executes on a given scan, which means SFC is the most explicitly scan-cycle-aware language in the standard by design. It is the right tool for multi-step sequential processes: batch recipes, machine startup sequences, and any process with distinct operational phases that must execute in a defined order.
Practical Language Selection
Use this as your decision framework:
- LD: discrete safety logic, relay replacement, any logic a non-programmer must read
- ST: calculations, data manipulation, complex conditional branching
- FBD: closed-loop control, PID, analog signal chains
- SFC: any process with named phases or operational states
Most real programs mix languages. A single project might use SFC for the top-level machine sequence, FBD inside each step for PID control, and ST for calculations feeding those blocks. If you want to go deeper on how practitioners approach this in real projects, Engineering For Fun: A Controls Engineer’s Blog by Atsu Bedjean applies exactly this kind of field-grounded thinking to automation concepts.
Common Beginner Mistakes in PLC Programming (And Why They Are All Scan-Cycle Problems)
Knowing which language to use only gets you so far. The mistakes that actually cost engineers hours on the plant floor come from the same root cause every time: a broken mental model of the scan cycle. Here are the five you will almost certainly encounter.
Assuming outputs update mid-scan. If rung 10 sets a bit and rung 11 immediately reads that bit as energized, your logic may work on one platform and silently fail on another. Some platforms resolve intra-scan coil visibility; others do not. Writing logic that depends on this behavior produces code that is fragile and platform-specific. Design each rung to work correctly against the input image snapshot taken at the start of the scan, not against values written by earlier rungs in the same pass.
Ignoring scan time in timer logic. A Boolean latch is not a timer. If you use a latch to approximate a time delay, the actual delay will drift with scan load and fail entirely if the scan lengthens under heavy communication overhead or large data moves. Always use a proper TON (timer on-delay) instruction for any time-based sequence. The TON accumulates elapsed time correctly across scans regardless of how long each individual scan takes.
Misusing retentive versus non-retentive coils. A standard output coil resets to false on every power cycle. A retentive coil, or a SET/LATCH instruction, holds its last state through a power loss. Using the wrong type means your machine may restart in an unexpected state after an e-stop or power interruption. Before writing any coil, ask explicitly: should this output remember its state after power is restored, or should it always start fresh?
Treating Structured Text as sequential script. This is the most common mistake from engineers with a software background. An ST block does not run top to bottom once and exit. The entire block re-evaluates on every scan. Any logic intended to trigger only once, such as an initialization routine or a single-shot action on button press, requires explicit edge detection using a dedicated R_TRIG or F_TRIG function block. Without it, that “one-time” logic fires on every scan for as long as its condition is true.
Over-writing outputs from multiple locations. Driving the same output tag from two separate rungs or program blocks means scan order determines which write wins. The last rung evaluated in the scan sets the final output state. This conflict often goes undetected in commissioning because it only surfaces under specific timing conditions where both logic paths are active simultaneously. Keep each physical output driven from exactly one location. If multiple conditions must control an output, consolidate them into one rung using series or parallel contacts, not separate coils.
Every one of these mistakes disappears once you stop thinking about your code as a script and start thinking about it as logic evaluated continuously against a machine state snapshot. That shift is the foundation the next section builds on.
How the Scan-Cycle Mental Model Makes You a Better Troubleshooter
Those beginner mistakes all share a root cause: the scan cycle was an abstraction, not a working mental model. Once it becomes your default lens, troubleshooting changes completely.
Start Every Fault Investigation at the Scan
When logic fails in the field, the instinct for most beginners is to check wiring first. An engineer with scan-cycle fluency asks a more precise question first: at what point in the scan is this value being evaluated? That single reframe narrows the search space immediately. A wiring fault and a scan-order conflict can look identical at the output, but the fix is completely different. Knowing which phase of the scan to inspect tells you whether to pick up a multimeter or open the program editor.
Scan Time Is a Performance Diagnostic
Your PLC’s programming software reports current scan time, minimum scan time, and maximum scan time. These numbers are not just telemetry; they are diagnostic data. A scan time that has crept above its normal baseline points to one of three causes: a runaway logic loop iterating too many times per scan, a large block data move executing synchronously in the task, or communication overhead from a messaging instruction that is not executing asynchronously. Checking scan time takes ten seconds. It is consistently the fastest way to determine whether a sluggish response is a logic problem or a hardware problem.
Forces Interact with the Image Table, Not the Field
The I/O force feature is the most misunderstood tool in PLC diagnostics. When you force an input tag to TRUE, you are writing to the input image table. The physical field device has not changed state. If the physical device is a stuck sensor sending a FALSE signal, forcing the tag confirms that your downstream logic works correctly, but it tells you nothing about whether the sensor itself is functional. Engineers who forget this distinction draw incorrect conclusions: they clear a fault using a force, assume the sensor is fine, remove the force, and the fault returns. Always document what a force is masking and verify the physical device independently.
A Four-Step Troubleshooting Sequence
Apply these questions in order whenever logic does not behave as expected:
- Is the input image showing the correct state? Use live monitoring to confirm the tag value, not the field wiring, first.
- Is the logic evaluating correctly given that input state? Step through the relevant rungs or ST block in online monitoring mode.
- Is the output image updating? Confirm the output tag is changing in the image table before assuming the physical output is the problem.
- Is the physical output responding to the image? Only after confirming steps one through three does it make sense to check terminal voltage or module status.
This sequence prevents you from jumping to hardware when the fault is in logic, and vice versa.
The Upfront Investment Pays in Commissioning Hours
Engineers who skip foundational scan-cycle study do not avoid the learning curve; they pay for it later in commissioning hours and intermittent faults that take days to reproduce. The scan cycle is not background knowledge you pick up eventually. It is the diagnostic lens through which every PLC fault makes sense. Build the mental model now, and every other skill in industrial PLC programming stacks cleanly on top of it.
Before You Open the Software: What to Carry Into Your First Session
The mental model you’ve built across this guide is your real deliverable. The software is just where you apply it.
Before writing a single rung, ask three questions:
- What scan phase does this logic execute in?
- What is the state of this variable at the start of this scan?
- Does this output need to persist across scans, or should it be driven fresh every scan?
These aren’t warm-up questions. They’re the filter that catches the majority of logic errors before they exist in code. A coil that needs to latch requires different handling than one that should reflect a live input state. Getting that wrong costs commissioning time that compounds fast.
When you first open the software, orient before you create. Find the I/O mapping table and trace at least a few tags from physical address to symbolic name before you touch the logic editor. Locate the scan cycle configuration, which is often in the task or controller properties, and note the configured scan time. Identify which IEC 61131-3 language the existing project uses. Reading someone else’s code in the wrong language frame wastes time and creates misdiagnoses.
Build your documentation strategy before your first tag exists. Decide on a tag naming convention and write it down. A consistent prefix scheme, such as separating inputs, outputs, and internal bits by a clear naming pattern, means you can read logic cold six months later without cross-referencing hardware drawings. Engineers who skip this step spend disproportionate time chasing intermittent faults that well-named, well-documented code would have made obvious in seconds. The habit also pays forward when someone else inherits your project.
For next steps, follow the sequence the mental model suggests. Start with hands-on ladder logic using real discrete I/O, where the scan cycle’s behavior is most visible and the feedback loop is immediate. Add timer and counter function blocks next, since they expose scan-time dependency directly. Then build a small sequential machine in SFC, which will force you to think explicitly about state transitions and output persistence. Each step reinforces the conceptual layer beneath it rather than adding disconnected syntax.
One parallel note: if you’re also building tools or internal utilities alongside your controls work, the same discipline of understanding your execution model before writing code applies. The step-by-step workflow Atsu Bedjean outlines for shipping a working app without a development background follows the same logic: plan the structure first, then build.
The engineers who move fastest in this field aren’t the ones who learned more syntax. They’re the ones who internalized the scan cycle early and let it guide every decision after.
Conclusion
Everything in PLC programming traces back to three foundational ideas: the scan cycle drives all behavior, I/O mapping connects your logic to physical reality, and documentation decisions made early determine how maintainable your system becomes later. Master these before worrying about syntax, and the rest follows naturally.
The engineers who struggle are almost always fighting the execution model without realizing it. The engineers who excel internalized it first and let it answer their questions automatically.
Your call to action is straightforward. Open your first project with a wiring diagram in hand, name every tag before you write a single rung, and build something small enough that the scan cycle’s behavior is visible. Ladder logic with discrete I/O is your starting point. From there, every concept in this post becomes something you feel rather than something you remember.
The mental model is the shortcut. Use it.
Frequently Asked Questions
How fast does a PLC scan cycle typically execute?
A full scan cycle on a typical industrial PLC completes in 1 to 20 milliseconds. This speed directly constrains your design because any event shorter than one scan time can be missed entirely. Time-sensitive sequences, pulse detection, and high-speed counting require dedicated hardware or instructions that operate outside normal scan execution.
What are the three phases of a PLC scan cycle?
Every scan cycle executes three phases in fixed order: (1) Input image table refresh—the PLC reads all physical inputs and stores them in memory, (2) Logic execution—the PLC evaluates all program logic using the frozen input values and writes outputs to the output image table, and (3) Output image table update—the PLC pushes output values to physical hardware. Then the cycle repeats immediately and continuously.
Why do outputs set in one rung sometimes fail to trigger in the next rung on the same scan?
This happens because outputs are not written directly to physical devices during a scan. When you set an output coil in rung 5, that value is written to the output image table, not the physical terminal. The actual device only responds after the entire scan completes and the output image table is pushed to hardware. If rung 8 tries to read that output as a live condition in the same scan, it has not energized yet, creating a logic failure. Always design logic that works against the input image snapshot taken at the scan start, not against values written by earlier rungs.
Which IEC 61131-3 language should I use for a sequential batch process?
Sequential Function Chart (SFC) is the best choice for sequential batch processes. SFC is the state-machine language that organizes logic around distinct steps, transitions, and actions. Only the active step executes on a given scan, making it naturally suited for processes with defined phases like batch recipes, machine startup sequences, and multi-step operational workflows.
What is the key difference between using edge detection (R_TRIG/F_TRIG) and simply checking if a bit is TRUE?
Simply checking if a bit is TRUE will trigger your logic repeatedly on every scan while that bit remains TRUE. If a pushbutton is held down, a TRUE condition fires continuously instead of once. Edge detection instructions like R_TRIG (rising edge) and F_TRIG (falling edge) internally store the previous scan's state and fire their output for exactly one scan on the transition. This gives you the one-shot response needed for actions that should trigger only when a state changes, not continuously while it stays in that state.

Leave a Reply