DriveLab
Account

What is a PLC?

Definition, the parts of a PLC, the scan cycle and process images, why it replaced relay panels, and the five IEC 61131-3 languages. Start here.

25 min

Show me

A programmable logic controller (PLC, in French automate programmable industriel, API) is an industrial computer that reads sensors and switches, runs a control program over and over, and drives actuators: contactors, valves, lamps, drives. IEC 61131-1 defines it as a digitally operating electronic system designed for industrial environments, which uses a programmable memory to implement functions such as logic, sequencing, timing, counting and arithmetic to control machines and processes.

What makes it different from a PC is the environment and the promise: 24 V inputs and outputs that survive electrical noise, a program that restarts on its own after a power cut, a scan that repeats every few milliseconds for years, and modules that a technician can replace without a computer.

From relay panels to PLCs

Before 1970 machine logic was a cabinet of relays, timers and wires, like the starters of Chapter 2. Changing the sequence meant rewiring. The first PLCs (Modicon 084, 1969, for General Motors) replaced the wiring with a program but kept the drawing electricians knew: the ladder diagram. That is why a PLC program still looks like a relay schematic.

The parts of a PLC

  • CPU: the processor and memory that run the program. On the PLC-200 trainer: a Siemens S7-200 CPU 224.
  • Digital inputs: 24 V DC signals from switches and sensors, read as bits (the CPU 224 has 14: I0.0–I0.7, I1.0–I1.5).
  • Digital outputs: transistors or relays driving loads (10 on the CPU 224: Q0.0–Q1.1; the DC/DC/DC version has transistor outputs).
  • Power supply, communication port (port 0, PPI protocol) and, on larger systems, analogue and expansion modules.
  • Programming device: a PC with STEP 7-Micro/WIN, connected through the USB/PPI cable.

The scan cycle

A PLC does not react to a button the moment it is pressed. It works in scans, repeated as fast as it can (a few milliseconds for a small program):

  1. Read the inputs into the process-image input (the I area).
  2. Execute the program: network 1, 2, 3… from top to bottom, using and changing images and memory.
  3. Communicate and self-test: answer Micro/WIN, update the status chart, check itself.
  4. Write the outputs: copy the process-image output (the Q area) to the terminals, all at once.
The scan cycle
  1. Read inputs. The CPU copies every input terminal into the process-image input (I). The program sees this snapshot, not the live terminals.
  2. Execute the program. Networks 1, 2, 3… from top to bottom, each from left to right, working on the images.
  3. Communication and self-test. Serve Micro/WIN, the status chart, and check the CPU.
  4. Write outputs. The process-image output (Q) is copied to the output terminals all at once.
push button (terminal) input image I0.0 lamp Q0.0
presses seen
0
presses missed
0

Make the press shorter than the scan time and press a few times: some presses fall between two input reads and the program never sees them. That is why fast signals (encoders) go to high-speed counters, not to ordinary inputs.

Two consequences you will meet in every TP:

  • An input shorter than one scan can be missed entirely. Fast pulses (the encoder of TP 3 and TP 4) go to high-speed counters, which count in hardware.
  • Within one scan, a network sees what the networks above it wrote, but not what the networks below will write. Order matters.

Predict first

A program has 200 networks and a scan time of 8 ms. A limit switch closes for 3 ms as a cam passes. Will the program see it?

Try it: your first program

This is a real ladder rung running on a simulated CPU 224: a switch on I0.0 lights a lamp on Q0.0. Flip the I0.0 lever on the panel. Then pause the time and use One scan to step through scans. Change the switch while paused: the lamp waits for the next scan.

Ladder editor on a virtual PLC-200

Drag an instruction onto the rung (or click it, then click a place). Drop below a contact to put it in parallel. Click an element to edit its address; Delete removes it.

Network 1
SWITCHI0.0
LAMPQ0.0
SIMATIC S7-200 · CPU 224SFRUNSTOP
I0.0SWITCH
Q0.0LAMP0
Timet = 0.00 s · 0 scans

No errors: the program compiles.

The five IEC 61131-3 languages

LanguageLooks likeOn the S7-200 (Micro/WIN)
LD / LAD, ladder diagrama relay schematicyes: the booklet's main language
FBD, function block diagramlogic gates and boxesyes
IL / STL, instruction listassembly-like textyes: statement list, what Micro/WIN exports
SFC, sequential function charta GRAFCETnot as a language: you translate the GRAFCET into SCR steps
ST, structured textPascal-like codeno (it is on newer PLCs such as the S7-1200)

Micro/WIN converts freely between LAD, FBD and STL for the same program (View menu). This course uses LAD to write, STL to understand what the CPU does, and GRAFCET (IEC 60848) to design sequences before writing any network.

ExplorerGo deeper: derivations and open questions

Deterministic by design. A PLC's scan has a bounded duration and a watchdog: if one scan takes longer than 500 ms on the S7-200, the CPU goes to STOP. That is why PLC programs do not wait inside a loop for an event; they test the condition once per scan and move on. Every sequence in this course is written that way.