1. What a PLC is and the scan cycle
A PLC (programmable logic controller) is an industrial computer built to control machines. It receives signals from push buttons, sensors and contacts (the inputs), runs a program and switches contactors, lamps and valves (the outputs).
The PLC works in a continuous loop called the scan cycle:
- Read all inputs and store a "snapshot" of them in memory.
- Run the program from top to bottom, rung by rung, using that snapshot.
- Update all outputs at once with the result.
A scan usually takes 1 to 20 ms. That is why the program seems to run "all at once", but rung order matters: a lower rung sees what the rungs above it have already calculated in the same scan.
2. From relay logic to Ladder
Ladder (contact diagram, IEC 61131-3) imitates a relay control schematic. The name comes from its shape:
- The vertical rails, left and right, act as the supply.
- Each rung is a step: contacts on the left, coil on the right.
- Contacts in series form AND logic; contacts in parallel form OR logic.
- The coil turns on when there is a continuous "current" path from the left rail to it.
| Symbol | Name | Conducts when… |
|---|---|---|
--| |-- | NO contact (normally open) | the variable bit is 1 |
--|/|-- | NC contact (normally closed) | the variable bit is 0 |
--( )-- | Coil | writes 1 to the variable while the rung conducts |
--(S)-- / --(R)-- | SET / RESET coil | turns on and holds / turns off and holds |
3. Inputs, outputs and addresses
Each PLC terminal has an address. The format changes from one manufacturer to another:
| Type | IEC 61131-3 / CODESYS | Siemens S7 | Typical use |
|---|---|---|---|
| Digital input | %IX0.0 | I0.0 | push button, sensor, overload contact |
| Digital output | %QX0.0 | Q0.0 | contactor coil, lamp, valve |
| Internal memory | %MX0.0 | M0.0 | auxiliary bit, interlock |
Always give each address a name (tag), such as B1_START or K1_MOTOR. The program becomes readable and maintenance is much easier.
4. First program: direct-on-line start with seal-in
The classic automation exercise is starting a motor with a momentary button and keeping it running after the button is released. PLC wiring:
- B1 — start button, NO contact, on input
%IX0.0; - B0 — stop button, NC contact, on input
%IX0.1(tagB0_OK); - F1 — NC contact 95-96 of the overload relay, on input
%IX0.2(tagF1_OK); - K1 — contactor coil, on output
%QX0.0.
How the rung works:
- With B0 and F1 at rest, inputs
B0_OKandF1_OKare 1, and their NO contacts conduct. - Pressing B1 makes the rung conduct and K1 turns on.
- The K1 contact in parallel with B1 keeps the rung conducting after B1 is released. This is the seal-in (latch).
- Pressing B0, or the overload tripping, takes the input to 0, the rung opens and K1 turns off.
5. The NC stop button trap
In the relay schematic the stop button is NC. The temptation is to draw an NC contact in Ladder too. With the NC button wired to the input, this goes wrong:
- Button at rest → physical contact closed → input = 1 → the Ladder NC contact opens. The motor never starts.
The rule of thumb: a program contact must conduct when the machine is in a condition to run. An NC stop button and an NC overload contact go into Ladder as an NO contact testing the "OK" input.
6. TON, TOF and TP timers
IEC 61131-3 timers have an input IN, a preset time PT and an output Q:
| Block | Name | Behaviour | Typical use |
|---|---|---|---|
| TON | On-delay | Q turns on when IN has been on for PT | star → delta changeover, sequential start |
| TOF | Off-delay | Q turns on with IN and only turns off PT after IN turns off | ventilation after stopping, post-lubrication |
| TP | Pulse | Q produces a pulse of length PT on the rising edge of IN | alarm pulse, fixed-length command |
In a star-delta start, for example, a 5 to 10 s TON started with the star contactor drops the star and enables the delta. An NC contact of each contactor in the other one (interlock) prevents both from closing at the same time.
7. Counters, SET/RESET and edges
- CTU / CTD — count pulses up or down. The output turns on when the count reaches the preset value (PV). Example: stop the conveyor every 12 parts.
- SET / RESET — the SET coil turns on and holds, the RESET coil turns off. It replaces the seal-in but needs care: if both conditions are true in the same scan, the one lower in the program wins.
- Rising (P) and falling (N) edge — the contact conducts for a single scan when the signal changes. Essential for counters and for "press and release" commands.
8. From the electrical schematic to Ladder
If you can already read a control schematic, you are halfway there. The translation follows a few steps:
- Identify each branch of the control circuit: what lies between the phase and each contactor coil.
- Each push button, sensor or overload contact becomes a PLC input.
- Each contactor coil becomes an output; its auxiliary contacts become contacts of that output in the program.
- Contacts in series stay in series; parallel branches stay in parallel.
- Review the field NC contacts as described in section 5.
In the CamposLH Electrical Schematic Editor you can draw the control circuit, or open a CADe SIMU file, and send it to PLC Studio with the ⇄ Send to PLC Studio button. PLC Studio analyses the paths, generates Ladder and FBD and shows warnings about what needs checking.
9. Safety: what the PLC must not do alone
- Keep the electrical interlock between reversing and star-delta contactors, in addition to the interlock in the program.
- Test the program in simulation before powering the machine, and check every input and output on the panel (I/O test).
- Document changes: date, reason and who made them.
10. Next steps
The best way to learn Ladder is to practise. Build the direct-on-line start, then reversing with interlock and finally star-delta with a timer. Simulate each case by pressing the virtual buttons and watch the rung conduct. When you feel confident, move the program to the manufacturer's tool (TIA Portal, CODESYS, GX Works, ISPSoft…) and run the I/O test on the real panel.